Page MenuHome
Paste P2271

Support per tool widget group defaults
ActivePublic

Authored by Campbell Barton (campbellbarton) on Wed, Jul 21, 2:48 PM.
diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py
index 58b20d9e3c8..4783f5ea684 100644
--- a/release/scripts/modules/bpy/utils/__init__.py
+++ b/release/scripts/modules/bpy/utils/__init__.py
@@ -861,6 +861,7 @@ def register_tool(tool_cls, *, after=None, separator=False, group=False):
"icon": getattr(tool_cls, "bl_icon", None),
"cursor": getattr(tool_cls, "bl_cursor", None),
"widget": getattr(tool_cls, "bl_widget", None),
+ "widget_properties": getattr(tool_cls, "bl_widget_properties", None),
"keymap": getattr(tool_cls, "bl_keymap", None),
"data_block": getattr(tool_cls, "bl_data_block", None),
"operator": getattr(tool_cls, "bl_operator", None),
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index cde430c1e6f..b299f05475b 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -75,6 +75,8 @@ ToolDef = namedtuple(
"icon",
# An optional cursor to use when this tool is active.
"cursor",
+ # The properties to use for the widget.
+ "widget_properties",
# An optional gizmo group to activate when the tool is set or None for no gizmo.
"widget",
# Optional key-map for tool, possible values are:
@@ -132,6 +134,7 @@ def from_dict(kw_args):
"icon": None,
"cursor": None,
"widget": None,
+ "widget_properties": None,
"keymap": None,
"data_block": None,
"operator": None,
@@ -983,11 +986,13 @@ def _activate_by_item(context, space_type, item, index, *, as_fallback=False):
item_fallback, _index = cls._tool_get_active_by_index(context, select_index)
# End calculating fallback.
+ gizmo_group = item.widget or ""
+
tool.setup(
idname=item.idname,
keymap=item.keymap[0] if item.keymap is not None else "",
cursor=item.cursor or 'DEFAULT',
- gizmo_group=item.widget or "",
+ gizmo_group=gizmo_group,
data_block=item.data_block or "",
operator=item.operator or "",
index=index,
@@ -995,6 +1000,14 @@ def _activate_by_item(context, space_type, item, index, *, as_fallback=False):
keymap_fallback=(item_fallback and item_fallback.keymap and item_fallback.keymap[0]) or "",
)
+ if gizmo_group:
+ gizmo_properties = item.widget_properties
+ if gizmo_properties:
+ props = tool.gizmo_group_properties(gizmo_group)
+ # TODO: support nested assignments as we do for key-maps.
+ for key, value in gizmo_properties.items():
+ setattr(props, key, value)
+
WindowManager = bpy.types.WindowManager
handle_map = _activate_by_item._cursor_draw_handle
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index c55f637f8b2..5dffb117097 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -819,7 +819,10 @@ class _defs_edit_mesh:
idname="builtin.inset_faces",
label="Inset Faces",
icon="ops.mesh.inset",
- widget="VIEW3D_GGT_tool_generic_handle_normal",
+ widget="VIEW3D_GGT_tool_generic_handle_free",
+ widget_properties={
+ "scale": 8.0,
+ },
keymap=(),
draw_settings=draw_settings,
)
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c b/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c
index ad91af73a71..42157b387bb 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c
@@ -36,6 +36,7 @@
#include "WM_toolsystem.h"
#include "RNA_access.h"
+#include "RNA_define.h"
#include "WM_api.h"
#include "WM_message.h"
@@ -72,6 +73,7 @@ static bool WIDGETGROUP_tool_generic_poll(const bContext *C, wmGizmoGroupType *g
static wmGizmo *tool_generic_create_gizmo(const bContext *C, wmGizmoGroup *gzgroup)
{
+
wmGizmo *gz = WM_gizmo_new("GIZMO_GT_button_2d", gzgroup, NULL);
gz->flag |= WM_GIZMO_OPERATOR_TOOL_INIT;
@@ -105,6 +107,13 @@ static wmGizmo *tool_generic_create_gizmo(const bContext *C, wmGizmoGroup *gzgro
struct wmKeyConfig *kc = wm->defaultconf;
gz->keymap = WM_keymap_ensure(kc, tref->runtime->keymap, tref->space_type, RGN_TYPE_WINDOW);
+
+ /* Properties. */
+ PointerRNA gzgt_ptr;
+ if (WM_toolsystem_ref_properties_get_from_gizmo_group(tref, gzgroup->type, &gzgt_ptr)) {
+ const float scale = RNA_float_get(&gzgt_ptr, "scale");
+ gz->scale_basis *= scale;
+ }
return gz;
}
@@ -206,6 +215,8 @@ void VIEW3D_GGT_tool_generic_handle_normal(wmGizmoGroupType *gzgt)
gzgt->setup = WIDGETGROUP_tool_generic_setup;
gzgt->refresh = WIDGETGROUP_tool_generic_refresh;
gzgt->message_subscribe = WIDGETGROUP_gizmo_message_subscribe;
+
+ RNA_def_float(gzgt->srna, "scale", 1.0, 0.0f, 1000.0, "Scale", "", 0.0f, 1000.0f);
}
void VIEW3D_GGT_tool_generic_handle_free(wmGizmoGroupType *gzgt)
@@ -224,6 +235,8 @@ void VIEW3D_GGT_tool_generic_handle_free(wmGizmoGroupType *gzgt)
gzgt->setup = WIDGETGROUP_tool_generic_setup;
gzgt->refresh = WIDGETGROUP_tool_generic_refresh;
gzgt->message_subscribe = WIDGETGROUP_gizmo_message_subscribe;
+
+ RNA_def_float(gzgt->srna, "scale", 1.0, 0.0f, 1000.0, "Scale", "", 0.0f, 1000.0f);
}
/** \} */