WM: space, region type filtering for paint cursor
authorCampbell Barton <ideasman42@gmail.com>
Thu, 25 Oct 2018 05:06:47 +0000 (16:06 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 25 Oct 2018 05:06:47 +0000 (16:06 +1100)
Avoids calling poll on mouse-move for unrelated space/region types.

14 files changed:
source/blender/editors/gpencil/annotate_paint.c
source/blender/editors/gpencil/gpencil_paint.c
source/blender/editors/gpencil/gpencil_utils.c
source/blender/editors/physics/particle_edit.c
source/blender/editors/sculpt_paint/paint_cursor.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_stroke.c
source/blender/editors/sculpt_paint/sculpt_uv.c
source/blender/editors/transform/transform.c
source/blender/python/intern/bpy_rna_callback.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_draw.c
source/blender/windowmanager/intern/wm_operators.c
source/blender/windowmanager/wm.h

index 31c66ac8d55999ddab8d2cbf03d7057aa9d31490..57be09d807c7a20f5d89413c08f2fbc7c4eb2ee5 100644 (file)
@@ -1458,6 +1458,7 @@ static void gpencil_draw_toggle_eraser_cursor(bContext *C, tGPsdata *p, short en
                /* enable cursor */
                p->erasercursor = WM_paint_cursor_activate(
                        CTX_wm_manager(C),
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
                        NULL, /* XXX */
                        gpencil_draw_eraser, p);
        }
index 711f77c5890d025bda8676e40f7bd9fd513be341..4e45db6aa7625a7952a5bb9fadcc03bf30f9d636 100644 (file)
@@ -2209,9 +2209,10 @@ static void gpencil_draw_toggle_eraser_cursor(bContext *C, tGPsdata *p, short en
                ED_gpencil_toggle_brush_cursor(p->C, false, NULL);
                /* enable cursor */
                p->erasercursor = WM_paint_cursor_activate(
-                       CTX_wm_manager(C),
-                       NULL, /* XXX */
-                       gpencil_draw_eraser, p);
+                       CTX_wm_manager(C),
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                       NULL, /* XXX */
+                       gpencil_draw_eraser, p);
        }
 }
 
index 77a838d2f221bd9e03ed42b45e642b9f67da19a0..fd7ce2d41394beacbc81fc08f1856bbd7cbd4b93 100644 (file)
@@ -1684,6 +1684,7 @@ void ED_gpencil_toggle_brush_cursor(bContext *C, bool enable, void *customdata)
                /* enable cursor */
                gset->paintcursor = WM_paint_cursor_activate(
                        CTX_wm_manager(C),
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
                        NULL,
                        gp_brush_drawcursor,
                        (lastpost) ? customdata : NULL);
index 8009148480e3d0d4c5d6d64708f19b879a3388fe..72ece2c8bd5b1bf19048fc4046649ab42931b57e 100644 (file)
@@ -2945,7 +2945,12 @@ static void toggle_particle_cursor(bContext *C, int enable)
                pset->paintcursor = NULL;
        }
        else if (enable)
-               pset->paintcursor = WM_paint_cursor_activate(CTX_wm_manager(C), PE_poll_view3d, brush_drawcursor, NULL);
+               pset->paintcursor = WM_paint_cursor_activate(
+                       CTX_wm_manager(C),
+                       SPACE_VIEW3D, RGN_TYPE_WINDOW,
+                       PE_poll_view3d,
+                       brush_drawcursor,
+                       NULL);
 }
 
 /*************************** delete operator **************************/
index 7d94e63e2bcdf869a95f64ab53b6f114a6ebe8bb..294981e7303680c6ea3cc22150a72e6147535d0b 100644 (file)
@@ -41,6 +41,7 @@
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
+#include "DNA_space_types.h"
 #include "DNA_userdef_types.h"
 #include "DNA_view3d_types.h"
 
@@ -1153,8 +1154,14 @@ void paint_cursor_start(bContext *C, bool (*poll)(bContext *C))
 {
        Paint *p = BKE_paint_get_active_from_context(C);
 
-       if (p && !p->paint_cursor)
-               p->paint_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), poll, paint_draw_cursor, NULL);
+       if (p && !p->paint_cursor) {
+               p->paint_cursor = WM_paint_cursor_activate(
+                       CTX_wm_manager(C),
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                       poll,
+                       paint_draw_cursor,
+                       NULL);
+       }
 
        /* invalidate the paint cursors */
        BKE_paint_invalidate_overlay_all();
@@ -1162,6 +1169,12 @@ void paint_cursor_start(bContext *C, bool (*poll)(bContext *C))
 
 void paint_cursor_start_explicit(Paint *p, wmWindowManager *wm, bool (*poll)(bContext *C))
 {
-       if (p && !p->paint_cursor)
-               p->paint_cursor = WM_paint_cursor_activate(wm, poll, paint_draw_cursor, NULL);
+       if (p && !p->paint_cursor) {
+               p->paint_cursor = WM_paint_cursor_activate(
+                       wm,
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                       poll,
+                       paint_draw_cursor,
+                       NULL);
+       }
 }
