[Bf-blender-cvs] [83d92f55b81] master: Fix error for tools that share gizmo types doubling up gizmos

Campbell Barton noreply at git.blender.org
Fri Jun 28 03:29:27 CEST 2019


Commit: 83d92f55b81f3d2b6b20c2c39a140df30caef5e4
Author: Campbell Barton
Date:   Fri Jun 28 10:04:52 2019 +1000
Branches: master
https://developer.blender.org/rB83d92f55b81f3d2b6b20c2c39a140df30caef5e4

Fix error for tools that share gizmo types doubling up gizmos

Introduced in recent commit c93af8529dfec

===================================================================

M	source/blender/windowmanager/gizmo/WM_gizmo_api.h
M	source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
M	source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h
M	source/blender/windowmanager/intern/wm_toolsystem.c

===================================================================

diff --git a/source/blender/windowmanager/gizmo/WM_gizmo_api.h b/source/blender/windowmanager/gizmo/WM_gizmo_api.h
index 5025291a746..293b0cd91dc 100644
--- a/source/blender/windowmanager/gizmo/WM_gizmo_api.h
+++ b/source/blender/windowmanager/gizmo/WM_gizmo_api.h
@@ -34,6 +34,7 @@ struct GHashIterator;
 struct IDProperty;
 struct Main;
 struct PropertyRNA;
+struct bToolRef;
 struct wmGizmo;
 struct wmGizmoGroup;
 struct wmGizmoGroupType;
@@ -364,5 +365,9 @@ void WM_gizmo_group_type_reinit(struct Main *bmain, const char *idname);
 bool WM_gizmo_context_check_drawstep(const struct bContext *C, eWM_GizmoFlagMapDrawStep step);
 
 bool WM_gizmo_group_type_poll(const struct bContext *C, const struct wmGizmoGroupType *gzgt);
+void WM_gizmo_group_remove_by_tool(struct bContext *C,
+                                   struct Main *bmain,
+                                   const struct wmGizmoGroupType *gzgt,
+                                   const struct bToolRef *tref);
 
 #endif /* __WM_GIZMO_API_H__ */
diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
index 2ec0e4e7ec3..f996d938dd7 100644
--- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
+++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
@@ -80,6 +80,11 @@ wmGizmoGroup *wm_gizmogroup_new_from_type(wmGizmoMap *gzmap, wmGizmoGroupType *g
   return gzgroup;
 }
 
