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.
This commit is contained in:
Falk David
2024-04-26 15:42:32 +02:00
parent 03cb588529
commit c87e8790bb
6 changed files with 24 additions and 7 deletions

View File

@@ -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;
}

View File

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

View File

@@ -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;
}

View File

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

View File

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

View File

@@ -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<GreasePencilStrokeOperation> new_paint_operation()