[Bf-blender-cvs] [6fb51ece54b] master: Workspace: remove global active tool

Campbell Barton noreply at git.blender.org
Thu May 2 09:04:20 CEST 2019


Commit: 6fb51ece54b6b439c70f3a9010e7a52aaf1a806d
Author: Campbell Barton
Date:   Thu May 2 17:02:05 2019 +1000
Branches: master
https://developer.blender.org/rB6fb51ece54b6b439c70f3a9010e7a52aaf1a806d

Workspace: remove global active tool

This was needed for a global top-bar to show a single tool,
no longer needed now the top-bar is per-space.

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

M	source/blender/editors/interface/interface_icons.c
M	source/blender/makesdna/DNA_workspace_types.h
M	source/blender/windowmanager/intern/wm_toolsystem.c

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

diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 4b66461e186..7e295f83390 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -1826,15 +1826,14 @@ static int ui_id_brush_get_icon(const bContext *C, ID *id)
     ui_id_icon_render(C, id, true);
   }
   else {
-    WorkSpace *workspace = CTX_wm_workspace(C);
     Object *ob = CTX_data_active_object(C);
     const EnumPropertyItem *items = NULL;
     ePaintMode paint_mode = PAINT_MODE_INVALID;
     ScrArea *sa = CTX_wm_area(C);
     char space_type = sa->spacetype;
-    /* When in an unsupported space. */
-    if (!ELEM(space_type, SPACE_VIEW3D, SPACE_IMAGE)) {
-      space_type = workspace->tools_space_type;
+    /* Fallback to 3D view. */
+    if (space_type == SPACE_PROPERTIES) {
+      space_type = SPACE_VIEW3D;
     }
 
     /* XXX: this is not nice, should probably make brushes
@@ -1856,17 +1855,11 @@ static int ui_id_brush_get_icon(const bContext *C, ID *id)
       }
     }
     else if (space_type == SPACE_IMAGE) {
-      int sima_mode;
       if (sa->spacetype == space_type) {
-        SpaceImage *sima = sa->spacedata.first;
-        sima_mode = sima->mode;
-      }
-      else {
-        sima_mode = workspace->tools_mode;
-      }
-
-      if (sima_mode == SI_MODE_PAINT) {
-        paint_mode = PAINT_MODE_TEXTURE_2D;
+        const SpaceImage *sima = sa->spacedata.first;
+        if (sima->mode == SI_MODE_PAINT) {
+          paint_mode = PAINT_MODE_TEXTURE_2D;
+        }
       }
     }
 
diff --git a/source/blender/makesdna/DNA_workspace_types.h b/source/blender/makesdna/DNA_workspace_types.h
index 49c709b972c..1fd5e6a952a 100644
--- a/source/blender/makesdna/DNA_workspace_types.h
+++ b/source/blender/makesdna/DNA_workspace_types.h
@@ -122,10 +122,7 @@ typedef struct WorkSpace {
   /**
    * BAD DESIGN WARNING:
    * This is a workaround for the topbar not knowing which tools spec. */
-  char tools_space_type;
-  /** Type is different for each space-type. */
-  char tools_mode;
-  char _pad[2];
+  char _pad[4];
 
   int object_mode;
 
diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c
index dc0f02f22dd..f429415bee9 100644
--- a/source/blender/windowmanager/intern/wm_toolsystem.c
+++ b/source/blender/windowmanager/intern/wm_toolsystem.c
@@ -362,10 +362,6 @@ void WM_toolsystem_ref_set_from_runtime(struct bContext *C,
 
   STRNCPY(tref->idname, idname);
 
-  /* BAD DESIGN WARNING: used for topbar. */
-  workspace->tools_space_type = tref->space_type;
-  workspace->tools_mode = tref->mode;
-
   if (tref->runtime == NULL) {
     tref->runtime = MEM_callocN(sizeof(*tref->runtime), __func__);
   }
@@ -558,31 +554,24 @@ void WM_toolsystem_refresh_active(bContext *C)
       WorkSpace *workspace = WM_window_get_active_workspace(win);
       bScreen *screen = WM_window_get_active_screen(win);
       ViewLayer *view_layer = WM_window_get_active_view_layer(win);
-      int mode_other = 0;
-      enum { UNSET = -1, CHANGE = 0, MATCH = 1 } mode_match = UNSET;
       /* Could skip loop for modes that don't depend on space type. */
+      int space_type_mask_handled = 0;
       for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
         /* Don't change the space type of the active tool, only update it's mode. */
-        if (sa->spacetype == workspace->tools_space_type) {
-          const int mode = WM_toolsystem_mode_from_spacetype(view_layer, sa, sa->spacetype);
-          if (workspace->tools_mode == mode) {
-            mode_match = MATCH;
-            break;
-          }
-          else if (mode_match == -1) {
-            mode_match = CHANGE;
-            mode_other = mode;
+        const int space_type_mask = (1 << sa->spacetype);
+        if ((space_type_mask & WM_TOOLSYSTEM_SPACE_MASK) &&
+            ((space_type_mask_handled & space_type_mask) == 0)) {
+          space_type_mask_handled |= space_type_mask;
+          const bToolKey tkey = {
+              .space_type = sa->spacetype,
+              .mode = WM_toolsystem_mode_from_spacetype(view_layer, sa, sa->spacetype),
+          };
+          bToolRef *tref = WM_toolsystem_ref_find(workspace, &tkey);
+          if (tref != sa->runtime.tool) {
+            toolsystem_reinit_ensure_toolref(C, workspace, &tkey, NULL);
           }
         }
       }
-
-      if (mode_match == CHANGE) {
-        const bToolKey tkey = {
-            .space_type = workspace->tools_space_type,
-            .mode = mode_other,
-        };
-        toolsystem_reinit_ensure_toolref(C, workspace, &tkey, NULL);
-      }
     }
   }
 }



More information about the Bf-blender-cvs mailing list