diff --git a/source/blender/editors/gpencil_legacy/gpencil_data.c b/source/blender/editors/gpencil_legacy/gpencil_data.c index 6f8d3e61e28..4a827cda582 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_data.c +++ b/source/blender/editors/gpencil_legacy/gpencil_data.c @@ -65,6 +65,7 @@ #include "ED_gpencil_legacy.h" #include "ED_object.h" +#include "ED_view3d.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" @@ -332,6 +333,10 @@ static int gpencil_layer_remove_exec(bContext *C, wmOperator *op) BKE_gpencil_layer_active_set(gpd, gpl->next); } + if (gpl->flag & GP_LAYER_IS_RULER) { + ED_view3d_gizmo_ruler_remove_all(C); + } + /* delete the layer now... */ BKE_gpencil_layer_delete(gpd, gpl); diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index ca23f3ac664..184de08d276 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -1364,6 +1364,13 @@ void ED_view3d_gizmo_mesh_preselect_get_active(struct bContext *C, struct BMElem **r_ele); void ED_view3d_gizmo_mesh_preselect_clear(struct wmGizmo *gz); +/* view3d_gizmo_ruler.cc */ + +/** + * Remove all rulers when Annotation layer is removed. + */ +void ED_view3d_gizmo_ruler_remove_all(struct bContext *C); + /* space_view3d.cc */ void ED_view3d_buttons_region_layout_ex(const struct bContext *C, diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc b/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc index 5afb78e2150..8a9d1651ece 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc +++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc @@ -621,6 +621,20 @@ static bool view3d_ruler_from_gpencil(const bContext *C, wmGizmoGroup *gzgroup) return changed; } +void ED_view3d_gizmo_ruler_remove_all(bContext *C) +{ + ARegion *region = CTX_wm_region(C); + wmGizmoMap *gzmap = region->gizmo_map; + wmGizmoGroup *gzgroup = WM_gizmomap_group_find(gzmap, view3d_gzgt_ruler_id); + + RulerItem *ruler_item; + while ((ruler_item = gzgroup_ruler_item_first_get(gzgroup))) { + ruler_item_remove(C, gzgroup, ruler_item); + } + + ED_region_tag_redraw_editor_overlays(region); +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -1189,7 +1203,9 @@ static void gizmo_ruler_exit(bContext *C, wmGizmo *gz, const bool cancel) ruler_state_set(ruler_info, RULER_STATE_NORMAL); } /* We could convert only the current gizmo, for now just re-generate. */ - view3d_ruler_to_gpencil(C, gzgroup); + if (view3d_ruler_to_gpencil(C, gzgroup)) { + WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL); + } } MEM_SAFE_FREE(gz->interaction_data);