[Bf-blender-cvs] [d79df6c0bc6] blender2.8: Tool System: sync changes from changes to brushes

Campbell Barton noreply at git.blender.org
Thu Aug 2 11:28:34 CEST 2018


Commit: d79df6c0bc65e4c94a6fd24160445b98eb408949
Author: Campbell Barton
Date:   Thu Aug 2 16:24:22 2018 +1000
Branches: blender2.8
https://developer.blender.org/rBd79df6c0bc65e4c94a6fd24160445b98eb408949

Tool System: sync changes from changes to brushes

Changing a brush now updates the tool.

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

M	release/scripts/startup/bl_ui/space_toolsystem_common.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/makesrna/intern/rna_workspace_api.c

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

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index 4f6e42d4a98..91ded3e4456 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -275,6 +275,7 @@ class ToolSelectPanelHelper:
                 mode = context.mode
             tool = context.workspace.tools.from_space_view3d_mode(mode, create)
             if tool is not None:
+                tool.refresh_from_context()
                 return tool
         elif space_type == 'IMAGE_EDITOR':
             space_data = context.space_data
@@ -282,6 +283,7 @@ class ToolSelectPanelHelper:
                 mode = space_data.mode
             tool = context.workspace.tools.from_space_image_mode(mode, create)
             if tool is not None:
+                tool.refresh_from_context()
                 return tool
         return None
 
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 8ce4a52fbbc..c1d417ef12d 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -66,6 +66,7 @@ def generate_from_brushes_ex(
                     category = brush_type[0]
                     name = brush.name
 
+                    """
                     # rename default brushes for tool bar
                     if name.startswith("Draw "):
                         text = name.replace("Draw ", "")
@@ -75,6 +76,8 @@ def generate_from_brushes_ex(
                         text = name.replace(" Area", "")
                     else:
                         text = name
+                    """
+                    text = name
 
                     # define icon
                     gp_icon = brush.gpencil_settings.gp_icon
diff --git a/source/blender/makesrna/intern/rna_workspace_api.c b/source/blender/makesrna/intern/rna_workspace_api.c
index 98e84f60b33..4469b88da6d 100644
--- a/source/blender/makesrna/intern/rna_workspace_api.c
+++ b/source/blender/makesrna/intern/rna_workspace_api.c
@@ -41,6 +41,8 @@
 
 #ifdef RNA_RUNTIME
 
+#include "BKE_paint.h"
+
 #include "ED_screen.h"
 
 static void rna_WorkspaceTool_setup(
@@ -68,6 +70,34 @@ static void rna_WorkspaceTool_setup(
 	WM_toolsystem_ref_set_from_runtime(C, (WorkSpace *)id, tref, &tref_rt, name);
 }
 
+static void rna_WorkspaceTool_refresh_from_context(
+        ID *id,
+        bToolRef *tref,
+        Main *bmain)
+{
+	bToolRef_Runtime *tref_rt = tref->runtime;
+	if ((tref_rt == NULL) || (tref_rt->data_block[0] == '\0')) {
+		return;
+	}
+	wmWindowManager *wm = bmain->wm.first;
+	for (wmWindow *win = wm->windows.first; win; win = win->next) {
+		WorkSpace *workspace = WM_window_get_active_workspace(win);
+		if (&workspace->id == id) {
+			Scene *scene = WM_window_get_active_scene(win);
+			ViewLayer *view_layer = WM_window_get_active_view_layer(win);
+			Paint *paint = BKE_paint_get_active(scene, view_layer);
+			if (paint) {
+				const ID *brush = (ID *)paint->brush;
+				if (!STREQ(tref_rt->data_block, brush->name + 2)) {
+					STRNCPY(tref_rt->data_block, brush->name + 2);
+					STRNCPY(tref->idname, brush->name + 2);
+					printf("Found\n");
+				}
+			}
+		}
+	}
+}
+
 static PointerRNA rna_WorkspaceTool_operator_properties(
         bToolRef *tref,
         const char *idname)
@@ -124,6 +154,8 @@ void RNA_api_workspace_tool(StructRNA *srna)
 	RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR);
 	RNA_def_function_return(func, parm);
 
+	func = RNA_def_function(srna, "refresh_from_context", "rna_WorkspaceTool_refresh_from_context");
+	RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN);
 }
 
 #endif



More information about the Bf-blender-cvs mailing list