Tool System: sync changes from changes to brushes

Changing a brush now updates the tool.
This commit is contained in:
Campbell Barton
2018-08-02 16:24:22 +10:00
parent d3c387d605
commit d79df6c0bc
3 changed files with 37 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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