Cleanup:
authorAntony Riakiotakis <kalast@gmail.com>
Sun, 13 Apr 2014 15:14:45 +0000 (18:14 +0300)
committerAntony Riakiotakis <kalast@gmail.com>
Sun, 13 Apr 2014 15:14:45 +0000 (18:14 +0300)
Naming:

Change pressure to size_pressure, it notes correctly that this value is
updated and expected to be used for size updating only.
Change name of cursor function and since it is used for uv sculpting
only now move to the relevant file. Also cleanup unneeded functionality
from function.

Stroke:

Separate updating of stroke variables to invariants (updated when
stroke->init = false) and variants.

source/blender/editors/sculpt_paint/paint_cursor.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_intern.h
source/blender/editors/sculpt_paint/paint_stroke.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/sculpt_paint/sculpt_uv.c
source/blender/makesdna/DNA_scene_types.h

index 97c2a5bdee639fae3127970af47198e42c3b54c3..97c1a994629f0d5fcb2092d98ec9ec71f79b69ed 100644 (file)
@@ -597,7 +597,7 @@ static void paint_draw_tex_overlay(UnifiedPaintSettings *ups, Brush *brush,
                        /* scale based on tablet pressure */
                        if (primary && ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush)) {
                                glTranslatef(0.5f, 0.5f, 0);
-                               glScalef(1.0f / ups->pressure_value, 1.0f / ups->pressure_value, 1);
+                               glScalef(1.0f / ups->size_pressure_value, 1.0f / ups->size_pressure_value, 1);
                                glTranslatef(-0.5f, -0.5f, 0);
                        }
 
@@ -725,7 +725,7 @@ static void paint_draw_cursor_overlay(UnifiedPaintSettings *ups, Brush *brush,
                        glPushMatrix();
                        glLoadIdentity();
                        glTranslatef(center[0], center[1], 0);
-                       glScalef(ups->pressure_value, ups->pressure_value, 1);
+                       glScalef(ups->size_pressure_value, ups->size_pressure_value, 1);
                        glTranslatef(-center[0], -center[1], 0);
                }
 
@@ -815,7 +815,7 @@ static void paint_cursor_on_hit(UnifiedPaintSettings *ups, Brush *brush, ViewCon
 
                /* scale 3D brush radius by pressure */
                if (ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush))
-                       unprojected_radius *= ups->pressure_value;
+                       unprojected_radius *= ups->size_pressure_value;
 
                /* set cached value in either Brush or UnifiedPaintSettings */
                BKE_brush_unprojected_radius_set(vc->scene, brush, unprojected_radius);
@@ -910,7 +910,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
        /* draw an inner brush */
        if (ups->stroke_active && BKE_brush_use_size_pressure(scene, brush)) {
                /* inner at full alpha */
-               glutil_draw_lined_arc(0.0, M_PI * 2.0, final_radius * ups->pressure_value, 40);
+               glutil_draw_lined_arc(0.0, M_PI * 2.0, final_radius * ups->size_pressure_value, 40);
                /* outer at half alpha */
                glColor4f(outline_col[0], outline_col[1], outline_col[2], outline_alpha * 0.5f);
        }
index 2f4caeeef1b1959ad66aa8221acd16bd07cf3081..6961064522808df2fff8111506c3c52d6af60ac5 100644 (file)
@@ -718,71 +718,6 @@ int get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
 
 /************************ cursor drawing *******************************/
 
