Blender V5.3
space_graph.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdio>
10#include <cstring>
11
12#include "DNA_anim_types.h"
14#include "DNA_scene_types.h"
15#include "DNA_space_types.h"
16
17#include "MEM_guardedalloc.h"
18
19#include "BLI_listbase.hh"
20#include "BLI_math_color_c.hh"
21#include "BLI_math_vector_c.hh"
22#include "BLI_string_utf8.hh"
23#include "BLI_utildefines.hh"
24
25#include "BLF_api.hh"
26
27#include "BKE_context.hh"
28#include "BKE_fcurve.hh"
29#include "BKE_lib_query.hh"
30#include "BKE_lib_remap.hh"
31#include "BKE_screen.hh"
32
33#include "ED_anim_api.hh"
34#include "ED_markers.hh"
35#include "ED_screen.hh"
36#include "ED_space_api.hh"
37#include "ED_time_scrub_ui.hh"
38
39#include "GPU_immediate.hh"
40#include "GPU_state.hh"
41
42#include "WM_api.hh"
43#include "WM_message.hh"
44#include "WM_types.hh"
45
46#include "RNA_access.hh"
47#include "RNA_define.hh"
48#include "RNA_enum_types.hh"
49
50#include "UI_interface.hh"
51#include "UI_resources.hh"
52#include "UI_view2d.hh"
53
54#include "BLO_read_write.hh"
55
56#include "graph_intern.hh" /* own include */
57
58namespace blender {
59
60/* ******************** default callbacks for ipo space ***************** */
61
62static SpaceLink *graph_create(const ScrArea * /*area*/, const Scene *scene)
63{
64 ARegion *region;
65 SpaceGraph *sipo;
66
67 /* Graph Editor - general stuff */
68 sipo = MEM_new<SpaceGraph>("init graphedit");
69 sipo->spacetype = SPACE_GRAPH;
70
71 /* allocate DopeSheet data for Graph Editor */
72 sipo->ads = MEM_new<bDopeSheet>("GraphEdit DopeSheet");
73 sipo->ads->source = id_cast<ID *>(const_cast<Scene *>(scene));
74
75 /* settings for making it easier by default to just see what you're interested in tweaking */
77 sipo->flag |= SIPO_SHOW_MARKERS;
78
79 /* header */
80 region = BKE_area_region_new();
81
82 BLI_addtail(&sipo->regionbase, region);
85
86 /* footer */
87 region = BKE_area_region_new();
88
89 BLI_addtail(&sipo->regionbase, region);
92 region->flag = RGN_FLAG_HIDDEN;
93
94 /* channels */
95 region = BKE_area_region_new();
96
97 BLI_addtail(&sipo->regionbase, region);
99 region->alignment = RGN_ALIGN_LEFT;
100
102
103 /* ui buttons */
104 region = BKE_area_region_new();
105
106 BLI_addtail(&sipo->regionbase, region);
107 region->regiontype = RGN_TYPE_UI;
108 region->alignment = RGN_ALIGN_RIGHT;
109
110 /* main region */
111 region = BKE_area_region_new();
112
113 BLI_addtail(&sipo->regionbase, region);
114 region->regiontype = RGN_TYPE_WINDOW;
115
116 region->v2d.tot.xmin = 0.0f;
117 region->v2d.tot.ymin = float(scene->r.sfra) - 10.0f;
118 region->v2d.tot.xmax = float(scene->r.efra);
119 region->v2d.tot.ymax = 10.0f;
120
121 region->v2d.cur = region->v2d.tot;
122
123 region->v2d.min[0] = FLT_MIN;
124 region->v2d.min[1] = FLT_MIN;
125
126 region->v2d.max[0] = MAXFRAMEF;
127 region->v2d.max[1] = FLT_MAX;
128
131
132 region->v2d.keeptot = eView2D_KeepTot{};
133
134 return reinterpret_cast<SpaceLink *>(sipo);
135}
136
137/* Doesn't free the space-link itself. */
138static void graph_free(SpaceLink *sl)
139{
140 SpaceGraph *si = reinterpret_cast<SpaceGraph *>(sl);
141
142 if (si->ads) {
144 MEM_delete(si->ads);
145 }
146
147 if (si->runtime.ghost_curves.first_) {
149 }
150}
151
152/* spacetype; init callback */
154{
155 SpaceGraph *sipo = area->spacedata.first_as<SpaceGraph>();
156
157 /* Init dope-sheet if non-existent (i.e. for old files). */
158 if (sipo->ads == nullptr) {
159 wmWindow *win = WM_window_find_by_area(wm, area);
160 sipo->ads = MEM_new<bDopeSheet>("GraphEdit DopeSheet");
161 sipo->ads->source = win ? id_cast<ID *>(WM_window_get_active_scene(win)) : nullptr;
162 }
163
164 /* force immediate init of any invalid F-Curve colors */
165 /* XXX: but, don't do SIPO_TEMP_NEEDCHANSYNC (i.e. channel select state sync)
166 * as this is run on each region resize; setting this here will cause selection
167 * state to be lost on area/region resizing. #35744.
168 */
170}
171
173{
174 SpaceGraph *sipon = MEM_dupalloc(reinterpret_cast<SpaceGraph *>(sl));
175
176 sipon->runtime = SpaceGraph_Runtime{};
177
178 /* clear or remove stuff from old */
180 &(reinterpret_cast<SpaceGraph *>(sl))->runtime.ghost_curves);
181 sipon->ads = MEM_dupalloc(sipon->ads);
182
183 return reinterpret_cast<SpaceLink *>(sipon);
184}
185
186/* add handlers, stuff you only do once or on area/region changes */
188{
189 wmKeyMap *keymap;
190
191 view2d_region_reinit(&region->v2d, ui::V2D_COMMONVIEW_CUSTOM, region->winx, region->winy);
192
193 /* own keymap */
194 keymap = WM_keymap_ensure(
195 wm->runtime->defaultconf, "Graph Editor", SPACE_GRAPH, RGN_TYPE_WINDOW);
198 keymap = WM_keymap_ensure(
199 wm->runtime->defaultconf, "Graph Editor Generic", SPACE_GRAPH, RGN_TYPE_WINDOW);
201}
202
203/* Draw a darker area above 1 and below -1. */
204static void draw_normalization_borders(Scene *scene, View2D *v2d)
205{
207
208 GPUVertFormat *format = immVertexFormat();
209 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
210
213
214 if (v2d->cur.ymax >= 1) {
215 immRectf(pos, scene->r.sfra, 1, scene->r.efra, v2d->cur.ymax);
216 }
217 if (v2d->cur.ymin <= -1) {
218 immRectf(pos, scene->r.sfra, v2d->cur.ymin, scene->r.efra, -1);
219 }
220
223}
224
225static void graph_main_region_draw(const bContext *C, ARegion *region)
226{
227 /* draw entirely, view changes should be handled here */
229 Scene *scene = CTX_data_scene(C);
230 bAnimContext ac;
231 View2D *v2d = &region->v2d;
232
233 const int min_height = UI_ANIM_MINY;
234
235 /* clear and setup matrix */
237
239
240 /* In driver mode, both X and Y axes are in the same units as the driven property, and so the
241 * grid size should be independent of the scene's frame rate. */
242 constexpr int driver_step = 10;
243 /* grid */
244 const bool display_seconds = (sipo->mode == SIPO_MODE_ANIMATION) && (sipo->flag & SIPO_DRAWTIME);
245 if (region->winy > min_height) {
246 if (sipo->mode == SIPO_MODE_DRIVERS) {
247 ui::view2d_draw_lines_x(v2d, scene, false, true, true, driver_step);
248 }
249 else {
250 ui::view2d_draw_lines_x_frames(v2d, scene, display_seconds, true, true);
251 }
252 ui::view2d_draw_lines_y(v2d, true, 10);
253 }
254
256
257 /* start and end frame (in F-Curve mode only) */
258 if (sipo->mode != SIPO_MODE_DRIVERS && region->winy > min_height) {
259 ANIM_draw_framerange(scene, v2d);
260 }
261
262 if (sipo->mode == SIPO_MODE_ANIMATION && (sipo->flag & SIPO_NORMALIZE)) {
263 draw_normalization_borders(scene, v2d);
264 }
265
266 /* draw data */
267 if (ANIM_animdata_get_context(C, &ac)) {
268 /* draw ghost curves */
269 graph_draw_ghost_curves(&ac, sipo, region);
270
271 /* draw curves twice - unselected, then selected, so that the are fewer occlusion problems */
272 graph_draw_curves(&ac, sipo, region, 0);
273 graph_draw_curves(&ac, sipo, region, 1);
274
275 /* XXX(ton): the slow way to set tot rect... but for nice sliders needed. */
276 /* Excluding handles from the calculation to save performance. This cuts the time it takes for
277 * this function to run in half which is a major performance bottleneck on heavy scenes. */
279 &ac, &v2d->tot.xmin, &v2d->tot.xmax, &v2d->tot.ymin, &v2d->tot.ymax, false, false);
280 /* extra offset so that these items are visible */
281 v2d->tot.xmin -= 10.0f;
282 v2d->tot.xmax += 10.0f;
283 }
284
285 if ((sipo->flag & SIPO_NODRAWCURSOR) == 0) {
286 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
287
289
290 /* horizontal component of value-cursor (value line before the current frame line) */
291 float y = sipo->cursorVal;
292
293 /* Draw a line to indicate the cursor value. */
296 GPU_line_width(2.0);
297
299 immVertex2f(pos, v2d->cur.xmin, y);
300 immVertex2f(pos, v2d->cur.xmax, y);
301 immEnd();
302
304
305 /* Vertical component of the cursor. */
306 if (sipo->mode == SIPO_MODE_DRIVERS) {
307 /* cursor x-value */
308 float x = sipo->cursorTime;
309
310 /* to help differentiate this from the current frame,
311 * draw slightly darker like the horizontal one */
314 GPU_line_width(2.0);
315
317 immVertex2f(pos, x, v2d->cur.ymin);
318 immVertex2f(pos, x, v2d->cur.ymax);
319 immEnd();
320
322 }
323
325 }
326
327 /* markers */
328 if (sipo->mode != SIPO_MODE_DRIVERS) {
329 ui::view2d_view_orthoSpecial(region, v2d, true);
330 int marker_draw_flag = DRAW_MARKERS_MARGIN;
332 ED_markers_draw(C, marker_draw_flag);
333 }
334 }
335
336 /* preview range */
337 if (sipo->mode != SIPO_MODE_DRIVERS) {
339 ANIM_draw_previewrange(scene, v2d, 0);
340 }
341
342 /* callback */
345
346 /* reset view matrix */
348
349 if (sipo->local_view_bit) {
350 const float margin = 25 * UI_SCALE_FAC;
351 const float x = margin;
352 const float y = region->winy - UI_TIME_SCRUB_MARGIN_Y - margin;
353 const std::string name = "Local View";
354 BLF_draw_default(x, y, 0.0f, name.c_str(), name.length());
355 }
356
357 /* time-scrubbing */
358 int base = round_db_to_int(scene->frames_per_second());
359 if (sipo->mode == SIPO_MODE_DRIVERS) {
360 base = driver_step;
361 }
362 ED_time_scrub_draw(region, scene, display_seconds, false, base);
363}
364
366{
367 /* draw entirely, view changes should be handled here */
368 const SpaceGraph *sipo = CTX_wm_space_graph(C);
369 const bool minimized = (region->winy < UI_ANIM_MINY);
370
371 const Scene *scene = CTX_data_scene(C);
372 View2D *v2d = &region->v2d;
373
374 /* Driver Editor's X axis is not time. */
375 if (sipo->mode != SIPO_MODE_DRIVERS) {
376 /* scrubbing region */
377 ED_time_scrub_draw_current_frame(region, scene, sipo->flag & SIPO_DRAWTIME, !minimized);
378 }
379
380 if (!minimized) {
381 /* scrollers */
382 const rcti scroller_mask = ED_time_scrub_clamp_scroller_mask(v2d->mask);
383 /* FIXME: args for scrollers depend on the type of data being shown. */
384 region->v2d.scroll |= V2D_SCROLL_BOTTOM;
385 ui::view2d_scrollers_draw(v2d, &scroller_mask);
386
387 /* scale numbers */
388 {
389 rcti rect;
391 &rect, 0, 15 * UI_SCALE_FAC, 15 * UI_SCALE_FAC, region->winy - UI_TIME_SCRUB_MARGIN_Y);
392 ui::view2d_draw_scale_y(region, v2d, &rect, TH_SCROLL_TEXT, 10);
393 }
394 }
395 else {
396 region->v2d.scroll &= ~V2D_SCROLL_BOTTOM;
397 }
398}
399
401{
402 wmKeyMap *keymap;
403
404 /* make sure we keep the hide flags */
405 region->v2d.scroll |= V2D_SCROLL_RIGHT;
406
407 /* prevent any noise of past */
409
412
413 view2d_region_reinit(&region->v2d, ui::V2D_COMMONVIEW_LIST, region->winx, region->winy);
414
415 /* own keymap */
416 keymap = WM_keymap_ensure(
417 wm->runtime->defaultconf, "Animation Channels", SPACE_EMPTY, RGN_TYPE_WINDOW);
419 keymap = WM_keymap_ensure(
420 wm->runtime->defaultconf, "Graph Editor Generic", SPACE_GRAPH, RGN_TYPE_WINDOW);
422}
423
424static void set_v2d_height(View2D *v2d, const size_t item_count)
425{
426 const int height = ANIM_UI_get_channels_total_height(v2d, item_count);
427 v2d->tot.ymin = -height;
429}
430
431static void graph_channel_region_draw(const bContext *C, ARegion *region)
432{
433 bAnimContext ac;
434 if (!ANIM_animdata_get_context(C, &ac)) {
435 return;
436 }
437 View2D *v2d = &region->v2d;
438
439 /* clear and setup matrix */
441
442 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
445 const size_t item_count = ANIM_animdata_filter(
446 &ac, &anim_data, filter, ac.data, eAnimCont_Types(ac.datatype));
447 set_v2d_height(v2d, item_count);
449
450 /* draw channels */
451 graph_draw_channel_names(const_cast<bContext *>(C), &ac, region, anim_data);
452
453 /* channel filter next to scrubbing area */
455
456 /* reset view matrix */
458
459 /* scrollers */
460 ui::view2d_scrollers_draw(v2d, nullptr);
461
462 ANIM_animdata_freelist(&anim_data);
463}
464
465/* add handlers, stuff you only do once or on area/region changes */
467{
468 ED_region_header_init(region);
469}
470
471static void graph_header_region_draw(const bContext *C, ARegion *region)
472{
473 ED_region_header(C, region);
474}
475
476/* add handlers, stuff you only do once or on area/region changes */
478{
479 wmKeyMap *keymap;
480
481 ED_region_panels_init(wm, region);
482
483 keymap = WM_keymap_ensure(
484 wm->runtime->defaultconf, "Graph Editor Generic", SPACE_GRAPH, RGN_TYPE_WINDOW);
486}
487
488static void graph_buttons_region_draw(const bContext *C, ARegion *region)
489{
490 ED_region_panels(C, region);
491}
492
494{
495 ARegion *region = params->region;
496 const wmNotifier *wmn = params->notifier;
497
498 /* context changes */
499 switch (wmn->category) {
500 case NC_ANIMATION:
501 ED_region_tag_redraw(region);
502 break;
503 case NC_SCENE:
504 switch (wmn->data) {
506 case ND_OB_ACTIVE:
507 case ND_FRAME:
508 case ND_FRAME_RANGE:
509 case ND_MARKERS:
510 ED_region_tag_redraw(region);
511 break;
512 case ND_SEQUENCER:
513 if (wmn->action == NA_SELECTED) {
514 ED_region_tag_redraw(region);
515 }
516 break;
517 }
518 break;
519 case NC_OBJECT:
520 switch (wmn->data) {
521 case ND_BONE_ACTIVE:
522 case ND_BONE_SELECT:
523 case ND_KEYS:
524 ED_region_tag_redraw(region);
525 break;
526 case ND_MODIFIER:
527 if (wmn->action == NA_RENAME) {
528 ED_region_tag_redraw(region);
529 }
530 break;
531 }
532 break;
533 case NC_NODE:
534 switch (wmn->action) {
535 case NA_EDITED:
536 case NA_SELECTED:
537 ED_region_tag_redraw(region);
538 break;
539 }
540 break;
541 case NC_ID:
542 if (wmn->action == NA_RENAME) {
543 ED_region_tag_redraw(region);
544 }
545 break;
546 case NC_SCREEN:
547 if (ELEM(wmn->data, ND_LAYER)) {
548 ED_region_tag_redraw(region);
549 }
550 break;
551 default:
552 if (wmn->data == ND_KEYS) {
553 ED_region_tag_redraw(region);
554 }
555 break;
556 }
557}
558
560{
561 wmMsgBus *mbus = params->message_bus;
562 Scene *scene = params->scene;
563 ARegion *region = params->region;
564
565 wmMsgSubscribeValue msg_sub_value_region_tag_redraw{};
566 msg_sub_value_region_tag_redraw.owner = region;
567 msg_sub_value_region_tag_redraw.user_data = region;
568 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
569
570 /* Timeline depends on scene properties. */
571 {
572 bool use_preview = (scene->r.flag & SCER_PRV_RANGE);
573 const PropertyRNA *props[] = {
574 use_preview ? &rna_Scene_frame_preview_start : &rna_Scene_frame_start,
575 use_preview ? &rna_Scene_frame_preview_end : &rna_Scene_frame_end,
576 &rna_Scene_use_preview_range,
577 &rna_Scene_frame_current,
578 };
579
580 PointerRNA idptr = RNA_id_pointer_create(&scene->id);
581
582 for (int i = 0; i < ARRAY_SIZE(props); i++) {
583 WM_msg_subscribe_rna(mbus, &idptr, props[i], &msg_sub_value_region_tag_redraw, __func__);
584 }
585 }
586
587 /* All dope-sheet filter settings, etc. affect the drawing of this editor,
588 * also same applies for all animation-related data-types that may appear here,
589 * so just whitelist the entire structs for updates
590 */
591 {
592 wmMsgParams_RNA msg_key_params = {{}};
593 StructRNA *type_array[] = {
594 RNA_DopeSheet, /* dope-sheet filters */
595
596 RNA_ActionGroup, /* channel groups */
597 RNA_FCurve, /* F-Curve */
598 RNA_Keyframe,
599 RNA_FCurveSample,
600
601 RNA_FModifier, /* F-Modifiers (XXX: Why can't we just do all subclasses too?) */
602 RNA_FModifierCycles,
603 RNA_FModifierEnvelope,
604 RNA_FModifierEnvelopeControlPoint,
605 RNA_FModifierFunctionGenerator,
606 RNA_FModifierGenerator,
607 RNA_FModifierLimits,
608 RNA_FModifierNoise,
609 RNA_FModifierStepped,
610 };
611
612 for (int i = 0; i < ARRAY_SIZE(type_array); i++) {
613 msg_key_params.ptr.type = type_array[i];
615 mbus, &msg_key_params, &msg_sub_value_region_tag_redraw, __func__);
616 }
617 }
618}
619
620/* editor level listener */
622{
623 ScrArea *area = params->area;
624 const wmNotifier *wmn = params->notifier;
625 SpaceGraph *sipo = area->spacedata.first_as<SpaceGraph>();
626
627 /* context changes */
628 switch (wmn->category) {
629 case NC_ANIMATION:
630 /* For selection changes of animation data, we can just redraw...
631 * otherwise auto-color might need to be done again. */
632 if (ELEM(wmn->data, ND_KEYFRAME, ND_ANIMCHAN) && (wmn->action == NA_SELECTED)) {
633 ED_area_tag_redraw(area);
634 }
635 else {
637 }
638 break;
639 case NC_SCENE:
640 switch (wmn->data) {
641 case ND_OB_ACTIVE: /* Selection changed, so force refresh to flush
642 * (needs flag set to do syncing). */
643 case ND_OB_SELECT:
646 break;
647
648 default: /* just redrawing the view will do */
649 ED_area_tag_redraw(area);
650 break;
651 }
652 break;
653 case NC_OBJECT:
654 switch (wmn->data) {
655 case ND_BONE_SELECT: /* Selection changed, so force refresh to flush
656 * (needs flag set to do syncing). */
657 case ND_BONE_ACTIVE:
660 break;
661 case ND_TRANSFORM:
662 break; /* Do nothing. */
663
664 default: /* just redrawing the view will do */
665 ED_area_tag_redraw(area);
666 break;
667 }
668 break;
669 case NC_NODE:
670 if (wmn->action == NA_SELECTED) {
671 /* selection changed, so force refresh to flush (needs flag set to do syncing) */
674 }
675 break;
676 case NC_SPACE:
677 if (wmn->data == ND_SPACE_GRAPH) {
678 ED_area_tag_redraw(area);
679 }
680 break;
681 case NC_WINDOW:
682 if (sipo->runtime.flag &
684 {
685 /* force redraw/refresh after undo/redo - prevents "black curve" problem */
687 }
688 break;
689
690#if 0 /* XXX: restore the case below if not enough updates occur... */
691 default: {
692 if (wmn->data == ND_KEYS) {
693 ED_area_tag_redraw(area);
694 }
695 }
696#endif
697 }
698}
699
700/* Exit local view when no fcurve channel exists. */
702{
703 if (!sipo->local_view_bit) {
704 return;
705 }
706
707 bAnimContext ac;
708 if (!ANIM_animdata_get_context(C, &ac)) {
709 return;
710 }
711
712 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
715 const size_t item_count = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
716 if (item_count == 0) {
717 sipo->local_view_bit = 0;
718 }
719
720 ANIM_animdata_freelist(&anim_data);
721}
722
723/* Update F-Curve colors */
725{
726 bAnimContext ac;
727
728 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
729 bAnimListElem *ale;
730 size_t items;
731 int filter;
732 int i;
733
734 if (ANIM_animdata_get_context(C, &ac) == false) {
735 return;
736 }
737
739
740 /* build list of F-Curves which will be visible as channels in channel-region
741 * - we don't include ANIMFILTER_CURVEVISIBLE filter, as that will result in a
742 * mismatch between channel-colors and the drawn curves
743 */
745 items = ANIM_animdata_filter(
746 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
747
748 /* loop over F-Curves, assigning colors */
749 for (ale = anim_data.first(), i = 0; ale; ale = ale->next, i++) {
751 "Expecting only FCurves when using the ANIMFILTER_FCURVESONLY filter");
752 FCurve *fcu = static_cast<FCurve *>(ale->data);
753
754 /* set color of curve here */
755 switch (fcu->color_mode) {
756 case FCURVE_COLOR_CUSTOM: {
757 /* User has defined a custom color for this curve already
758 * (we assume it's not going to cause clashes with text colors),
759 * which should be left alone... Nothing needs to be done here.
760 */
761 break;
762 }
764 /* F-Curve's array index is automatically mapped to RGB values.
765 * This works best of 3-value vectors.
766 * TODO: find a way to module the hue so that not all curves have same color...
767 */
768 float *col = fcu->color;
769
770 switch (fcu->array_index) {
771 case 0:
773 break;
774 case 1:
776 break;
777 case 2:
779 break;
780 default:
781 /* 'unknown' color - bluish so as to not conflict with handles */
782 col[0] = 0.3f;
783 col[1] = 0.8f;
784 col[2] = 1.0f;
785 break;
786 }
787 break;
788 }
790 /* Like FCURVE_COLOR_AUTO_RGB, except this is for quaternions... */
791 float *col = fcu->color;
792
793 switch (fcu->array_index) {
794 case 1:
796 break;
797 case 2:
799 break;
800 case 3:
802 break;
803
804 case 0: {
806 break;
807 }
808
809 default:
810 /* 'unknown' color - bluish so as to not conflict with handles */
811 col[0] = 0.3f;
812 col[1] = 0.8f;
813 col[2] = 1.0f;
814 break;
815 }
816 break;
817 }
819 default: {
820 /* determine color 'automatically' using 'magic function' which uses the given args
821 * of current item index + total items to determine some RGB color
822 */
823 getcolor_fcurve_rainbow(i, items, fcu->color);
824 break;
825 }
826 }
827 }
828
829 /* free temp list */
830 ANIM_animdata_freelist(&anim_data);
831}
832
833static void graph_refresh(const bContext *C, ScrArea *area)
834{
835 SpaceGraph *sipo = area->spacedata.first_as<SpaceGraph>();
836
837 /* updates to data needed depends on Graph Editor mode... */
838 switch (sipo->mode) {
839 case SIPO_MODE_ANIMATION: /* all animation */
840 {
841 break;
842 }
843
844 case SIPO_MODE_DRIVERS: /* Drivers only. */
845 {
846 break;
847 }
848 }
849
850 /* region updates? */
851 /* XXX re-sizing y-extents of tot should go here? */
852
853 /* Update the state of the animchannels in response to changes from the data they represent
854 * NOTE: the temp flag is used to indicate when this needs to be done,
855 * and will be cleared once handled. */
859 ED_area_tag_redraw(area);
860 }
861
862 /* We could check 'SIPO_RUNTIME_FLAG_NEED_CHAN_SYNC_COLOR', but color is recalculated anyway. */
865#if 0 /* Done below. */
867#endif
868 ED_area_tag_redraw(area);
869 }
870
873
874 /* init/adjust F-Curve colors */
876 /* Exit local view if no F-Curve channels there. */
878}
879
880static void graph_id_remap(ScrArea * /*area*/,
881 SpaceLink *slink,
882 const bke::id::IDRemapper &mappings)
883{
884 SpaceGraph *sgraph = reinterpret_cast<SpaceGraph *>(slink);
885 if (!sgraph->ads) {
886 return;
887 }
888
889 mappings.apply(reinterpret_cast<ID **>(&sgraph->ads->filter_grp), ID_REMAP_APPLY_DEFAULT);
890 mappings.apply((&sgraph->ads->source), ID_REMAP_APPLY_DEFAULT);
891}
892
894{
895 SpaceGraph *sgraph = reinterpret_cast<SpaceGraph *>(space_link);
896 const int data_flags = BKE_lib_query_foreachid_process_flags_get(data);
897 const bool is_readonly = (data_flags & IDWALK_READONLY) != 0;
898
899 /* NOTE: Could be deduplicated with the #bDopeSheet handling of #SpaceAction and #SpaceNla. */
900 if (sgraph->ads == nullptr) {
901 return;
902 }
903
906
907 if (!is_readonly) {
908 /* Force recalc of list of channels (i.e. including calculating F-Curve colors) to
909 * prevent the "black curves" problem post-undo. */
911 }
912}
913
915{
916 SpaceGraph *sgraph = area->spacedata.first_as<SpaceGraph>();
917 return sgraph->mode;
918}
919
920static void graph_space_subtype_set(ScrArea *area, int value)
921{
922 SpaceGraph *sgraph = area->spacedata.first_as<SpaceGraph>();
923 sgraph->mode = eGraphEdit_Mode(value);
924}
925
927 EnumPropertyItem **item,
928 int *totitem)
929{
931}
932
934{
935 SpaceGraph *sgraph = area->spacedata.first_as<SpaceGraph>();
938 return item.name;
939}
940
941static int graph_space_icon_get(const ScrArea *area)
942{
943 SpaceGraph *sgraph = area->spacedata.first_as<SpaceGraph>();
946 return item.icon;
947}
948
950{
951 SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(sl);
952
953 BLO_read_struct(reader, bDopeSheet, &sipo->ads);
954 sipo->runtime = SpaceGraph_Runtime{};
955}
956
958{
959 SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(sl);
960 writer->write_struct_cast<SpaceGraph>(sl, [](BlendStructWriter<SpaceGraph> &struct_writer) {
961 struct_writer.shallow_data.runtime = {};
962 });
963 if (sipo->ads) {
964 writer->write_struct(sipo->ads);
965 }
966}
967
969{
971 const SpaceGraph *sipo = params->area->spacedata.first_as<SpaceGraph>();
972 return sipo->mode != SIPO_MODE_DRIVERS;
973}
974
976{
977 std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
978 ARegionType *art;
979
980 st->spaceid = SPACE_GRAPH;
981 STRNCPY_UTF8(st->name, "Graph");
982 st->struct_size = sizeof(SpaceGraph);
983
984 st->create = graph_create;
985 st->free = graph_free;
986 st->init = graph_init;
987 st->duplicate = graph_duplicate;
988 st->operatortypes = graphedit_operatortypes;
989 st->keymap = graphedit_keymap;
990 st->listener = graph_listener;
991 st->refresh = graph_refresh;
992 st->id_remap = graph_id_remap;
993 st->foreach_id = graph_foreach_id;
994 st->space_subtype_item_extend = graph_space_subtype_item_extend;
995 st->space_subtype_get = graph_space_subtype_get;
996 st->space_subtype_set = graph_space_subtype_set;
997 st->space_name_get = graph_space_name_get;
998 st->space_icon_get = graph_space_icon_get;
999 st->blend_read_data = graph_space_blend_read_data;
1000 st->blend_read_after_liblink = nullptr;
1001 st->blend_write = graph_space_blend_write;
1002
1003 /* regions: main window */
1004 art = MEM_new_zeroed<ARegionType>("spacetype graphedit region");
1012
1013 BLI_addhead(&st->regiontypes, art);
1014
1015 /* regions: header */
1016 art = MEM_new_zeroed<ARegionType>("spacetype graphedit region");
1018 art->prefsizey = HEADERY;
1023
1024 BLI_addhead(&st->regiontypes, art);
1025
1026 /* regions: footer */
1027 art = MEM_new_zeroed<ARegionType>("spacetype graphedit region");
1029 art->prefsizey = HEADERY;
1034
1035 BLI_addhead(&st->regiontypes, art);
1036
1037 /* regions: channels */
1038 art = MEM_new_zeroed<ARegionType>("spacetype graphedit region");
1040 /* 200 is the 'standard', but due to scrollers, we want a bit more to fit the lock icons in */
1041 art->prefsizex = 200 + V2D_SCROLL_WIDTH;
1047
1048 BLI_addhead(&st->regiontypes, art);
1049
1050 /* regions: UI buttons */
1051 art = MEM_new_zeroed<ARegionType>("spacetype graphedit region");
1052 art->regionid = RGN_TYPE_UI;
1059
1060 BLI_addhead(&st->regiontypes, art);
1061
1063
1064 art = ui::ED_area_type_hud(st->spaceid);
1065 BLI_addhead(&st->regiontypes, art);
1066
1067 BKE_spacetype_register(std::move(st));
1068}
1069
1070} // namespace blender
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
#define BKE_LIB_FOREACHID_PROCESS_ID(data_, id_, cb_flag_)
#define STRNCPY_UTF8(dst, src)
#define BLO_read_struct(reader, struct_name, ptr_p)
Object groups, one object can be in many groups at once.
#define MAXFRAMEF
#define HEADERY
#define UI_SCALE_FAC
#define REGION_DRAW_POST_VIEW
#define REGION_DRAW_PRE_VIEW
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_SIDEBAR_PANEL_WIDTH
#define UI_ANIM_MINY
Definition UI_view2d.hh:495
#define V2D_SCROLL_WIDTH
Definition UI_view2d.hh:79
#define UI_TIME_SCRUB_MARGIN_Y
Definition UI_view2d.hh:493
#define ND_SEQUENCER
Definition WM_types.hh:456
#define NC_WINDOW
Definition WM_types.hh:388
#define NC_ID
Definition WM_types.hh:408
#define NC_NODE
Definition WM_types.hh:407
#define ND_OB_ACTIVE
Definition WM_types.hh:459
#define ND_RENDER_OPTIONS
Definition WM_types.hh:454
#define NC_ANIMATION
Definition WM_types.hh:401
#define NC_SCREEN
Definition WM_types.hh:390
#define ND_OB_SELECT
Definition WM_types.hh:461
#define NC_SCENE
Definition WM_types.hh:391
#define ND_MODIFIER
Definition WM_types.hh:503
#define NA_EDITED
Definition WM_types.hh:634
#define ND_SPACE_GRAPH
Definition WM_types.hh:575
#define ND_FRAME_RANGE
Definition WM_types.hh:470
#define ND_MARKERS
Definition WM_types.hh:452
#define ND_FRAME
Definition WM_types.hh:453
#define ND_BONE_ACTIVE
Definition WM_types.hh:483
#define ND_TRANSFORM
Definition WM_types.hh:475
#define ND_LAYER
Definition WM_types.hh:469
#define ND_KEYS
Definition WM_types.hh:504
#define NA_RENAME
Definition WM_types.hh:638
#define ND_BONE_SELECT
Definition WM_types.hh:491
#define ND_KEYFRAME
Definition WM_types.hh:537
#define NC_OBJECT
Definition WM_types.hh:392
#define ND_ANIMCHAN
Definition WM_types.hh:539
#define NC_SPACE
Definition WM_types.hh:405
#define NA_SELECTED
Definition WM_types.hh:639
#define ELEM(...)
#define BLI_assert_msg(a, msg)
IDRemapperApplyResult apply(ID **r_id_ptr, IDRemapperApplyOptions options, ID *id_self=nullptr) const
#define FLT_MAX
#define FLT_MIN
void get_color_3fv(int colorid, float col[3])
void theme_set(int spacetype, int regionid)
void frame_buffer_clear(int colorid)
void view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1080
void view2d_view_restore(const bContext *C)
Definition view2d.cc:1147
void view2d_draw_lines_x(const View2D *v2d, const Scene *scene, bool display_seconds, bool show_fractions, bool draw_minor_lines, int base)
ARegionType * ED_area_type_hud(int space_type)
void view2d_draw_lines_y(const View2D *v2d, bool show_fractions, int base)
void view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom)
Definition view2d.cc:1487
void view2d_curRect_clamp_y(View2D *v2d)
Definition view2d.cc:829
void view2d_draw_scale_y(const ARegion *region, const View2D *v2d, const rcti *rect, int colorid, int base)
@ V2D_COMMONVIEW_LIST
Definition UI_view2d.hh:60
@ V2D_COMMONVIEW_CUSTOM
Definition UI_view2d.hh:56
void view2d_draw_lines_x_frames(const View2D *v2d, const Scene *scene, bool display_seconds, bool show_fractions, bool draw_minor_lines)
void view2d_view_orthoSpecial(ARegion *region, View2D *v2d, bool xaxis)
Definition view2d.cc:1121
BMesh Iterators.
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void ED_time_scrub_draw_current_frame(const ARegion *region, const Scene *scene, bool display_seconds, bool display_stalk, bool clamp_playhead)
void ANIM_draw_framerange(Scene *scene, View2D *v2d)
Definition anim_draw.cc:176
ScrArea * CTX_wm_area(const bContext *C)
void ED_time_scrub_draw(const ARegion *region, const Scene *scene, bool display_seconds, bool discrete_frames, const int base)
void ED_region_draw_cb_draw(const bContext *C, ARegion *region, int type)
static void graph_free(SpaceLink *sl)
void graphedit_keymap(wmKeyConfig *keyconf)
Definition graph_ops.cc:539
static void graph_header_region_init(wmWindowManager *, ARegion *region)
void immEnd()
unsigned int uint
Definition BKE_text.h:55
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
void graph_draw_ghost_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *region)
PointerRNA RNA_id_pointer_create(ID *id)
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
Definition listbase.cc:834
void BKE_fcurves_free(ListBaseT< FCurve > *list)
GPUVertFormat * immVertexFormat()
static int graph_space_icon_get(const ScrArea *area)
bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
void ED_markers_draw(const bContext *C, int flag)
bool ED_markers_region_visible(const ScrArea *area, const ARegion *region)
void immBegin(GPUPrimType, uint vertex_len)
static void graph_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
void WM_msg_subscribe_rna_params(wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
@ ANIMTYPE_NLACURVE
@ ANIMTYPE_FCURVE
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
LibraryForeachIDFlag BKE_lib_query_foreachid_process_flags_get(const LibraryForeachIDData *data)
Definition lib_query.cc:133
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
void immUnbindProgram()
void GPU_line_width(float width)
Definition gpu_state.cc:151
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
static void graph_init(wmWindowManager *wm, ScrArea *area)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
static void draw_normalization_borders(Scene *scene, View2D *v2d)
wmWindow * WM_window_find_by_area(wmWindowManager *wm, const ScrArea *area)
Scene * WM_window_get_active_scene(const wmWindow *win)
size_t ANIM_animdata_filter(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data, const eAnimFilter_Flags filter_mode, void *data, const eAnimCont_Types datatype)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:504
void immVertex2f(uint attr_id, float x, float y)
@ ANIMFILTER_FCURVESONLY
@ ANIMFILTER_LIST_VISIBLE
@ ANIMFILTER_DATA_VISIBLE
@ ANIMFILTER_NODUPLIS
@ ANIMFILTER_LIST_CHANNELS
void RNA_enum_items_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
BMesh const char void * data
static void graph_space_subtype_item_extend(bContext *, EnumPropertyItem **item, int *totitem)
wmEventHandler_Keymap * WM_event_add_keymap_handler_v2d_mask(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap)
static void graph_channel_region_init(wmWindowManager *wm, ARegion *region)
const EnumPropertyItem rna_enum_space_graph_mode_items[]
Definition rna_space.cc:195
void ED_region_panels(const bContext *C, ARegion *region)
Definition area.cc:3999
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void graph_buttons_register(ARegionType *art)
static void graph_region_listener(const wmRegionListenerParams *params)
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
static void graph_main_region_draw_overlay(const bContext *C, ARegion *region)
rcti ED_time_scrub_clamp_scroller_mask(const rcti &scroller_mask)
static void graph_buttons_region_draw(const bContext *C, ARegion *region)
SpaceGraph * CTX_wm_space_graph(const bContext *C)
static SpaceLink * graph_create(const ScrArea *, const Scene *scene)
bool WM_event_handler_region_v2d_mask_no_marker_poll(const wmWindow *win, const ScrArea *area, const ARegion *region, const wmEvent *event)
void immUniformThemeColorShadeAlpha(int color_id, int color_offset, int alpha_offset)
void graphedit_operatortypes()
Definition graph_ops.cc:433
void ANIM_draw_previewrange(const Scene *scene, View2D *v2d, int end_frame_width)
Definition anim_draw.cc:88
wmEventHandler_Keymap * WM_event_add_keymap_handler(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap)
@ DRAW_MARKERS_MARGIN
Definition ED_markers.hh:35
static StringRefNull graph_space_name_get(const ScrArea *area)
ARegion * BKE_area_region_new()
Definition screen.cc:522
static SpaceLink * graph_duplicate(SpaceLink *sl)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
@ ED_KEYMAP_UI
Definition ED_screen.hh:852
@ ED_KEYMAP_FOOTER
Definition ED_screen.hh:859
@ ED_KEYMAP_HEADER
Definition ED_screen.hh:858
@ ED_KEYMAP_ANIMATION
Definition ED_screen.hh:856
@ ED_KEYMAP_VIEW2D
Definition ED_screen.hh:855
@ ED_KEYMAP_FRAMES
Definition ED_screen.hh:857
void get_graph_keyframe_extents(bAnimContext *ac, float *xmin, float *xmax, float *ymin, float *ymax, bool do_sel_only, bool include_handles) ATTR_NONNULL(2
void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *region, const ListBaseT< bAnimListElem > &anim_data)
wmEventHandler_Keymap * WM_event_add_keymap_handler_poll(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap, EventHandlerPoll poll)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:428
void WM_msg_subscribe_rna(wmMsgBus *mbus, PointerRNA *ptr, const PropertyRNA *prop, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL()
@ V2D_SCROLL_VERTICAL_HIDE
@ V2D_SCROLL_HORIZONTAL_HIDE
@ V2D_SCROLL_HORIZONTAL_HANDLES
@ V2D_SCROLL_VERTICAL_HANDLES
static void set_v2d_height(View2D *v2d, const size_t item_count, const bool add_marker_padding)
static int graph_space_subtype_get(ScrArea *area)
static bool action_region_poll_hide_in_driver_mode(const RegionPollParams *params)
void graph_draw_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *region, short sel)
static void graph_id_remap(ScrArea *, SpaceLink *slink, const bke::id::IDRemapper &mappings)
static void graph_space_blend_read_data(BlendDataReader *reader, SpaceLink *sl)
float ANIM_UI_get_channels_total_height(View2D *v2d, const int item_count)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void ANIM_sync_animchannels_to_data(const bContext *C)
Definition anim_deps.cc:270
@ SIPO_RUNTIME_FLAG_NEED_CHAN_SYNC_COLOR
@ SIPO_RUNTIME_FLAG_TWEAK_HANDLES_RIGHT
@ SIPO_RUNTIME_FLAG_NEED_CHAN_SYNC
@ SIPO_RUNTIME_FLAG_TWEAK_HANDLES_LEFT
void BKE_spacetype_register(std::unique_ptr< SpaceType > st)
Definition screen.cc:379
void ANIM_animdata_freelist(ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:472
static void local_view_exit_if_unused(const bContext *C, SpaceGraph *sipo)
void getcolor_fcurve_rainbow(int cur, int tot, float out[3])
void ED_region_header_init(ARegion *region)
Definition area.cc:4406
static void graph_listener(const wmSpaceTypeListenerParams *params)
static void graph_space_blend_write(BlendWriter *writer, SpaceLink *sl)
Scene * CTX_data_scene(const bContext *C)
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
void ED_area_tag_refresh(ScrArea *area)
Definition area.cc:813
static void graph_main_region_draw(const bContext *C, ARegion *region)
void ED_spacetype_ipo()
@ ID_REMAP_APPLY_DEFAULT
@ IDWALK_CB_DIRECT_WEAK_LINK
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:394
@ FCURVE_COLOR_AUTO_YRGB
@ FCURVE_COLOR_CUSTOM
@ FCURVE_COLOR_AUTO_RGB
@ FCURVE_COLOR_AUTO_RAINBOW
static void graph_channel_region_draw(const bContext *C, ARegion *region)
void ED_time_scrub_channel_search_draw(const bContext *C, ARegion *region, bDopeSheet *dopesheet)
void ED_region_header(const bContext *C, ARegion *region)
Definition area.cc:4391
static void graph_foreach_id(SpaceLink *space_link, LibraryForeachIDData *data)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
static void graph_header_region_draw(const bContext *C, ARegion *region)
void ED_region_panels_init(wmWindowManager *wm, ARegion *region)
Definition area.cc:4006
static void graph_refresh(const bContext *C, ScrArea *area)
MINLINE int round_db_to_int(double a)
static void graph_buttons_region_init(wmWindowManager *wm, ARegion *region)
static void graph_refresh_fcurve_colors(const bContext *C)
static void graph_main_region_init(wmWindowManager *wm, ARegion *region)
static void graph_space_subtype_set(ScrArea *area, int value)
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
void(*) draw_overlay(const bContext *C, ARegion *region)
ARegionTypeFlag flag
void(*) message_subscribe(const wmRegionMessageSubscribeParams *params)
void(*) draw(const bContext *C, ARegion *region)
void(*) listener(const wmRegionListenerParams *params)
bool(*) poll(const RegionPollParams *params)
void(*) init(wmWindowManager *wm, ARegion *region)
bke::ARegionRuntime * runtime
eRegion_Alignment alignment
eRegion_Type regiontype
void write_struct_cast(const void *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
eFCurve_Coloring color_mode
StructRNA * type
Definition RNA_types.hh:63
struct RenderData r
ListBaseT< SpaceLink > spacedata
ListBaseT< FCurve > ghost_curves
ListBaseT< ARegion > regionbase
struct bDopeSheet * ads
SpaceGraph_Runtime runtime
eGraphEdit_Flag flag
eGraphEdit_Mode mode
eView2D_KeepTot keeptot
eView2D_Scroll scroll
eAnimCont_Types datatype
eAnim_ChannelType type
bAnimListElem * next
eDopeSheet_FilterFlag filterflag
struct Collection * filter_grp
ListBaseT< wmEventHandler > handlers
unsigned int action
Definition WM_types.hh:371
unsigned int category
Definition WM_types.hh:371
unsigned int data
Definition WM_types.hh:371