From d79df6c0bc65e4c94a6fd24160445b98eb408949 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 2 Aug 2018 16:24:22 +1000 Subject: Tool System: sync changes from changes to brushes Changing a brush now updates the tool. --- source/blender/makesrna/intern/rna_workspace_api.c | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source/blender/makesrna/intern/rna_workspace_api.c') 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 -- cgit v1.2.3