Blender V5.3
view3d_gizmo_tool_generic.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "BLI_math_vector_c.hh"
11#include "BLI_utildefines.hh"
12
13#include "BKE_context.hh"
14#include "BKE_global.hh"
15
16#include "ED_gizmo_library.hh"
17#include "ED_gizmo_utils.hh"
18#include "ED_screen.hh"
19#include "ED_transform.hh"
20
21#include "UI_resources.hh"
22
23#include "MEM_guardedalloc.h"
24
25#include "RNA_access.hh"
26#include "RNA_define.hh"
27
28#include "WM_api.hh"
29#include "WM_message.hh"
30#include "WM_toolsystem.hh"
31#include "WM_types.hh"
32
33#include "view3d_intern.hh" /* own include */
34
35namespace blender {
36
37static const char *handle_normal_id = "VIEW3D_GGT_tool_generic_handle_normal";
38static const char *handle_free_id = "VIEW3D_GGT_tool_generic_handle_free";
39
40static const float handle_normal_radius_default = 100.0f;
41static const float handle_free_radius_default = 36.0f;
42
43/* -------------------------------------------------------------------- */
46
48{
50 return false;
51 }
52
53 View3D *v3d = CTX_wm_view3d(C);
55 return false;
56 }
57
58 /* Without this, refreshing the gizmo jitters in some cases with edit-mesh smooth. See #72948. */
59 if (G.moving & G_TRANSFORM_EDIT) {
60 return false;
61 }
62
63 return true;
64}
65
67{
68
69 wmGizmo *gz = WM_gizmo_new("GIZMO_GT_button_2d", gzgroup, nullptr);
71
74
76
77 RNA_enum_set(gz->ptr, "icon", ICON_NONE);
78
79 bToolRef *tref = WM_toolsystem_ref_from_context(const_cast<bContext *>(C));
80 PointerRNA gzgt_ptr;
81 const bool gzgt_ptr_is_valid = WM_toolsystem_ref_properties_get_from_gizmo_group(
82 tref, gzgroup->type, &gzgt_ptr);
83
84 if (gzgroup->type->idname == handle_normal_id) {
85 const float radius = (gzgt_ptr_is_valid ? RNA_float_get(&gzgt_ptr, "radius") :
87 12.0f;
88
89 gz->scale_basis = radius / U.gizmo_size;
90 gz->matrix_offset[3][2] -= 12.0;
91 RNA_enum_set(gz->ptr,
92 "draw_options",
95 }
96 else {
97 const float radius = gzgt_ptr_is_valid ? RNA_float_get(&gzgt_ptr, "radius") :
99
100 gz->scale_basis = radius / U.gizmo_size;
101
102 RNA_enum_set(gz->ptr, "draw_options", ED_GIZMO_BUTTON_SHOW_BACKDROP);
103
104 /* Make the center low alpha. */
105 WM_gizmo_set_line_width(gz, 2.0f);
106 RNA_float_set(gz->ptr,
107 "backdrop_fill_alpha",
108 gzgt_ptr_is_valid ? RNA_float_get(&gzgt_ptr, "backdrop_fill_alpha") : 0.125f);
109 }
110
112 wmKeyConfig *kc = wm->runtime->defaultconf;
113
115 return gz;
116}
117
119{
121 wwrapper->gizmo = tool_generic_create_gizmo(C, gzgroup);
122 gzgroup->customdata = wwrapper;
123
124 /* The tool handles undo, no need to set #WM_GIZMO_NEEDS_UNDO. */
125}
126
128{
129 wmGizmoWrapper *wwrapper = static_cast<wmGizmoWrapper *>(gzgroup->customdata);
130 wmGizmo *gz = wwrapper->gizmo;
131
135 return;
136 }
137
138 /* skip, we don't draw anything anyway */
139 {
140 int orientation;
141 if (gzgroup->type->idname == handle_normal_id) {
142 orientation = V3D_ORIENT_NORMAL;
143 }
144 else {
145 orientation = V3D_ORIENT_GLOBAL; /* dummy, use view. */
146 }
147
148 RegionView3D *rv3d = static_cast<RegionView3D *>(CTX_wm_region_data(C));
151 params.use_only_center = true;
152 params.orientation_index = orientation + 1;
153 const bool hide = ed::transform::calc_gizmo_stats(C, &params, &tbounds, rv3d) == 0;
154
156 if (hide) {
157 return;
158 }
159 copy_m4_m3(gz->matrix_basis, tbounds.axis);
160 copy_v3_v3(gz->matrix_basis[3], tbounds.center);
161 negate_v3(gz->matrix_basis[2]);
162 }
163
165}
166
168 wmGizmoGroup *gzgroup,
169 wmMsgBus *mbus)
170{
171 ARegion *region = CTX_wm_region(C);
172
173 wmMsgSubscribeValue msg_sub_value_gz_tag_refresh{};
174 msg_sub_value_gz_tag_refresh.owner = region;
175 msg_sub_value_gz_tag_refresh.user_data = gzgroup->parent_gzmap;
176 msg_sub_value_gz_tag_refresh.notify = WM_gizmo_do_msg_notify_tag_refresh;
177
178 {
179 const PropertyRNA *props[] = {
180 &rna_ToolSettings_workspace_tool_type,
181 };
182
183 Scene *scene = CTX_data_scene(C);
184 PointerRNA toolsettings_ptr = RNA_pointer_create_discrete(
185 &scene->id, RNA_ToolSettings, scene->toolsettings);
186
187 for (int i = 0; i < ARRAY_SIZE(props); i++) {
189 mbus, &toolsettings_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__);
190 }
191 }
192}
193
195{
196 gzgt->name = "Generic Tool Widget Normal";
197 gzgt->idname = handle_normal_id;
198
201
204
209
210 RNA_def_float(gzgt->srna,
211 "radius",
213 0.0f,
214 1000.0,
215 "Radius",
216 "Radius in pixels",
217 0.0f,
218 1000.0f);
219}
220
222{
223 gzgt->name = "Generic Tool Widget Free";
224 gzgt->idname = handle_free_id;
225
226 /* Don't use 'WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK' here since this style of gizmo
227 * is better suited to being activated immediately. */
229
232
237
238 RNA_def_float(gzgt->srna,
239 "radius",
241 0.0f,
242 1000.0,
243 "Radius",
244 "Radius in pixels",
245 0.0f,
246 1000.0f);
248 gzgt->srna, "backdrop_fill_alpha", 0.125, 0.0f, 1.0f, "Backdrop Alpha", "", 0.0f, 1.0f);
249}
250
252
253} // namespace blender
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define WM_toolsystem_ref_properties_get_from_gizmo_group(tref, gzgroup, r_ptr)
int calc_gizmo_stats(const bContext *C, const TransformCalcParams *params, TransformBounds *tbounds, RegionView3D *rv3d)
void get_color_3fv(int colorid, float col[3])
BMesh Iterators.
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
UserDef U
Definition blender.cc:58
void WM_gizmo_do_msg_notify_tag_refresh(bContext *, wmMsgSubscribeKey *, wmMsgSubscribeValue *msg_val)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void copy_m4_m3(float m1[4][4], const float m2[3][3])
static bool WIDGETGROUP_tool_generic_poll(const bContext *C, wmGizmoGroupType *gzgt)
static void WIDGETGROUP_tool_generic_refresh(const bContext *C, wmGizmoGroup *gzgroup)
static const char * handle_free_id
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
void WM_gizmo_set_line_width(wmGizmo *gz, const float line_width)
Definition wm_gizmo.cc:318
void * CTX_wm_region_data(const bContext *C)
Global G
Definition blender.cc:57
void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable)
Definition wm_gizmo.cc:303
void VIEW3D_GGT_tool_generic_handle_free(wmGizmoGroupType *gzgt)
wmWindowManager * CTX_wm_manager(const bContext *C)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
MINLINE void negate_v3(float r[3])
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
void unit_m4(float m[4][4])
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
ToolSettings * CTX_data_tool_settings(const bContext *C)
wmGizmo * WM_gizmo_new(const StringRef idname, wmGizmoGroup *gzgroup, PointerRNA *properties)
Definition wm_gizmo.cc:97
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
@ SCE_WORKSPACE_TOOL_FALLBACK
void WM_msg_subscribe_rna(wmMsgBus *mbus, PointerRNA *ptr, const PropertyRNA *prop, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
@ WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK
@ WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP
@ WM_GIZMO_OPERATOR_TOOL_INIT
@ WM_GIZMO_DRAW_OFFSET_SCALE
void VIEW3D_GGT_tool_generic_handle_normal(wmGizmoGroupType *gzgt)
static const float handle_normal_radius_default
bToolRef * WM_toolsystem_ref_from_context(const bContext *C)
static const char * handle_normal_id
@ G_TRANSFORM_EDIT
Scene * CTX_data_scene(const bContext *C)
static void WIDGETGROUP_tool_generic_setup(const bContext *C, wmGizmoGroup *gzgroup)
static wmGizmo * tool_generic_create_gizmo(const bContext *C, wmGizmoGroup *gzgroup)
static const float handle_free_radius_default
bool ED_gizmo_poll_or_unlink_delayed_from_tool(const bContext *C, wmGizmoGroupType *gzgt)
@ ED_GIZMO_BUTTON_SHOW_BACKDROP
@ ED_GIZMO_BUTTON_SHOW_OUTLINE
@ ED_GIZMO_BUTTON_SHOW_HELPLINE
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
ARegion * CTX_wm_region(const bContext *C)
float RNA_float_get(PointerRNA *ptr, const char *name)
View3D * CTX_wm_view3d(const bContext *C)
static void WIDGETGROUP_gizmo_message_subscribe(const bContext *C, wmGizmoGroup *gzgroup, wmMsgBus *mbus)
struct ToolSettings * toolsettings
eView3D_GizmoFlag gizmo_flag
bToolRef_Runtime * runtime
wmGizmoGroupFnMsgBusSubscribe message_subscribe
wmGizmoGroupFnRefresh refresh
wmGizmoMapType_Params gzmap_params
eWM_GizmoFlagGroupTypeFlag flag
wmGizmoGroupType * type
float matrix_basis[4][4]
float matrix_offset[4][4]
eWM_GizmoFlag flag