-void brush_drawcursor_texpaint_uvsculpt(bContext *C, int x, int y, void *UNUSED(customdata))
-{
-#define PX_SIZE_FADE_MAX 12.0f
-#define PX_SIZE_FADE_MIN 4.0f
-
-       Scene *scene = CTX_data_scene(C);
-       //Brush *brush = image_paint_brush(C);
-       Paint *paint = BKE_paint_get_active_from_context(C);
-       Brush *brush = BKE_paint_brush(paint);
-
-       if (paint && brush && paint->flags & PAINT_SHOW_BRUSH) {
-               float zoomx, zoomy;
-               const float size = (float)BKE_brush_size_get(scene, brush);
-               short use_zoom;
-               float pixel_size;
-               float alpha = 0.5f;
-
-               use_zoom = get_imapaint_zoom(C, &zoomx, &zoomy);
-
-               if (use_zoom) {
-                       pixel_size = size * max_ff(zoomx, zoomy);
-               }
-               else {
-                       pixel_size = size;
-               }
-
-               /* fade out the brush (cheap trick to work around brush interfering with sampling [#])*/
-               if (pixel_size < PX_SIZE_FADE_MIN) {
-                       return;
-               }
-               else if (pixel_size < PX_SIZE_FADE_MAX) {
-                       alpha *= (pixel_size - PX_SIZE_FADE_MIN) / (PX_SIZE_FADE_MAX - PX_SIZE_FADE_MIN);
-               }
-
-               glPushMatrix();
-
-               glTranslatef((float)x, (float)y, 0.0f);
-
-               /* No need to scale for uv sculpting, on the contrary it might be useful to keep un-scaled */
-               if (use_zoom)
-                       glScalef(zoomx, zoomy, 1.0f);
-
-               glColor4f(brush->add_col[0], brush->add_col[1], brush->add_col[2], alpha);
-               glEnable(GL_LINE_SMOOTH);
-               glEnable(GL_BLEND);
-               {
-                       UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
-                       /* hrmf, duplicate paint_draw_cursor logic here */
-                       if (ups->stroke_active && BKE_brush_use_size_pressure(scene, brush)) {
-                               /* inner at full alpha */
-                               glutil_draw_lined_arc(0, (float)(M_PI * 2.0), size * ups->pressure_value, 40);
-                               /* outer at half alpha */
-                               glColor4f(brush->add_col[0], brush->add_col[1], brush->add_col[2], alpha * 0.5f);
-                       }
-               }
-               glutil_draw_lined_arc(0, (float)(M_PI * 2.0), size, 40);
-               glDisable(GL_BLEND);
-               glDisable(GL_LINE_SMOOTH);
-
-               glPopMatrix();
-       }
-#undef PX_SIZE_FADE_MAX
-#undef PX_SIZE_FADE_MIN
-}
-
 static void toggle_paint_cursor(bContext *C, int enable)
 {
        wmWindowManager *wm = CTX_wm_manager(C);
index 0c3cdc7a205355704bf82f655e6177c76fe10179..bdb1c88c0ce6bf14e5209d35357b005554ceacff 100644 (file)
@@ -201,7 +201,6 @@ void paint_calc_redraw_planes(float planes[4][4],
 float paint_calc_object_space_radius(struct ViewContext *vc, const float center[3], float pixel_radius);
 float paint_get_tex_pixel(struct MTex *mtex, float u, float v, struct ImagePool *pool, int thread);
 void paint_get_tex_pixel_col(struct MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread, bool convert, struct ImBuf *ibuf);
-void brush_drawcursor_texpaint_uvsculpt(struct bContext *C, int x, int y, void *customdata);
 
 void paint_sample_color(const struct bContext *C, struct ARegion *ar, int x, int y);
 void BRUSH_OT_curve_preset(struct wmOperatorType *ot);
index 15f21cc44c8e75463d354248b7a3bb681bba3189..a8f3a6cbc72aa268d233d45b0b934a3e35ab0500 100644 (file)
@@ -98,7 +98,7 @@ typedef struct PaintStroke {
        bool brush_init;
        float initial_mouse[2];
        /* cached_pressure stores initial pressure for size pressure influence mainly */
-       float cached_pressure;
+       float cached_size_pressure;
        /* last pressure will store last pressure value for use in interpolation for space strokes */
        float last_pressure;
 
@@ -166,22 +166,30 @@ static void paint_brush_update(bContext *C, Brush *brush, PaintMode mode,
         *      brush coord/pressure/etc.
         *      It's more an events design issue, which doesn't split coordinate/pressure/angle
         *      changing events. We should avoid this after events system re-design */
-       if (paint_supports_dynamic_size(brush, mode) || !stroke->brush_init) {
+       if(!stroke->brush_init) {
                copy_v2_v2(stroke->initial_mouse, mouse);
+               copy_v2_v2(ups->last_rake, mouse);
                copy_v2_v2(ups->tex_mouse, mouse);
                copy_v2_v2(ups->mask_tex_mouse, mouse);
-               stroke->cached_pressure = pressure;
+               stroke->cached_size_pressure = pressure;
+               stroke->brush_init = true;
+       }
+
+       if (paint_supports_dynamic_size(brush, mode)) {
+               copy_v2_v2(ups->tex_mouse, mouse);
+               copy_v2_v2(ups->mask_tex_mouse, mouse);
+               stroke->cached_size_pressure = pressure;
        }
 
        /* Truly temporary data that isn't stored in properties */
 
        ups->stroke_active = true;
-       ups->pressure_value = stroke->cached_pressure;
+       ups->size_pressure_value = stroke->cached_size_pressure;
 
        ups->pixel_radius = BKE_brush_size_get(scene, brush);
 
        if (BKE_brush_use_size_pressure(scene, brush) && paint_supports_dynamic_size(brush, mode)) {
-               ups->pixel_radius *= stroke->cached_pressure;
+               ups->pixel_radius *= stroke->cached_size_pressure;
        }
 
        if (paint_supports_dynamic_tex_coords(brush, mode)) {
@@ -251,13 +259,8 @@ static void paint_brush_update(bContext *C, Brush *brush, PaintMode mode,
                ups->draw_anchored = true;
        }
        else if (brush->flag & BRUSH_RAKE) {
-               if (!stroke->brush_init)
-                       copy_v2_v2(ups->last_rake, mouse);
-               else
-                       paint_calculate_rake_rotation(ups, mouse);
+               paint_calculate_rake_rotation(ups, mouse);
        }
-
-       stroke->brush_init = true;
 }
 
 
index d90f9a80b37356a97bf64eb1db96b7a0e389d4f9..1d127cd5f4e614bc1b094e80da8f5b11e48441f5 100644 (file)
@@ -2496,11 +2496,6 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
 
        swap_m4m4(vc->rv3d->persmat, mat);
 
-       {
-               UnifiedPaintSettings *ups = &ts->unified_paint_settings;
-               ups->pressure_value = pressure;
-       }
-
        DAG_id_tag_update(ob->data, 0);
        ED_region_tag_redraw(vc->ar);
 }
@@ -3017,11 +3012,6 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
                do_shared_vertexcol(me, vpd->mlooptag, vpd->mfacetag, do_tessface);
        }
 
-       {
-               UnifiedPaintSettings *ups = &ts->unified_paint_settings;
-               ups->pressure_value = pressure;
-       }
-
        ED_region_tag_redraw(vc->ar);
 
        if (vpd->use_fast_update == false) {
index da2b62bce8bf3864d71cfcd3d7aadfede4e3205f..c064612a55192666cc1e8c0ef2dc75ec07df69dc 100644 (file)
@@ -68,6 +68,9 @@
 #include "paint_intern.h"
 #include "uvedit_intern.h"
 
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
 #include "UI_view2d.h"
 
 #define MARK_BOUNDARY   1
@@ -185,6 +188,45 @@ static int uv_sculpt_brush_poll(bContext *C)
        return 0;
 }
 
+static void brush_drawcursor_uvsculpt(bContext *C, int x, int y, void *UNUSED(customdata))
+{
+#define PX_SIZE_FADE_MAX 12.0f
+#define PX_SIZE_FADE_MIN 4.0f
+
+       Scene *scene = CTX_data_scene(C);
+       //Brush *brush = image_paint_brush(C);
+       Paint *paint = BKE_paint_get_active_from_context(C);
+       Brush *brush = BKE_paint_brush(paint);
+
+       if (paint && brush && paint->flags & PAINT_SHOW_BRUSH) {
+               const float size = (float)BKE_brush_size_get(scene, brush);
+               float alpha = 0.5f;
+
+               /* fade out the brush (cheap trick to work around brush interfering with sampling [#])*/
+               if (size < PX_SIZE_FADE_MIN) {
+                       return;
+               }
+               else if (size < PX_SIZE_FADE_MAX) {
+                       alpha *= (size - PX_SIZE_FADE_MIN) / (PX_SIZE_FADE_MAX - PX_SIZE_FADE_MIN);
+               }
+
+               glPushMatrix();
+
+               glTranslatef((float)x, (float)y, 0.0f);
+
+               glColor4f(brush->add_col[0], brush->add_col[1], brush->add_col[2], alpha);
+               glEnable(GL_LINE_SMOOTH);
+               glEnable(GL_BLEND);
+               glutil_draw_lined_arc(0, (float)(M_PI * 2.0), size, 40);
+               glDisable(GL_BLEND);
+               glDisable(GL_LINE_SMOOTH);
+
+               glPopMatrix();
+       }
+#undef PX_SIZE_FADE_MAX
+#undef PX_SIZE_FADE_MIN
+}
+
 
 void ED_space_image_uv_sculpt_update(wmWindowManager *wm, ToolSettings *settings)
 {
@@ -201,7 +243,7 @@ void ED_space_image_uv_sculpt_update(wmWindowManager *wm, ToolSettings *settings
                BKE_paint_init(&settings->uvsculpt->paint, PAINT_CURSOR_SCULPT);
 
                WM_paint_cursor_activate(wm, uv_sculpt_brush_poll,
-                                        brush_drawcursor_texpaint_uvsculpt, NULL);
+                                        brush_drawcursor_uvsculpt, NULL);
        }
        else {
                if (settings->uvsculpt)
index b92aafd610bc0f2e1f49e5a876e8b066d4d6fbc0..aada838fce5cefb1b69aa32c4dd507e1b91ac575 100644 (file)
@@ -941,7 +941,7 @@ typedef struct UnifiedPaintSettings {
        int stroke_active;
 
        /* drawing pressure */
-       float pressure_value;
+       float size_pressure_value;
 
        /* position of mouse, used to sample the texture */
        float tex_mouse[2];