+wmGizmoGroup *wm_gizmogroup_find_by_type(const wmGizmoMap *gzmap, const wmGizmoGroupType *gzgt)
+{
+  return BLI_findptr(&gzmap->groups, gzgt, offsetof(wmGizmoGroup, type));
+}
+
 void wm_gizmogroup_free(bContext *C, wmGizmoGroup *gzgroup)
 {
   wmGizmoMap *gzmap = gzgroup->parent_gzmap;
@@ -285,6 +290,34 @@ bool WM_gizmo_group_type_poll(const bContext *C, const struct wmGizmoGroupType *
   return (!gzgt->poll || gzgt->poll(C, (wmGizmoGroupType *)gzgt));
 }
 
+void WM_gizmo_group_remove_by_tool(bContext *C,
+                                   Main *bmain,
+                                   const wmGizmoGroupType *gzgt,
+                                   const bToolRef *tref)
+{
+  wmGizmoMapType *gzmap_type = WM_gizmomaptype_find(&gzgt->gzmap_params);
+  for (bScreen *sc = bmain->screens.first; sc; sc = sc->id.next) {
+    for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
+      if (sa->runtime.tool == tref) {
+        for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+          wmGizmoMap *gzmap = ar->gizmo_map;
+          if (gzmap && gzmap->type == gzmap_type) {
+            wmGizmoGroup *gzgroup, *gzgroup_next;
+            for (gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup_next) {
+              gzgroup_next = gzgroup->next;
+              if (gzgroup->type == gzgt) {
+                BLI_assert(gzgroup->parent_gzmap == gzmap);
+                wm_gizmogroup_free(C, gzgroup);
+                ED_region_tag_redraw(ar);
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
+
 bool wm_gizmogroup_is_visible_in_drawstep(const wmGizmoGroup *gzgroup,
                                           const eWM_GizmoFlagMapDrawStep drawstep)
 {
diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h b/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h
index 1018cc4d58b..98c3ad8295c 100644
--- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h
+++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h
@@ -61,6 +61,8 @@ struct wmGizmoGroup *wm_gizmogroup_new_from_type(struct wmGizmoMap *gzmap,
                                                  struct wmGizmoGroupType *gzgt);
 void wm_gizmogroup_free(bContext *C, struct wmGizmoGroup *gzgroup);
 void wm_gizmogroup_gizmo_register(struct wmGizmoGroup *gzgroup, struct wmGizmo *gz);
+struct wmGizmoGroup *wm_gizmogroup_find_by_type(const struct wmGizmoMap *gzmap,
+                                                const struct wmGizmoGroupType *gzgt);
 struct wmGizmo *wm_gizmogroup_find_intersected_gizmo(wmWindowManager *wm,
                                                      const struct wmGizmoGroup *gzgroup,
                                                      struct bContext *C,
diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c
index 330ef2944ad..ae9c6e267e2 100644
--- a/source/blender/windowmanager/intern/wm_toolsystem.c
+++ b/source/blender/windowmanager/intern/wm_toolsystem.c
@@ -128,41 +128,15 @@ bool WM_toolsystem_ref_ensure(struct WorkSpace *workspace, const bToolKey *tkey,
 
 /** \} */
 
-/**
- * \param do_gizmo: Make removing the gizmo optional because it complicates multi-window support
- * since the tool might be used in another window. The gizmos poll function must handle this,
- * since this is needed for switching workspaces anyway.
- */
-static void toolsystem_unlink_ref(bContext *C, WorkSpace *workspace, bToolRef *tref, bool do_gizmo)
+static void toolsystem_unlink_ref(bContext *C, WorkSpace *UNUSED(workspace), bToolRef *tref)
 {
   bToolRef_Runtime *tref_rt = tref->runtime;
 
-  if (do_gizmo && tref_rt->gizmo_group[0]) {
+  if (tref_rt->gizmo_group[0]) {
     wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(tref_rt->gizmo_group, false);
     if (gzgt != NULL) {
-      bool found = false;
-
-      /* TODO(campbell) */
       Main *bmain = CTX_data_main(C);
-#if 0
-      wmWindowManager *wm = bmain->wm.first;
-      /* Check another workspace isn't using this tool. */
-      for (wmWindow *win = wm->windows.first; win; win = win->next) {
-        const WorkSpace *workspace_iter = WM_window_get_active_workspace(win);
-        if (workspace != workspace_iter) {
-          if (STREQ(workspace->tool.gizmo_group, workspace_iter->tool.gizmo_group)) {
-            found = true;
-            break;
-          }
-        }
-      }
-#else
-      UNUSED_VARS(workspace);
-#endif
-      if (!found) {
-        wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(&gzgt->gzmap_params);
-        WM_gizmomaptype_group_unlink(C, bmain, gzmap_type, gzgt);
-      }
+      WM_gizmo_group_remove_by_tool(C, bmain, gzgt, tref);
     }
   }
 }
@@ -170,7 +144,7 @@ void WM_toolsystem_unlink(bContext *C, WorkSpace *workspace, const bToolKey *tke
 {
   bToolRef *tref = WM_toolsystem_ref_find(workspace, tkey);
   if (tref && tref->runtime) {
-    toolsystem_unlink_ref(C, workspace, tref, false);
+    toolsystem_unlink_ref(C, workspace, tref);
   }
 }
 
@@ -317,7 +291,7 @@ void WM_toolsystem_unlink_all(struct bContext *C, struct WorkSpace *workspace)
   LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) {
     if (tref->runtime) {
       if (tref->tag == 0) {
-        toolsystem_unlink_ref(C, workspace, tref, true);
+        toolsystem_unlink_ref(C, workspace, tref);
         tref->tag = 1;
       }
     }
@@ -364,7 +338,7 @@ void WM_toolsystem_ref_set_from_runtime(struct bContext *C,
   Main *bmain = CTX_data_main(C);
 
   if (tref->runtime) {
-    toolsystem_unlink_ref(C, workspace, tref, false);
+    toolsystem_unlink_ref(C, workspace, tref);
   }
 
   STRNCPY(tref->idname, idname);



More information about the Bf-blender-cvs mailing list