From b85e2d492dc096c0d16ef09660d9ee923a9715c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 30 Jan 2025 14:24:59 +0100 Subject: [PATCH] Fix #133720: Grease Pencil fill operator always enters modal operation If the "Visual Aids" option (aka. "show extension lines") is disabled the operator should just apply and exit immediately. Pull Request: https://projects.blender.org/blender/blender/pulls/133809 --- .../sculpt_paint/grease_pencil_draw_ops.cc | 61 +++++++++++-------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/source/blender/editors/sculpt_paint/grease_pencil_draw_ops.cc b/source/blender/editors/sculpt_paint/grease_pencil_draw_ops.cc index 2815c849d3e..dae7f5b857c 100644 --- a/source/blender/editors/sculpt_paint/grease_pencil_draw_ops.cc +++ b/source/blender/editors/sculpt_paint/grease_pencil_draw_ops.cc @@ -1677,36 +1677,45 @@ static int grease_pencil_fill_modal(bContext *C, wmOperator *op, const wmEvent * auto &op_data = *static_cast(op->customdata); - int estate = OPERATOR_RUNNING_MODAL; - switch (event->type) { - case EVT_MODAL_MAP: - estate = grease_pencil_fill_event_modal_map(C, op, event); - break; - case MOUSEMOVE: { - if (!op_data.is_extension_drag_active) { + int estate = OPERATOR_CANCELLED; + if (!op_data.show_extension) { + /* Apply fill immediately if "Visual Aids" (aka. extension lines) is disabled. */ + op_data.fill_mouse_pos = float2(event->mval); + estate = (grease_pencil_apply_fill(*C, *op, *event) ? OPERATOR_FINISHED : OPERATOR_CANCELLED); + } + else { + estate = OPERATOR_RUNNING_MODAL; + switch (event->type) { + case EVT_MODAL_MAP: + estate = grease_pencil_fill_event_modal_map(C, op, event); + break; + case MOUSEMOVE: { + if (!op_data.is_extension_drag_active) { + break; + } + + const Object &ob = *CTX_data_active_object(C); + const float pixel_size = ED_view3d_pixel_size(&rv3d, ob.loc); + const float2 mouse_pos = float2(event->mval); + const float initial_dist = math::distance(op_data.extension_mouse_pos, + op_data.fill_mouse_pos); + const float current_dist = math::distance(mouse_pos, op_data.fill_mouse_pos); + + float delta = (current_dist - initial_dist) * pixel_size * 0.5f; + op_data.extension_length = std::clamp(op_data.extension_length + delta, 0.0f, 10.0f); + + /* Update cursor line and extend lines. */ + WM_main_add_notifier(NC_GEOM | ND_DATA, nullptr); + WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, nullptr); + + grease_pencil_update_extend(*C, op_data); break; } - - const Object &ob = *CTX_data_active_object(C); - const float pixel_size = ED_view3d_pixel_size(&rv3d, ob.loc); - const float2 mouse_pos = float2(event->mval); - const float initial_dist = math::distance(op_data.extension_mouse_pos, - op_data.fill_mouse_pos); - const float current_dist = math::distance(mouse_pos, op_data.fill_mouse_pos); - - float delta = (current_dist - initial_dist) * pixel_size * 0.5f; - op_data.extension_length = std::clamp(op_data.extension_length + delta, 0.0f, 10.0f); - - /* Update cursor line and extend lines. */ - WM_main_add_notifier(NC_GEOM | ND_DATA, nullptr); - WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, nullptr); - - grease_pencil_update_extend(*C, op_data); - break; + default: + break; } - default: - break; } + /* Process last operations before exiting. */ switch (estate) { case OPERATOR_FINISHED: