38
#include "MEM_guardedalloc.h"
40
42
#include "BLI_blenlib.h"
41
43
#include "BLI_math.h"
44
#include "BLI_utildefines.h"
43
46
#include "DNA_anim_types.h"
44
47
#include "DNA_object_types.h"
45
48
#include "DNA_screen_types.h"
46
49
#include "DNA_space_types.h"
47
50
#include "DNA_windowmanager_types.h"
51
#include "DNA_userdef_types.h"
49
#include "BKE_animsys.h"
50
53
#include "BKE_context.h"
51
54
#include "BKE_curve.h"
52
#include "BKE_depsgraph.h"
53
55
#include "BKE_fcurve.h"
54
#include "BKE_global.h"
56
#include "BKE_object.h"
57
#include "BKE_screen.h"
58
#include "BKE_utildefines.h"
60
58
#include "BIF_gl.h"
61
59
#include "BIF_glutil.h"
75
73
* drawing components for some F-Curve (fcu)
76
74
* - selected F-Curves should be more visible than partially visible ones
78
#define drawFCurveFade(fcu) ( ((fcu)->flag & FCURVE_SELECTED)? 1.0f : 0.25f )
80
/* set the colour for some point from some value given packed into an int
81
* - intV: integer value containing color info packed into an int
82
* - alpha: float value describing the
84
#define cpackA(intVC, alpha) \
87
cpack_to_rgb(intVC, &_cpackCol[0], &_cpackCol[1], &_cpackCol[2]); \
88
glColor4f(_cpackCol[0], _cpackCol[1], _cpackCol[2], alpha); \
76
static float fcurve_display_alpha(FCurve *fcu)
78
return (fcu->flag & FCURVE_SELECTED) ? 1.0f : U.fcu_inactive_alpha;
91
81
/* *************************** */
92
82
/* F-Curve Modifier Drawing */
94
84
/* Envelope -------------- */
96
86
// TODO: draw a shaded poly showing the region of influence too!!!
97
static void draw_fcurve_modifier_controls_envelope (FCurve *fcu, FModifier *fcm, View2D *v2d)
87
static void draw_fcurve_modifier_controls_envelope (FModifier *fcm, View2D *v2d)
99
89
FMod_Envelope *env= (FMod_Envelope *)fcm->data;
100
90
FCM_EnvelopeData *fed;
128
118
/* only draw if visible
129
119
* - min/max here are fixed, not relative
131
if IN_RANGE(fed->time, (v2d->cur.xmin - fac), (v2d->cur.xmax + fac)) {
121
if (IN_RANGE(fed->time, (v2d->cur.xmin - fac), (v2d->cur.xmax + fac))) {
132
122
glVertex2f(fed->time, fed->min);
133
123
glVertex2f(fed->time, fed->max);
144
134
/* Points ---------------- */
146
136
/* helper func - draw keyframe vertices only for an F-Curve */
147
static void draw_fcurve_vertices_keyframes (bAnimContext *ac, FCurve *fcu, View2D *v2d, short edit, short sel)
137
static void draw_fcurve_vertices_keyframes (FCurve *fcu, SpaceIpo *UNUSED(sipo), View2D *v2d, short edit, short sel)
149
139
BezTriple *bezt= fcu->bezt;
150
140
const float fac= 0.05f * (v2d->cur.xmax - v2d->cur.xmin);
156
146
bglBegin(GL_POINTS);
158
148
for (i = 0; i < fcu->totvert; i++, bezt++) {
159
/* as an optimisation step, only draw those in view
149
/* as an optimization step, only draw those in view
160
150
* - we apply a correction factor to ensure that points don't pop in/out due to slight twitches of view size
162
if IN_RANGE(bezt->vec[1][0], (v2d->cur.xmin - fac), (v2d->cur.xmax + fac)) {
152
if (IN_RANGE(bezt->vec[1][0], (v2d->cur.xmin - fac), (v2d->cur.xmax + fac))) {
164
154
/* 'Keyframe' vertex only, as handle lines and handles have already been drawn
165
155
* - only draw those with correct selection state for the current drawing color
218
208
/* helper func - draw handle vertices only for an F-Curve (if it is not protected) */
219
static void draw_fcurve_vertices_handles (bAnimContext *ac, SpaceIpo *sipo, FCurve *fcu, View2D *v2d, short sel)
209
static void draw_fcurve_vertices_handles (FCurve *fcu, SpaceIpo *sipo, View2D *v2d, short sel, short sel_handle_only)
221
211
BezTriple *bezt= fcu->bezt;
222
212
BezTriple *prevbezt = NULL;
232
222
else UI_ThemeColor(TH_HANDLE_VERTEX);
234
224
/* anti-aliased lines for more consistent appearance */
235
glEnable(GL_LINE_SMOOTH);
225
if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glEnable(GL_LINE_SMOOTH);
236
226
glEnable(GL_BLEND);
238
228
for (i=0; i < fcu->totvert; i++, prevbezt=bezt, bezt++) {
244
234
* Also, need to take into account whether the keyframe was selected
245
235
* if a Graph Editor option to only show handles of selected keys is on.
247
if ( !(sipo->flag & SIPO_SELVHANDLESONLY) || BEZSELECTED(bezt) ) {
237
if ( !sel_handle_only || BEZSELECTED(bezt) ) {
248
238
if ( (!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ)) ) {
249
239
if ((bezt->f1 & SELECT) == sel)/* && v2d->cur.xmin < bezt->vec[0][0] < v2d->cur.xmax)*/
250
240
draw_fcurve_handle_control(bezt->vec[0][0], bezt->vec[0][1], xscale, yscale, hsize);
260
glDisable(GL_LINE_SMOOTH);
250
if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glDisable(GL_LINE_SMOOTH);
261
251
glDisable(GL_BLEND);
264
254
/* helper func - set color to draw F-Curve data with */
265
static void set_fcurve_vertex_color (SpaceIpo *sipo, FCurve *fcu, short sel)
255
static void set_fcurve_vertex_color (FCurve *fcu, short sel)
267
257
/* Fade the 'intensity' of the vertices based on the selection of the curves too */
268
int alphaOffset= (int)((drawFCurveFade(fcu) - 1.0f) * 255);
258
int alphaOffset= (int)((fcurve_display_alpha(fcu) - 1.0f) * 255);
270
260
/* Set color of curve vertex based on state of curve (i.e. 'Edit' Mode) */
271
261
if ((fcu->flag & FCURVE_PROTECTED)==0) {
284
static void draw_fcurve_vertices (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, FCurve *fcu, int do_handles)
274
static void draw_fcurve_vertices (SpaceIpo *sipo, ARegion *ar, FCurve *fcu, short do_handles, short sel_handle_only)
286
276
View2D *v2d= &ar->v2d;
295
285
glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
297
287
/* draw the two handles first (if they're shown, the curve doesn't have just a single keyframe, and the curve is being edited) */
300
set_fcurve_vertex_color(sipo, fcu, 0);
301
draw_fcurve_vertices_handles(ac, sipo, fcu, v2d, 0);
289
set_fcurve_vertex_color(fcu, 0);
290
draw_fcurve_vertices_handles(fcu, sipo, v2d, 0, sel_handle_only);
303
set_fcurve_vertex_color(sipo, fcu, 1);
304
draw_fcurve_vertices_handles(ac, sipo, fcu, v2d, 1);
292
set_fcurve_vertex_color(fcu, 1);
293
draw_fcurve_vertices_handles(fcu, sipo, v2d, 1, sel_handle_only);
307
296
/* draw keyframes over the handles */
308
set_fcurve_vertex_color(sipo, fcu, 0);
309
draw_fcurve_vertices_keyframes(ac, fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 0);
297
set_fcurve_vertex_color(fcu, 0);
298
draw_fcurve_vertices_keyframes(fcu, sipo, v2d, !(fcu->flag & FCURVE_PROTECTED), 0);
311
set_fcurve_vertex_color(sipo, fcu, 1);
312
draw_fcurve_vertices_keyframes(ac, fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 1);
300
set_fcurve_vertex_color(fcu, 1);
301
draw_fcurve_vertices_keyframes(fcu, sipo, v2d, !(fcu->flag & FCURVE_PROTECTED), 1);
314
303
glPointSize(1.0f);
321
310
/* don't draw handle lines if handles are not to be shown */
322
311
if ( (sipo->flag & SIPO_NOHANDLES) || /* handles shouldn't be shown anywhere */
323
312
(fcu->flag & FCURVE_PROTECTED) || /* keyframes aren't editable */
313
#if 0 /* handles can still be selected and handle types set, better draw - campbell */
324
314
(fcu->flag & FCURVE_INT_VALUES) || /* editing the handles here will cause weird/incorrect interpolation issues */
325
316
((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) || /* group that curve belongs to is not editable */
326
317
(fcu->totvert <= 1) /* do not show handles if there is only 1 keyframe, otherwise they all clump together in an ugly ball */
337
327
/* draw lines for F-Curve handles only (this is only done in EditMode)
338
328
* note: draw_fcurve_handles_check must be checked before running this. */
339
static void draw_fcurve_handles (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
329
static void draw_fcurve_handles (SpaceIpo *sipo, FCurve *fcu)
343
333
/* a single call to GL_LINES here around these calls should be sufficient to still
344
* get separate line segments, but which aren't wrapped with GL_LINE_STRIP everytime we
334
* get separate line segments, but which aren't wrapped with GL_LINE_STRIP every time we
345
335
* want a single line
347
337
glBegin(GL_LINES);
353
343
BezTriple *bezt=fcu->bezt, *prevbezt=NULL;
354
344
int basecol= (sel)? TH_HANDLE_SEL_FREE : TH_HANDLE_FREE;
358
/* if only selected keyframes have handles shown, skip the first round */
359
if ((sel == 0) && (sipo->flag & SIPO_SELVHANDLESONLY))
346
unsigned char col[4];
362
348
for (b= 0; b < fcu->totvert; b++, prevbezt=bezt, bezt++) {
363
349
/* if only selected keyframes can get their handles shown,
371
357
/* draw handle with appropriate set of colors if selection is ok */
372
358
if ((bezt->f2 & SELECT)==sel) {
373
359
fp= bezt->vec[0];
375
361
/* only draw first handle if previous segment had handles */
376
if ( (!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ)) )
362
if ((!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ))) {
378
363
UI_GetThemeColor3ubv(basecol + bezt->h1, col);
379
col[3]= drawFCurveFade(fcu) * 255;
364
col[3]= fcurve_display_alpha(fcu) * 255;
380
365
glColor4ubv((GLubyte *)col);
382
367
glVertex2fv(fp); glVertex2fv(fp+3);
385
370
/* only draw second handle if this segment is bezier */
386
if (bezt->ipo == BEZT_IPO_BEZ)
371
if (bezt->ipo == BEZT_IPO_BEZ) {
388
372
UI_GetThemeColor3ubv(basecol + bezt->h2, col);
389
col[3]= drawFCurveFade(fcu) * 255;
373
col[3]= fcurve_display_alpha(fcu) * 255;
390
374
glColor4ubv((GLubyte *)col);
392
376
glVertex2fv(fp+3); glVertex2fv(fp+6);
400
384
fp= bezt->vec[0];
401
385
UI_GetThemeColor3ubv(basecol + bezt->h1, col);
402
col[3]= drawFCurveFade(fcu) * 255;
386
col[3]= fcurve_display_alpha(fcu) * 255;
403
387
glColor4ubv((GLubyte *)col);
405
389
glVertex2fv(fp); glVertex2fv(fp+3);
412
396
fp= bezt->vec[1];
413
397
UI_GetThemeColor3ubv(basecol + bezt->h2, col);
414
col[3]= drawFCurveFade(fcu) * 255;
398
col[3]= fcurve_display_alpha(fcu) * 255;
415
399
glColor4ubv((GLubyte *)col);
417
401
glVertex2fv(fp); glVertex2fv(fp+3);
464
448
/* helper func - draw keyframe vertices only for an F-Curve */
465
static void draw_fcurve_samples (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
449
static void draw_fcurve_samples (SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
467
451
FPoint *first, *last;
468
452
float hsize, xscale, yscale;
483
467
if (first && last) {
484
468
/* anti-aliased lines for more consistent appearance */
485
glEnable(GL_LINE_SMOOTH);
469
if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glEnable(GL_LINE_SMOOTH);
486
470
glEnable(GL_BLEND);
488
472
draw_fcurve_sample_control(first->vec[0], first->vec[1], xscale, yscale, hsize);
489
473
draw_fcurve_sample_control(last->vec[0], last->vec[1], xscale, yscale, hsize);
491
475
glDisable(GL_BLEND);
492
glDisable(GL_LINE_SMOOTH);
476
if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glDisable(GL_LINE_SMOOTH);
496
480
/* Curve ---------------- */
498
482
/* helper func - just draw the F-Curve by sampling the visible region (for drawing curves with modifiers) */
499
static void draw_fcurve_curve (bAnimContext *ac, ID *id, FCurve *fcu, SpaceIpo *sipo, View2D *v2d, View2DGrid *grid)
483
static void draw_fcurve_curve (bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, View2DGrid *grid)
501
485
ChannelDriver *driver;
502
486
float samplefreq, ctime;
636
620
/* helper func - draw one repeat of an F-Curve */
637
static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, View2DGrid *grid)
621
static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d)
639
623
BezTriple *prevbezt= fcu->bezt;
640
624
BezTriple *bezt= prevbezt+1;
685
669
/* draw curve between first and last keyframe (if there are enough to do so) */
670
// TODO: optimize this to not have to calc stuff out of view too?
687
672
if (prevbezt->ipo==BEZT_IPO_CONST) {
688
673
/* Constant-Interpolation: draw segment between previous keyframe and next, but holding same value */
705
690
* - resol determines number of points to sample in between keyframes
708
/* resol not depending on horizontal resolution anymore, drivers for example... */
709
// TODO: would be nice to make this depend on the scale of the graph too...
693
/* resol depends on distance between points (not just horizontal) OR is a fixed high res */
694
// TODO: view scale should factor into this someday too...
713
resol= (int)(3.0*sqrt(bezt->vec[1][0] - prevbezt->vec[1][0]));
698
resol= (int)(5.0f*len_v2v2(bezt->vec[1], prevbezt->vec[1]));
716
701
/* only draw one */
791
777
/* Draw the 'ghost' F-Curves (i.e. snapshots of the curve)
792
778
* NOTE: unit mapping has already been applied to the values, so do not try and apply again
794
void graph_draw_ghost_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid *grid)
780
void graph_draw_ghost_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar)
835
821
/* build list of curves to draw */
836
filter= (ANIMFILTER_VISIBLE|ANIMFILTER_CURVESONLY|ANIMFILTER_CURVEVISIBLE);
822
filter= (ANIMFILTER_DATA_VISIBLE|ANIMFILTER_CURVE_VISIBLE);
837
823
filter |= ((sel) ? (ANIMFILTER_SEL) : (ANIMFILTER_UNSEL));
838
824
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
854
840
* - curve line may be result of one or more destructive modifiers or just the raw data,
855
841
* so we need to check which method should be used
856
* - controls from active modifier take precidence over keyframes
842
* - controls from active modifier take precedence over keyframes
857
843
* (XXX! editing tools need to take this into account!)
873
859
/* set whatever color the curve has set
874
860
* - unselected curves draw less opaque to help distinguish the selected ones
876
glColor4f(fcu->color[0], fcu->color[1], fcu->color[2], drawFCurveFade(fcu));
862
glColor4f(fcu->color[0], fcu->color[1], fcu->color[2], fcurve_display_alpha(fcu));
865
/* draw active F-Curve thicker than the rest to make it stand out */
866
if (fcu->flag & FCURVE_ACTIVE) {
879
870
/* anti-aliased lines for less jagged appearance */
880
glEnable(GL_LINE_SMOOTH);
871
if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glEnable(GL_LINE_SMOOTH);
881
872
glEnable(GL_BLEND);
883
874
/* draw F-Curve */
885
876
/* draw a curve affected by modifiers or only allowed to have integer values
886
877
* by sampling it at various small-intervals over the visible region
888
draw_fcurve_curve(ac, ale->id, fcu, sipo, &ar->v2d, grid);
879
draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid);
890
881
else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) {
891
882
/* just draw curve based on defined data (i.e. no modifiers) */
893
draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d, grid);
884
draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d);
894
885
else if (fcu->fpt)
895
886
draw_fcurve_curve_samples(ac, ale->id, fcu, &ar->v2d);
898
889
/* restore settings */
901
glDisable(GL_LINE_SMOOTH);
893
if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glDisable(GL_LINE_SMOOTH);
902
894
glDisable(GL_BLEND);
906
898
* - if the option to only show controls if the F-Curve is selected is enabled, we must obey this
908
900
if (!(sipo->flag & SIPO_SELCUVERTSONLY) || (fcu->flag & FCURVE_SELECTED)) {
909
if (fcurve_needs_draw_fmodifier_controls(fcu, fcm)) {
901
if (fcurve_are_keyframes_usable(fcu) == 0) {
910
902
/* only draw controls if this is the active modifier */
911
903
if ((fcu->flag & FCURVE_ACTIVE) && (fcm)) {
912
904
switch (fcm->type) {
913
905
case FMODIFIER_TYPE_ENVELOPE: /* envelope */
914
draw_fcurve_modifier_controls_envelope(fcu, fcm, &ar->v2d);
906
draw_fcurve_modifier_controls_envelope(fcm, &ar->v2d);
926
918
if (do_handles) {
927
919
/* only draw handles/vertices on keyframes */
928
920
glEnable(GL_BLEND);
929
draw_fcurve_handles(ac, sipo, ar, fcu);
921
draw_fcurve_handles(sipo, fcu);
930
922
glDisable(GL_BLEND);
933
draw_fcurve_vertices(ac, sipo, ar, fcu, do_handles);
925
draw_fcurve_vertices(sipo, ar, fcu, do_handles, (sipo->flag & SIPO_SELVHANDLESONLY));
936
928
/* samples: only draw two indicators at either end as indicators */
937
draw_fcurve_samples(ac, sipo, ar, fcu);
929
draw_fcurve_samples(sipo, ar, fcu);
940
932
/* unapply unit mapping */
955
947
/* Channel List */
957
949
/* left hand part */
958
void graph_draw_channel_names(bContext *C, bAnimContext *ac, SpaceIpo *sipo, ARegion *ar)
950
void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar)
960
952
ListBase anim_data = {NULL, NULL};
961
953
bAnimListElem *ale;
964
956
View2D *v2d= &ar->v2d;
965
957
float y= 0.0f, height;
968
961
/* build list of channels to draw */
969
filter= (ANIMFILTER_VISIBLE|ANIMFILTER_CHANNELS);
962
filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
970
963
items= ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
972
965
/* Update max-extent of channels here (taking into account scrollers):
1001
994
{ /* second pass: widgets */
1002
uiBlock *block= uiBeginBlock(C, ar, "graph channel buttons", UI_EMBOSS);
995
uiBlock *block= uiBeginBlock(C, ar, __func__, UI_EMBOSS);
996
size_t channel_index = 0;
1004
998
y= (float)ACHANNEL_FIRST;
1016
1010
IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) )
1018
1012
/* draw all channels using standard channel-drawing API */
1019
ANIM_channel_draw_widgets(ac, ale, block, yminc, ymaxc);
1013
ANIM_channel_draw_widgets(C, ac, ale, block, yminc, ymaxc, channel_index);
1022
1016
/* adjust y-position for next one */
1023
1017
y -= ACHANNEL_STEP;
1026
1021
uiEndBlock(C, block);