Edit last commit
authorCampbell Barton <ideasman42@gmail.com>
Tue, 4 Dec 2018 03:29:23 +0000 (14:29 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 4 Dec 2018 03:33:45 +0000 (14:33 +1100)
Split out ensure-tool check into its own function.

source/blender/windowmanager/WM_toolsystem.h
source/blender/windowmanager/intern/wm_toolsystem.c

index 23f9161025e6234f32500cdf53f78e4b46bef2f6..4318179c203a6969da4aaae1e7dfeb0bffd9a987 100644 (file)
@@ -82,9 +82,6 @@ void WM_toolsystem_ref_sync_from_context(
 
 void WM_toolsystem_init(struct bContext *C);
 
-int WM_toolsystem_mode_from_spacetype_ex(
-        struct ViewLayer *view_layer, struct ScrArea *sa, int space_type,
-        bool *r_ensure);
 int WM_toolsystem_mode_from_spacetype(
         struct ViewLayer *view_layer, struct ScrArea *sa, int space_type);
 bool WM_toolsystem_key_from_context(
index f070ac59e8f57961c23232fbdc0599927e43f784..4b3b5695a8ebb3f60bfa448173975c9a0f417d31 100644 (file)
@@ -559,12 +559,26 @@ void WM_toolsystem_init(bContext *C)
        /* Rely on screen initialization for gizmos. */
 }
 
-int WM_toolsystem_mode_from_spacetype_ex(
-        ViewLayer *view_layer, ScrArea *sa, int spacetype,
-        bool *r_ensure)
+static bool toolsystem_key_ensure_check(const bToolKey *tkey)
+{
+       switch (tkey->space_type) {
+               case SPACE_VIEW3D:
+                       return true;
+               case SPACE_IMAGE:
+                       if (ELEM(tkey->mode, SI_MODE_PAINT, SI_MODE_UV)) {
+                               return true;
+                       }
+                       break;
+               case SPACE_NODE:
+                       return true;
+       }
+       return false;
+}
+
+int WM_toolsystem_mode_from_spacetype(
+        ViewLayer *view_layer, ScrArea *sa, int spacetype)
 {
        int mode = -1;
-       bool ensure = false;
        switch (spacetype) {
                case SPACE_VIEW3D:
                {
@@ -577,39 +591,23 @@ int WM_toolsystem_mode_from_spacetype_ex(
                        else {
                                mode = CTX_MODE_OBJECT;
                        }
-                       ensure = true;
                        break;
                }
                case SPACE_IMAGE:
                {
                        SpaceImage *sima = sa->spacedata.first;
                        mode = sima->mode;
-                       if (ELEM(mode, SI_MODE_PAINT, SI_MODE_UV)) {
-                               ensure = true;
-                       }
                        break;
                }
                case SPACE_NODE:
                {
                        mode = 0;
-                       ensure = true;
                        break;
                }
        }
-       if (r_ensure) {
-               *r_ensure = ensure;
-       }
        return mode;
 }
 
-int WM_toolsystem_mode_from_spacetype(
-        ViewLayer *view_layer, ScrArea *sa, int spacetype)
-{
-       return WM_toolsystem_mode_from_spacetype_ex(
-               view_layer, sa, spacetype,
-               NULL);
-}
-
 bool WM_toolsystem_key_from_context(
         ViewLayer *view_layer, ScrArea *sa, bToolKey *tkey)
 {
@@ -849,12 +847,11 @@ void WM_toolsystem_update_from_context(
         bContext *C, WorkSpace *workspace, ViewLayer *view_layer,
         ScrArea *sa)
 {
-       bool ensure = false;
        const bToolKey tkey = {
                .space_type = sa->spacetype,
-               .mode = WM_toolsystem_mode_from_spacetype_ex(view_layer, sa, sa->spacetype, &ensure),
+               .mode = WM_toolsystem_mode_from_spacetype(view_layer, sa, sa->spacetype),
        };
-       if (ensure) {
+       if (toolsystem_key_ensure_check(&tkey)) {
                toolsystem_reinit_ensure_toolref(C, workspace, &tkey, NULL);
        }
 }