diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-07 18:06:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-07 18:39:40 +0300 |
commit | cf38b08f5271f00ff9e0008cb338ae9fdac49dd6 (patch) | |
tree | e194ff8bcbe88557d0447553778692b3e4fd5c91 /source/blender/windowmanager/gizmo | |
parent | 605749ffaaa1dc004eb8595c2b5c3bad00f2bb34 (diff) |
Fix gizmos not responding to theme color updates
Re-create gizmos when changing theme colors, since
theme colors don't change often this allows gizmos to setup their
colors on initialization.
Diffstat (limited to 'source/blender/windowmanager/gizmo')
3 files changed, 63 insertions, 10 deletions
diff --git a/source/blender/windowmanager/gizmo/WM_gizmo_api.h b/source/blender/windowmanager/gizmo/WM_gizmo_api.h index 56e22855d68..b48f58cda7f 100644 --- a/source/blender/windowmanager/gizmo/WM_gizmo_api.h +++ b/source/blender/windowmanager/gizmo/WM_gizmo_api.h @@ -246,6 +246,7 @@ int WM_gizmo_cmp_temp_fl_reverse(const void *gz_a_ptr, const void *gz_b_ptr); struct wmGizmoMap *WM_gizmomap_new_from_type( const struct wmGizmoMapType_Params *gzmap_params); +void WM_gizmomap_reinit(struct wmGizmoMap *gzmap); const struct ListBase *WM_gizmomap_group_list(struct wmGizmoMap *gzmap); struct wmGizmoGroup *WM_gizmomap_group_find( struct wmGizmoMap *gzmap, diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h b/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h index 4a7a6fa964a..6263bfaf58d 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h @@ -91,6 +91,9 @@ struct wmGizmoMap { /* private, update tagging (enum defined in C source). */ char update_flag[WM_GIZMOMAP_DRAWSTEP_MAX]; + /** Private, true when not yet used. */ + bool is_init; + /** * \brief Gizmo map runtime context * diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c index f2620499661..a4207704ab0 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c @@ -30,6 +30,7 @@ #include "BKE_context.h" #include "BKE_global.h" +#include "BKE_main.h" #include "ED_screen.h" #include "ED_select_utils.h" @@ -156,17 +157,12 @@ void wm_gizmomap_select_array_remove(wmGizmoMap *gzmap, wmGizmo *gz) * * \{ */ -/** - * Creates a gizmo-map with all registered gizmos for that type - */ -wmGizmoMap *WM_gizmomap_new_from_type( - const struct wmGizmoMapType_Params *gzmap_params) +static wmGizmoMap *wm_gizmomap_new_from_type_ex( + struct wmGizmoMapType *gzmap_type, + wmGizmoMap *gzmap) { - wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(gzmap_params); - wmGizmoMap *gzmap; - - gzmap = MEM_callocN(sizeof(wmGizmoMap), "GizmoMap"); gzmap->type = gzmap_type; + gzmap->is_init = true; WM_gizmomap_tag_refresh(gzmap); /* create all gizmo-groups for this gizmo-map. We may create an empty one @@ -178,7 +174,19 @@ wmGizmoMap *WM_gizmomap_new_from_type( return gzmap; } -void wm_gizmomap_remove(wmGizmoMap *gzmap) +/** + * Creates a gizmo-map with all registered gizmos for that type + */ +wmGizmoMap *WM_gizmomap_new_from_type( + const struct wmGizmoMapType_Params *gzmap_params) +{ + wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(gzmap_params); + wmGizmoMap *gzmap = MEM_callocN(sizeof(wmGizmoMap), "GizmoMap"); + wm_gizmomap_new_from_type_ex(gzmap_type, gzmap); + return gzmap; +} + +static void wm_gizmomap_free_data(wmGizmoMap *gzmap) { /* Clear first so further calls don't waste time trying to maintain correct array state. */ wm_gizmomap_select_array_clear(gzmap); @@ -189,10 +197,22 @@ void wm_gizmomap_remove(wmGizmoMap *gzmap) wm_gizmogroup_free(NULL, gzgroup); } BLI_assert(BLI_listbase_is_empty(&gzmap->groups)); +} +void wm_gizmomap_remove(wmGizmoMap *gzmap) +{ + wm_gizmomap_free_data(gzmap); MEM_freeN(gzmap); } +/** Re-create the gizmos (use when changing theme settings). */ +void WM_gizmomap_reinit(wmGizmoMap *gzmap) +{ + wmGizmoMapType *gzmap_type = gzmap->type; + wm_gizmomap_free_data(gzmap); + memset(gzmap, 0x0, sizeof(*gzmap)); + wm_gizmomap_new_from_type_ex(gzmap_type, gzmap); +} wmGizmoGroup *WM_gizmomap_group_find( struct wmGizmoMap *gzmap, @@ -326,6 +346,9 @@ static void gizmomap_prepare_drawing( { if (!gzmap || BLI_listbase_is_empty(&gzmap->groups)) return; + + gzmap->is_init = false; + wmGizmo *gz_modal = gzmap->gzmap_context.modal; /* only active gizmo needs updating */ @@ -1233,3 +1256,29 @@ void WM_gizmoconfig_update(struct Main *bmain) } /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Recreate All Gizmos + * + * Use when adjusting themes. + * + * \{ */ + +void WM_reinit_gizmomap_all(Main *bmain) +{ + for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; + for (ARegion *ar = regionbase->first; ar; ar = ar->next) { + wmGizmoMap *gzmap = ar->gizmo_map; + if ((gzmap != NULL) && (gzmap->is_init == false)) { + WM_gizmomap_reinit(gzmap); + } + } + } + } + } +} + +/** \} */ |