From bcb343c59786746076ca199578538f153528cd4e Mon Sep 17 00:00:00 2001 From: Jonas Holzman Date: Fri, 21 Mar 2025 12:20:22 +0100 Subject: [PATCH] Python Templates: Add Gizmo Simple 2D Following discussion to document the `icon_value` property of `GIZMO_GT_button_2d` in PR #136080, and generally improve the documentation of this Gizmo Type, this patch adds a new "Gizmo Simple 2D" Python template, and renames the existing "Gizmo Simple" template to "Gizmo Simple 3D". Pull Request: https://projects.blender.org/blender/blender/pulls/136304 --- scripts/templates_py/gizmo_simple_2d.py | 59 +++++++++++++++++++ .../{gizmo_simple.py => gizmo_simple_3d.py} | 0 2 files changed, 59 insertions(+) create mode 100644 scripts/templates_py/gizmo_simple_2d.py rename scripts/templates_py/{gizmo_simple.py => gizmo_simple_3d.py} (100%) diff --git a/scripts/templates_py/gizmo_simple_2d.py b/scripts/templates_py/gizmo_simple_2d.py new file mode 100644 index 00000000000..d1200cfe5e0 --- /dev/null +++ b/scripts/templates_py/gizmo_simple_2d.py @@ -0,0 +1,59 @@ +# Example of a group that lets you move an object in the 3D view +# using the default translate transform operator. +# +# Usage: Select and object and drag the Gizmo to +# move it in the 3D Viewport. +# +import bpy +from bpy.types import ( + GizmoGroup, +) + + +class MyTranslateWidgetGroup(GizmoGroup): + bl_idname = "OBJECT_GGT_translate_test" + bl_label = "Test Translate Widget" + bl_space_type = 'VIEW_3D' + bl_region_type = 'WINDOW' + bl_options = {'PERSISTENT', 'SCALE'} + + @classmethod + def poll(cls, context): + ob = context.object + return ob is not None + + def draw_prepare(self, context): + region = context.region + + # Place the Gizmo in the lower center of the 3D Viewport. + self.translate_gizmo.matrix_basis[0][3] = region.width / 2 + self.translate_gizmo.matrix_basis[1][3] = region.height / 16 + + def setup(self, context): + gz = self.gizmos.new("GIZMO_GT_button_2d") + gz.target_set_operator("transform.translate") + gz.draw_options = {'BACKDROP', 'OUTLINE'} + + gz.color = 0.0, 0.5, 1.0 + gz.alpha = 0.2 + gz.backdrop_fill_alpha = 0.1 + + gz.color_highlight = 1.0, 0.5, 0.0 + gz.alpha_highlight = 0.8 + + gz.use_tooltip = True + gz.line_width = 1.5 + + # Same as buttons defined in C++ code. + gz.scale_basis = (80 * 0.35) / 2 + + # Show a dragging mouse cursor when hovering the gizmo. + gz.show_drag = True + + # Can also use gz.icon_value to use a custom/generated preview icon. + gz.icon = 'EMPTY_ARROWS' + + self.translate_gizmo = gz + + +bpy.utils.register_class(MyTranslateWidgetGroup) diff --git a/scripts/templates_py/gizmo_simple.py b/scripts/templates_py/gizmo_simple_3d.py similarity index 100% rename from scripts/templates_py/gizmo_simple.py rename to scripts/templates_py/gizmo_simple_3d.py