GPv3: Add poll function to brush_stroke operator

This adds a proper poll function to the `brush_stroke` operator.
Ensures that this operator is only used by tools that are brushes.

Also changes the poll for the drawing of the cursor to only run
with tools that are brushes.
This commit is contained in:
Falk David
2024-01-26 15:23:02 +01:00
parent f3c9449521
commit 9f563c3ec2

View File

@@ -120,7 +120,18 @@ static void stroke_done(const bContext *C, PaintStroke *stroke)
operation->~GreasePencilStrokeOperation();
}
static int grease_pencil_stroke_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool grease_pencil_brush_stroke_poll(bContext *C)
{
if (!ed::greasepencil::grease_pencil_painting_poll(C)) {
return false;
}
if (!WM_toolsystem_active_tool_is_brush(C)) {
return false;
}
return true;
}
static int grease_pencil_brush_stroke_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
const Scene *scene = CTX_data_scene(C);
const Object *object = CTX_data_active_object(C);
@@ -192,12 +203,12 @@ static int grease_pencil_stroke_invoke(bContext *C, wmOperator *op, const wmEven
return OPERATOR_RUNNING_MODAL;
}
static int grease_pencil_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
static int grease_pencil_brush_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
return paint_stroke_modal(C, op, event, reinterpret_cast<PaintStroke **>(&op->customdata));
}
static void grease_pencil_stroke_cancel(bContext *C, wmOperator *op)
static void grease_pencil_brush_stroke_cancel(bContext *C, wmOperator *op)
{
paint_stroke_cancel(C, op, static_cast<PaintStroke *>(op->customdata));
}
@@ -208,9 +219,10 @@ static void GREASE_PENCIL_OT_brush_stroke(wmOperatorType *ot)
ot->idname = "GREASE_PENCIL_OT_brush_stroke";
ot->description = "Draw a new stroke in the active Grease Pencil object";
ot->invoke = grease_pencil_stroke_invoke;
ot->modal = grease_pencil_stroke_modal;
ot->cancel = grease_pencil_stroke_cancel;
ot->poll = grease_pencil_brush_stroke_poll;
ot->invoke = grease_pencil_brush_stroke_invoke;
ot->modal = grease_pencil_brush_stroke_modal;
ot->cancel = grease_pencil_brush_stroke_cancel;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -223,9 +235,9 @@ static void GREASE_PENCIL_OT_brush_stroke(wmOperatorType *ot)
/** \name Toggle Draw Mode
* \{ */
static bool grease_pencil_mode_poll_view3d(bContext *C)
static bool grease_pencil_mode_poll_paint_cursor(bContext *C)
{
if (!ed::greasepencil::grease_pencil_painting_poll(C)) {
if (!grease_pencil_brush_stroke_poll(C)) {
return false;
}
if (CTX_wm_region_view3d(C) == nullptr) {
@@ -246,7 +258,7 @@ static void grease_pencil_draw_mode_enter(bContext *C)
ob->mode = OB_MODE_PAINT_GREASE_PENCIL;
/* TODO: Setup cursor color. BKE_paint_init() could be used, but creates an additional brush. */
ED_paint_cursor_start(&grease_pencil_paint->paint, grease_pencil_mode_poll_view3d);
ED_paint_cursor_start(&grease_pencil_paint->paint, grease_pencil_mode_poll_paint_cursor);
paint_init_pivot(ob, scene);
/* Necessary to change the object mode on the evaluated object. */