WM: space, region type filtering for paint cursor

Avoids calling poll on mouse-move for unrelated space/region types.
This commit is contained in:
2018-10-25 16:06:47 +11:00
parent 46587b3ccb
commit 6d49b623e2
14 changed files with 99 additions and 26 deletions

View 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);
}

View 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);
}
}

View 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);

View 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 **************************/

View 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);
}
}

View 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;

View 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;

View 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 {

View 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

View 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)) {

View 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);

View 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);

View 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);

View 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;