diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-05-01 12:42:25 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-05-01 12:42:25 +0300 |
commit | 70d352d994d0f8187ad2c871ee22712b1bf4b855 (patch) | |
tree | 85b0e430b9eeae5fb6c6ded78f54da236108652d /source | |
parent | 2c9670b92d32e79d0f071475731bcaf79aae42f5 (diff) |
Tool System: add paint poll which ignores the tool
Needed for tools which ensure paint context but aren't brushes
(color sample & gradient).
Diffstat (limited to 'source')
4 files changed, 40 insertions, 8 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 06df1632593..3207b4f6a0a 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -264,7 +264,7 @@ static Brush *image_paint_brush(bContext *C) return BKE_paint_brush(&settings->imapaint.paint); } -static int image_paint_poll(bContext *C) +static int image_paint_poll_ex(bContext *C, bool check_tool) { Object *obact; @@ -273,7 +273,7 @@ static int image_paint_poll(bContext *C) obact = CTX_data_active_object(C); if ((obact && obact->mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) { - if (WM_toolsystem_active_tool_is_brush(C)) { + if (!check_tool || WM_toolsystem_active_tool_is_brush(C)) { return 1; } } @@ -292,6 +292,16 @@ static int image_paint_poll(bContext *C) return 0; } +static int image_paint_poll(bContext *C) +{ + return image_paint_poll_ex(C, true); +} + +static int image_paint_poll_ignore_tool(bContext *C) +{ + return image_paint_poll_ex(C, false); +} + static int image_paint_2d_clone_poll(bContext *C) { Brush *brush = image_paint_brush(C); @@ -1001,7 +1011,7 @@ static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event) static int sample_color_poll(bContext *C) { - return (image_paint_poll(C) || vertex_paint_poll(C)); + return (image_paint_poll_ignore_tool(C) || image_paint_poll_ignore_tool(C)); } void PAINT_OT_sample_color(wmOperatorType *ot) diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index ca82ca52463..a6d8a90e95a 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -94,8 +94,10 @@ void paint_cursor_delete_textures(void); /* paint_vertex.c */ int weight_paint_poll(struct bContext *C); +int weight_paint_poll_ignore_tool(bContext *C); int weight_paint_mode_poll(struct bContext *C); int vertex_paint_poll(struct bContext *C); +int vertex_paint_poll_ignore_tool(struct bContext *C); int vertex_paint_mode_poll(struct bContext *C); typedef void (*VPaintTransform_Callback)(const float col[3], const void *user_data, float r_col[3]); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index fc43fe97648..68e0f34a685 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -206,7 +206,7 @@ int vertex_paint_mode_poll(bContext *C) return ob && ob->mode == OB_MODE_VERTEX_PAINT && ((Mesh *)ob->data)->totpoly; } -int vertex_paint_poll(bContext *C) +static int vertex_paint_poll_ex(bContext *C, bool check_tool) { if (vertex_paint_mode_poll(C) && BKE_paint_brush(&CTX_data_tool_settings(C)->vpaint->paint)) @@ -215,7 +215,7 @@ int vertex_paint_poll(bContext *C) if (sa && sa->spacetype == SPACE_VIEW3D) { ARegion *ar = CTX_wm_region(C); if (ar->regiontype == RGN_TYPE_WINDOW) { - if (WM_toolsystem_active_tool_is_brush(C)) { + if (!check_tool || WM_toolsystem_active_tool_is_brush(C)) { return 1; } } @@ -224,6 +224,16 @@ int vertex_paint_poll(bContext *C) return 0; } +int vertex_paint_poll(bContext *C) +{ + return vertex_paint_poll_ex(C, true); +} + +int vertex_paint_poll_ignore_tool(bContext *C) +{ + return vertex_paint_poll_ex(C, true); +} + int weight_paint_mode_poll(bContext *C) { Object *ob = CTX_data_active_object(C); @@ -231,7 +241,7 @@ int weight_paint_mode_poll(bContext *C) return ob && ob->mode == OB_MODE_WEIGHT_PAINT && ((Mesh *)ob->data)->totpoly; } -int weight_paint_poll(bContext *C) +static int weight_paint_poll_ex(bContext *C, bool check_tool) { Object *ob = CTX_data_active_object(C); ScrArea *sa; @@ -244,7 +254,7 @@ int weight_paint_poll(bContext *C) { ARegion *ar = CTX_wm_region(C); if (ar->regiontype == RGN_TYPE_WINDOW) { - if (WM_toolsystem_active_tool_is_brush(C)) { + if (!check_tool || WM_toolsystem_active_tool_is_brush(C)) { return 1; } } @@ -252,6 +262,16 @@ int weight_paint_poll(bContext *C) return 0; } +int weight_paint_poll(bContext *C) +{ + return weight_paint_poll_ex(C, true); +} + +int weight_paint_poll_ignore_tool(bContext *C) +{ + return weight_paint_poll_ex(C, false); +} + static VPaint *new_vpaint(void) { VPaint *vp = MEM_callocN(sizeof(VPaint), "VPaint"); diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c index 3773806e192..e560a4cddff 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c @@ -849,7 +849,7 @@ void PAINT_OT_weight_gradient(wmOperatorType *ot) ot->invoke = paint_weight_gradient_invoke; ot->modal = paint_weight_gradient_modal; ot->exec = paint_weight_gradient_exec; - ot->poll = weight_paint_poll; + ot->poll = weight_paint_poll_ignore_tool; ot->cancel = WM_gesture_straightline_cancel; /* flags */ |