Blender V4.5
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.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/* -------------------------------------------------------------------- */
29
31{
32 int index = BLI_findstringindex(
34 if (index != -1) {
35 return &gz->target_properties[index];
36 }
37 return nullptr;
38}
39
41 const wmGizmoPropertyType *gz_prop_type,
43 PropertyRNA *prop,
44 int index)
45{
46 wmGizmoProperty *gz_prop = &gz->target_properties[gz_prop_type->index_in_type];
47
48 /* If gizmo evokes an operator we cannot use it for property manipulation. */
50 BLI_assert(prop != nullptr);
51
52 gz_prop->type = gz_prop_type;
53
54 gz_prop->ptr = *ptr;
55 gz_prop->prop = prop;
56 gz_prop->index = index;
57
58 if (gz->type->property_update) {
59 gz->type->property_update(gz, gz_prop);
60 }
61}
62
64 wmGizmo *gz, const char *idname, PointerRNA *ptr, const char *propname, int index)
65{
66 const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname);
67 PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
68 if (prop == nullptr) {
69 RNA_warning("%s: %s.%s not found", __func__, RNA_struct_identifier(ptr->type), propname);
70 }
71 WM_gizmo_target_property_def_rna_ptr(gz, gz_prop_type, ptr, prop, index);
72}
73
75 const wmGizmoPropertyType *gz_prop_type,
77{
78 wmGizmoProperty *gz_prop = &gz->target_properties[gz_prop_type->index_in_type];
79
80 /* If gizmo evokes an operator we cannot use it for property manipulation. */
82
83 gz_prop->type = gz_prop_type;
84
85 gz_prop->custom_func.value_get_fn = params->value_get_fn;
86 gz_prop->custom_func.value_set_fn = params->value_set_fn;
87 gz_prop->custom_func.range_get_fn = params->range_get_fn;
88 gz_prop->custom_func.free_fn = params->free_fn;
89 gz_prop->custom_func.user_data = params->user_data;
90
91 if (gz->type->property_update) {
92 gz->type->property_update(gz, gz_prop);
93 }
94}
95
97 const char *idname,
99{
100 const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname);
102}
103
105{
106 wmGizmoProperty *gz_prop = &gz->target_properties[gz_prop_type->index_in_type];
107
108 /* If gizmo evokes an operator we cannot use it for property manipulation. */
110
111 *gz_prop = {};
112}
113
114void WM_gizmo_target_property_clear_rna(wmGizmo *gz, const char *idname)
115{
116 const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname);
118}
119
121
122/* -------------------------------------------------------------------- */
125
127{
128 for (const wmGizmoProperty &gz_prop : gz->target_properties) {
129 if (WM_gizmo_target_property_is_valid(&gz_prop)) {
130 return true;
131 }
132 }
133 return false;
134}
135
137{
138 return ((gz_prop->prop != nullptr) ||
139 (gz_prop->custom_func.value_get_fn && gz_prop->custom_func.value_set_fn));
140}
141
143{
144 if (gz_prop->custom_func.value_get_fn) {
145 float value = 0.0f;
146 BLI_assert(gz_prop->type->array_length == 1);
147 gz_prop->custom_func.value_get_fn(gz, gz_prop, &value);
148 return value;
149 }
150
151 if (gz_prop->index == -1) {
152 return RNA_property_float_get(&gz_prop->ptr, gz_prop->prop);
153 }
154 return RNA_property_float_get_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index);
155}
156
158 const wmGizmo *gz,
159 wmGizmoProperty *gz_prop,
160 const float value)
161{
162 if (gz_prop->custom_func.value_set_fn) {
163 BLI_assert(gz_prop->type->array_length == 1);
164 gz_prop->custom_func.value_set_fn(gz, gz_prop, &value);
165 return;
166 }
167
168 /* Reset property. */
169 if (gz_prop->index == -1) {
170 RNA_property_float_set(&gz_prop->ptr, gz_prop->prop, value);
171 }
172 else {
173 RNA_property_float_set_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index, value);
174 }
175 RNA_property_update(C, &gz_prop->ptr, gz_prop->prop);
176}
177
179 wmGizmoProperty *gz_prop,
180 float *value)
181{
182 if (gz_prop->custom_func.value_get_fn) {
183 gz_prop->custom_func.value_get_fn(gz, gz_prop, value);
184 return;
185 }
186 RNA_property_float_get_array(&gz_prop->ptr, gz_prop->prop, value);
187}
188
190 const wmGizmo *gz,
191 wmGizmoProperty *gz_prop,
192 const float *value)
193{
194 if (gz_prop->custom_func.value_set_fn) {
195 gz_prop->custom_func.value_set_fn(gz, gz_prop, value);
196 return;
197 }
198 RNA_property_float_set_array(&gz_prop->ptr, gz_prop->prop, value);
199
200 RNA_property_update(C, &gz_prop->ptr, gz_prop->prop);
201}
202
204 wmGizmoProperty *gz_prop,
205 float range[2])
206{
207 if (gz_prop->custom_func.value_get_fn) {
208 if (gz_prop->custom_func.range_get_fn) {
209 gz_prop->custom_func.range_get_fn(gz, gz_prop, range);
210 return true;
211 }
212 return false;
213 }
214
215 float step, precision;
217 &gz_prop->ptr, gz_prop->prop, &range[0], &range[1], &step, &precision);
218 return true;
219}
220
222{
223 if (gz_prop->custom_func.value_get_fn) {
224 return gz_prop->type->array_length;
225 }
226 return RNA_property_array_length(&gz_prop->ptr, gz_prop->prop);
227}
228
230
231/* -------------------------------------------------------------------- */
234
236 const char *idname)
237{
238 return static_cast<const wmGizmoPropertyType *>(
240}
241
243 const char *idname,
244 int data_type,
245 int array_length)
246{
247
248 BLI_assert(WM_gizmotype_target_property_find(gzt, idname) == nullptr);
249
250 const uint idname_size = strlen(idname) + 1;
251 wmGizmoPropertyType *gz_prop_type = static_cast<wmGizmoPropertyType *>(
252 MEM_callocN(sizeof(wmGizmoPropertyType) + idname_size, __func__));
253 memcpy(gz_prop_type->idname, idname, idname_size);
254 gz_prop_type->data_type = data_type;
255 gz_prop_type->array_length = array_length;
256 gz_prop_type->index_in_type = gzt->target_property_defs_len;
257 gzt->target_property_defs_len += 1;
258 BLI_addtail(&gzt->target_property_defs, gz_prop_type);
259}
260
262
263/* -------------------------------------------------------------------- */
266
268 wmMsgSubscribeKey * /*msg_key*/,
269 wmMsgSubscribeValue *msg_val)
270{
271 ARegion *region = static_cast<ARegion *>(msg_val->owner);
272 wmGizmoMap *gzmap = static_cast<wmGizmoMap *>(msg_val->user_data);
273
274 /* Could possibly avoid a full redraw and only tag for editor overlays
275 * redraw in some cases, see #ED_region_tag_redraw_editor_overlays(). */
276 ED_region_tag_redraw(region);
277
279}
280
282{
283 for (wmGizmoProperty &gz_prop : gz->target_properties) {
284 if (WM_gizmo_target_property_is_valid(&gz_prop)) {
285 if (gz_prop.prop) {
286 {
287 wmMsgSubscribeValue value{};
288 value.owner = region;
289 value.user_data = region;
291 WM_msg_subscribe_rna(mbus, &gz_prop.ptr, gz_prop.prop, &value, __func__);
292 }
293 {
294 wmMsgSubscribeValue value{};
295 value.owner = region;
298 WM_msg_subscribe_rna(mbus, &gz_prop.ptr, gz_prop.prop, &value, __func__);
299 }
300 }
301 }
302 }
303}
304
306 const wmGizmo * /*gz*/,
307 wmGizmoProperty *gz_prop)
308{
309 if (gz_prop->prop != nullptr) {
310 Scene *scene = CTX_data_scene(C);
311 const float cfra = float(scene->r.cfra);
312 const int index = gz_prop->index == -1 ? 0 : gz_prop->index;
314 C, scene, &gz_prop->ptr, gz_prop->prop, index, cfra, false);
315 }
316}
317
Functions to insert, delete or modify keyframes.
Scene * CTX_data_scene(const bContext *C)
#define BLI_assert(a)
Definition BLI_assert.h:46
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:608
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
int BLI_findstringindex(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:780
unsigned int uint
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:639
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:384
Read Guarded memory(de)allocation.
#define RNA_warning(format,...)
#define C
Definition RandGen.cpp:29
bool is_empty() const
#define offsetof(t, d)
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
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)
struct RenderData r
wmGizmoMap * parent_gzmap
wmGizmoPropertyFnRangeGet range_get_fn
const wmGizmoPropertyType * type
PropertyRNA * prop
wmGizmoPropertyFnGet value_get_fn
wmGizmoPropertyFnSet value_set_fn
struct wmGizmoProperty::@040041342156246322372067060316112006150370104023 custom_func
wmGizmoPropertyFnFree free_fn
ListBase target_property_defs
int target_property_defs_len
wmGizmoFnPropertyUpdate property_update
wmGizmoGroup * parent_gzgroup
const wmGizmoType * type
blender::Vector< wmGizmoProperty, 0 > target_properties
blender::Vector< wmGizmoOpElem, 4 > op_data
PointerRNA * ptr
Definition wm_files.cc:4227
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(const wmGizmoProperty *gz_prop)
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)
bool WM_gizmo_target_property_is_valid_any(const wmGizmo *gz)
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)
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)