Commit: f7c57c5cd6ac335342411f2f6488427816a9d8ab
Author: Antonio Vazquez
Date:   Fri Jun 23 09:22:03 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBf7c57c5cd6ac335342411f2f6488427816a9d8ab

Fix problem with sculpt cursor

The cursor was not set when switch between object in different modes.

===================================================================

M       source/blender/editors/gpencil/gpencil_brush.c
M       source/blender/editors/gpencil/gpencil_intern.h
M       source/blender/editors/gpencil/gpencil_utils.c
M       source/blender/editors/include/ED_gpencil.h
M       source/blender/editors/space_view3d/view3d_select.c

===================================================================

diff --git a/source/blender/editors/gpencil/gpencil_brush.c 
b/source/blender/editors/gpencil/gpencil_brush.c
index 146c6eafca6..3fdfd4a65c5 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -78,6 +78,7 @@
 #include "GPU_immediate.h"
 #include "GPU_immediate_util.h"
 
+#include "ED_gpencil.h"
 #include "gpencil_intern.h"
 
 /* ************************************************ */
@@ -1014,57 +1015,6 @@ static bool gpsculpt_brush_apply_clone(bContext *C, 
tGP_BrushEditData *gso)
 }
 
 /* ************************************************ */
-/* Cursor drawing */
-
-/* Helper callback for drawing the cursor itself */
-static void gp_brush_drawcursor(bContext *C, int x, int y, void 
*UNUSED(customdata))
-{
-       GP_EditBrush_Data *brush = gpsculpt_get_brush(CTX_data_scene(C));
-
-       if (brush) {
-               Gwn_VertFormat *format = immVertexFormat();
-               unsigned int pos = GWN_vertformat_attr_add(format, "pos", 
GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
-               immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-
-               glEnable(GL_LINE_SMOOTH);
-               glEnable(GL_BLEND);
-
-               /* Inner Ring: Light color for action of the brush */
-               /* TODO: toggle between add and remove? */
-               immUniformColor4ub(255, 255, 255, 200);
-               imm_draw_circle_wire(pos, x, y, brush->size, 40);
-
-               /* Outer Ring: Dark color for contrast on light backgrounds 
(e.g. gray on white) */
-               immUniformColor3ub(30, 30, 30);
-               imm_draw_circle_wire(pos, x, y, brush->size + 1, 40);
-
-               immUnbindProgram();
-
-               glDisable(GL_BLEND);
-               glDisable(GL_LINE_SMOOTH);
-       }
-}
-
-/* Turn brush cursor in on/off */
-void ED_gpencil_toggle_brush_cursor(bContext *C, bool enable)
-{
-       GP_BrushEdit_Settings *gset = gpsculpt_get_settings(CTX_data_scene(C));
-       
-       if (gset->paintcursor && !enable) {
-               /* clear cursor */
-               WM_paint_cursor_end(CTX_wm_manager(C), gset->paintcursor);
-               gset->paintcursor = NULL;
-       }
-       else if (enable) {
-               /* enable cursor */
-               gset->paintcursor = WM_paint_cursor_activate(CTX_wm_manager(C), 
-                                                            NULL, 
-                                                            
gp_brush_drawcursor, NULL);
-       }
-}
-
-
-/* ************************************************ */
 /* Header Info for GPencil Sculpt */
 
 static void gpsculpt_brush_header_set(bContext *C, tGP_BrushEditData *gso)
diff --git a/source/blender/editors/gpencil/gpencil_intern.h 
b/source/blender/editors/gpencil/gpencil_intern.h
index 2a258c52200..98adebf779a 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -121,9 +121,6 @@ bool gp_smooth_stroke_thickness(bGPDstroke *gps, int i, 
float inf);
 void gp_subdivide_stroke(bGPDstroke *gps, const int new_totpoints);
 void gp_randomize_stroke(bGPDstroke *gps, bGPDbrush *brush);
 
-/* set sculpt cursor */
-void ED_gpencil_toggle_brush_cursor(struct bContext *C, bool enable);
-
 /* Layers Enums -------------------------------------- */
 
 struct EnumPropertyItem *ED_gpencil_layers_enum_itemf(struct bContext *C, 
struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
diff --git a/source/blender/editors/gpencil/gpencil_utils.c 
b/source/blender/editors/gpencil/gpencil_utils.c
index 760633c003b..59c7e9274c7 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -69,6 +69,9 @@
 #include "ED_view3d.h"
 #include "ED_object.h"
 
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+
 #include "gpencil_intern.h"
 
 /* ******************************************************** */
@@ -1287,3 +1290,54 @@ void ED_gp_get_drawing_reference(ToolSettings *ts, 
View3D *v3d, Scene *scene, Ob
        }
 }
 /* ******************************************************** */
+/* Cursor drawing */
+
+/* Helper callback for drawing the cursor itself */
+static void gp_brush_drawcursor(bContext *C, int x, int y, void 
*UNUSED(customdata))
+{
+       Scene *scene = CTX_data_scene(C);
+       GP_BrushEdit_Settings *gset = &scene->toolsettings->gp_sculpt;
+       GP_EditBrush_Data *brush = &gset->brush[gset->brushtype]; 
+
+       if (brush) {
+               Gwn_VertFormat *format = immVertexFormat();
+               unsigned int pos = GWN_vertformat_attr_add(format, "pos", 
GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+               immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+               glEnable(GL_LINE_SMOOTH);
+               glEnable(GL_BLEND);
+
+               /* Inner Ring: Light color for action of the brush */
+               /* TODO: toggle between add and remove? */
+               immUniformColor4ub(255, 255, 255, 200);
+               imm_draw_circle_wire(pos, x, y, brush->size, 40);
+
+               /* Outer Ring: Dark color for contrast on light backgrounds 
(e.g. gray on white) */
+               immUniformColor3ub(30, 30, 30);
+               imm_draw_circle_wire(pos, x, y, brush->size + 1, 40);
+
+               immUnbindProgram();
+
+               glDisable(GL_BLEND);
+               glDisable(GL_LINE_SMOOTH);
+       }
+}
+
+/* Turn brush cursor in on/off */
+void ED_gpencil_toggle_brush_cursor(bContext *C, bool enable)
+{
+       Scene *scene = CTX_data_scene(C);
+       GP_BrushEdit_Settings *gset = &scene->toolsettings->gp_sculpt;
+
+       if (gset->paintcursor && !enable) {
+               /* clear cursor */
+               WM_paint_cursor_end(CTX_wm_manager(C), gset->paintcursor);
+               gset->paintcursor = NULL;
+       }
+       else if (enable) {
+               /* enable cursor */
+               gset->paintcursor = WM_paint_cursor_activate(CTX_wm_manager(C),
+                       NULL,
+                       gp_brush_drawcursor, NULL);
+       }
+}
diff --git a/source/blender/editors/include/ED_gpencil.h 
b/source/blender/editors/include/ED_gpencil.h
index 8e75aeda03b..cc9f9b0dd8b 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -212,4 +212,7 @@ void ED_gp_project_stroke_to_plane(struct Object *ob, 
struct RegionView3D *rv3d,
 void ED_gp_project_point_to_plane(struct Object *ob, struct RegionView3D 
*rv3d, const float origin[3], const int axis, char type, struct bGPDspoint *pt);
 void ED_gp_get_drawing_reference(struct ToolSettings *ts, struct View3D *v3d, 
struct Scene *scene, struct Object *ob, struct bGPDlayer *gpl, char align_flag, 
float vec[3]);
 
+/* set sculpt cursor */
+void ED_gpencil_toggle_brush_cursor(struct bContext *C, bool enable);
+
 #endif /*  __ED_GPENCIL_H__ */
diff --git a/source/blender/editors/space_view3d/view3d_select.c 
b/source/blender/editors/space_view3d/view3d_select.c
index c8fbbde8a15..69068fbb0f7 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -91,6 +91,7 @@
 #include "ED_screen.h"
 #include "ED_sculpt.h"
 #include "ED_mball.h"
+#include "ED_gpencil.h"
 
 #include "UI_interface.h"
 
@@ -1604,13 +1605,18 @@ static bool ed_object_select_pick(
                                /* set cursor */
                                if (basact->object->mode == 
OB_MODE_GPENCIL_PAINT) {
                                        WM_cursor_modal_set(CTX_wm_window(C), 
BC_PAINTBRUSHCURSOR);
+                                       ED_gpencil_toggle_brush_cursor(C, 
false);
                                }
-                               else if (basact->object->mode == 
OB_MODE_GPENCIL_PAINT) {
+                               else if (basact->object->mode == 
OB_MODE_GPENCIL_SCULPT) {
                                        WM_cursor_modal_set(CTX_wm_window(C), 
BC_CROSSCURSOR);
+                                       /* first disable to avoid duplicate 
cursors */
+                                       ED_gpencil_toggle_brush_cursor(C, 
false);
+                                       ED_gpencil_toggle_brush_cursor(C, true);
                                }
                                else {
                                        /* TODO: maybe is better use restore */
                                        WM_cursor_modal_set(CTX_wm_window(C), 
CURSOR_STD);
+                                       ED_gpencil_toggle_brush_cursor(C, 
false);
                                }
                                /* set workspace mode */
                                
BKE_workspace_object_mode_set(CTX_wm_workspace(C), basact->object->mode);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to