WM: space, region type filtering for paint cursor
Avoids calling poll on mouse-move for unrelated space/region types.
This commit is contained in:
@@ -1458,6 +1458,7 @@ static void gpencil_draw_toggle_eraser_cursor(bContext *C, tGPsdata *p, short en
|
|||||||
/* enable cursor */
|
/* enable cursor */
|
||||||
p->erasercursor = WM_paint_cursor_activate(
|
p->erasercursor = WM_paint_cursor_activate(
|
||||||
CTX_wm_manager(C),
|
CTX_wm_manager(C),
|
||||||
|
SPACE_TYPE_ANY, RGN_TYPE_ANY,
|
||||||
NULL, /* XXX */
|
NULL, /* XXX */
|
||||||
gpencil_draw_eraser, p);
|
gpencil_draw_eraser, p);
|
||||||
}
|
}
|
||||||
|
@@ -2210,6 +2210,7 @@ static void gpencil_draw_toggle_eraser_cursor(bContext *C, tGPsdata *p, short en
|
|||||||
/* enable cursor */
|
/* enable cursor */
|
||||||
p->erasercursor = WM_paint_cursor_activate(
|
p->erasercursor = WM_paint_cursor_activate(
|
||||||
CTX_wm_manager(C),
|
CTX_wm_manager(C),
|
||||||
|
SPACE_TYPE_ANY, RGN_TYPE_ANY,
|
||||||
NULL, /* XXX */
|
NULL, /* XXX */
|
||||||
gpencil_draw_eraser, p);
|
gpencil_draw_eraser, p);
|
||||||
}
|
}
|
||||||
|
@@ -1684,6 +1684,7 @@ void ED_gpencil_toggle_brush_cursor(bContext *C, bool enable, void *customdata)
|
|||||||
/* enable cursor */
|
/* enable cursor */
|
||||||
gset->paintcursor = WM_paint_cursor_activate(
|
gset->paintcursor = WM_paint_cursor_activate(
|
||||||
CTX_wm_manager(C),
|
CTX_wm_manager(C),
|
||||||
|
SPACE_TYPE_ANY, RGN_TYPE_ANY,
|
||||||
NULL,
|
NULL,
|
||||||
gp_brush_drawcursor,
|
gp_brush_drawcursor,
|
||||||
(lastpost) ? customdata : NULL);
|
(lastpost) ? customdata : NULL);
|
||||||
|
@@ -2945,7 +2945,12 @@ static void toggle_particle_cursor(bContext *C, int enable)
|
|||||||
pset->paintcursor = NULL;
|
pset->paintcursor = NULL;
|
||||||
}
|
}
|
||||||
else if (enable)
|
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 **************************/
|
/*************************** delete operator **************************/
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
#include "DNA_object_types.h"
|
#include "DNA_object_types.h"
|
||||||
#include "DNA_scene_types.h"
|
#include "DNA_scene_types.h"
|
||||||
#include "DNA_screen_types.h"
|
#include "DNA_screen_types.h"
|
||||||
|
#include "DNA_space_types.h"
|
||||||
#include "DNA_userdef_types.h"
|
#include "DNA_userdef_types.h"
|
||||||
#include "DNA_view3d_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);
|
Paint *p = BKE_paint_get_active_from_context(C);
|
||||||
|
|
||||||
if (p && !p->paint_cursor)
|
if (p && !p->paint_cursor) {
|
||||||
p->paint_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), poll, paint_draw_cursor, NULL);
|
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 */
|
/* invalidate the paint cursors */
|
||||||
BKE_paint_invalidate_overlay_all();
|
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))
|
void paint_cursor_start_explicit(Paint *p, wmWindowManager *wm, bool (*poll)(bContext *C))
|
||||||
{
|
{
|
||||||
if (p && !p->paint_cursor)
|
if (p && !p->paint_cursor) {
|
||||||
p->paint_cursor = WM_paint_cursor_activate(wm, poll, paint_draw_cursor, NULL);
|
p->paint_cursor = WM_paint_cursor_activate(
|
||||||
|
wm,
|
||||||
|
SPACE_TYPE_ANY, RGN_TYPE_ANY,
|
||||||
|
poll,
|
||||||
|
paint_draw_cursor,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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)) {
|
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;
|
settings->imapaint.flag |= IMAGEPAINT_DRAWING;
|
||||||
|
@@ -1201,8 +1201,10 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||||||
return OPERATOR_FINISHED;
|
return OPERATOR_FINISHED;
|
||||||
|
|
||||||
if (paint_supports_smooth_stroke(br, mode))
|
if (paint_supports_smooth_stroke(br, mode))
|
||||||
stroke->stroke_cursor =
|
stroke->stroke_cursor = WM_paint_cursor_activate(
|
||||||
WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_smooth_cursor, stroke);
|
CTX_wm_manager(C),
|
||||||
|
SPACE_TYPE_ANY, RGN_TYPE_ANY,
|
||||||
|
paint_poll, paint_draw_smooth_cursor, stroke);
|
||||||
|
|
||||||
stroke->stroke_init = true;
|
stroke->stroke_init = true;
|
||||||
first_modal = 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);
|
stroke->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, stroke->brush->rate);
|
||||||
|
|
||||||
if (br->flag & BRUSH_LINE) {
|
if (br->flag & BRUSH_LINE) {
|
||||||
stroke->stroke_cursor =
|
stroke->stroke_cursor = WM_paint_cursor_activate(
|
||||||
WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_line_cursor, stroke);
|
CTX_wm_manager(C),
|
||||||
|
SPACE_TYPE_ANY, RGN_TYPE_ANY,
|
||||||
|
paint_poll, paint_draw_line_cursor, stroke);
|
||||||
}
|
}
|
||||||
|
|
||||||
first_dab = true;
|
first_dab = true;
|
||||||
|
@@ -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);
|
BKE_paint_init(bmain, scene, ePaintSculptUV, PAINT_CURSOR_SCULPT);
|
||||||
|
|
||||||
settings->uvsculpt->paint.paint_cursor = WM_paint_cursor_activate(
|
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);
|
brush_drawcursor_uvsculpt, NULL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@@ -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_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_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_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) {
|
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_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_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) {
|
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_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) {
|
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_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_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) {
|
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_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_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) {
|
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_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_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
|
createTransData(C, t); // make TransData structs from selection
|
||||||
|
@@ -266,7 +266,10 @@ PyObject *pyrna_callback_classmethod_add(PyObject *UNUSED(self), PyObject *args)
|
|||||||
}
|
}
|
||||||
bContext *C = BPy_GetContext();
|
bContext *C = BPy_GetContext();
|
||||||
struct wmWindowManager *wm = CTX_wm_manager(C);
|
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);
|
Py_INCREF(args);
|
||||||
}
|
}
|
||||||
else if (RNA_struct_is_a(srna, &RNA_Space)) {
|
else if (RNA_struct_is_a(srna, &RNA_Space)) {
|
||||||
|
@@ -173,6 +173,7 @@ void WM_cursor_time (struct wmWindow *win, int nr);
|
|||||||
|
|
||||||
struct wmPaintCursor *WM_paint_cursor_activate(
|
struct wmPaintCursor *WM_paint_cursor_activate(
|
||||||
struct wmWindowManager *wm,
|
struct wmWindowManager *wm,
|
||||||
|
short space_type, short region_type,
|
||||||
bool (*poll)(struct bContext *C),
|
bool (*poll)(struct bContext *C),
|
||||||
void (*draw)(struct bContext *C, int, int, void *customdata),
|
void (*draw)(struct bContext *C, int, int, void *customdata),
|
||||||
void *customdata);
|
void *customdata);
|
||||||
|
@@ -85,7 +85,7 @@
|
|||||||
|
|
||||||
/* ******************* paint cursor *************** */
|
/* ******************* 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);
|
wmWindowManager *wm = CTX_wm_manager(C);
|
||||||
wmWindow *win = CTX_wm_window(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) {
|
if (ar->visible && ar == screen->active_region) {
|
||||||
for (pc = wm->paintcursors.first; pc; pc = pc->next) {
|
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)) {
|
if (pc->poll == NULL || pc->poll(C)) {
|
||||||
/* Prevent drawing outside region. */
|
/* Prevent drawing outside region. */
|
||||||
glEnable(GL_SCISSOR_TEST);
|
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);
|
CTX_wm_region_set(C, ar);
|
||||||
|
|
||||||
/* make region ready for draw, scissor, pixelspace */
|
/* 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_region_set(C, NULL);
|
||||||
CTX_wm_area_set(C, NULL);
|
CTX_wm_area_set(C, NULL);
|
||||||
|
@@ -1845,7 +1845,9 @@ static void WM_OT_console_toggle(wmOperatorType *ot)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
wmPaintCursor *WM_paint_cursor_activate(
|
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)
|
wmPaintCursorDraw draw, void *customdata)
|
||||||
{
|
{
|
||||||
wmPaintCursor *pc = MEM_callocN(sizeof(wmPaintCursor), "paint cursor");
|
wmPaintCursor *pc = MEM_callocN(sizeof(wmPaintCursor), "paint cursor");
|
||||||
@@ -1856,6 +1858,9 @@ wmPaintCursor *WM_paint_cursor_activate(
|
|||||||
pc->poll = poll;
|
pc->poll = poll;
|
||||||
pc->draw = draw;
|
pc->draw = draw;
|
||||||
|
|
||||||
|
pc->space_type = space_type;
|
||||||
|
pc->region_type = region_type;
|
||||||
|
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2443,7 +2448,10 @@ static int radial_control_invoke(bContext *C, wmOperator *op, const wmEvent *eve
|
|||||||
BLI_listbase_clear(&wm->paintcursors);
|
BLI_listbase_clear(&wm->paintcursors);
|
||||||
|
|
||||||
/* add radial control paint cursor */
|
/* add radial control paint cursor */
|
||||||
rc->cursor = WM_paint_cursor_activate(wm, op->type->poll,
|
rc->cursor = WM_paint_cursor_activate(
|
||||||
|
wm,
|
||||||
|
SPACE_TYPE_ANY, RGN_TYPE_ANY,
|
||||||
|
op->type->poll,
|
||||||
radial_control_paint_cursor, rc);
|
radial_control_paint_cursor, rc);
|
||||||
|
|
||||||
WM_event_add_modal_handler(C, op);
|
WM_event_add_modal_handler(C, op);
|
||||||
|
@@ -44,6 +44,9 @@ typedef struct wmPaintCursor {
|
|||||||
|
|
||||||
bool (*poll)(struct bContext *C);
|
bool (*poll)(struct bContext *C);
|
||||||
void (*draw)(bContext *C, int, int, void *customdata);
|
void (*draw)(bContext *C, int, int, void *customdata);
|
||||||
|
|
||||||
|
short space_type;
|
||||||
|
short region_type;
|
||||||
} wmPaintCursor;
|
} wmPaintCursor;
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user