index 897a74eb497595731b2eae081a0c21956579b9d0..aaf82d8ef2bdaf6818c121f2f511bd9ed2b937a4 100644 (file)
@@ -485,7 +485,11 @@ static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const flo
        }
 
        if ((brush->imagepaint_tool == PAINT_TOOL_FILL) && (brush->flag & BRUSH_USE_GRADIENT)) {
-               pop->cursor = WM_paint_cursor_activate(CTX_wm_manager(C), image_paint_poll, gradient_draw_line, pop);
+               pop->cursor = WM_paint_cursor_activate(
+                       CTX_wm_manager(C),
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                       image_paint_poll, gradient_draw_line,
+                       pop);
        }
 
        settings->imapaint.flag |= IMAGEPAINT_DRAWING;
index af27ad5d30708dd9602b284ca166042dee944d87..a1ae32f2e9a49c92db334ea2de545e26228c74d2 100644 (file)
@@ -1201,8 +1201,10 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
                        return OPERATOR_FINISHED;
 
                if (paint_supports_smooth_stroke(br, mode))
-                       stroke->stroke_cursor =
-                           WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_smooth_cursor, stroke);
+                       stroke->stroke_cursor = WM_paint_cursor_activate(
+                               CTX_wm_manager(C),
+                               SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                               paint_poll, paint_draw_smooth_cursor, stroke);
 
                stroke->stroke_init = true;
                first_modal = true;
@@ -1220,8 +1222,10 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
                                stroke->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, stroke->brush->rate);
 
                        if (br->flag & BRUSH_LINE) {
-                               stroke->stroke_cursor =
-                                       WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_line_cursor, stroke);
+                               stroke->stroke_cursor = WM_paint_cursor_activate(
+                                       CTX_wm_manager(C),
+                                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                                       paint_poll, paint_draw_line_cursor, stroke);
                        }
 
                        first_dab = true;
index 8fafc545fa910a310e5d197fec909690ea76717e..897539bddd7ad6ea704ab86ecb72148c9a8590bd 100644 (file)
@@ -248,7 +248,9 @@ void ED_space_image_uv_sculpt_update(Main *bmain, wmWindowManager *wm, Scene *sc
                BKE_paint_init(bmain, scene, ePaintSculptUV, PAINT_CURSOR_SCULPT);
 
                settings->uvsculpt->paint.paint_cursor = WM_paint_cursor_activate(
-                       wm, uv_sculpt_brush_poll,
+                       wm,
+                       SPACE_IMAGE, RGN_TYPE_WINDOW,
+                       uv_sculpt_brush_poll,
                        brush_drawcursor_uvsculpt, NULL);
        }
        else {
index 6dad6e968195ccf0c11c09b642df3b6f673f4e87..de41e6d3906c374c0312c6e450e1f5a572e485cc 100644 (file)
@@ -2319,31 +2319,49 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
                t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);
                t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
                t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
-               t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
+               t->draw_handle_cursor = WM_paint_cursor_activate(
+                       CTX_wm_manager(C),
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                       helpline_poll, drawHelpline, t);
        }
        else if (t->spacetype == SPACE_IMAGE) {
                t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
                //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
-               t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
+               t->draw_handle_cursor = WM_paint_cursor_activate(
+                       CTX_wm_manager(C),
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                       helpline_poll, drawHelpline, t);
        }
        else if (t->spacetype == SPACE_CLIP) {
                t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
-               t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
+               t->draw_handle_cursor = WM_paint_cursor_activate(
+                       CTX_wm_manager(C),
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                       helpline_poll, drawHelpline, t);
        }
        else if (t->spacetype == SPACE_NODE) {
                /*t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);*/
                t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
-               t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
+               t->draw_handle_cursor = WM_paint_cursor_activate(
+                       CTX_wm_manager(C),
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                       helpline_poll, drawHelpline, t);
        }
        else if (t->spacetype == SPACE_IPO) {
                t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
                //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
-               t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
+               t->draw_handle_cursor = WM_paint_cursor_activate(
+                       CTX_wm_manager(C),
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                       helpline_poll, drawHelpline, t);
        }
        else if (t->spacetype == SPACE_ACTION) {
                t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
                //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
-               t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
+               t->draw_handle_cursor = WM_paint_cursor_activate(
+                       CTX_wm_manager(C),
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                       helpline_poll, drawHelpline, t);
        }
 
        createTransData(C, t);          // make TransData structs from selection
