Blender V5.3
fmodifier_ui.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
15
16#include <cstring>
17
18#include "DNA_anim_types.h"
19#include "DNA_scene_types.h"
20#include "DNA_userdef_types.h"
21
22#include "MEM_guardedalloc.h"
23
24#include "BLT_translation.hh"
25
26#include "BLI_listbase.hh"
27#include "BLI_string_utf8.hh"
28#include "BLI_utildefines.hh"
29
30#include "BKE_context.hh"
31#include "BKE_fcurve.hh"
32#include "BKE_screen.hh"
33
34#include "WM_api.hh"
35#include "WM_types.hh"
36
37#include "RNA_access.hh"
38#include "RNA_prototypes.hh"
39
40#include "UI_interface.hh"
42#include "UI_resources.hh"
43
44#include "ED_anim_api.hh"
45#include "ED_undo.hh"
46
47#include "DEG_depsgraph.hh"
48
49namespace blender {
50
51using PanelDrawFn = void (*)(const bContext *, Panel *);
52static void fmodifier_panel_header(const bContext *C, Panel *panel);
53
54/* -------------------------------------------------------------------- */
57
61static ListBaseT<FModifier> *fmodifier_list_space_specific(const bContext *C)
62{
63 ScrArea *area = CTX_wm_area(C);
64
65 if (area->spacetype == SPACE_GRAPH) {
67 return &fcu->modifiers;
68 }
69
70 if (area->spacetype == SPACE_NLA) {
72 return &strip->modifiers;
73 }
74
75 /* This should not be called in any other space. */
76 BLI_assert(false);
77 return nullptr;
78}
79
84static PointerRNA *fmodifier_get_pointers(const bContext *C, const Panel *panel, ID **r_owner_id)
85{
87
88 if (r_owner_id != nullptr) {
89 *r_owner_id = ptr->owner_id;
90 }
91
92 if (C != nullptr && CTX_wm_space_graph(C)) {
94 panel->layout->active_set(!(fcu->flag & FCURVE_MOD_OFF));
95 }
96
97 return ptr;
98}
99
103static void fmodifier_reorder(bContext *C, Panel *panel, int new_index)
104{
105 ID *owner_id;
106 PointerRNA *ptr = fmodifier_get_pointers(nullptr, panel, &owner_id);
107 FModifier *fcm = static_cast<FModifier *>(ptr->data);
108
109 ListBaseT<FModifier> *modifiers = fmodifier_list_space_specific(C);
110
111 int current_index = BLI_findindex(modifiers, fcm);
112 BLI_assert(current_index >= 0);
113 BLI_assert(new_index >= 0);
114
115 /* Don't do anything if the drag didn't change the index. */
116 if (current_index == new_index) {
117 return;
118 }
119
120 /* Move the FModifier in the list. */
121 BLI_listbase_link_move(modifiers, fcm, new_index - current_index);
122
123 BKE_fmodifier_ensure_flag(modifiers);
124
125 ED_undo_push(C, "Reorder F-Curve Modifier");
126
129}
130
131static short get_fmodifier_expand_flag(const bContext * /*C*/, Panel *panel)
132{
133 PointerRNA *ptr = fmodifier_get_pointers(nullptr, panel, nullptr);
134 FModifier *fcm = static_cast<FModifier *>(ptr->data);
135
136 return fcm->ui_expand_flag;
137}
138
139static void set_fmodifier_expand_flag(const bContext * /*C*/, Panel *panel, short expand_flag)
140{
141 PointerRNA *ptr = fmodifier_get_pointers(nullptr, panel, nullptr);
142 FModifier *fcm = static_cast<FModifier *>(ptr->data);
143
144 fcm->ui_expand_flag = expand_flag;
145}
146
148 eFModifier_Types type,
150 PanelTypePollFn poll,
151 const char *id_prefix)
152{
153 PanelType *panel_type = MEM_new_zeroed<PanelType>(__func__);
154
155 /* Intentionally leave the label field blank. The header is filled with buttons. */
156 const FModifierTypeInfo *fmi = get_fmodifier_typeinfo(type);
157 SNPRINTF_UTF8(panel_type->idname, "%s_PT_%s", id_prefix, fmi->name);
158 STRNCPY_UTF8(panel_type->category, "Modifiers");
160
162 panel_type->draw = draw;
163 panel_type->poll = poll;
164
165 /* Give the panel the special flag that says it was built here and corresponds to a
166 * modifier rather than a #PanelType. */
168 panel_type->reorder = fmodifier_reorder;
171
172 BLI_addtail(&region_type->paneltypes, panel_type);
173
174 return panel_type;
175}
176
184 const char *name,
185 const char *label,
186 PanelDrawFn draw_header,
188 PanelTypePollFn poll,
189 PanelType *parent)
190{
191 PanelType *panel_type = MEM_new_zeroed<PanelType>(__func__);
192
193 BLI_assert(parent != nullptr);
194 SNPRINTF_UTF8(panel_type->idname, "%s_%s", parent->idname, name);
195 STRNCPY_UTF8(panel_type->label, label);
196 STRNCPY_UTF8(panel_type->category, "Modifiers");
198
199 panel_type->draw_header = draw_header;
200 panel_type->draw = draw;
201 panel_type->poll = poll;
202 panel_type->flag = PANEL_TYPE_DEFAULT_CLOSED;
203
204 STRNCPY_UTF8(panel_type->parent_id, parent->idname);
205 panel_type->parent = parent;
206 BLI_addtail(&parent->children, BLI_genericNodeN(panel_type));
207 BLI_addtail(&region_type->paneltypes, panel_type);
208
209 return panel_type;
210}
211
213
214/* -------------------------------------------------------------------- */
217
218/* Callback to remove the given modifier. */
221 ListBaseT<FModifier> *modifiers;
222};
223
224static void delete_fmodifier_cb(bContext *C, void *ctx_v, void *fcm_v)
225{
226 FModifierDeleteContext *ctx = static_cast<FModifierDeleteContext *>(ctx_v);
227 ListBaseT<FModifier> *modifiers = ctx->modifiers;
228 FModifier *fcm = static_cast<FModifier *>(fcm_v);
229
230 /* remove the given F-Modifier from the active modifier-stack */
231 remove_fmodifier(modifiers, fcm);
232
233 ED_undo_push(C, "Delete F-Curve Modifier");
234
237}
238
240{
241 FModifier *fcm = static_cast<FModifier *>(ptr->data);
242 layout.separator();
243
244 ui::Layout &row = layout.row(true, IFACE_("Influence"));
245 row.prop(ptr, "use_influence", UI_ITEM_NONE, "", ICON_NONE);
246
247 ui::Layout &sub = row.row(true);
249 sub.prop(ptr, "influence", UI_ITEM_NONE, "", ICON_NONE);
250}
251
253{
254 ui::Layout &layout = *panel->layout;
255
256 PointerRNA *ptr = fmodifier_get_pointers(C, panel, nullptr);
257
258 layout.prop(ptr, "use_restricted_range", UI_ITEM_NONE, std::nullopt, ICON_NONE);
259}
260
261static void fmodifier_frame_range_draw(const bContext *C, Panel *panel)
262{
263 ui::Layout &layout = *panel->layout;
264
265 PointerRNA *ptr = fmodifier_get_pointers(C, panel, nullptr);
266
267 layout.use_property_split_set(true);
268 layout.use_property_decorate_set(false);
269
270 FModifier *fcm = static_cast<FModifier *>(ptr->data);
272
273 ui::Layout *col = &layout.column(true);
274 col->prop(ptr, "frame_start", UI_ITEM_NONE, IFACE_("Start"), ICON_NONE);
275 col->prop(ptr, "frame_end", UI_ITEM_NONE, IFACE_("End"), ICON_NONE);
276
277 col = &layout.column(true);
278 col->prop(ptr, "blend_in", UI_ITEM_NONE, IFACE_("Blend In"), ICON_NONE);
279 col->prop(ptr, "blend_out", UI_ITEM_NONE, IFACE_("Out"), ICON_NONE);
280}
281
282static void fmodifier_panel_header(const bContext *C, Panel *panel)
283{
284 ui::Layout &layout = *panel->layout;
285
286 ID *owner_id;
287 PointerRNA *ptr = fmodifier_get_pointers(C, panel, &owner_id);
288 FModifier *fcm = static_cast<FModifier *>(ptr->data);
290
291 ui::Block *block = layout.block();
292
293 ui::Layout *sub = &layout.row(true);
294
295 /* Checkbox for 'active' status (for now). */
296 sub->prop(ptr, "active", ui::ITEM_R_ICON_ONLY, "", ICON_NONE);
297 if (fcm->flag & FMODIFIER_FLAG_DISABLED) {
298 sub->red_alert_set(true);
299 }
300
301 /* Name. */
302 if (fmi) {
303 sub->prop(ptr, "name", UI_ITEM_NONE, "", ICON_NONE);
304 }
305 else {
306 sub->label(IFACE_("<Unknown Modifier>"), ICON_NONE);
307 }
308 /* Right align. */
309 sub = &layout.row(true);
312
313 /* 'Mute' button. */
314 sub->prop(ptr, "mute", ui::ITEM_R_ICON_ONLY, "", ICON_NONE);
315
316 /* Delete button. */
317 ui::Button *but = uiDefIconBut(block,
319 ICON_X,
320 0,
321 0,
322 UI_UNIT_X,
323 UI_UNIT_Y,
324 nullptr,
325 0.0,
326 0.0,
327 TIP_("Delete Modifier"));
329 ctx->owner_id = owner_id;
331 BLI_assert(ctx->modifiers != nullptr);
332
333 button_funcN_set(but, delete_fmodifier_cb, ctx, fcm);
334
335 layout.separator();
336}
337
339
340/* -------------------------------------------------------------------- */
343
344static void generator_panel_draw(const bContext *C, Panel *panel)
345{
346 ui::Layout &layout = *panel->layout;
347
348 ID *owner_id;
349 PointerRNA *ptr = fmodifier_get_pointers(C, panel, &owner_id);
350 FModifier *fcm = static_cast<FModifier *>(ptr->data);
351 FMod_Generator *data = static_cast<FMod_Generator *>(fcm->data);
352
353 layout.prop(ptr, "mode", UI_ITEM_NONE, "", ICON_NONE);
354
355 layout.use_property_split_set(true);
356 layout.use_property_decorate_set(false);
357
358 layout.prop(ptr, "use_additive", UI_ITEM_NONE, std::nullopt, ICON_NONE);
359
360 layout.prop(ptr, "poly_order", UI_ITEM_NONE, IFACE_("Order"), ICON_NONE);
361
362 PropertyRNA *prop = RNA_struct_find_property(ptr, "coefficients");
363 ui::Layout &col = layout.column(true);
364 switch (data->mode) {
365 case FCM_GENERATOR_POLYNOMIAL: /* Polynomial expression. */
366 {
367
368 char xval[32];
369
370 /* The first value gets the mathematical "Constant" label. */
372
373 for (int i = 0; i < data->arraysize; i++) {
374 col.prop(ptr, prop, i, 0, UI_ITEM_NONE, xval, ICON_NONE);
375 SNPRINTF_UTF8(xval, "x^%d", i + 1);
376 }
377 break;
378 }
379 case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* Factorized polynomial expression */
380 {
381 {
382 /* Add column labels above the buttons to prevent confusion.
383 * Fake the property split layout, otherwise the labels use the full row. */
384 ui::Layout &split = col.split(0.4f, false);
385 split.column(false);
386 ui::Layout &title_col = split.column(false);
387 ui::Layout &title_row = title_col.row(true);
388 title_row.label(CTX_IFACE_(BLT_I18NCONTEXT_ID_ACTION, "A"), ICON_NONE);
389 title_row.label(CTX_IFACE_(BLT_I18NCONTEXT_ID_ACTION, "B"), ICON_NONE);
390 }
391
392 ui::Layout &first_row = col.row(true);
393 first_row.prop(ptr, prop, 0, 0, UI_ITEM_NONE, IFACE_("y = (Ax + B)"), ICON_NONE);
394 first_row.prop(ptr, prop, 1, 0, UI_ITEM_NONE, "", ICON_NONE);
395 for (int i = 2; i < data->arraysize - 1; i += 2) {
396 /* \u00d7 is the multiplication symbol. */
397 ui::Layout &row = col.row(true);
398 row.prop(ptr, prop, i, 0, UI_ITEM_NONE, IFACE_("\u00d7 (Ax + B)"), ICON_NONE);
399 row.prop(ptr, prop, i + 1, 0, UI_ITEM_NONE, "", ICON_NONE);
400 }
401 break;
402 }
403 }
404
405 fmodifier_influence_draw(layout, ptr);
406}
407
408static void panel_register_generator(ARegionType *region_type,
409 const char *id_prefix,
410 PanelTypePollFn poll_fn)
411{
413 region_type, FMODIFIER_TYPE_GENERATOR, generator_panel_draw, poll_fn, id_prefix);
414 fmodifier_subpanel_register(region_type,
415 "frame_range",
416 "",
419 poll_fn,
420 panel_type);
421}
422
424
425/* -------------------------------------------------------------------- */
428
429static void fn_generator_panel_draw(const bContext *C, Panel *panel)
430{
431 ui::Layout &layout = *panel->layout;
432
433 PointerRNA *ptr = fmodifier_get_pointers(C, panel, nullptr);
434
435 layout.prop(ptr, "function_type", UI_ITEM_NONE, "", ICON_NONE);
436
437 layout.use_property_split_set(true);
438 layout.use_property_decorate_set(false);
439
440 ui::Layout *col = &layout.column(false);
441 col->prop(ptr, "use_additive", UI_ITEM_NONE, std::nullopt, ICON_NONE);
442
443 col = &layout.column(false);
444 col->prop(ptr, "amplitude", UI_ITEM_NONE, std::nullopt, ICON_NONE);
445 col->prop(ptr, "phase_multiplier", UI_ITEM_NONE, std::nullopt, ICON_NONE);
446 col->prop(ptr, "phase_offset", UI_ITEM_NONE, std::nullopt, ICON_NONE);
447 col->prop(ptr, "value_offset", UI_ITEM_NONE, std::nullopt, ICON_NONE);
448
449 fmodifier_influence_draw(layout, ptr);
450}
451
453 const char *id_prefix,
454 PanelTypePollFn poll_fn)
455{
457 region_type, FMODIFIER_TYPE_FN_GENERATOR, fn_generator_panel_draw, poll_fn, id_prefix);
458 fmodifier_subpanel_register(region_type,
459 "frame_range",
460 "",
463 poll_fn,
464 panel_type);
465}
466
468
469/* -------------------------------------------------------------------- */
472
473static void cycles_panel_draw(const bContext *C, Panel *panel)
474{
475 ui::Layout &layout = *panel->layout;
476
477 PointerRNA *ptr = fmodifier_get_pointers(C, panel, nullptr);
478 const FModifier *fcm = static_cast<FModifier *>(ptr->data);
479
480 layout.use_property_split_set(true);
481 layout.use_property_decorate_set(false);
482
483 if (fcm->flag & FMODIFIER_FLAG_DISABLED) {
484 layout.label("Modifier must be first in the stack.", ICON_STATUS_ERROR);
485 }
486
487 /* Before. */
488 ui::Layout *col = &layout.column(false);
489 col->prop(ptr, "mode_before", UI_ITEM_NONE, std::nullopt, ICON_NONE);
490 col->prop(ptr, "cycles_before", UI_ITEM_NONE, IFACE_("Count"), ICON_NONE);
491
492 /* After. */
493 col = &layout.column(false);
494 col->prop(ptr, "mode_after", UI_ITEM_NONE, std::nullopt, ICON_NONE);
495 col->prop(ptr, "cycles_after", UI_ITEM_NONE, IFACE_("Count"), ICON_NONE);
496
497 fmodifier_influence_draw(layout, ptr);
498}
499
500static void panel_register_cycles(ARegionType *region_type,
501 const char *id_prefix,
502 PanelTypePollFn poll_fn)
503{
505 region_type, FMODIFIER_TYPE_CYCLES, cycles_panel_draw, poll_fn, id_prefix);
506 fmodifier_subpanel_register(region_type,
507 "frame_range",
508 "",
511 poll_fn,
512 panel_type);
513}
514
516
517/* -------------------------------------------------------------------- */
520
521static void noise_panel_draw(const bContext *C, Panel *panel)
522{
523 ui::Layout &layout = *panel->layout;
524
525 PointerRNA *ptr = fmodifier_get_pointers(C, panel, nullptr);
526
527 layout.use_property_split_set(true);
528 layout.use_property_decorate_set(false);
529
530 layout.prop(ptr, "blend_type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
531
532 ui::Layout &col = layout.column(false);
533 col.prop(ptr, "scale", UI_ITEM_NONE, std::nullopt, ICON_NONE);
534 col.prop(ptr, "strength", UI_ITEM_NONE, std::nullopt, ICON_NONE);
535 col.prop(ptr, "offset", UI_ITEM_NONE, std::nullopt, ICON_NONE);
536 col.prop(ptr, "phase", UI_ITEM_NONE, std::nullopt, ICON_NONE);
537 col.prop(ptr, "depth", UI_ITEM_NONE, std::nullopt, ICON_NONE);
538 col.prop(ptr, "use_legacy_noise", UI_ITEM_NONE, std::nullopt, ICON_NONE);
539 PropertyRNA *prop = RNA_struct_find_property(ptr, "use_legacy_noise");
540 const bool use_legacy_noise = RNA_property_boolean_get(ptr, prop);
541 if (!use_legacy_noise) {
542 col.prop(ptr, "lacunarity", UI_ITEM_NONE, std::nullopt, ICON_NONE);
543 col.prop(ptr, "roughness", UI_ITEM_NONE, std::nullopt, ICON_NONE);
544 }
545
546 fmodifier_influence_draw(layout, ptr);
547}
548
549static void panel_register_noise(ARegionType *region_type,
550 const char *id_prefix,
551 PanelTypePollFn poll_fn)
552{
554 region_type, FMODIFIER_TYPE_NOISE, noise_panel_draw, poll_fn, id_prefix);
555 fmodifier_subpanel_register(region_type,
556 "frame_range",
557 "",
560 poll_fn,
561 panel_type);
562}
563
565
566/* -------------------------------------------------------------------- */
569
570static void fmod_envelope_addpoint_cb(bContext *C, void *fcm_dv, void * /*arg*/)
571{
572 Scene *scene = CTX_data_scene(C);
573 FMod_Envelope *env = static_cast<FMod_Envelope *>(fcm_dv);
574 FCM_EnvelopeData *fedn;
576
577 /* init template data */
578 fed.min = -1.0f;
579 fed.max = 1.0f;
580 fed.time = float(scene->r.cfra); /* XXX make this int for ease of use? */
581 fed.f1 = fed.f2 = 0;
582
583 /* check that no data exists for the current frame... */
584 if (env->data) {
585 bool exists;
586 int i = BKE_fcm_envelope_find_index(env->data, float(scene->r.cfra), env->totvert, &exists);
587
588 /* binarysearch_...() will set exists by default to 0,
589 * so if it is non-zero, that means that the point exists already */
590 if (exists) {
591 return;
592 }
593
594 /* add new */
595 fedn = MEM_new_array<FCM_EnvelopeData>((env->totvert + 1), "FCM_EnvelopeData");
596
597 /* add the points that should occur before the point to be pasted */
598 if (i > 0) {
599 memcpy(fedn, env->data, i * sizeof(FCM_EnvelopeData));
600 }
601
602 /* add point to paste at index i */
603 *(fedn + i) = fed;
604
605 /* add the points that occur after the point to be pasted */
606 if (i < env->totvert) {
607 memcpy(fedn + i + 1, env->data + i, (env->totvert - i) * sizeof(FCM_EnvelopeData));
608 }
609
610 /* replace (+ free) old with new */
611 MEM_delete(env->data);
612 env->data = fedn;
613
614 env->totvert++;
615 }
616 else {
617 env->data = MEM_new<FCM_EnvelopeData>("FCM_EnvelopeData");
618 *(env->data) = fed;
619
620 env->totvert = 1;
621 }
623}
624
625/* callback to remove envelope data point */
626/* TODO: should we have a separate file for things like this? */
627static void fmod_envelope_deletepoint_cb(bContext *C, void *fcm_dv, void *ind_v)
628{
629 FMod_Envelope *env = static_cast<FMod_Envelope *>(fcm_dv);
630 FCM_EnvelopeData *fedn;
631 int index = POINTER_AS_INT(ind_v);
632
633 /* check that no data exists for the current frame... */
634 if (env->totvert > 1) {
635 /* allocate a new smaller array */
636 fedn = MEM_new_array<FCM_EnvelopeData>((env->totvert - 1), "FCM_EnvelopeData");
637
638 memcpy(fedn, env->data, sizeof(FCM_EnvelopeData) * (index));
639 memcpy(fedn + index,
640 env->data + (index + 1),
641 sizeof(FCM_EnvelopeData) * ((env->totvert - index) - 1));
642
643 /* free old array, and set the new */
644 MEM_delete(env->data);
645 env->data = fedn;
646 env->totvert--;
647 }
648 else {
649 /* just free array, since the only vert was deleted */
650 MEM_SAFE_DELETE(env->data);
651 env->totvert = 0;
652 }
654}
655
656/* draw settings for envelope modifier */
657static void envelope_panel_draw(const bContext *C, Panel *panel)
658{
659 ui::Layout &layout = *panel->layout;
660
661 ID *owner_id;
662 PointerRNA *ptr = fmodifier_get_pointers(C, panel, &owner_id);
663 FModifier *fcm = static_cast<FModifier *>(ptr->data);
664 FMod_Envelope *env = static_cast<FMod_Envelope *>(fcm->data);
665
666 layout.use_property_split_set(true);
667 layout.use_property_decorate_set(false);
668
669 /* General settings. */
670 ui::Layout *col = &layout.column(true);
671 col->prop(ptr, "reference_value", UI_ITEM_NONE, IFACE_("Reference"), ICON_NONE);
672 col->prop(ptr, "default_min", UI_ITEM_NONE, IFACE_("Min"), ICON_NONE);
673 col->prop(ptr, "default_max", UI_ITEM_NONE, IFACE_("Max"), ICON_NONE);
674
675 /* Control points list. */
676
677 ui::Layout *row = &layout.row(false);
678 ui::Block *block = row->block();
679
680 ui::Button *but = uiDefBut(block,
682 IFACE_("Add Control Point"),
683 0,
684 0,
685 7.5 * UI_UNIT_X,
686 UI_UNIT_Y,
687 nullptr,
688 0,
689 0,
690 TIP_("Add a new control-point to the envelope on the current frame"));
691 button_func_set(but, fmod_envelope_addpoint_cb, env, nullptr);
692
693 col = &layout.column(false);
694 col->use_property_split_set(false);
695
696 FCM_EnvelopeData *fed = env->data;
697 for (int i = 0; i < env->totvert; i++, fed++) {
699 owner_id, RNA_FModifierEnvelopeControlPoint, fed);
700
701 /* get a new row to operate on */
702 row = &col->row(true);
703 block = row->block();
704
705 row->prop(&ctrl_ptr, "frame", UI_ITEM_NONE, std::nullopt, ICON_NONE);
706 row->prop(&ctrl_ptr, "min", UI_ITEM_NONE, IFACE_("Min"), ICON_NONE);
707 row->prop(&ctrl_ptr, "max", UI_ITEM_NONE, IFACE_("Max"), ICON_NONE);
708
709 but = uiDefIconBut(block,
711 ICON_X,
712 0,
713 0,
714 0.9 * UI_UNIT_X,
715 UI_UNIT_Y,
716 nullptr,
717 0.0,
718 0.0,
719 TIP_("Delete envelope control point"));
720 button_func_set(but, fmod_envelope_deletepoint_cb, env, POINTER_FROM_INT(i));
721 block_align_begin(block);
722 }
723
724 fmodifier_influence_draw(layout, ptr);
725}
726
727static void panel_register_envelope(ARegionType *region_type,
728 const char *id_prefix,
729 PanelTypePollFn poll_fn)
730{
732 region_type, FMODIFIER_TYPE_ENVELOPE, envelope_panel_draw, poll_fn, id_prefix);
733 fmodifier_subpanel_register(region_type,
734 "frame_range",
735 "",
738 poll_fn,
739 panel_type);
740}
741
743
744/* -------------------------------------------------------------------- */
747
748static void limits_panel_draw(const bContext *C, Panel *panel)
749{
750 ui::Layout &layout = *panel->layout;
751
752 PointerRNA *ptr = fmodifier_get_pointers(C, panel, nullptr);
753
754 layout.use_property_split_set(true);
755 layout.use_property_decorate_set(false);
756
757 /* Minimums. */
758 ui::Layout *col = &layout.column(false);
759 ui::Layout *row = &col->row(true, IFACE_("Minimum X"));
760 row->prop(ptr, "use_min_x", UI_ITEM_NONE, "", ICON_NONE);
761 ui::Layout *sub = &row->column(true);
762 sub->active_set(RNA_boolean_get(ptr, "use_min_x"));
763 sub->prop(ptr, "min_x", UI_ITEM_NONE, "", ICON_NONE);
764
765 row = &col->row(true, IFACE_("Y"));
766 row->prop(ptr, "use_min_y", UI_ITEM_NONE, "", ICON_NONE);
767 sub = &row->column(true);
768 sub->active_set(RNA_boolean_get(ptr, "use_min_y"));
769 sub->prop(ptr, "min_y", UI_ITEM_NONE, "", ICON_NONE);
770
771 /* Maximums. */
772 col = &layout.column(false);
773 row = &col->row(true, IFACE_("Maximum X"));
774 row->prop(ptr, "use_max_x", UI_ITEM_NONE, "", ICON_NONE);
775 sub = &row->column(true);
776 sub->active_set(RNA_boolean_get(ptr, "use_max_x"));
777 sub->prop(ptr, "max_x", UI_ITEM_NONE, "", ICON_NONE);
778
779 row = &col->row(true, IFACE_("Y"));
780 row->prop(ptr, "use_max_y", UI_ITEM_NONE, "", ICON_NONE);
781 sub = &row->column(true);
782 sub->active_set(RNA_boolean_get(ptr, "use_max_y"));
783 sub->prop(ptr, "max_y", UI_ITEM_NONE, "", ICON_NONE);
784
785 fmodifier_influence_draw(layout, ptr);
786}
787
788static void panel_register_limits(ARegionType *region_type,
789 const char *id_prefix,
790 PanelTypePollFn poll_fn)
791{
793 region_type, FMODIFIER_TYPE_LIMITS, limits_panel_draw, poll_fn, id_prefix);
794 fmodifier_subpanel_register(region_type,
795 "frame_range",
796 "",
799 poll_fn,
800 panel_type);
801}
802
804
805/* -------------------------------------------------------------------- */
808
809static void stepped_panel_draw(const bContext *C, Panel *panel)
810{
811 ui::Layout &layout = *panel->layout;
812
813 PointerRNA *ptr = fmodifier_get_pointers(C, panel, nullptr);
814
815 layout.use_property_split_set(true);
816 layout.use_property_decorate_set(false);
817
818 /* Stepping Settings. */
819 ui::Layout &col = layout.column(false);
820 col.prop(ptr, "frame_step", UI_ITEM_NONE, std::nullopt, ICON_NONE);
821 col.prop(ptr, "frame_offset", UI_ITEM_NONE, std::nullopt, ICON_NONE);
822
823 /* Start range settings. */
824 ui::Layout *row = &layout.row(true, IFACE_("Start Frame"));
825 row->prop(ptr, "use_frame_start", UI_ITEM_NONE, "", ICON_NONE);
826 ui::Layout *sub = &row->column(true);
827 sub->active_set(RNA_boolean_get(ptr, "use_frame_start"));
828 sub->prop(ptr, "frame_start", UI_ITEM_NONE, "", ICON_NONE);
829
830 /* End range settings. */
831 row = &layout.row(true, IFACE_("End Frame"));
832 row->prop(ptr, "use_frame_end", UI_ITEM_NONE, "", ICON_NONE);
833 sub = &row->column(true);
834 sub->active_set(RNA_boolean_get(ptr, "use_frame_end"));
835 sub->prop(ptr, "frame_end", UI_ITEM_NONE, "", ICON_NONE);
836
837 fmodifier_influence_draw(layout, ptr);
838}
839
840static void panel_register_stepped(ARegionType *region_type,
841 const char *id_prefix,
842 PanelTypePollFn poll_fn)
843{
845 region_type, FMODIFIER_TYPE_STEPPED, stepped_panel_draw, poll_fn, id_prefix);
846 fmodifier_subpanel_register(region_type,
847 "frame_range",
848 "",
851 poll_fn,
852 panel_type);
853}
854
856
857/* -------------------------------------------------------------------- */
860
861static void smooth_panel_draw(const bContext *C, Panel *panel)
862{
863 ui::Layout &layout = *panel->layout;
864
865 PointerRNA *ptr = fmodifier_get_pointers(C, panel, nullptr);
866 const FModifier *fcm = static_cast<FModifier *>(ptr->data);
867
868 layout.use_property_split_set(true);
869 layout.use_property_decorate_set(false);
870
871 if (fcm->flag & FMODIFIER_FLAG_DISABLED) {
872 layout.label_multiline("Modifier must be first in the stack.", ICON_STATUS_ERROR);
873 }
874
875 ui::Layout &col = layout.column(false);
876 col.prop(ptr, "sigma", UI_ITEM_NONE, std::nullopt, ICON_NONE);
877 col.prop(ptr, "filter_width", UI_ITEM_NONE, std::nullopt, ICON_NONE);
878
879 fmodifier_influence_draw(layout, ptr);
880}
881
882static void panel_register_smooth(ARegionType *region_type,
883 const char *id_prefix,
884 PanelTypePollFn poll_fn)
885{
887 region_type, FMODIFIER_TYPE_SMOOTH, smooth_panel_draw, poll_fn, id_prefix);
888 fmodifier_subpanel_register(region_type,
889 "frame_range",
890 "",
893 poll_fn,
894 panel_type);
895}
896
898
899/* -------------------------------------------------------------------- */
902
904 ID *owner_id,
905 ListBaseT<FModifier> *fmodifiers,
906 uiListPanelIDFromDataFunc panel_id_fn)
907{
908 ARegion *region = CTX_wm_region(C);
909
910 bool panels_match = ui::panel_list_matches_data(region, fmodifiers, panel_id_fn);
911
912 if (!panels_match) {
914 for (FModifier &fcm : *fmodifiers) {
915 char panel_idname[MAX_NAME];
916 panel_id_fn(&fcm, panel_idname);
917
918 PointerRNA *fcm_ptr = MEM_new<PointerRNA>("panel customdata");
919 *fcm_ptr = RNA_pointer_create_discrete(owner_id, RNA_FModifier, &fcm);
920
921 ui::panel_add_instanced(C, region, &region->panels, panel_idname, fcm_ptr);
922 }
923 }
924 else {
925 /* Assuming there's only one group of instanced panels, update the custom data pointers. */
926 Panel *panel = region->panels.first();
927 for (FModifier &fcm : *fmodifiers) {
928
929 /* Move to the next instanced panel corresponding to the next modifier. */
930 while ((panel->type == nullptr) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) {
931 panel = panel->next;
932 BLI_assert(panel !=
933 nullptr); /* There shouldn't be fewer panels than modifiers with UIs. */
934 }
935
936 PointerRNA *fcm_ptr = MEM_new<PointerRNA>("panel customdata");
937 *fcm_ptr = RNA_pointer_create_discrete(owner_id, RNA_FModifier, &fcm);
938 ui::panel_custom_data_set(panel, fcm_ptr);
939
940 panel = panel->next;
941 }
942 }
943}
944
946 const char *modifier_panel_prefix,
947 PanelTypePollFn poll_function)
948{
949 panel_register_generator(region_type, modifier_panel_prefix, poll_function);
950 panel_register_fn_generator(region_type, modifier_panel_prefix, poll_function);
951 panel_register_noise(region_type, modifier_panel_prefix, poll_function);
952 panel_register_envelope(region_type, modifier_panel_prefix, poll_function);
953 panel_register_limits(region_type, modifier_panel_prefix, poll_function);
954 panel_register_stepped(region_type, modifier_panel_prefix, poll_function);
955 panel_register_smooth(region_type, modifier_panel_prefix, poll_function);
956}
957
959 const char *modifier_panel_prefix,
960 PanelTypePollFn poll_function)
961{
962 panel_register_cycles(region_type, modifier_panel_prefix, poll_function);
963}
964
966
967/* -------------------------------------------------------------------- */
973
974/* Copy/Paste Buffer itself (list of FModifier 's) */
975static ListBaseT<FModifier> fmodifier_copypaste_buf = {nullptr, nullptr};
976
977/* ---------- */
978
980{
981 /* just free the whole buffer */
983}
984
985bool ANIM_fmodifiers_copy_to_buf(ListBaseT<FModifier> *modifiers, bool active)
986{
987 bool ok = true;
988
989 /* sanity checks */
990 if (ELEM(nullptr, modifiers, modifiers->first())) {
991 return false;
992 }
993
994 /* copy the whole list, or just the active one? */
995 if (active) {
996 FModifier *fcm = find_active_fmodifier(modifiers);
997
998 if (fcm) {
999 FModifier *fcmN = copy_fmodifier(fcm);
1001 }
1002 else {
1003 ok = false;
1004 }
1005 }
1006 else {
1008 }
1009
1010 /* did we succeed? */
1011 return ok;
1012}
1013
1014bool ANIM_fmodifiers_paste_from_buf(ListBaseT<FModifier> *modifiers, bool replace, FCurve *curve)
1015{
1016 bool ok = false;
1017
1018 /* sanity checks */
1019 if (modifiers == nullptr) {
1020 return false;
1021 }
1022
1023 bool was_cyclic = curve && BKE_fcurve_is_cyclic(*curve);
1024
1025 /* if replacing the list, free the existing modifiers */
1026 if (replace) {
1027 free_fmodifiers(modifiers);
1028 }
1029
1030 /* now copy over all the modifiers in the buffer to the end of the list */
1031 for (FModifier &fcm : fmodifier_copypaste_buf) {
1032 /* make a copy of it */
1033 FModifier *fcmN = copy_fmodifier(&fcm);
1034
1035 fcmN->curve = curve;
1036
1037 /* make sure the new one isn't active, otherwise the list may get several actives */
1039
1040 /* now add it to the end of the list */
1041 BLI_addtail(modifiers, fcmN);
1042 ok = true;
1043 }
1044
1045 /* adding or removing the Cycles modifier requires an update to handles */
1046 if (curve && BKE_fcurve_is_cyclic(*curve) != was_cyclic) {
1048 }
1049
1050 /* did we succeed? */
1051 return ok;
1052}
1053
1055
1056} // namespace blender
#define SNPRINTF_UTF8(dst, format,...)
#define STRNCPY_UTF8(dst, src)
#define BLT_I18NCONTEXT_MODIFIER
#define BLT_I18NCONTEXT_ID_ACTION
#define TIP_(msgid)
#define CTX_IFACE_(context, msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_DEFAULT_BPYRNA
#define MAX_NAME
Definition DNA_defs.h:63
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_UNIT_X
#define UI_ITEM_NONE
#define NC_ANIMATION
Definition WM_types.hh:401
#define NA_EDITED
Definition WM_types.hh:634
#define ND_KEYFRAME
Definition WM_types.hh:537
#define POINTER_FROM_INT(i)
#define POINTER_AS_INT(i)
#define ELEM(...)
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:68
bool panel_list_matches_data(ARegion *region, ListBase *data, ListPanelIDFromDataFunc panel_idname_func)
void panels_free_instanced(const bContext *C, ARegion *region)
void panel_custom_data_set(Panel *panel, PointerRNA *custom_data)
Panel * panel_add_instanced(const bContext *C, ARegion *region, ListBaseT< Panel > *panels, const char *panel_idname, PointerRNA *custom_data)
PointerRNA * panel_custom_data_get(const Panel *panel)
BMesh Iterators.
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static void fmodifier_panel_header(const bContext *C, Panel *panel)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void envelope_panel_draw(const bContext *C, Panel *panel)
ScrArea * CTX_wm_area(const bContext *C)
static PointerRNA * fmodifier_get_pointers(const bContext *C, const Panel *panel, ID **r_owner_id)
static void panel_register_envelope(ARegionType *region_type, const char *id_prefix, PanelTypePollFn poll_fn)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
static void stepped_panel_draw(const bContext *C, Panel *panel)
void(*)(void *data_link, char *r_idname) uiListPanelIDFromDataFunc
static void generator_panel_draw(const bContext *C, Panel *panel)
@ FCM_GENERATOR_POLYNOMIAL
@ FCM_GENERATOR_POLYNOMIAL_FACTORISED
void BKE_fmodifier_ensure_flag(ListBaseT< FModifier > *modifiers)
static void panel_register_noise(ARegionType *region_type, const char *id_prefix, PanelTypePollFn poll_fn)
void copy_fmodifiers(ListBaseT< FModifier > *dst, const ListBaseT< FModifier > *src)
static short get_fmodifier_expand_flag(const bContext *, Panel *panel)
static void fmod_envelope_deletepoint_cb(bContext *C, void *fcm_dv, void *ind_v)
void ANIM_modifier_panels_register_graph_only(ARegionType *region_type, const char *modifier_panel_prefix, PanelTypePollFn poll_function)
const FModifierTypeInfo * fmodifier_get_typeinfo(const FModifier *fcm)
static void fmodifier_frame_range_draw(const bContext *C, Panel *panel)
static void fmodifier_reorder(bContext *C, Panel *panel, int new_index)
bool remove_fmodifier(ListBaseT< FModifier > *modifiers, FModifier *fcm)
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
@ FMODIFIER_TYPE_ENVELOPE
@ FMODIFIER_TYPE_STEPPED
@ FMODIFIER_TYPE_FN_GENERATOR
@ FMODIFIER_TYPE_LIMITS
@ FMODIFIER_TYPE_CYCLES
@ FMODIFIER_TYPE_SMOOTH
@ FMODIFIER_TYPE_GENERATOR
@ FMODIFIER_TYPE_NOISE
static void set_fmodifier_expand_flag(const bContext *, Panel *panel, short expand_flag)
static void noise_panel_draw(const bContext *C, Panel *panel)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BKE_fcurve_handles_recalc(FCurve &fcu)
static void fn_generator_panel_draw(const bContext *C, Panel *panel)
void DEG_id_tag_update(ID *id, unsigned int flags)
static void panel_register_limits(ARegionType *region_type, const char *id_prefix, PanelTypePollFn poll_fn)
BMesh const char void * data
void ANIM_fmodifier_panels(const bContext *C, ID *owner_id, ListBaseT< FModifier > *fmodifiers, uiListPanelIDFromDataFunc panel_id_fn)
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
Definition ed_undo.cc:103
static ListBaseT< FModifier > fmodifier_copypaste_buf
static void panel_register_fn_generator(ARegionType *region_type, const char *id_prefix, PanelTypePollFn poll_fn)
NlaStrip * ANIM_nla_context_strip(const bContext *C)
FModifier * find_active_fmodifier(ListBaseT< FModifier > *modifiers)
LinkData * BLI_genericNodeN(void *data)
Definition listbase.cc:936
void(*)(const bContext *, Panel *) PanelDrawFn
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
SpaceGraph * CTX_wm_space_graph(const bContext *C)
bool ANIM_fmodifiers_paste_from_buf(ListBaseT< FModifier > *modifiers, bool replace, FCurve *curve)
static void fmodifier_frame_range_header_draw(const bContext *C, Panel *panel)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void free_fmodifiers(ListBaseT< FModifier > *modifiers)
static void limits_panel_draw(const bContext *C, Panel *panel)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
static ListBaseT< FModifier > * fmodifier_list_space_specific(const bContext *C)
bool BKE_fcurve_is_cyclic(const FCurve &fcu)
static void smooth_panel_draw(const bContext *C, Panel *panel)
static void fmod_envelope_addpoint_cb(bContext *C, void *fcm_dv, void *)
static void panel_register_generator(ARegionType *region_type, const char *id_prefix, PanelTypePollFn poll_fn)
static void fmodifier_influence_draw(ui::Layout &layout, PointerRNA *ptr)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
static void cycles_panel_draw(const bContext *C, Panel *panel)
void ANIM_fmodifiers_copybuf_free()
@ PANEL_TYPE_HEADER_EXPAND
@ PANEL_TYPE_DEFAULT_CLOSED
@ PANEL_TYPE_INSTANCED
FCurve * ANIM_graph_context_fcurve(const bContext *C)
FModifier * copy_fmodifier(const FModifier *src)
int BKE_fcm_envelope_find_index(FCM_EnvelopeData *array, float frame, int arraylen, bool *r_exists)
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
bool ANIM_fmodifiers_copy_to_buf(ListBaseT< FModifier > *modifiers, bool active)
Scene * CTX_data_scene(const bContext *C)
void ANIM_modifier_panels_register_graph_and_NLA(ARegionType *region_type, const char *modifier_panel_prefix, PanelTypePollFn poll_function)
bool(*)(const bContext *C, PanelType *pt) PanelTypePollFn
static void panel_register_stepped(ARegionType *region_type, const char *id_prefix, PanelTypePollFn poll_fn)
static void delete_fmodifier_cb(bContext *C, void *ctx_v, void *fcm_v)
static void panel_register_cycles(ARegionType *region_type, const char *id_prefix, PanelTypePollFn poll_fn)
ARegion * CTX_wm_region(const bContext *C)
static void panel_register_smooth(ARegionType *region_type, const char *id_prefix, PanelTypePollFn poll_fn)
const FModifierTypeInfo * get_fmodifier_typeinfo(int type)
static PanelType * fmodifier_panel_register(ARegionType *region_type, eFModifier_Types type, PanelDrawFn draw, PanelTypePollFn poll, const char *id_prefix)
static PanelType * fmodifier_subpanel_register(ARegionType *region_type, const char *name, const char *label, PanelDrawFn draw_header, PanelDrawFn draw, PanelTypePollFn poll, PanelType *parent)
void void void bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) ATTR_NONNULL()
Definition listbase.cc:443
@ FMODIFIER_FLAG_DISABLED
@ FMODIFIER_FLAG_RANGERESTRICT
@ FMODIFIER_FLAG_USEINFLUENCE
@ FMODIFIER_FLAG_ACTIVE
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< PanelType > paneltypes
ListBaseT< Panel > panels
eFCurve_Flags flag
ListBaseT< FModifier > modifiers
FCM_EnvelopeData * data
ListBaseT< FModifier > * modifiers
eFModifier_Flags flag
struct FCurve * curve
ListBaseT< FModifier > modifiers
void(*) reorder(bContext *C, Panel *pa, int new_index)
char translation_context[BKE_ST_MAXNAME]
short(*) get_list_data_expand_flag(const bContext *C, Panel *pa)
PanelType * parent
ListBaseT< LinkData > children
char parent_id[BKE_ST_MAXNAME]
void(*) draw(const bContext *C, Panel *panel)
char category[BKE_ST_MAXNAME]
void(*) set_list_data_expand_flag(const bContext *C, Panel *pa, short expand_flag)
bool(*) poll(const bContext *C, PanelType *pt)
void(*) draw_header(const bContext *C, Panel *panel)
char idname[BKE_ST_MAXNAME]
char label[BKE_ST_MAXNAME]
struct PanelType * type
ui::Layout * layout
struct Panel * next
struct RenderData r
void alignment_set(LayoutAlign alignment)
void use_property_decorate_set(bool is_decorate)
void label_multiline(StringRefNull label, int icon, FontStyleAlign align=UI_STYLE_TEXT_LEFT, int max_lines=0)
void use_property_split_set(bool is_sep)
void label(StringRef name, int icon)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void red_alert_set(bool red_alert)
void active_set(bool active)
Layout & split(float percentage, bool align)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
Layout & row(bool align)
void emboss_set(EmbossType emboss)