Commit: 987d1df57159afd57f33d7e58681be2fcdebda16
Author: Campbell Barton
Date:   Fri May 18 09:35:10 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB987d1df57159afd57f33d7e58681be2fcdebda16

Tool System: store the active tool in ScrArea

Without this we need to have the context to get the
(space_type, mode) args for an active tool lookup.

For event handling & poll its more convenient to have direct access.

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

M       source/blender/blenloader/intern/readfile.c
M       source/blender/editors/mesh/editmesh_extrude.c
M       source/blender/editors/screen/area.c
M       source/blender/editors/transform/transform_manipulator_3d.c
M       source/blender/makesdna/DNA_screen_types.h
M       source/blender/windowmanager/WM_api.h
M       source/blender/windowmanager/intern/wm_event_system.c
M       source/blender/windowmanager/intern/wm_toolsystem.c

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

diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 3d1707f2e77..85c67047be0 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6603,6 +6603,8 @@ static void lib_link_area(FileData *fd, ID *parent_id, 
ScrArea *area)
 {
        area->full = newlibadr(fd, parent_id->lib, area->full);
 
+       memset(&area->runtime, 0x0, sizeof(area->runtime));
+
        for (SpaceLink *sl = area->spacedata.first; sl; sl= sl->next) {
                switch (sl->spacetype) {
                        case SPACE_VIEW3D:
diff --git a/source/blender/editors/mesh/editmesh_extrude.c 
b/source/blender/editors/mesh/editmesh_extrude.c
index 95bf8e89b0e..4841de3c856 100644
--- a/source/blender/editors/mesh/editmesh_extrude.c
+++ b/source/blender/editors/mesh/editmesh_extrude.c
@@ -419,9 +419,8 @@ static void manipulator_mesh_extrude_orientation_matrix_set(
 
 static bool manipulator_mesh_extrude_poll(const bContext *C, 
wmManipulatorGroupType *wgt)
 {
-       WorkSpace *workspace = CTX_wm_workspace(C);
-       const bToolKey tkey = { .space_type = SPACE_VIEW3D, .mode = 
CTX_MODE_EDIT_MESH, };
-       bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_find(workspace, 
&tkey);
+       ScrArea *sa = CTX_wm_area(C);
+       bToolRef_Runtime *tref_rt = sa->runtime.tool ? 
sa->runtime.tool->runtime : NULL;
        if ((tref_rt == NULL) ||
            !STREQ(wgt->idname, tref_rt->manipulator_group) ||
            !ED_operator_editmesh_view3d((bContext *)C))
diff --git a/source/blender/editors/screen/area.c 
b/source/blender/editors/screen/area.c
index 24d6b7c6ecf..4c5ba38984b 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1393,7 +1393,10 @@ void ED_area_update_region_sizes(wmWindowManager *wm, 
wmWindow *win, ScrArea *ar
 /* called in screen_refresh, or screens_init, also area size changes */
 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
 {
-       const bScreen *screen = WM_window_get_active_screen(win);
+       WorkSpace *workspace = WM_window_get_active_workspace(win);
+       const bScreen *screen = 
BKE_workspace_active_screen_get(win->workspace_hook);
+       Scene *scene = WM_window_get_active_scene(win);
+
        const int window_size_x = WM_window_pixels_x(win);
        const int window_size_y = WM_window_pixels_y(win);
        ARegion *ar;
@@ -1452,6 +1455,8 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow 
*win, ScrArea *sa)
                /* Some AZones use View2D data which is only updated in region 
init, so call that first! */
                region_azones_add(screen, sa, ar, ar->alignment & 
~RGN_SPLIT_PREV);
        }
+
+       WM_toolsystem_refresh_screen_area(workspace, scene, sa);
 }
 
 static void region_update_rect(ARegion *ar)
diff --git a/source/blender/editors/transform/transform_manipulator_3d.c 
b/source/blender/editors/transform/transform_manipulator_3d.c
index c24291953c8..8b635bb26db 100644
--- a/source/blender/editors/transform/transform_manipulator_3d.c
+++ b/source/blender/editors/transform/transform_manipulator_3d.c
@@ -1282,15 +1282,9 @@ static void WIDGETGROUP_manipulator_setup(const bContext 
*C, wmManipulatorGroup
        {
                /* TODO: support mixing modes again? - it's supported but tool 
system makes it unobvious. */
                man->twtype = 0;
-               WorkSpace *workspace = CTX_wm_workspace(C);
-               Scene *scene = CTX_data_scene(C);
                ScrArea *sa = CTX_wm_area(C);
-               const bToolKey tkey = {
-                       .space_type = sa->spacetype,
-                       .mode = WM_toolsystem_mode_from_spacetype(workspace, 
scene, NULL, sa->spacetype),
-               };
-               bToolRef_Runtime *tref_rt = 
WM_toolsystem_runtime_find(workspace, &tkey);
-               wmKeyMap *km = WM_keymap_find_all(C, tref_rt->keymap, 
sa->spacetype, RGN_TYPE_WINDOW);
+               bToolRef_Runtime *tref_rt = sa->runtime.tool ? 
sa->runtime.tool->runtime : NULL;
+               wmKeyMap *km = tref_rt ? WM_keymap_find_all(C, tref_rt->keymap, 
sa->spacetype, RGN_TYPE_WINDOW) : NULL;
                /* Weak, check first event */
                wmKeyMapItem *kmi = km ? km->items.first : NULL;
 
diff --git a/source/blender/makesdna/DNA_screen_types.h 
b/source/blender/makesdna/DNA_screen_types.h
index 395fcddb861..1f14bb58e78 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -248,6 +248,12 @@ enum GlobalAreaFlag {
        GLOBAL_AREA_IS_HIDDEN = (1 << 0),
 };
 
+typedef struct ScrArea_Runtime {
+       struct bToolRef *tool;
+       char          is_tool_set;
+       char _pad0[7];
+} ScrArea_Runtime;
+
 typedef struct ScrArea {
        struct ScrArea *next, *prev;
        
@@ -288,6 +294,8 @@ typedef struct ScrArea {
        ListBase handlers;   /* wmEventHandler */
 
        ListBase actionzones;   /* AZone */
+
+       ScrArea_Runtime runtime;
 } ScrArea;
 
 typedef struct ARegion {
diff --git a/source/blender/windowmanager/WM_api.h 
b/source/blender/windowmanager/WM_api.h
index 39132184371..afa6e71e610 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -653,6 +653,9 @@ void WM_tooltip_clear(struct bContext *C, struct wmWindow 
*win);
 void WM_tooltip_init(struct bContext *C, struct wmWindow *win);
 void WM_tooltip_refresh(struct bContext *C, struct wmWindow *win);
 
+void WM_toolsystem_refresh_screen_area(struct WorkSpace *workspace, struct 
Scene *scene, struct ScrArea *sa);
+void WM_toolsystem_refresh_screen_all(struct Main *bmain);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/windowmanager/intern/wm_event_system.c 
b/source/blender/windowmanager/intern/wm_event_system.c
index 8bbbd1b60df..ad10475906d 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -2874,12 +2874,7 @@ void wm_event_do_handlers(bContext *C)
                                                                         */
                                                                        
wmEventHandler sneaky_handler = {NULL};
                                                                        if 
(ar->regiontype == RGN_TYPE_WINDOW) {
-                                                                               
WorkSpace *workspace = WM_window_get_active_workspace(win);
-                                                                               
const bToolKey tkey = {
-                                                                               
        .space_type = sa->spacetype,
-                                                                               
        .mode = WM_toolsystem_mode_from_spacetype(workspace, win->scene, sa, 
sa->spacetype),
-                                                                               
};
-                                                                               
bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_find(workspace, &tkey);
+                                                                               
bToolRef_Runtime *tref_rt = sa->runtime.tool ? sa->runtime.tool->runtime : NULL;
                                                                                
if (tref_rt && tref_rt->keymap[0]) {
                                                                                
        wmKeyMap *km = WM_keymap_find_all(
                                                                                
                C, tref_rt->keymap, sa->spacetype, RGN_TYPE_WINDOW);
diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c 
b/source/blender/windowmanager/intern/wm_toolsystem.c
index 93481dcd56c..122e292985a 100644
--- a/source/blender/windowmanager/intern/wm_toolsystem.c
+++ b/source/blender/windowmanager/intern/wm_toolsystem.c
@@ -54,7 +54,7 @@
 #include "WM_message.h"
 
 static void toolsystem_reinit_with_toolref(
-        bContext *C, WorkSpace *UNUSED(workspace), const bToolRef *tref);
+        bContext *C, WorkSpace *UNUSED(workspace), bToolRef *tref);
 static void toolsystem_reinit_ensure_toolref(
         bContext *C, WorkSpace *workspace, const bToolKey *tkey, const char 
*default_tool);
 
@@ -71,7 +71,12 @@ struct bToolRef *WM_toolsystem_ref_from_context(struct 
bContext *C)
                .space_type = sa->spacetype,
                .mode = WM_toolsystem_mode_from_spacetype(workspace, scene, sa, 
sa->spacetype),
        };
-       return WM_toolsystem_ref_find(workspace, &tkey);
+       bToolRef *tref = WM_toolsystem_ref_find(workspace, &tkey);
+       /* We could return 'sa->runtime.tool' in this case. */
+       if (sa->runtime.is_tool_set) {
+               BLI_assert(tref == sa->runtime.tool);
+       }
+       return tref;
 }
 
 struct bToolRef_Runtime *WM_toolsystem_runtime_from_context(struct bContext *C)
@@ -357,12 +362,71 @@ bool WM_toolsystem_key_from_context(
        return false;
 }
 
-/**
- * Run after changing modes.
- */
+void WM_toolsystem_refresh_screen_area(WorkSpace *workspace, Scene *scene, 
ScrArea *sa)
+{
+       sa->runtime.tool = NULL;
+       sa->runtime.is_tool_set = true;
+       const int mode = WM_toolsystem_mode_from_spacetype(workspace, scene, 
sa, sa->spacetype);
+       for (bToolRef *tref = workspace->tools.first; tref; tref = tref->next) {
+               if ((tref->space_type == sa->spacetype)) {
+                       if (tref->mode == mode) {
+                               sa->runtime.tool = tref;
+                               break;
+                       }
+               }
+       }
+}
+
+void WM_toolsystem_refresh_screen_all(Main *bmain)
+{
+       /* Update all ScrArea's tools */
+       for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
+               for (wmWindow *win = wm->windows.first; win; win = win->next) {
+                       WorkSpace *workspace = 
WM_window_get_active_workspace(win);
+                       bool space_type_has_tools[SPACE_TYPE_LAST + 1] = {0};
+                       for (bToolRef *tref = workspace->tools.first; tref; 
tref = tref->next) {
+                               space_type_has_tools[tref->space_type] = true;
+                       }
+                       bScreen *screen = WM_window_get_active_screen(win);
+                       Scene *scene = WM_window_get_active_scene(win);
+                       for (ScrArea *sa = screen->areabase.first; sa; sa = 
sa->next) {
+                               sa->runtime.tool = NULL;
+                               sa->runtime.is_tool_set = true;
+                               if (space_type_has_tools[sa->spacetype]) {
+                                       
WM_toolsystem_refresh_screen_area(workspace, scene, sa);
+                               }
+                       }
+               }
+       }
+}
+
+static void toolsystem_refresh_screen_from_active_tool(
+        Main *bmain, WorkSpace *workspace, bToolRef *tref)
+{
+       /* Update all ScrArea's tools */
+       for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
+               for (wmWindow *win = wm->windows.first; win; win = win->next) {
+                       if (workspace == WM_window_get_active_workspace(win)) {
+                               bScreen *screen = 
WM_window_get_active_screen(win);
+                               Scene *scene = WM_window_get_active_scene(win);
+                               for (ScrArea *sa = screen->areabase.first; sa; 
sa = sa->next) {
+                                       if (sa->spacetype == tref->space_type) {
+                                               int mode = 
WM_toolsystem_mode_from_spacetype(workspace, scene, sa, sa->spacetype);
+                                               if (mode == tref->mode) {
+                                                       sa->runtime.tool = tref;
+                                                       sa->runtime.is_tool_set 
= true;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
 static void toolsystem_reinit_with_toolref(
-        bContext *C, WorkSpace *UNUSED(workspace), const bToolRef *tref)
+        bContext *C, WorkSpace *workspace, bToolRef *tref)
 {
+
        wmOperatorType *ot = WM_operatortype_find("WM_OT_tool_set_by_name", 
false);
        /* On startup, Python operatores are not yet loaded. */
        if (ot == NULL) {
@@ -374,8 +438,14 @@ static void toolsystem_reinit_with_toolref(
        RNA_enum_set(&op_props, "space_type", tref->sp

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to