Blender V4.3
wm_gizmo_target_props.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
9#include "BLI_listbase.h"
10
11#include "BKE_context.hh"
12
13#include "MEM_guardedalloc.h"
14
15#include "RNA_access.hh"
16
17#include "WM_message.hh"
18#include "WM_types.hh"
19
20#include "ED_screen.hh"
21
22#include "ANIM_keyframing.hh"
23
24/* Own includes. */
25
26/* -------------------------------------------------------------------- */
34
39
41{
42 BLI_assert(index < gz->type->target_property_defs_len);
43 BLI_assert(index != -1);
45 return &gz_prop_array[index];
46}
47
49{
50 int index = BLI_findstringindex(
52 if (index != -1) {
53 return WM_gizmo_target_property_at_index(gz, index);
54 }
55 return nullptr;
56}
57
59 const wmGizmoPropertyType *gz_prop_type,
61 PropertyRNA *prop,
62 int index)
63{
65
66 /* If gizmo evokes an operator we cannot use it for property manipulation. */
68 BLI_assert(prop != nullptr);
69
70 gz_prop->type = gz_prop_type;
71
72 gz_prop->ptr = *ptr;
73 gz_prop->prop = prop;
74 gz_prop->index = index;
75
76 if (gz->type->property_update) {
77 gz->type->property_update(gz, gz_prop);
78 }
79}
80
82 wmGizmo *gz, const char *idname, PointerRNA *ptr, const char *propname, int index)
83{
84 const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname);
85 PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
86 if (prop == nullptr) {
87 RNA_warning("%s: %s.%s not found", __func__, RNA_struct_identifier(ptr->type), propname);
88 }
89 WM_gizmo_target_property_def_rna_ptr(gz, gz_prop_type, ptr, prop, index);
90}
91
93 const wmGizmoPropertyType *gz_prop_type,
95{
97
98 /* If gizmo evokes an operator we cannot use it for property manipulation. */
100
101 gz_prop->type = gz_prop_type;
102
103 gz_prop->custom_func.value_get_fn = params->value_get_fn;
104 gz_prop->custom_func.value_set_fn = params->value_set_fn;
105 gz_prop->custom_func.range_get_fn = params->range_get_fn;
106 gz_prop->custom_func.free_fn = params->free_fn;
107 gz_prop->custom_func.user_data = params->user_data;
108
109 if (gz->type->property_update) {
110 gz->type->property_update(gz, gz_prop);
111 }
112}
113
115 const char *idname,
117{
118 const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname);
120}
121
123{
125
126 /* If gizmo evokes an operator we cannot use it for property manipulation. */
128
129 gz_prop->type = nullptr;
130
131 gz_prop->ptr = PointerRNA_NULL;
132 gz_prop->prop = nullptr;
133 gz_prop->index = -1;
134}
135
136void WM_gizmo_target_property_clear_rna(wmGizmo *gz, const char *idname)
137{
138 const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname);
140}
141
144/* -------------------------------------------------------------------- */
149{
151 for (int i = 0; i < gz->type->target_property_defs_len; i++) {
152 wmGizmoProperty *gz_prop = &gz_prop_array[i];
154 return true;
155 }
156 }
157 return false;
158}
159
161{
162 return ((gz_prop->prop != nullptr) ||
163 (gz_prop->custom_func.value_get_fn && gz_prop->custom_func.value_set_fn));
164}
165
167{
168 if (gz_prop->custom_func.value_get_fn) {
169 float value = 0.0f;
170 BLI_assert(gz_prop->type->array_length == 1);
171 gz_prop->custom_func.value_get_fn(gz, gz_prop, &value);
172 return value;
173 }
174
175 if (gz_prop->index == -1) {
176 return RNA_property_float_get(&gz_prop->ptr, gz_prop->prop);
177 }
178 return RNA_property_float_get_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index);
179}
180
182 const wmGizmo *gz,
183 wmGizmoProperty *gz_prop,
184 const float value)
185{
186 if (gz_prop->custom_func.value_set_fn) {
187 BLI_assert(gz_prop->type->array_length == 1);
188 gz_prop->custom_func.value_set_fn(gz, gz_prop, &value);
189 return;
190 }
191
192 /* Reset property. */
193 if (gz_prop->index == -1) {
194 RNA_property_float_set(&gz_prop->ptr, gz_prop->prop, value);
195 }
196 else {
197 RNA_property_float_set_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index, value);
198 }
199 RNA_property_update(C, &gz_prop->ptr, gz_prop->prop);
200}
201
203 wmGizmoProperty *gz_prop,
204 float *value)
205{
206 if (gz_prop->custom_func.value_get_fn) {
207 gz_prop->custom_func.value_get_fn(gz, gz_prop, value);
208 return;
209 }
210 RNA_property_float_get_array(&gz_prop->ptr, gz_prop->prop, value);
211}
212
214 const wmGizmo *gz,
215 wmGizmoProperty *gz_prop,
216 const float *value)
217{
218 if (gz_prop->custom_func.value_set_fn) {
219 gz_prop->custom_func.value_set_fn(gz, gz_prop, value);
220 return;
221 }
222 RNA_property_float_set_array(&gz_prop->ptr, gz_prop->prop, value);
223
224 RNA_property_update(C, &gz_prop->ptr, gz_prop->prop);
225}
226
228 wmGizmoProperty *gz_prop,
229 float range[2])
230{
231 if (gz_prop->custom_func.value_get_fn) {
232 if (gz_prop->custom_func.range_get_fn) {
233 gz_prop->custom_func.range_get_fn(gz, gz_prop, range);
234 return true;
235 }
236 return false;
237 }
238
239 float step, precision;
241 &gz_prop->ptr, gz_prop->prop, &range[0], &range[1], &step, &precision);
242 return true;
243}
244
246{
247 if (gz_prop->custom_func.value_get_fn) {
248 return gz_prop->type->array_length;
249 }
250 return RNA_property_array_length(&gz_prop->ptr, gz_prop->prop);
251}
252
255/* -------------------------------------------------------------------- */
260 const char *idname)
261{
262 return static_cast<const wmGizmoPropertyType *>(
264}
265
267 const char *idname,
268 int data_type,
269 int array_length)
270{
271
272 BLI_assert(WM_gizmotype_target_property_find(gzt, idname) == nullptr);
273
274 const uint idname_size = strlen(idname) + 1;
275 wmGizmoPropertyType *gz_prop_type = static_cast<wmGizmoPropertyType *>(
276 MEM_callocN(sizeof(wmGizmoPropertyType) + idname_size, __func__));
277 memcpy(gz_prop_type->idname, idname, idname_size);
278 gz_prop_type->data_type = data_type;
279 gz_prop_type->array_length = array_length;
280 gz_prop_type->index_in_type = gzt->target_property_defs_len;
281 gzt->target_property_defs_len += 1;
282 BLI_addtail(&gzt->target_property_defs, gz_prop_type);
283}
284
287/* -------------------------------------------------------------------- */
292 wmMsgSubscribeKey * /*msg_key*/,
293 wmMsgSubscribeValue *msg_val)
294{
295 ARegion *region = static_cast<ARegion *>(msg_val->owner);
296 wmGizmoMap *gzmap = static_cast<wmGizmoMap *>(msg_val->user_data);
297
298 /* Could possibly avoid a full redraw and only tag for editor overlays
299 * redraw in some cases, see #ED_region_tag_redraw_editor_overlays(). */
300 ED_region_tag_redraw(region);
301
303}
304
306{
309 for (int i = 0; i < gz->type->target_property_defs_len; i++) {
310 wmGizmoProperty *gz_prop = &gz_prop_array[i];
312 if (gz_prop->prop) {
313 {
314 wmMsgSubscribeValue value{};
315 value.owner = region;
316 value.user_data = region;
318 WM_msg_subscribe_rna(mbus, &gz_prop->ptr, gz_prop->prop, &value, __func__);
319 }
320 {
321 wmMsgSubscribeValue value{};
322 value.owner = region;
323 value.user_data = gz->parent_gzgroup->parent_gzmap;
325 WM_msg_subscribe_rna(mbus, &gz_prop->ptr, gz_prop->prop, &value, __func__);
326 }
327 }
328 }
329 }
330 }
331}
332
334 const wmGizmo * /*gz*/,
335 wmGizmoProperty *gz_prop)
336{
337 if (gz_prop->prop != nullptr) {
338 Scene *scene = CTX_data_scene(C);
339 const float cfra = float(scene->r.cfra);
340 const int index = gz_prop->index == -1 ? 0 : gz_prop->index;
342 C, scene, &gz_prop->ptr, gz_prop->prop, index, cfra, false);
343 }
344}
345
Functions to insert, delete or modify keyframes.
Scene * CTX_data_scene(const bContext *C)
#define BLI_assert(a)
Definition BLI_assert.h:50
#define BLI_INLINE
void * BLI_findstring(const struct ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:110
int BLI_findstringindex(const struct ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
unsigned int uint
#define POINTER_OFFSET(v, ofs)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:634
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:381
Read Guarded memory(de)allocation.
#define RNA_warning(format,...)
constexpr PointerRNA PointerRNA_NULL
Definition RNA_types.hh:45
bool is_empty() const
#define offsetof(t, d)
draw_view in_light_buf[] float
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
bool autokeyframe_property(bContext *C, Scene *scene, PointerRNA *ptr, PropertyRNA *prop, int rnaindex, float cfra, bool only_if_property_keyed)
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision)
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
const char * RNA_struct_identifier(const StructRNA *type)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
StructRNA * type
Definition RNA_types.hh:41
wmGizmoMap * parent_gzmap
wmGizmoPropertyFnRangeGet range_get_fn
const wmGizmoPropertyType * type
PropertyRNA * prop
wmGizmoPropertyFnGet value_get_fn
struct wmGizmoProperty::@1373 custom_func
wmGizmoPropertyFnSet value_set_fn
wmGizmoPropertyFnFree free_fn
ListBase target_property_defs
int target_property_defs_len
wmGizmoFnPropertyUpdate property_update
wmGizmoGroup * parent_gzgroup
const wmGizmoType * type
blender::Vector< wmGizmoOpElem, 4 > op_data
PointerRNA * ptr
Definition wm_files.cc:4126
void WM_gizmomap_tag_refresh(wmGizmoMap *gzmap)
void WM_gizmo_target_property_float_set(bContext *C, const wmGizmo *gz, wmGizmoProperty *gz_prop, const float value)
void WM_gizmo_target_property_anim_autokey(bContext *C, const wmGizmo *, wmGizmoProperty *gz_prop)
const wmGizmoPropertyType * WM_gizmotype_target_property_find(const wmGizmoType *gzt, const char *idname)
bool WM_gizmo_target_property_is_valid_any(wmGizmo *gz)
bool WM_gizmo_target_property_is_valid(const wmGizmoProperty *gz_prop)
wmGizmoProperty * WM_gizmo_target_property_array(wmGizmo *gz)
BLI_INLINE wmGizmoProperty * wm_gizmo_target_property_array(wmGizmo *gz)
void WM_gizmo_target_property_float_get_array(const wmGizmo *gz, wmGizmoProperty *gz_prop, float *value)
void WM_gizmo_target_property_clear_rna_ptr(wmGizmo *gz, const wmGizmoPropertyType *gz_prop_type)
int WM_gizmo_target_property_array_length(const wmGizmo *, wmGizmoProperty *gz_prop)
void WM_gizmo_do_msg_notify_tag_refresh(bContext *, wmMsgSubscribeKey *, wmMsgSubscribeValue *msg_val)
void WM_gizmotype_target_property_def(wmGizmoType *gzt, const char *idname, int data_type, int array_length)
void WM_gizmo_target_property_def_func_ptr(wmGizmo *gz, const wmGizmoPropertyType *gz_prop_type, const wmGizmoPropertyFnParams *params)
wmGizmoProperty * WM_gizmo_target_property_at_index(wmGizmo *gz, int index)
void WM_gizmo_target_property_clear_rna(wmGizmo *gz, const char *idname)
void WM_gizmo_target_property_def_rna(wmGizmo *gz, const char *idname, PointerRNA *ptr, const char *propname, int index)
float WM_gizmo_target_property_float_get(const wmGizmo *gz, wmGizmoProperty *gz_prop)
void WM_gizmo_target_property_float_set_array(bContext *C, const wmGizmo *gz, wmGizmoProperty *gz_prop, const float *value)
void WM_gizmo_target_property_subscribe_all(wmGizmo *gz, wmMsgBus *mbus, ARegion *region)
wmGizmoProperty * WM_gizmo_target_property_find(wmGizmo *gz, const char *idname)
void WM_gizmo_target_property_def_rna_ptr(wmGizmo *gz, const wmGizmoPropertyType *gz_prop_type, PointerRNA *ptr, PropertyRNA *prop, int index)
void WM_gizmo_target_property_def_func(wmGizmo *gz, const char *idname, const wmGizmoPropertyFnParams *params)
bool WM_gizmo_target_property_float_range_get(const wmGizmo *gz, wmGizmoProperty *gz_prop, float range[2])
void WM_msg_subscribe_rna(wmMsgBus *mbus, PointerRNA *ptr, const PropertyRNA *prop, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)