Style changes to refactor commit.
[blender.git] / source / blender / editors / sculpt_paint / paint_cursor.c
index 05fe23eb223a84555fb9d047ae0cf4e74118b065..8f4454eb2da828f6bb7a7d4282d8d93957be6c7d 100644 (file)
@@ -73,7 +73,6 @@ typedef struct TexSnapshot {
        GLuint overlay_texture;
        int winx;
        int winy;
-       bool init;
        int old_size;
        float old_zoom;
        bool old_col;
@@ -90,15 +89,18 @@ static TexSnapshot secondary_snap  = {0};
 static CursorSnapshot cursor_snap  = {0};
 
 /* delete overlay cursor textures to preserve memory and invalidate all overlay flags */
-void paint_cursor_delete_textures()
+void paint_cursor_delete_textures(void)
 {
-       glDeleteTextures(1, &primary_snap.overlay_texture);
-       glDeleteTextures(1, &secondary_snap.overlay_texture);
-       glDeleteTextures(1, &cursor_snap.overlay_texture);
+       if (primary_snap.overlay_texture)
+               glDeleteTextures(1, &primary_snap.overlay_texture);
+       if (secondary_snap.overlay_texture)
+               glDeleteTextures(1, &secondary_snap.overlay_texture);
+       if (cursor_snap.overlay_texture)
+               glDeleteTextures(1, &cursor_snap.overlay_texture);
 
        memset(&primary_snap, 0, sizeof(TexSnapshot));
        memset(&secondary_snap, 0, sizeof(TexSnapshot));
-       memset(&cursor_snap, 0, sizeof(TexSnapshot));
+       memset(&cursor_snap, 0, sizeof(CursorSnapshot));
 
        BKE_paint_invalidate_overlay_all();
 }
@@ -417,7 +419,6 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom)
        if (refresh) {
                if (!init) {
                        glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, size, size, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
-                       init = 1;
                }
                else {
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
@@ -568,7 +569,7 @@ static void paint_draw_tex_overlay(UnifiedPaintSettings *ups, Brush *brush,
                        glTranslatef(-0.5f, -0.5f, 0);
 
                        /* scale based on tablet pressure */
-                       if (primary && ups->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush)) {
+                       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);
                                glTranslatef(-0.5f, -0.5f, 0);
@@ -693,7 +694,7 @@ static void paint_draw_cursor_overlay(UnifiedPaintSettings *ups, Brush *brush,
                }
 
                /* scale based on tablet pressure */
-               if (ups->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush)) {
+               if (ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush)) {
                        do_pop = true;
                        glPushMatrix();
                        glLoadIdentity();
@@ -787,7 +788,7 @@ static void paint_cursor_on_hit(UnifiedPaintSettings *ups, Brush *brush, ViewCon
                                                                    projected_radius);
 
                /* scale 3D brush radius by pressure */
-               if (ups->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush))
+               if (ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush))
                        unprojected_radius *= ups->pressure_value;
 
                /* set cached value in either Brush or UnifiedPaintSettings */
@@ -827,11 +828,10 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
        outline_col = brush->add_col;
        final_radius = BKE_brush_size_get(scene, brush) * zoomx;
 
-       if (brush->flag & BRUSH_RAKE)
-               /* here, translation contains the mouse coordinates. */
+       /* don't calculate rake angles while a stroke is active because the rake variables are global and
+        * we may get interference with the stroke itself. For line strokes, such interference is visible */
+       if (!ups->stroke_active && (brush->flag & BRUSH_RAKE))
                paint_calculate_rake_rotation(ups, translation);
-       else if (!(brush->flag & BRUSH_ANCHORED))
-               ups->brush_rotation = 0.0;
 
        /* draw overlay */
        paint_draw_alpha_overlay(ups, brush, &vc, x, y, zoomx, mode);
@@ -882,7 +882,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
        glTranslatef(translation[0], translation[1], 0);
 
        /* draw an inner brush */
-       if (ups->draw_pressure && BKE_brush_use_size_pressure(scene, 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);
                /* outer at half alpha */