From c87e8790bb152d6f7acf33ee38e0106034cbea67 Mon Sep 17 00:00:00 2001 From: Falk David Date: Fri, 26 Apr 2024 15:42:32 +0200 Subject: [PATCH] Fix: GPv3: Redraw editors showing grease pencil keys when new on is added When e.g. using auto-key to draw on a new frame, the dopesheet (and other editors) would not redraw to show the newly added keyframe. This fix makes sure we send notifiers to those editors when a keyframe is added. --- .../editors/grease_pencil/intern/grease_pencil_edit.cc | 7 ++++++- .../editors/grease_pencil/intern/grease_pencil_frames.cc | 5 ++++- .../editors/grease_pencil/intern/grease_pencil_utils.cc | 7 +++++-- source/blender/editors/include/ED_grease_pencil.hh | 4 +++- .../blender/editors/sculpt_paint/grease_pencil_draw_ops.cc | 6 +++++- source/blender/editors/sculpt_paint/grease_pencil_paint.cc | 2 +- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc index da0854b495c..7f7404573cd 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc @@ -2227,7 +2227,8 @@ static int grease_pencil_paste_strokes_exec(bContext *C, wmOperator *op) } /* Ensure active keyframe. */ - if (!ensure_active_keyframe(scene, grease_pencil)) { + bool inserted_keyframe = false; + if (!ensure_active_keyframe(scene, grease_pencil, inserted_keyframe)) { BKE_report(op->reports, RPT_ERROR, "No Grease Pencil frame to draw on"); return OPERATOR_CANCELLED; } @@ -2252,6 +2253,10 @@ static int grease_pencil_paste_strokes_exec(bContext *C, wmOperator *op) DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_GEOM | ND_DATA, &grease_pencil); + if (inserted_keyframe) { + WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, nullptr); + } + return OPERATOR_FINISHED; } diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc index e1de54d61b2..fdae37d75af 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc @@ -335,7 +335,9 @@ void create_keyframe_edit_data_selected_frames_list(KeyframeEditData *ked, } } -bool ensure_active_keyframe(const Scene &scene, GreasePencil &grease_pencil) +bool ensure_active_keyframe(const Scene &scene, + GreasePencil &grease_pencil, + bool &r_inserted_keyframe) { const int current_frame = scene.r.cfra; bke::greasepencil::Layer &active_layer = *grease_pencil.get_active_layer(); @@ -366,6 +368,7 @@ bool ensure_active_keyframe(const Scene &scene, GreasePencil &grease_pencil) /* Otherwise we just insert a blank keyframe at the current frame. */ grease_pencil.insert_blank_frame(active_layer, current_frame, 0, BEZT_KEYTYPE_KEYFRAME); } + r_inserted_keyframe = true; } /* There should now always be a drawing at the current frame. */ BLI_assert(active_layer.has_drawing_at(current_frame)); diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_utils.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_utils.cc index 3a1fdb617b1..b314addcc61 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_utils.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_utils.cc @@ -1172,11 +1172,14 @@ int grease_pencil_draw_operator_invoke(bContext *C, wmOperator *op) } /* Ensure a drawing at the current keyframe. */ - if (!ed::greasepencil::ensure_active_keyframe(*scene, grease_pencil)) { + bool inserted_keyframe = false; + if (!ed::greasepencil::ensure_active_keyframe(*scene, grease_pencil, inserted_keyframe)) { BKE_report(op->reports, RPT_ERROR, "No Grease Pencil frame to draw on"); return OPERATOR_CANCELLED; } - + if (inserted_keyframe) { + WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, nullptr); + } return OPERATOR_RUNNING_MODAL; } diff --git a/source/blender/editors/include/ED_grease_pencil.hh b/source/blender/editors/include/ED_grease_pencil.hh index 4efbd4b298b..5da3a83b3bd 100644 --- a/source/blender/editors/include/ED_grease_pencil.hh +++ b/source/blender/editors/include/ED_grease_pencil.hh @@ -209,7 +209,9 @@ bool has_any_frame_selected(const bke::greasepencil::Layer &layer); * create one when auto-key is on (taking additive drawing setting into account). * \return false when no keyframe could be found or created. */ -bool ensure_active_keyframe(const Scene &scene, GreasePencil &grease_pencil); +bool ensure_active_keyframe(const Scene &scene, + GreasePencil &grease_pencil, + bool &r_inserted_keyframe); void create_keyframe_edit_data_selected_frames_list(KeyframeEditData *ked, const bke::greasepencil::Layer &layer); 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 0e9216df944..3ca3af5bd48 100644 --- a/source/blender/editors/sculpt_paint/grease_pencil_draw_ops.cc +++ b/source/blender/editors/sculpt_paint/grease_pencil_draw_ops.cc @@ -279,10 +279,14 @@ static int grease_pencil_sculpt_paint_invoke(bContext *C, wmOperator *op, const } /* Ensure a drawing at the current keyframe. */ - if (!ed::greasepencil::ensure_active_keyframe(*scene, grease_pencil)) { + bool inserted_keyframe = false; + if (!ed::greasepencil::ensure_active_keyframe(*scene, grease_pencil, inserted_keyframe)) { BKE_report(op->reports, RPT_ERROR, "No Grease Pencil frame to draw on"); return OPERATOR_CANCELLED; } + if (inserted_keyframe) { + WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, nullptr); + } op->customdata = paint_stroke_new(C, op, diff --git a/source/blender/editors/sculpt_paint/grease_pencil_paint.cc b/source/blender/editors/sculpt_paint/grease_pencil_paint.cc index c8f7828fd19..0af2d7bcd9c 100644 --- a/source/blender/editors/sculpt_paint/grease_pencil_paint.cc +++ b/source/blender/editors/sculpt_paint/grease_pencil_paint.cc @@ -709,7 +709,7 @@ void PaintOperation::on_stroke_done(const bContext &C) drawing.tag_topology_changed(); DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY); - WM_main_add_notifier(NC_GEOM | ND_DATA, &grease_pencil.id); + WM_event_add_notifier(&C, NC_GEOM | ND_DATA, &grease_pencil.id); } std::unique_ptr new_paint_operation()