* Cleanup: collapse unneeded paint 2d function to the caller. Also, new
authorAntony Riakiotakis <kalast@gmail.com>
Sun, 10 Mar 2013 02:30:53 +0000 (02:30 +0000)
committerAntony Riakiotakis <kalast@gmail.com>
Sun, 10 Mar 2013 02:30:53 +0000 (02:30 +0000)
code now does not use painter_2d_paint at all. Made sure the approprate
variables of painter_2d are still initialized (They may be refactored to
become part of the ImagePaintState struct)

* Enable pressure control for new code path in texture paint. This revealed a bug, also present in blender 2.66: Size pressure is broken.
This was pretty interesting for me because it indicates that we could support
dynamic size in texture paint: (See anchored brushes)

source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_image_2d.c
source/blender/editors/sculpt_paint/paint_image_proj.c
source/blender/editors/sculpt_paint/paint_intern.h

index 18a464f..6b3fe9a 100644 (file)
@@ -5058,8 +5058,7 @@ void paint_brush_init_tex(Brush *brush)
                MTex *mtex = &brush->mtex;
                if (mtex->tex && mtex->tex->nodetree)
                        ntreeTexBeginExecTree(mtex->tex->nodetree, 1);  /* has internal flag to detect it only does it once */
-       }
-       
+       }       
 }
 
 static int texture_paint_init(bContext *C, wmOperator *op)
index 0c1346d..5447ad0 100644 (file)
@@ -179,10 +179,6 @@ static void brush_pressure_apply(BrushPainter *painter, Brush *brush, float pres
                BKE_brush_alpha_set(painter->scene, brush, max_ff(0.0f, painter->startalpha * pressure));
        if (BKE_brush_use_size_pressure(painter->scene, brush))
                BKE_brush_size_set(painter->scene, brush, max_ff(1.0f, painter->startsize * pressure));
-       if (brush->flag & BRUSH_JITTER_PRESSURE)
-               brush->jitter = max_ff(0.0f, painter->startjitter * pressure);
-       if (brush->flag & BRUSH_SPACING_PRESSURE)
-               brush->spacing = max_ff(1.0f, painter->startspacing * (1.5f - pressure));
 }
 
 
@@ -892,51 +888,57 @@ static void paint_2d_canvas_free(ImagePaintState *s)
        BKE_image_release_ibuf(s->brush->clone.image, s->clonecanvas, NULL);
 }
 
