Blender V5.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
8
9#include "BLI_listbase.hh"
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_keyframes_edit.hh"
21#include "ED_screen.hh"
22
23#include "ANIM_keyframing.hh"
24
25namespace blender {
26
27/* Own includes. */
28
29/* -------------------------------------------------------------------- */
32
34{
37 if (index != -1) {
38 return &gz->target_properties[index];
39 }
40 return nullptr;
41}
42
44 const wmGizmoPropertyType *gz_prop_type,
45 PointerRNA *ptr,
46 PropertyRNA *prop,
47 int index)
48{
49 wmGizmoProperty *gz_prop = &gz->target_properties[gz_prop_type->index_in_type];
50
51 /* If gizmo evokes an operator we cannot use it for property manipulation. */
52 BLI_assert(gz->op_data.is_empty());
53 BLI_assert(prop != nullptr);
54
55 gz_prop->type = gz_prop_type;
56
57 gz_prop->ptr = *ptr;
58 gz_prop->prop = prop;
59 gz_prop->index = index;
60
61 if (gz->type->property_update) {
62 gz->type->property_update(gz, gz_prop);
63 }
64}
65
67 wmGizmo *gz, const char *idname, PointerRNA *ptr, const char *propname, int index)
68{
69 const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname);
70 PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
71 if (prop == nullptr) {
72 RNA_warning("%s: %s.%s not found", __func__, RNA_struct_identifier(ptr->type), propname);
73 }
74 WM_gizmo_target_property_def_rna_ptr(gz, gz_prop_type, ptr, prop, index);
75}
76
78 const wmGizmoPropertyType *gz_prop_type,
79 const wmGizmoPropertyFnParams *params)
80{
81 wmGizmoProperty *gz_prop = &gz->target_properties[gz_prop_type->index_in_type];
82
83 /* If gizmo evokes an operator we cannot use it for property manipulation. */
84 BLI_assert(gz->op_data.is_empty());
85
86 /* Unlikely, but shouldn't leak memory. */
87 if (gz_prop->custom_func.free_fn) {
88 gz_prop->custom_func.free_fn(gz, gz_prop);
89 }
90
91 gz_prop->type = gz_prop_type;
92
93 gz_prop->custom_func.value_get_fn = params->value_get_fn;
94 gz_prop->custom_func.value_set_fn = params->value_set_fn;
95 gz_prop->custom_func.range_get_fn = params->range_get_fn;
96 gz_prop->custom_func.free_fn = params->free_fn;
97 gz_prop->custom_func.foreach_rna_prop_fn = params->foreach_rna_prop_fn;
98 gz_prop->custom_func.user_data = params->user_data;
99
100 if (gz->type->property_update) {
101 gz->type->property_update(gz, gz_prop);
102 }
103}
104
106 const char *idname,
107 const wmGizmoPropertyFnParams *params)
108{
109 const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname);
110 WM_gizmo_target_property_def_func_ptr(gz, gz_prop_type, params);
111}
112
114{
115 wmGizmoProperty *gz_prop = &gz->target_properties[gz_prop_type->index_in_type];
116
117 /* If gizmo evokes an operator we cannot use it for property manipulation. */
118 BLI_assert(gz->op_data.is_empty());
119
120 /* Unlikely, but shouldn't leak memory. */
121 if (gz_prop->custom_func.free_fn) {
122 gz_prop->custom_func.free_fn(gz, gz_prop);
123 }
124
125 *gz_prop = {};
126}
127
128void WM_gizmo_target_property_clear_rna(wmGizmo *gz, const char *idname)
129{
130 const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname);
132}
133
135
136/* -------------------------------------------------------------------- */
139
141{
142 for (const wmGizmoProperty &gz_prop : gz->target_properties) {
143 if (WM_gizmo_target_property_is_valid(&gz_prop)) {
144 return true;
145 }
146 }
147 return false;
148}
149
151{
152 return ((gz_prop->prop != nullptr) ||
153 (gz_prop->custom_func.value_get_fn && gz_prop->custom_func.value_set_fn));
154}
155
157{
158 if (gz_prop->custom_func.value_get_fn) {
159 float value = 0.0f;
160 BLI_assert(gz_prop->type->array_length == 1);
161 gz_prop->custom_func.value_get_fn(gz, gz_prop, &value);
162 return value;
163 }
164
165 if (gz_prop->index == -1) {
166 return RNA_property_float_get(&gz_prop->ptr, gz_prop->prop);
167 }
168 return RNA_property_float_get_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index);
169}
170
172 const wmGizmo *gz,
173 wmGizmoProperty *gz_prop,
174 const float value)
175{
176 if (gz_prop->custom_func.value_set_fn) {
177 BLI_assert(gz_prop->type->array_length == 1);
178 gz_prop->custom_func.value_set_fn(gz, gz_prop, &value);
179 return;
180 }
181
182 /* Reset property. */
183 if (gz_prop->index == -1) {
184 RNA_property_float_set(&gz_prop->ptr, gz_prop->prop, value);
185 }
186 else {
187 RNA_property_float_set_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index, value);
188 }
189 RNA_property_update(C, &gz_prop->ptr, gz_prop->prop);
190}
191
193 wmGizmoProperty *gz_prop,
194 float *value)
195{
196 if (gz_prop->custom_func.value_get_fn) {
197 gz_prop->custom_func.value_get_fn(gz, gz_prop, value);
198 return;
199 }
200 RNA_property_float_get_array(&gz_prop->ptr, gz_prop->prop, value);
201}
202
204 const wmGizmo *gz,
205 wmGizmoProperty *gz_prop,
206 const float *value)
207{
208 if (gz_prop->custom_func.value_set_fn) {
209 gz_prop->custom_func.value_set_fn(gz, gz_prop, value);
210 return;
211 }
212 RNA_property_float_set_array(&gz_prop->ptr, gz_prop->prop, value);
213
214 RNA_property_update(C, &gz_prop->ptr, gz_prop->prop);
215}
216
218 wmGizmoProperty *gz_prop,
219 float range[2])
220{
221 if (gz_prop->custom_func.value_get_fn) {
222 if (gz_prop->custom_func.range_get_fn) {
223 gz_prop->custom_func.range_get_fn(gz, gz_prop, range);
224 return true;
225 }
226 return false;
227 }
228
229 float step, precision;
231 &gz_prop->ptr, gz_prop->prop, &range[0], &range[1], &step, &precision);
232 return true;
233}
234
236{
237 if (gz_prop->custom_func.value_get_fn) {
238 return gz_prop->type->array_length;
239 }
240 return RNA_property_array_length(&gz_prop->ptr, gz_prop->prop);
241}
242
244
245/* -------------------------------------------------------------------- */
248
250 const char *idname)
251{
252 return static_cast<const wmGizmoPropertyType *>(
254}
255
257 const char *idname,
258 int data_type,
259 int array_length)
260{
261
262 BLI_assert(WM_gizmotype_target_property_find(gzt, idname) == nullptr);
263
264 const uint idname_size = strlen(idname) + 1;
265 wmGizmoPropertyType *gz_prop_type = static_cast<wmGizmoPropertyType *>(
266 MEM_new_zeroed(sizeof(wmGizmoPropertyType) + idname_size, __func__));
267 memcpy(gz_prop_type->idname, idname, idname_size);
268 gz_prop_type->data_type = data_type;
269 gz_prop_type->array_length = array_length;
270 gz_prop_type->index_in_type = gzt->target_property_defs_len;
271 gzt->target_property_defs_len += 1;
272 BLI_addtail(&gzt->target_property_defs, gz_prop_type);
273}
274
276
277/* -------------------------------------------------------------------- */
280
282 wmMsgSubscribeKey * /*msg_key*/,
283 wmMsgSubscribeValue *msg_val)
284{
285 ARegion *region = static_cast<ARegion *>(msg_val->owner);
286 wmGizmoMap *gzmap = static_cast<wmGizmoMap *>(msg_val->user_data);
287
288 /* Could possibly avoid a full redraw and only tag for editor overlays
289 * redraw in some cases, see #ED_region_tag_redraw_editor_overlays(). */
290 ED_region_tag_redraw(region);
291
293}
294
296{
297 for (wmGizmoProperty &gz_prop : gz->target_properties) {
298 if (WM_gizmo_target_property_is_valid(&gz_prop)) {
299 if (gz_prop.prop) {
300 {
301 wmMsgSubscribeValue value{};
302 value.owner = region;
303 value.user_data = region;
305 WM_msg_subscribe_rna(mbus, &gz_prop.ptr, gz_prop.prop, &value, __func__);
306 }
307 {
308 wmMsgSubscribeValue value{};
309 value.owner = region;
312 WM_msg_subscribe_rna(mbus, &gz_prop.ptr, gz_prop.prop, &value, __func__);
313 }
314 }
315 }
316 }
317}
318
320 const wmGizmo * /*gz*/,
321 wmGizmoProperty *gz_prop)
322{
323 if (gz_prop->prop != nullptr) {
324 Scene *scene = CTX_data_scene(C);
325 const float cfra = float(scene->r.cfra);
328 C, scene, &gz_prop->ptr, gz_prop->prop, gz_prop->index, cfra, false);
329 }
330 else if (gz_prop->custom_func.foreach_rna_prop_fn) {
331 Scene *scene = CTX_data_scene(C);
332 auto autokey_fn = [C, scene](PointerRNA &ptr, PropertyRNA *prop, int index) {
333 animrig::autokeyframe_property(C, scene, &ptr, prop, index, float(scene->r.cfra), false);
334 };
336 gz_prop->custom_func.foreach_rna_prop_fn(gz_prop, autokey_fn);
337 }
338}
339
341
342} // namespace blender
Functions to insert, delete or modify keyframes.
Read Blender memory allocation and freeing.
#define RNA_warning(format,...)
#define C
Definition RandGen.cpp:29
#define offsetof(t, d)
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
bool autokeyframe_property(bContext *C, Scene *scene, PointerRNA *ptr, PropertyRNA *prop, int rnaindex, float cfra, bool only_if_property_keyed)
BMesh Iterators.
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
void WM_gizmo_do_msg_notify_tag_refresh(bContext *, wmMsgSubscribeKey *, wmMsgSubscribeValue *msg_val)
unsigned int uint
Definition BKE_text.h:55
void WM_gizmo_target_property_def_func(wmGizmo *gz, const char *idname, const wmGizmoPropertyFnParams *params)
void WM_gizmo_target_property_float_get_array(const wmGizmo *gz, wmGizmoProperty *gz_prop, float *value)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
const wmGizmoPropertyType * WM_gizmotype_target_property_find(const wmGizmoType *gzt, const char *idname)
void WM_gizmo_target_property_def_func_ptr(wmGizmo *gz, const wmGizmoPropertyType *gz_prop_type, const wmGizmoPropertyFnParams *params)
void WM_gizmo_target_property_anim_autokey(bContext *C, const wmGizmo *, wmGizmoProperty *gz_prop)
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
void WM_gizmotype_target_property_def(wmGizmoType *gzt, const char *idname, int data_type, int array_length)
void WM_gizmomap_tag_refresh(wmGizmoMap *gzmap)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
void WM_gizmo_target_property_float_set(bContext *C, const wmGizmo *gz, wmGizmoProperty *gz_prop, const float value)
void WM_gizmo_target_property_def_rna(wmGizmo *gz, const char *idname, PointerRNA *ptr, const char *propname, int index)
int BLI_findstringindex(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:794
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)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void WM_gizmo_target_property_clear_rna(wmGizmo *gz, const char *idname)
void WM_gizmo_target_property_clear_rna_ptr(wmGizmo *gz, const wmGizmoPropertyType *gz_prop_type)
void ANIM_deselect_keys_in_animation_editors(bContext *C)
Definition anim_deps.cc:487
wmGizmoProperty * WM_gizmo_target_property_find(wmGizmo *gz, const char *idname)
bool WM_gizmo_target_property_is_valid(const wmGizmoProperty *gz_prop)
const char * RNA_struct_identifier(const StructRNA *type)
void WM_msg_subscribe_rna(wmMsgBus *mbus, PointerRNA *ptr, const PropertyRNA *prop, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
Scene * CTX_data_scene(const bContext *C)
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)
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:394
void WM_gizmo_target_property_def_rna_ptr(wmGizmo *gz, const wmGizmoPropertyType *gz_prop_type, PointerRNA *ptr, PropertyRNA *prop, int index)
bool WM_gizmo_target_property_is_valid_any(const wmGizmo *gz)
int WM_gizmo_target_property_array_length(const wmGizmo *, wmGizmoProperty *gz_prop)
float WM_gizmo_target_property_float_get(const wmGizmo *gz, wmGizmoProperty *gz_prop)
bool WM_gizmo_target_property_float_range_get(const wmGizmo *gz, wmGizmoProperty *gz_prop, float range[2])
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
StructRNA * type
Definition RNA_types.hh:63
struct RenderData r
wmGizmoPropertyFnSet value_set_fn
wmGizmoPropertyFnRangeGet range_get_fn
wmGizmoPropertyFnGet value_get_fn
wmGizmoPropertyFnFree free_fn
wmGizmoPropertyFnForeachRNAProp foreach_rna_prop_fn
const wmGizmoPropertyType * type
struct blender::wmGizmoProperty::@216011055122204070127377170176223170047224321165 custom_func
ListBaseT< wmGizmoPropertyType > target_property_defs
wmGizmoFnPropertyUpdate property_update
const wmGizmoType * type
wmGizmoGroup * parent_gzgroup
Vector< wmGizmoProperty, 0 > target_properties
Vector< wmGizmoOpElem, 4 > op_data