Tool System: add paint poll which ignores the tool

Needed for tools which ensure paint context but aren't brushes
(color sample & gradient).
This commit is contained in:
Campbell Barton 2018-05-01 11:42:25 +02:00
parent 2c9670b92d
commit 70d352d994
Notes: blender-bot 2023-02-14 08:45:12 +01:00
Referenced by issue #60101, Sample color is not working in vertex paint.
4 changed files with 40 additions and 8 deletions

View File

@ -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)

View File

@ -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]);

View File

@ -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");

View File

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