-static int paint_2d_sub_stroke(ImagePaintState *s, BrushPainter *painter, Image *image, float *uv, int update, float pressure)
+int paint_2d_stroke(void *ps, const int prev_mval[2], const int mval[2], int eraser)
 {
-       ImBuf *ibuf = BKE_image_acquire_ibuf(image, s->sima ? &s->sima->iuser : NULL, NULL);
-       float pos[2];
-       int is_data;
+       float newuv[2], olduv[2];
+       int redraw = 0;
+       ImagePaintState *s = ps;
+       BrushPainter *painter = s->painter;
+       ImBuf *ibuf = BKE_image_acquire_ibuf(s->image, s->sima ? &s->sima->iuser : NULL, NULL);
+       int     is_data = ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA;
 
        if (!ibuf)
                return 0;
 
-       is_data = ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA;
+       s->blend = s->brush->blend;
+       if (eraser)
+               s->blend = IMB_BLEND_ERASE_ALPHA;
 
-       pos[0] = uv[0] * ibuf->x;
-       pos[1] = uv[1] * ibuf->y;
+       UI_view2d_region_to_view(s->v2d, mval[0], mval[1], &newuv[0], &newuv[1]);
+       UI_view2d_region_to_view(s->v2d, prev_mval[0], prev_mval[1], &olduv[0], &olduv[1]);
 
-       brush_painter_2d_require_imbuf(painter, ((ibuf->rect_float) ? 1 : 0), 0, 0);
+       newuv[0] *= ibuf->x;
+       newuv[1] *= ibuf->y;
 
+       olduv[0] *= ibuf->x;
+       olduv[1] *= ibuf->y;
+
+       if (painter->firsttouch) {
+               /* paint exactly once on first touch */
+               painter->startpaintpos[0] = newuv[0];
+               painter->startpaintpos[1] = newuv[1];
+
+               painter->firsttouch = 0;
+               copy_v2_v2(painter->lastpaintpos, newuv);
+       } else {
+               copy_v2_v2(painter->lastpaintpos, olduv);
+       }
        /* OCIO_TODO: float buffers are now always linear, so always use color correction
         *            this should probably be changed when texture painting color space is supported
         */
-       if (brush_painter_2d_paint(painter, paint_2d_op, pos, 0, pressure, s, is_data == FALSE)) {
-               if (update)
-                       imapaint_image_update(s->sima, image, ibuf, false);
-               BKE_image_release_ibuf(image, ibuf, NULL);
-               return 1;
+       brush_painter_2d_require_imbuf(painter, ((ibuf->rect_float) ? 1 : 0), 0, 0);
+
+       if (painter->cache.enabled)
+               brush_painter_2d_refresh_cache(painter, newuv, is_data == FALSE);
+
+       if (paint_2d_op(s, painter->cache.ibuf, olduv, newuv)) {
+               imapaint_image_update(s->sima, s->image, ibuf, false);
+               BKE_image_release_ibuf(s->image, ibuf, NULL);
+               redraw |= 1;
        }
        else {
-               BKE_image_release_ibuf(image, ibuf, NULL);
-               return 0;
+               BKE_image_release_ibuf(s->image, ibuf, NULL);
        }
-}
-
-int paint_2d_stroke(void *ps, const int mval[2], float pressure, int eraser)
-{
-       float newuv[2];
-       int redraw = 0;
-       ImagePaintState *s = ps;
-       BrushPainter *painter = s->painter;
-
-       s->blend = s->brush->blend;
-       if (eraser)
-               s->blend = IMB_BLEND_ERASE_ALPHA;
-
-       UI_view2d_region_to_view(s->v2d, mval[0], mval[1], &newuv[0], &newuv[1]);
-       redraw |= paint_2d_sub_stroke(s, painter, s->image, newuv,
-                                                   1, pressure);
 
        if (redraw)
                imapaint_clear_partial_redraw();
index c0f42ed..1f80ec5 100644 (file)
@@ -4463,6 +4463,13 @@ static PaintOperation * texture_paint_init(bContext *C, wmOperator *op)
 static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr)
 {
        PaintOperation *pop = paint_stroke_mode_data(stroke);
+       Scene *scene = CTX_data_scene(C);
+       Brush *brush = paint_brush(&scene->toolsettings->imapaint.paint);
+
+       /* initial brush values. Maybe it should be considered moving these to stroke system */
+       float startsize = BKE_brush_size_get(scene, brush);
+       float startalpha = BKE_brush_alpha_get(scene, brush);
+
        float mousef[2];
        float pressure;
        int mouse[2], redraw, eraser;
@@ -4473,6 +4480,11 @@ static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, Po
        pressure = RNA_float_get(itemptr, "pressure");
        eraser = RNA_boolean_get(itemptr, "pen_flip");
 
+       if (BKE_brush_use_alpha_pressure(scene, brush))
+               BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure));
+       if (BKE_brush_use_size_pressure(scene, brush))
+               BKE_brush_size_set(scene, brush, max_ff(1.0f, startsize * pressure));
+
        if (pop->mode == PAINT_MODE_3D_PROJECT) {
                if (pop->first)
                        project_paint_begin_clone(&pop->ps, mouse);
@@ -4483,11 +4495,16 @@ static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, Po
 
        }
        else {
-               redraw = paint_2d_stroke(pop->custom_paint, mouse, pressure, eraser);
+               redraw = paint_2d_stroke(pop->custom_paint, pop->prevmouse, mouse, eraser);
                pop->prevmouse[0] = mouse[0];
                pop->prevmouse[1] = mouse[1];
        }
 
+       /* restore brush values */
+       BKE_brush_alpha_set(scene, brush, startalpha);
+       BKE_brush_size_set(scene, brush, startsize);
+
+
        if (redraw)
                paint_redraw(C, pop, 0);
 
index 91ef6b8..cb3fda5 100644 (file)
@@ -127,7 +127,7 @@ void imapaint_dirty_region(struct Image *ima, struct ImBuf *ibuf, int x, int y,
 void *paint_2d_new_stroke(struct bContext *, struct wmOperator *);
 void paint_2d_redraw(const bContext *C, void *ps, int final);
 void paint_2d_stroke_done(void *ps);
-int paint_2d_stroke(void *ps, const int mval[2], float pressure, int eraser);
+int paint_2d_stroke(void *ps, const int prev_mval[2], const int mval[2], int eraser);
 void paint_brush_init_tex(struct Brush *brush);
 void paint_brush_exit_tex(struct Brush *brush);