index 7c1eebb9b1a8d27c703daac0e36aefb1937846b2..102677c23b8f3ed6389a0eeb12b5c4c197de7591 100644 (file)
@@ -266,7 +266,10 @@ PyObject *pyrna_callback_classmethod_add(PyObject *UNUSED(self), PyObject *args)
                }
                bContext *C = BPy_GetContext();
                struct wmWindowManager *wm = CTX_wm_manager(C);
-               handle = WM_paint_cursor_activate(wm, NULL, cb_wm_cursor_draw, (void *)args);
+               handle = WM_paint_cursor_activate(
+                       wm,
+                       SPACE_TYPE_ANY, RGN_TYPE_ANY,
+                       NULL, cb_wm_cursor_draw, (void *)args);
                Py_INCREF(args);
        }
        else if (RNA_struct_is_a(srna, &RNA_Space)) {
index 98df18169cdf3ac72c53a0f911d674503286cc28..4d3be1e3f3b513eaaf709c09f956ad324ff63cb8 100644 (file)
@@ -173,6 +173,7 @@ void                WM_cursor_time          (struct wmWindow *win, int nr);
 
 struct wmPaintCursor *WM_paint_cursor_activate(
         struct wmWindowManager *wm,
+        short space_type, short region_type,
         bool (*poll)(struct bContext *C),
         void (*draw)(struct bContext *C, int, int, void *customdata),
         void *customdata);
index b76fc0abfa71e6b73b80bd9f8d1250f6136365eb..c8e0360ed881b76bf4646290d034ec70828bf432 100644 (file)
@@ -85,7 +85,7 @@
 
 /* ******************* paint cursor *************** */
 
-static void wm_paintcursor_draw(bContext *C, ARegion *ar)
+static void wm_paintcursor_draw(bContext *C, ScrArea *sa, ARegion *ar)
 {
        wmWindowManager *wm = CTX_wm_manager(C);
        wmWindow *win = CTX_wm_window(C);
@@ -94,6 +94,15 @@ static void wm_paintcursor_draw(bContext *C, ARegion *ar)
 
        if (ar->visible && ar == screen->active_region) {
                for (pc = wm->paintcursors.first; pc; pc = pc->next) {
+
+                       if ((pc->space_type != SPACE_TYPE_ANY) && (sa->spacetype != pc->space_type)) {
+                               continue;
+                       }
+
+                       if ((pc->region_type != RGN_TYPE_ANY) && (ar->regiontype != pc->region_type)) {
+                               continue;
+                       }
+
                        if (pc->poll == NULL || pc->poll(C)) {
                                /* Prevent drawing outside region. */
                                glEnable(GL_SCISSOR_TEST);
@@ -612,7 +621,7 @@ static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view)
                                        CTX_wm_region_set(C, ar);
 
                                        /* make region ready for draw, scissor, pixelspace */
-                                       wm_paintcursor_draw(C, ar);
+                                       wm_paintcursor_draw(C, sa, ar);
 
                                        CTX_wm_region_set(C, NULL);
                                        CTX_wm_area_set(C, NULL);
index fa654e46cf1defdcede3853b3f93360a1aea4c87..e12107283a53469b06af9119ae27c89427ede74c 100644 (file)
@@ -1845,7 +1845,9 @@ static void WM_OT_console_toggle(wmOperatorType *ot)
  */
 
 wmPaintCursor *WM_paint_cursor_activate(
-        wmWindowManager *wm, bool (*poll)(bContext *C),
+        wmWindowManager *wm,
+        short space_type, short region_type,
+        bool (*poll)(bContext *C),
         wmPaintCursorDraw draw, void *customdata)
 {
        wmPaintCursor *pc = MEM_callocN(sizeof(wmPaintCursor), "paint cursor");
@@ -1856,6 +1858,9 @@ wmPaintCursor *WM_paint_cursor_activate(
        pc->poll = poll;
        pc->draw = draw;
 
+       pc->space_type = space_type;
+       pc->region_type = region_type;
+
        return pc;
 }
 
@@ -2443,8 +2448,11 @@ static int radial_control_invoke(bContext *C, wmOperator *op, const wmEvent *eve
        BLI_listbase_clear(&wm->paintcursors);
 
        /* add radial control paint cursor */
-       rc->cursor = WM_paint_cursor_activate(wm, op->type->poll,
-                                             radial_control_paint_cursor, rc);
+       rc->cursor = WM_paint_cursor_activate(
+               wm,
+               SPACE_TYPE_ANY, RGN_TYPE_ANY,
+               op->type->poll,
+               radial_control_paint_cursor, rc);
 
        WM_event_add_modal_handler(C, op);
 
index 04353b5533477eedfc2f7746d945fe8db2583869..89fd2fdf5576f65dda1a96afd97c1d3963892b48 100644 (file)
@@ -44,6 +44,9 @@ typedef struct wmPaintCursor {
 
        bool (*poll)(struct bContext *C);
        void (*draw)(bContext *C, int, int, void *customdata);
+
+       short space_type;
+       short region_type;
 } wmPaintCursor;