diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-04-29 15:30:09 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-04-29 15:30:09 +0300 |
commit | 6e76a35f07bb7e5c277347175804bb359b8f0477 (patch) | |
tree | 08b3ba9ddf39e7aadec5c838ecca9c2506e31756 | |
parent | f4ba7667dc34edc3fbd1118f8f0dbe818a8e7d43 (diff) |
Tool System: support data-blocks in tools
Needed so tools can set the active brush.
5 files changed, 33 insertions, 6 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py index f3ff59718ce..d5d921a64bc 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_common.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py @@ -79,12 +79,11 @@ class ToolDef: # All classes must have a name assert(cls.text is not None) # We must have a key-map or widget (otherwise the tool does nothing!) - assert(cls.keymap is not None or cls.widget is not None) + assert(not (cls.keymap is None and cls.widget is None and cls.data_block is None)) if type(cls.keymap) is tuple: cls.keymap = _keymap_fn_from_seq(cls.keymap) - # The name to display in the interface. text = None # The name of the icon to use (found in ``release/datafiles/icons``) or None for no icon. @@ -96,6 +95,9 @@ class ToolDef: # - A tuple filled with triple's of: # ``(operator_id, operator_properties, keymap_item_args)``. keymap = None + # Optional data-block assosiated with this tool. + # (Typically brush name, usage depends on mode, we could use for non-brush ID's in other modes). + data_block = None # Optional draw settings (operator options, toolsettings). draw_settings = None @@ -166,6 +168,7 @@ class ToolSelectPanelHelper: text = item.text icon_name = item.icon mp_idname = item.widget + datablock_idname = item.data_block keymap_fn = item.keymap if keymap_fn is None: km, km_idname = (None, None) @@ -174,13 +177,15 @@ class ToolSelectPanelHelper: if km_test is None and context_mode is not None: km_test = cls._tool_keymap[None, text] km, km_idname = km_test - return (km_idname, mp_idname), icon_name + return (km_idname, mp_idname, datablock_idname), icon_name @staticmethod def _tool_vars_from_active_with_index(context): workspace = context.workspace return ( - (workspace.tool_keymap or None, workspace.tool_manipulator_group or None), + (workspace.tool_keymap or None, + workspace.tool_manipulator_group or None, + workspace.tool_data_block or None), workspace.tool_index, ) @@ -387,6 +392,7 @@ class ToolSelectPanelHelper: tool_def, icon_name = self._tool_vars_from_def(item, context_mode) is_active = (tool_def == tool_def_active) + icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(icon_name) sub = ui_gen.send(False) @@ -408,6 +414,7 @@ class ToolSelectPanelHelper: ) props.keymap = tool_def[0] or "" props.manipulator_group = tool_def[1] or "" + props.data_block = tool_def[2] or "" props.index = index # Signal to finish any remaining layout edits. ui_gen.send(None) @@ -507,6 +514,7 @@ class WM_MT_toolsystem_submenu(Menu): ) props.keymap = tool_def[0] or "" props.manipulator_group = tool_def[1] or "" + props.data_block = tool_def[2] or "" props.index = index index += 1 diff --git a/source/blender/makesdna/DNA_workspace_types.h b/source/blender/makesdna/DNA_workspace_types.h index 1f1c69ad083..4cc3929b4ea 100644 --- a/source/blender/makesdna/DNA_workspace_types.h +++ b/source/blender/makesdna/DNA_workspace_types.h @@ -54,9 +54,11 @@ #define USE_WORKSPACE_TOOL typedef struct bToolDef { - /* either the keymap AND/OR manipulator_group must be defined. */ + /* One of these must be defined. */ char keymap[64]; char manipulator_group[64]; + char data_block[64]; + int spacetype; /* index when a tool is a member of a group */ int index; diff --git a/source/blender/makesrna/intern/rna_workspace.c b/source/blender/makesrna/intern/rna_workspace.c index 47c8254b015..b82ca145f5f 100644 --- a/source/blender/makesrna/intern/rna_workspace.c +++ b/source/blender/makesrna/intern/rna_workspace.c @@ -187,6 +187,11 @@ static void rna_def_workspace(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Active Tool", "Currently active tool manipulator"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); + prop = RNA_def_property(srna, "tool_data_block", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "tool.data_block"); + RNA_def_property_ui_text(prop, "Active Tool", "Currently active data-block"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + prop = RNA_def_property(srna, "tool_index", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "tool.index"); RNA_def_property_ui_text(prop, "Active Tool Index", "Tool group index"); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 4c96afff9a1..67db38c13ed 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1828,6 +1828,7 @@ static int wm_operator_tool_set_exec(bContext *C, wmOperator *op) tool_def.spacetype = sa->spacetype; RNA_string_get(op->ptr, "keymap", tool_def.keymap); RNA_string_get(op->ptr, "manipulator_group", tool_def.manipulator_group); + RNA_string_get(op->ptr, "data_block", tool_def.data_block); WM_toolsystem_set(C, &tool_def); @@ -1849,6 +1850,7 @@ static void WM_OT_tool_set(wmOperatorType *ot) RNA_def_string(ot->srna, "keymap", NULL, KMAP_MAX_NAME, "Key Map", ""); RNA_def_string(ot->srna, "manipulator_group", NULL, MAX_NAME, "Manipulator Group", ""); + RNA_def_string(ot->srna, "data_block", NULL, MAX_NAME, "Data Block", ""); RNA_def_int(ot->srna, "index", 0, INT_MIN, INT_MAX, "Index", "", INT_MIN, INT_MAX); } #endif /* USE_WORKSPACE_TOOL */ diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c index 22643c63368..7934d238cfb 100644 --- a/source/blender/windowmanager/intern/wm_toolsystem.c +++ b/source/blender/windowmanager/intern/wm_toolsystem.c @@ -37,6 +37,7 @@ #include "BKE_context.h" #include "BKE_library.h" #include "BKE_main.h" +#include "BKE_paint.h" #include "RNA_access.h" @@ -73,11 +74,19 @@ void WM_toolsystem_unlink(bContext *C, WorkSpace *workspace) } } -void WM_toolsystem_link(bContext *UNUSED(C), WorkSpace *workspace) +void WM_toolsystem_link(bContext *C, WorkSpace *workspace) { if (workspace->tool.manipulator_group[0]) { WM_manipulator_group_type_ensure(workspace->tool.manipulator_group); } + if (workspace->tool.data_block[0]) { + /* Currently only brush data-blocks supported. */ + Paint *p = BKE_paint_get_active_from_context(C); + struct Brush *brush = (struct Brush *)BKE_libblock_find_name(ID_BR, workspace->tool.data_block); + if (brush) { + BKE_paint_brush_set(p, brush); + } + } } void WM_toolsystem_set(bContext *C, const bToolDef *tool) @@ -92,6 +101,7 @@ void WM_toolsystem_set(bContext *C, const bToolDef *tool) if (&workspace->tool != tool) { BLI_strncpy(workspace->tool.keymap, tool->keymap, sizeof(tool->keymap)); BLI_strncpy(workspace->tool.manipulator_group, tool->manipulator_group, sizeof(tool->manipulator_group)); + BLI_strncpy(workspace->tool.data_block, tool->data_block, sizeof(tool->data_block)); workspace->tool.spacetype = tool->spacetype; } |