~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/animation/keyframes_draw.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
#include "DNA_speaker_types.h"
61
61
#include "DNA_world_types.h"
62
62
#include "DNA_gpencil_types.h"
 
63
#include "DNA_mask_types.h"
63
64
 
64
65
#include "BKE_key.h"
65
66
#include "BKE_material.h"
66
 
#include "BKE_global.h"         // XXX remove me!
 
67
#include "BKE_global.h"     // XXX remove me!
67
68
 
68
69
 
69
70
#include "BIF_gl.h"
80
81
 
81
82
/* Comparator callback used for ActKeyColumns and cframe float-value pointer */
82
83
/* NOTE: this is exported to other modules that use the ActKeyColumns for finding keyframes */
83
 
short compare_ak_cfraPtr (void *node, void *data)
 
84
short compare_ak_cfraPtr(void *node, void *data)
84
85
{
85
 
        ActKeyColumn *ak= (ActKeyColumn *)node;
86
 
        float *cframe= data;
 
86
        ActKeyColumn *ak = (ActKeyColumn *)node;
 
87
        float *cframe = data;
87
88
        
88
89
        if (*cframe < ak->cfra)
89
90
                return -1;
96
97
/* --------------- */
97
98
 
98
99
/* Comparator callback used for ActKeyColumns and BezTriple */
99
 
static short compare_ak_bezt (void *node, void *data)
 
100
static short compare_ak_bezt(void *node, void *data)
100
101
{
101
 
        ActKeyColumn *ak= (ActKeyColumn *)node;
102
 
        BezTriple *bezt= (BezTriple *)data;
 
102
        ActKeyColumn *ak = (ActKeyColumn *)node;
 
103
        BezTriple *bezt = (BezTriple *)data;
103
104
        
104
105
        if (bezt->vec[1][0] < ak->cfra)
105
106
                return -1;
110
111
}
111
112
 
112
113
/* New node callback used for building ActKeyColumns from BezTriples */
113
 
static DLRBT_Node *nalloc_ak_bezt (void *data)
 
114
static DLRBT_Node *nalloc_ak_bezt(void *data)
114
115
{
115
 
        ActKeyColumn *ak= MEM_callocN(sizeof(ActKeyColumn), "ActKeyColumn");
116
 
        BezTriple *bezt= (BezTriple *)data;
 
116
        ActKeyColumn *ak = MEM_callocN(sizeof(ActKeyColumn), "ActKeyColumn");
 
117
        BezTriple *bezt = (BezTriple *)data;
117
118
        
118
119
        /* store settings based on state of BezTriple */
119
 
        ak->cfra= bezt->vec[1][0];
120
 
        ak->sel= BEZSELECTED(bezt) ? SELECT : 0;
121
 
        ak->key_type= BEZKEYTYPE(bezt); 
 
120
        ak->cfra = bezt->vec[1][0];
 
121
        ak->sel = BEZSELECTED(bezt) ? SELECT : 0;
 
122
        ak->key_type = BEZKEYTYPE(bezt);
122
123
        
123
124
        /* set 'modified', since this is used to identify long keyframes */
124
125
        ak->modified = 1;
127
128
}
128
129
 
129
130
/* Node updater callback used for building ActKeyColumns from BezTriples */
130
 
static void nupdate_ak_bezt (void *node, void *data)
 
131
static void nupdate_ak_bezt(void *node, void *data)
131
132
{
132
 
        ActKeyColumn *ak= (ActKeyColumn *)node;
133
 
        BezTriple *bezt= (BezTriple *)data;
 
133
        ActKeyColumn *ak = (ActKeyColumn *)node;
 
134
        BezTriple *bezt = (BezTriple *)data;
134
135
        
135
136
        /* set selection status and 'touched' status */
136
137
        if (BEZSELECTED(bezt)) ak->sel = SELECT;
138
139
        
139
140
        /* for keyframe type, 'proper' keyframes have priority over breakdowns (and other types for now) */
140
141
        if (BEZKEYTYPE(bezt) == BEZT_KEYTYPE_KEYFRAME)
141
 
                ak->key_type= BEZT_KEYTYPE_KEYFRAME;
 
142
                ak->key_type = BEZT_KEYTYPE_KEYFRAME;
142
143
}
143
144
 
144
145
/* ......... */
145
146
 
146
147
/* Comparator callback used for ActKeyColumns and GPencil frame */
147
 
static short compare_ak_gpframe (void *node, void *data)
 
148
static short compare_ak_gpframe(void *node, void *data)
148
149
{
149
 
        ActKeyColumn *ak= (ActKeyColumn *)node;
150
 
        bGPDframe *gpf= (bGPDframe *)data;
 
150
        ActKeyColumn *ak = (ActKeyColumn *)node;
 
151
        bGPDframe *gpf = (bGPDframe *)data;
151
152
        
152
153
        if (gpf->framenum < ak->cfra)
153
154
                return -1;
158
159
}
159
160
 
160
161
/* New node callback used for building ActKeyColumns from GPencil frames */
161
 
static DLRBT_Node *nalloc_ak_gpframe (void *data)
 
162
static DLRBT_Node *nalloc_ak_gpframe(void *data)
162
163
{
163
 
        ActKeyColumn *ak= MEM_callocN(sizeof(ActKeyColumn), "ActKeyColumnGPF");
164
 
        bGPDframe *gpf= (bGPDframe *)data;
 
164
        ActKeyColumn *ak = MEM_callocN(sizeof(ActKeyColumn), "ActKeyColumnGPF");
 
165
        bGPDframe *gpf = (bGPDframe *)data;
165
166
        
166
167
        /* store settings based on state of BezTriple */
167
 
        ak->cfra= gpf->framenum;
168
 
        ak->sel= (gpf->flag & GP_FRAME_SELECT) ? SELECT : 0;
 
168
        ak->cfra = gpf->framenum;
 
169
        ak->sel = (gpf->flag & GP_FRAME_SELECT) ? SELECT : 0;
169
170
        
170
171
        /* set 'modified', since this is used to identify long keyframes */
171
172
        ak->modified = 1;
174
175
}
175
176
 
176
177
/* Node updater callback used for building ActKeyColumns from GPencil frames */
177
 
static void nupdate_ak_gpframe (void *node, void *data)
 
178
static void nupdate_ak_gpframe(void *node, void *data)
178
179
{
179
 
        ActKeyColumn *ak= (ActKeyColumn *)node;
180
 
        bGPDframe *gpf= (bGPDframe *)data;
 
180
        ActKeyColumn *ak = (ActKeyColumn *)node;
 
181
        bGPDframe *gpf = (bGPDframe *)data;
181
182
        
182
183
        /* set selection status and 'touched' status */
183
184
        if (gpf->flag & GP_FRAME_SELECT) ak->sel = SELECT;
184
185
        ak->modified += 1;
185
186
}
186
187
 
 
188
/* ......... */
 
189
 
 
190
/* Comparator callback used for ActKeyColumns and GPencil frame */
 
191
static short compare_ak_masklayshape(void *node, void *data)
 
192
{
 
193
        ActKeyColumn *ak = (ActKeyColumn *)node;
 
194
        MaskLayerShape *masklay_shape = (MaskLayerShape *)data;
 
195
 
 
196
        if (masklay_shape->frame < ak->cfra)
 
197
                return -1;
 
198
        else if (masklay_shape->frame > ak->cfra)
 
199
                return 1;
 
200
        else
 
201
                return 0;
 
202
}
 
203
 
 
204
/* New node callback used for building ActKeyColumns from GPencil frames */
 
205
static DLRBT_Node *nalloc_ak_masklayshape(void *data)
 
206
{
 
207
        ActKeyColumn *ak = MEM_callocN(sizeof(ActKeyColumn), "ActKeyColumnGPF");
 
208
        MaskLayerShape *masklay_shape = (MaskLayerShape *)data;
 
209
 
 
210
        /* store settings based on state of BezTriple */
 
211
        ak->cfra = masklay_shape->frame;
 
212
        ak->sel = (masklay_shape->flag & MASK_SHAPE_SELECT) ? SELECT : 0;
 
213
 
 
214
        /* set 'modified', since this is used to identify long keyframes */
 
215
        ak->modified = 1;
 
216
 
 
217
        return (DLRBT_Node *)ak;
 
218
}
 
219
 
 
220
/* Node updater callback used for building ActKeyColumns from GPencil frames */
 
221
static void nupdate_ak_masklayshape(void *node, void *data)
 
222
{
 
223
        ActKeyColumn *ak = (ActKeyColumn *)node;
 
224
        MaskLayerShape *masklay_shape = (MaskLayerShape *)data;
 
225
 
 
226
        /* set selection status and 'touched' status */
 
227
        if (masklay_shape->flag & MASK_SHAPE_SELECT) ak->sel = SELECT;
 
228
        ak->modified += 1;
 
229
}
 
230
 
 
231
 
187
232
/* --------------- */
188
233
 
189
234
/* Add the given BezTriple to the given 'list' of Keyframes */
204
249
                BLI_dlrbTree_add(keys, compare_ak_gpframe, nalloc_ak_gpframe, nupdate_ak_gpframe, gpf);
205
250
}
206
251
 
 
252
/* Add the given MaskLayerShape Frame to the given 'list' of Keyframes */
 
253
static void add_masklay_to_keycolumns_list(DLRBT_Tree *keys, MaskLayerShape *masklay_shape)
 
254
{
 
255
        if (ELEM(NULL, keys, masklay_shape))
 
256
                return;
 
257
        else
 
258
                BLI_dlrbTree_add(keys, compare_ak_masklayshape, nalloc_ak_masklayshape, nupdate_ak_masklayshape, masklay_shape);
 
259
}
 
260
 
207
261
/* ActBeztColumns (Helpers for Long Keyframes) ------------------------------ */
208
262
 
209
263
/* maximum size of default buffer for BezTriple columns */
210
 
#define MAX_ABK_BUFSIZE         4
 
264
#define MAX_ABK_BUFSIZE     4
211
265
 
212
266
/* BezTriple Container Node */
213
267
// NOTE: only used internally while building Long Keyframes for now, but may be useful externally?
214
268
typedef struct ActBeztColumn {
215
269
        /* Tree Node interface ---------------- */
216
 
                /* ListBase linkage */
 
270
        /* ListBase linkage */
217
271
        struct ActBeztColumn *next, *prev;
218
272
        
219
 
                /* sorting-tree linkage */
220
 
        struct ActBeztColumn *left, *right;     /* 'children' of this node, less than and greater than it (respectively) */
221
 
        struct ActBeztColumn *parent;           /* parent of this node in the tree */
222
 
        char tree_col;                                          /* DLRB_BLACK or DLRB_RED */
 
273
        /* sorting-tree linkage */
 
274
        struct ActBeztColumn *left, *right; /* 'children' of this node, less than and greater than it (respectively) */
 
275
        struct ActBeztColumn *parent;       /* parent of this node in the tree */
 
276
        char tree_col;                      /* DLRB_BLACK or DLRB_RED */
223
277
        char pad;
224
278
        
225
279
        /* BezTriple Store -------------------- */
226
 
        short numBezts;                                         /* number of BezTriples on this frame */
227
 
        float cfra;                                                     /* frame that the BezTriples occur on */
 
280
        short numBezts;                     /* number of BezTriples on this frame */
 
281
        float cfra;                         /* frame that the BezTriples occur on */
228
282
        
229
 
        BezTriple *bezts[MAX_ABK_BUFSIZE];      /* buffer of pointers to BezTriples on the same frame */
 
283
        BezTriple *bezts[MAX_ABK_BUFSIZE];  /* buffer of pointers to BezTriples on the same frame */
230
284
        //BezTriple **bezts_extra;                      /* secondary buffer of pointers if need be */
231
285
} ActBeztColumn;
232
286
 
233
287
/* --------------- */
234
288
 
235
289
/* Comparator callback used for ActBeztColumns and BezTriple */
236
 
static short compare_abk_bezt (void *node, void *data)
 
290
static short compare_abk_bezt(void *node, void *data)
237
291
{
238
 
        ActBeztColumn *abk= (ActBeztColumn *)node;
239
 
        BezTriple *bezt= (BezTriple *)data;
 
292
        ActBeztColumn *abk = (ActBeztColumn *)node;
 
293
        BezTriple *bezt = (BezTriple *)data;
240
294
        
241
295
        if (bezt->vec[1][0] < abk->cfra)
242
296
                return -1;
247
301
}
248
302
 
249
303
/* New node callback used for building ActBeztColumns from BezTriples */
250
 
static DLRBT_Node *nalloc_abk_bezt (void *data)
 
304
static DLRBT_Node *nalloc_abk_bezt(void *data)
251
305
{
252
 
        ActBeztColumn *abk= MEM_callocN(sizeof(ActBeztColumn), "ActKeyColumn");
253
 
        BezTriple *bezt= (BezTriple *)data;
 
306
        ActBeztColumn *abk = MEM_callocN(sizeof(ActBeztColumn), "ActKeyColumn");
 
307
        BezTriple *bezt = (BezTriple *)data;
254
308
        
255
309
        /* store the BeztTriple in the buffer, and keep track of its frame number */
256
 
        abk->cfra= bezt->vec[1][0];
257
 
        abk->bezts[abk->numBezts++]= bezt;
 
310
        abk->cfra = bezt->vec[1][0];
 
311
        abk->bezts[abk->numBezts++] = bezt;
258
312
        
259
313
        return (DLRBT_Node *)abk;
260
314
}
261
315
 
262
316
/* Node updater callback used for building ActBeztColumns from BezTriples */
263
 
static void nupdate_abk_bezt (void *node, void *data)
 
317
static void nupdate_abk_bezt(void *node, void *data)
264
318
{
265
 
        ActBeztColumn *abk= (ActBeztColumn *)node;
266
 
        BezTriple *bezt= (BezTriple *)data;
 
319
        ActBeztColumn *abk = (ActBeztColumn *)node;
 
320
        BezTriple *bezt = (BezTriple *)data;
267
321
        
268
322
        /* just add the BezTriple to the buffer if there's space, or allocate a new one */
269
323
        if (abk->numBezts >= MAX_ABK_BUFSIZE) {
270
324
                // TODO: need to allocate new array to cater...
271
 
                //bezts_extra= MEM_callocN(...);
 
325
                //bezts_extra = MEM_callocN(...);
272
326
                if (G.debug & G_DEBUG)
273
327
                        printf("FIXME: nupdate_abk_bezt() missing case for too many overlapping BezTriples\n");
274
328
        }
275
329
        else {
276
330
                /* just store an extra one */
277
 
                abk->bezts[abk->numBezts++]= bezt;
 
331
                abk->bezts[abk->numBezts++] = bezt;
278
332
        }
279
333
}
280
334
 
281
335
/* --------------- */
282
336
 
283
337
/* Return the BezTriple in the given ActBeztColumn that matches the requested value */
284
 
static BezTriple *abk_get_bezt_with_value (ActBeztColumn *abk, float value)
 
338
static BezTriple *abk_get_bezt_with_value(ActBeztColumn *abk, float value)
285
339
{
286
340
        BezTriple *bezt;
287
341
        int i;
291
345
                return NULL;
292
346
        
293
347
        /* look over each BezTriple in this container */
294
 
        for (i = 0; i < abk->numBezts; i++) {           
 
348
        for (i = 0; i < abk->numBezts; i++) {
295
349
                /* only do exact match for now... */
296
 
                if (/*i >= MAX_ABK_BUFSIZE*/0) {
 
350
                if (/*i >= MAX_ABK_BUFSIZE*/ 0) {
297
351
                        // TODO: this case needs special handling
298
352
                }
299
353
                else {
300
354
                        /* just use the default buffer */
301
 
                        bezt= abk->bezts[i];
 
355
                        bezt = abk->bezts[i];
302
356
                        
303
357
                        if (bezt->vec[1][1] == value)
304
358
                                return bezt;
312
366
 
313
367
/* Comparator callback used for ActKeyBlock and cframe float-value pointer */
314
368
/* NOTE: this is exported to other modules that use the ActKeyBlocks for finding long-keyframes */
315
 
short compare_ab_cfraPtr (void *node, void *data)
 
369
short compare_ab_cfraPtr(void *node, void *data)
316
370
{
317
 
        ActKeyBlock *ab= (ActKeyBlock *)node;
318
 
        float *cframe= data;
 
371
        ActKeyBlock *ab = (ActKeyBlock *)node;
 
372
        float *cframe = data;
319
373
        
320
374
        if (*cframe < ab->start)
321
375
                return -1;
330
384
/* Create a ActKeyColumn for a pair of BezTriples */
331
385
static ActKeyBlock *bezts_to_new_actkeyblock(BezTriple *prev, BezTriple *beztn)
332
386
{
333
 
        ActKeyBlock *ab= MEM_callocN(sizeof(ActKeyBlock), "ActKeyBlock");
334
 
        
335
 
        ab->start= prev->vec[1][0];
336
 
        ab->end= beztn->vec[1][0];
337
 
        ab->val= beztn->vec[1][1];
338
 
        
339
 
        ab->sel= (BEZSELECTED(prev) || BEZSELECTED(beztn)) ? SELECT : 0;
 
387
        ActKeyBlock *ab = MEM_callocN(sizeof(ActKeyBlock), "ActKeyBlock");
 
388
        
 
389
        ab->start = prev->vec[1][0];
 
390
        ab->end = beztn->vec[1][0];
 
391
        ab->val = beztn->vec[1][1];
 
392
        
 
393
        ab->sel = (BEZSELECTED(prev) || BEZSELECTED(beztn)) ? SELECT : 0;
340
394
        ab->modified = 1;
341
395
        
342
396
        return ab;
344
398
 
345
399
static void add_bezt_to_keyblocks_list(DLRBT_Tree *blocks, DLRBT_Tree *beztTree, BezTriple *beztn)
346
400
{
347
 
        ActKeyBlock *new_ab= NULL;
 
401
        ActKeyBlock *new_ab = NULL;
348
402
        ActBeztColumn *abk;
349
403
        BezTriple *prev;
350
404
        
351
405
        /* get the BezTriple immediately before the given one which has the same value */
352
 
                /* the keyframes immediately before the ones containing the specified keyframe */
353
 
        abk= (ActBeztColumn *)BLI_dlrbTree_search_prev(beztTree, compare_abk_bezt, beztn);
354
 
                /* if applicable, the BezTriple with the same value */
355
 
        prev= (abk) ? abk_get_bezt_with_value(abk, beztn->vec[1][1]) : NULL;
 
406
        /* the keyframes immediately before the ones containing the specified keyframe */
 
407
        abk = (ActBeztColumn *)BLI_dlrbTree_search_prev(beztTree, compare_abk_bezt, beztn);
 
408
        /* if applicable, the BezTriple with the same value */
 
409
        prev = (abk) ? abk_get_bezt_with_value(abk, beztn->vec[1][1]) : NULL;
356
410
        
357
411
        /* check if block needed - same value(s)?
358
412
         *      -> firstly, handles must have same central value as each other
359
413
         *      -> secondly, handles which control that section of the curve must be constant
360
414
         */
361
 
        if ((!prev) || (!beztn)) return;
362
 
        if (IS_EQF(beztn->vec[1][1], prev->vec[1][1])==0) return;
363
 
        if (IS_EQF(beztn->vec[1][1], beztn->vec[0][1])==0) return;
364
 
        if (IS_EQF(prev->vec[1][1], prev->vec[2][1])==0) return;
 
415
        if (prev == NULL) return;
 
416
        if (IS_EQF(beztn->vec[1][1], prev->vec[1][1]) == 0) return;
 
417
        if (IS_EQF(beztn->vec[1][1], beztn->vec[0][1]) == 0) return;
 
418
        if (IS_EQF(prev->vec[1][1], prev->vec[2][1]) == 0) return;
365
419
        
366
420
        
367
421
        /* if there are no blocks already, just add as root */
368
422
        if (blocks->root == NULL) {
369
423
                /* just add this as the root, then call the tree-balancing functions to validate */
370
 
                new_ab= bezts_to_new_actkeyblock(prev, beztn);
371
 
                blocks->root= (DLRBT_Node *)new_ab;
 
424
                new_ab = bezts_to_new_actkeyblock(prev, beztn);
 
425
                blocks->root = (DLRBT_Node *)new_ab;
372
426
        }
373
427
        else {
374
 
                ActKeyBlock *ab, *abn=NULL;
 
428
                ActKeyBlock *ab, *abn = NULL;
375
429
                
376
430
                /* try to find a keyblock that starts on the previous beztriple, and add a new one if none start there
377
431
                 * Note: we can't search from end to try to optimize this as it causes errors there's
378
 
                 *              an A ___ B |---| B situation
 
432
                 *      an A ___ B |---| B situation
379
433
                 */
380
434
                // FIXME: here there is a bug where we are trying to get the summary for the following channels
381
435
                //              A|--------------|A ______________ B|--------------|B
382
436
                //              A|------------------------------------------------|A
383
437
                //              A|----|A|---|A|-----------------------------------|A
384
 
                for (ab= blocks->root; ab; ab= abn) {
 
438
                for (ab = blocks->root; ab; ab = abn) {
385
439
                        /* check if this is a match, or whether we go left or right */
386
440
                        if (ab->start == prev->vec[1][0]) {
387
441
                                /* set selection status and 'touched' status */
392
446
                                return;
393
447
                        }
394
448
                        else {
395
 
                                ActKeyBlock **abnp= NULL; 
 
449
                                ActKeyBlock **abnp = NULL;
396
450
                                
397
451
                                /* check if go left or right, but if not available, add new node */
398
452
                                if (ab->start < prev->vec[1][0]) 
399
 
                                        abnp= &ab->right;
 
453
                                        abnp = &ab->right;
400
454
                                else
401
 
                                        abnp= &ab->left;
 
455
                                        abnp = &ab->left;
402
456
                                        
403
457
                                /* if this does not exist, add a new node, otherwise continue... */
404
458
                                if (*abnp == NULL) {
405
459
                                        /* add a new node representing this, and attach it to the relevant place */
406
 
                                        new_ab= bezts_to_new_actkeyblock(prev, beztn);
407
 
                                        new_ab->parent= ab;
408
 
                                        *abnp= new_ab;
 
460
                                        new_ab = bezts_to_new_actkeyblock(prev, beztn);
 
461
                                        new_ab->parent = ab;
 
462
                                        *abnp = new_ab;
409
463
                                        break;
410
464
                                }
411
465
                                else
412
 
                                        abn= *abnp;
 
466
                                        abn = *abnp;
413
467
                        }
414
468
                }
415
469
        }
421
475
/* --------- */
422
476
 
423
477
/* Handle the 'touched' status of ActKeyColumn tree nodes */
424
 
static void set_touched_actkeycolumn (ActKeyColumn *ak)
 
478
static void set_touched_actkeycolumn(ActKeyColumn *ak)
425
479
{
426
480
        /* sanity check */
427
481
        if (ak == NULL)
429
483
                
430
484
        /* deal with self first */
431
485
        if (ak->modified) {
432
 
                ak->modified= 0;
 
486
                ak->modified = 0;
433
487
                ak->totcurve++;
434
488
        }
435
489
        
439
493
}
440
494
 
441
495
/* Handle the 'touched' status of ActKeyBlock tree nodes */
442
 
static void set_touched_actkeyblock (ActKeyBlock *ab)
 
496
static void set_touched_actkeyblock(ActKeyBlock *ab)
443
497
{
444
498
        /* sanity check */
445
499
        if (ab == NULL)
447
501
                
448
502
        /* deal with self first */
449
503
        if (ab->modified) {
450
 
                ab->modified= 0;
 
504
                ab->modified = 0;
451
505
                ab->totcurve++;
452
506
        }
453
507
        
459
513
/* --------- */
460
514
 
461
515
/* Checks if ActKeyBlock should exist... */
462
 
short actkeyblock_is_valid (ActKeyBlock *ab, DLRBT_Tree *keys)
 
516
short actkeyblock_is_valid(ActKeyBlock *ab, DLRBT_Tree *keys)
463
517
{
464
518
        ActKeyColumn *ak;
465
519
        short startCurves, endCurves, totCurves;
469
523
                return 0;
470
524
        
471
525
        /* find out how many curves occur at each keyframe */
472
 
        ak= (ActKeyColumn *)BLI_dlrbTree_search_exact(keys, compare_ak_cfraPtr, &ab->start);
473
 
        startCurves = (ak)? ak->totcurve: 0;
 
526
        ak = (ActKeyColumn *)BLI_dlrbTree_search_exact(keys, compare_ak_cfraPtr, &ab->start);
 
527
        startCurves = (ak) ? ak->totcurve : 0;
474
528
        
475
 
        ak= (ActKeyColumn *)BLI_dlrbTree_search_exact(keys, compare_ak_cfraPtr, &ab->end);
476
 
        endCurves = (ak)? ak->totcurve: 0;
 
529
        ak = (ActKeyColumn *)BLI_dlrbTree_search_exact(keys, compare_ak_cfraPtr, &ab->end);
 
530
        endCurves = (ak) ? ak->totcurve : 0;
477
531
        
478
532
        /* only draw keyblock if it appears in at all of the keyframes at lowest end */
479
533
        if (!startCurves && !endCurves) 
480
534
                return 0;
481
535
        
482
 
        totCurves = (startCurves>endCurves)? endCurves: startCurves;
 
536
        totCurves = (startCurves > endCurves) ? endCurves : startCurves;
483
537
        return (ab->totcurve >= totCurves);
484
538
}
485
539
 
487
541
 
488
542
/* coordinates for diamond shape */
489
543
static const float _unit_diamond_shape[4][2] = {
490
 
        {0.0f, 1.0f},   /* top vert */
491
 
        {1.0f, 0.0f},   /* mid-right */
492
 
        {0.0f, -1.0f},  /* bottom vert */
493
 
        {-1.0f, 0.0f}   /* mid-left */
 
544
        {0.0f, 1.0f},   /* top vert */
 
545
        {1.0f, 0.0f},   /* mid-right */
 
546
        {0.0f, -1.0f},  /* bottom vert */
 
547
        {-1.0f, 0.0f}   /* mid-left */
494
548
}; 
495
549
 
496
550
/* draw a simple diamond shape with OpenGL */
497
 
void draw_keyframe_shape (float x, float y, float xscale, float hsize, short sel, short key_type, short mode, float alpha)
 
551
void draw_keyframe_shape(float x, float y, float xscale, float hsize, short sel, short key_type, short mode, float alpha)
498
552
{
499
 
        static GLuint displist1=0;
500
 
        static GLuint displist2=0;
 
553
        static GLuint displist1 = 0;
 
554
        static GLuint displist2 = 0;
501
555
        
502
556
        /* initialize 2 display lists for diamond shape - one empty, one filled */
503
557
        if (displist1 == 0) {
504
 
                displist1= glGenLists(1);
505
 
                        glNewList(displist1, GL_COMPILE);
 
558
                displist1 = glGenLists(1);
 
559
                glNewList(displist1, GL_COMPILE);
506
560
                        
507
 
                        glBegin(GL_LINE_LOOP);
508
 
                                glVertex2fv(_unit_diamond_shape[0]);
509
 
                                glVertex2fv(_unit_diamond_shape[1]);
510
 
                                glVertex2fv(_unit_diamond_shape[2]);
511
 
                                glVertex2fv(_unit_diamond_shape[3]);
512
 
                        glEnd();
 
561
                glBegin(GL_LINE_LOOP);
 
562
                glVertex2fv(_unit_diamond_shape[0]);
 
563
                glVertex2fv(_unit_diamond_shape[1]);
 
564
                glVertex2fv(_unit_diamond_shape[2]);
 
565
                glVertex2fv(_unit_diamond_shape[3]);
 
566
                glEnd();
 
567
 
513
568
                glEndList();
514
569
        }
515
570
        if (displist2 == 0) {
516
 
                displist2= glGenLists(1);
517
 
                        glNewList(displist2, GL_COMPILE);
 
571
                displist2 = glGenLists(1);
 
572
                glNewList(displist2, GL_COMPILE);
518
573
                        
519
 
                        glBegin(GL_QUADS);
520
 
                                glVertex2fv(_unit_diamond_shape[0]);
521
 
                                glVertex2fv(_unit_diamond_shape[1]);
522
 
                                glVertex2fv(_unit_diamond_shape[2]);
523
 
                                glVertex2fv(_unit_diamond_shape[3]);
524
 
                        glEnd();
 
574
                glBegin(GL_QUADS);
 
575
                glVertex2fv(_unit_diamond_shape[0]);
 
576
                glVertex2fv(_unit_diamond_shape[1]);
 
577
                glVertex2fv(_unit_diamond_shape[2]);
 
578
                glVertex2fv(_unit_diamond_shape[3]);
 
579
                glEnd();
 
580
 
525
581
                glEndList();
526
582
        }
527
583
        
528
584
        /* tweak size of keyframe shape according to type of keyframe 
529
 
         *      - 'proper' keyframes have key_type=0, so get drawn at full size
 
585
         * - 'proper' keyframes have key_type = 0, so get drawn at full size
530
586
         */
531
 
        hsize -= 0.5f*key_type;
 
587
        hsize -= 0.5f * key_type;
532
588
        
533
589
        /* adjust view transform before starting */
534
590
        glTranslatef(x, y, 0.0f);
535
 
        glScalef(1.0f/xscale*hsize, hsize, 1.0f);
 
591
        glScalef(1.0f / xscale * hsize, hsize, 1.0f);
536
592
        
537
593
        /* anti-aliased lines for more consistent appearance */
538
594
        glEnable(GL_LINE_SMOOTH);
546
602
                                if (sel) glColor4f(0.33f, 0.75f, 0.93f, alpha);
547
603
                                else glColor4f(0.70f, 0.86f, 0.91f, alpha);
548
604
                        }
549
 
                                break;
 
605
                        break;
550
606
                                
551
607
                        case BEZT_KEYTYPE_EXTREME: /* redish frames for now */
552
608
                        {
553
609
                                if (sel) glColor4f(0.95f, 0.5f, 0.5f, alpha);
554
610
                                else glColor4f(0.91f, 0.70f, 0.80f, alpha);
555
611
                        }
556
 
                                break;
 
612
                        break;
557
613
                                
558
614
                        case BEZT_KEYTYPE_JITTER: /* greenish frames for now? */
559
615
                        {
560
616
                                if (sel) glColor4f(0.38f, 0.75f, 0.26f, alpha);
561
617
                                else glColor4f(0.58f, 0.90f, 0.46f, alpha);
562
618
                        }
563
 
                                break;
 
619
                        break;
564
620
                                
565
621
                        case BEZT_KEYTYPE_KEYFRAME: /* traditional yellowish frames for now */
566
622
                        default:
567
623
                        {
568
 
                                if (sel) UI_ThemeColorShadeAlpha(TH_STRIP_SELECT, 50, -255*(1.0f-alpha));
 
624
                                if (sel) UI_ThemeColorShadeAlpha(TH_STRIP_SELECT, 50, -255 * (1.0f - alpha));
569
625
                                else glColor4f(0.91f, 0.91f, 0.91f, alpha);
570
626
                        }
571
 
                                break;
 
627
                        break;
572
628
                }
573
629
                
574
630
                glCallList(displist2);
584
640
        glDisable(GL_LINE_SMOOTH);
585
641
        
586
642
        /* restore view transform */
587
 
        glScalef(xscale/hsize, 1.0f/hsize, 1.0);
 
643
        glScalef(xscale / hsize, 1.0f / hsize, 1.0f);
588
644
        glTranslatef(-x, -y, 0.0f);
589
645
}
590
646
 
593
649
        ActKeyColumn *ak;
594
650
        ActKeyBlock *ab;
595
651
        float xscale;
596
 
        
 
652
        float iconsize = U.widget_unit / 4.0f;
597
653
        glEnable(GL_BLEND);
598
654
        
599
655
        /* get View2D scaling factor */
601
657
        
602
658
        /* draw keyblocks */
603
659
        if (blocks) {
604
 
                for (ab= blocks->first; ab; ab= ab->next) {
 
660
                for (ab = blocks->first; ab; ab = ab->next) {
605
661
                        if (actkeyblock_is_valid(ab, keys)) {
606
662
                                /* draw block */
607
663
                                if (ab->sel)
609
665
                                else
610
666
                                        UI_ThemeColor4(TH_STRIP);
611
667
                                
612
 
                                glRectf(ab->start, ypos-5, ab->end, ypos+5);
 
668
                                glRectf(ab->start, ypos - iconsize, ab->end, ypos + iconsize);
613
669
                        }
614
670
                }
615
671
        }
617
673
        /* draw keys */
618
674
        if (keys) {
619
675
                /* locked channels are less strongly shown, as feedback for locked channels in DopeSheet */
620
 
                // TODO: allow this opacity factor to be themed?
621
 
                float kalpha = (channelLocked)? 0.35f : 1.0f;
 
676
                /* TODO: allow this opacity factor to be themed? */
 
677
                float kalpha = (channelLocked) ? 0.25f : 1.0f;
622
678
                
623
 
                for (ak= keys->first; ak; ak= ak->next) {
624
 
                        /* optimization: if keyframe doesn't appear within 5 units (screenspace) in visible area, don't draw 
 
679
                for (ak = keys->first; ak; ak = ak->next) {
 
680
                        /* optimization: if keyframe doesn't appear within 5 units (screenspace) in visible area, don't draw
625
681
                         *      - this might give some improvements, since we current have to flip between view/region matrices
626
682
                         */
627
683
                        if (IN_RANGE_INCL(ak->cfra, v2d->cur.xmin, v2d->cur.xmax) == 0)
628
684
                                continue;
629
685
                        
630
686
                        /* draw using OpenGL - uglier but faster */
631
 
                        // NOTE1: a previous version of this didn't work nice for some intel cards
632
 
                        // NOTE2: if we wanted to go back to icons, these are  icon = (ak->sel & SELECT) ? ICON_SPACE2 : ICON_SPACE3;
633
 
                        draw_keyframe_shape(ak->cfra, ypos, xscale, 5.0f, (ak->sel & SELECT), ak->key_type, KEYFRAME_SHAPE_BOTH, kalpha);
634
 
                }       
 
687
                        /* NOTE1: a previous version of this didn't work nice for some intel cards
 
688
                         * NOTE2: if we wanted to go back to icons, these are  icon = (ak->sel & SELECT) ? ICON_SPACE2 : ICON_SPACE3; */
 
689
                        draw_keyframe_shape(ak->cfra, ypos, xscale, iconsize, (ak->sel & SELECT), ak->key_type, KEYFRAME_SHAPE_BOTH, kalpha);
 
690
                }
635
691
        }
636
 
        
 
692
 
637
693
        glDisable(GL_BLEND);
638
694
}
639
695
 
646
702
        BLI_dlrbTree_init(&keys);
647
703
        BLI_dlrbTree_init(&blocks);
648
704
        
649
 
                summary_to_keylist(ac, &keys, &blocks);
 
705
        summary_to_keylist(ac, &keys, &blocks);
650
706
        
651
707
        BLI_dlrbTree_linkedlist_sync(&keys);
652
708
        BLI_dlrbTree_linkedlist_sync(&blocks);
653
709
        
654
 
                draw_keylist(v2d, &keys, &blocks, ypos, 0);
 
710
        draw_keylist(v2d, &keys, &blocks, ypos, 0);
655
711
        
656
712
        BLI_dlrbTree_free(&keys);
657
713
        BLI_dlrbTree_free(&blocks);
664
720
        BLI_dlrbTree_init(&keys);
665
721
        BLI_dlrbTree_init(&blocks);
666
722
        
667
 
                scene_to_keylist(ads, sce, &keys, &blocks);
 
723
        scene_to_keylist(ads, sce, &keys, &blocks);
668
724
        
669
725
        BLI_dlrbTree_linkedlist_sync(&keys);
670
726
        BLI_dlrbTree_linkedlist_sync(&blocks);
671
727
        
672
 
                draw_keylist(v2d, &keys, &blocks, ypos, 0);
 
728
        draw_keylist(v2d, &keys, &blocks, ypos, 0);
673
729
        
674
730
        BLI_dlrbTree_free(&keys);
675
731
        BLI_dlrbTree_free(&blocks);
682
738
        BLI_dlrbTree_init(&keys);
683
739
        BLI_dlrbTree_init(&blocks);
684
740
        
685
 
                ob_to_keylist(ads, ob, &keys, &blocks);
 
741
        ob_to_keylist(ads, ob, &keys, &blocks);
686
742
        
687
743
        BLI_dlrbTree_linkedlist_sync(&keys);
688
744
        BLI_dlrbTree_linkedlist_sync(&blocks);
689
745
        
690
 
                draw_keylist(v2d, &keys, &blocks, ypos, 0);
 
746
        draw_keylist(v2d, &keys, &blocks, ypos, 0);
691
747
        
692
748
        BLI_dlrbTree_free(&keys);
693
749
        BLI_dlrbTree_free(&blocks);
697
753
{
698
754
        DLRBT_Tree keys, blocks;
699
755
        
 
756
        short locked = (fcu->flag & FCURVE_PROTECTED) ||
 
757
                       ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) ||
 
758
                       ((adt && adt->action) && (adt->action->id.lib));
 
759
        
700
760
        BLI_dlrbTree_init(&keys);
701
761
        BLI_dlrbTree_init(&blocks);
702
762
        
703
 
                fcurve_to_keylist(adt, fcu, &keys, &blocks);
 
763
        fcurve_to_keylist(adt, fcu, &keys, &blocks);
704
764
        
705
765
        BLI_dlrbTree_linkedlist_sync(&keys);
706
766
        BLI_dlrbTree_linkedlist_sync(&blocks);
707
767
        
708
 
                draw_keylist(v2d, &keys, &blocks, ypos, (fcu->flag & FCURVE_PROTECTED));
 
768
        draw_keylist(v2d, &keys, &blocks, ypos, locked);
709
769
        
710
770
        BLI_dlrbTree_free(&keys);
711
771
        BLI_dlrbTree_free(&blocks);
715
775
{
716
776
        DLRBT_Tree keys, blocks;
717
777
        
 
778
        short locked = (agrp->flag & AGRP_PROTECTED) ||
 
779
                       ((adt && adt->action) && (adt->action->id.lib));
 
780
        
718
781
        BLI_dlrbTree_init(&keys);
719
782
        BLI_dlrbTree_init(&blocks);
720
783
        
721
 
                agroup_to_keylist(adt, agrp, &keys, &blocks);
 
784
        agroup_to_keylist(adt, agrp, &keys, &blocks);
722
785
        
723
786
        BLI_dlrbTree_linkedlist_sync(&keys);
724
787
        BLI_dlrbTree_linkedlist_sync(&blocks);
725
788
        
726
 
                draw_keylist(v2d, &keys, &blocks, ypos, (agrp->flag & AGRP_PROTECTED));
 
789
        draw_keylist(v2d, &keys, &blocks, ypos, locked);
727
790
        
728
791
        BLI_dlrbTree_free(&keys);
729
792
        BLI_dlrbTree_free(&blocks);
733
796
{
734
797
        DLRBT_Tree keys, blocks;
735
798
        
 
799
        short locked = (act && act->id.lib != 0);
 
800
        
736
801
        BLI_dlrbTree_init(&keys);
737
802
        BLI_dlrbTree_init(&blocks);
738
803
        
739
 
                action_to_keylist(adt, act, &keys, &blocks);
 
804
        action_to_keylist(adt, act, &keys, &blocks);
740
805
        
741
806
        BLI_dlrbTree_linkedlist_sync(&keys);
742
807
        BLI_dlrbTree_linkedlist_sync(&blocks);
743
808
        
744
 
                draw_keylist(v2d, &keys, &blocks, ypos, 0);
 
809
        draw_keylist(v2d, &keys, &blocks, ypos, locked);
745
810
        
746
811
        BLI_dlrbTree_free(&keys);
747
812
        BLI_dlrbTree_free(&blocks);
753
818
        
754
819
        BLI_dlrbTree_init(&keys);
755
820
        
756
 
                gpl_to_keylist(ads, gpl, &keys);
757
 
        
758
 
        BLI_dlrbTree_linkedlist_sync(&keys);
759
 
        
760
 
                draw_keylist(v2d, &keys, NULL, ypos, (gpl->flag & GP_LAYER_LOCKED));
761
 
        
 
821
        gpl_to_keylist(ads, gpl, &keys);
 
822
        
 
823
        BLI_dlrbTree_linkedlist_sync(&keys);
 
824
        
 
825
        draw_keylist(v2d, &keys, NULL, ypos, (gpl->flag & GP_LAYER_LOCKED));
 
826
        
 
827
        BLI_dlrbTree_free(&keys);
 
828
}
 
829
 
 
830
void draw_masklay_channel(View2D *v2d, bDopeSheet *ads, MaskLayer *masklay, float ypos)
 
831
{
 
832
        DLRBT_Tree keys;
 
833
 
 
834
        BLI_dlrbTree_init(&keys);
 
835
 
 
836
        mask_to_keylist(ads, masklay, &keys);
 
837
 
 
838
        BLI_dlrbTree_linkedlist_sync(&keys);
 
839
 
 
840
        draw_keylist(v2d, &keys, NULL, ypos, (masklay->flag & MASK_LAYERFLAG_LOCKED));
 
841
 
762
842
        BLI_dlrbTree_free(&keys);
763
843
}
764
844
 
772
852
                int filter;
773
853
                
774
854
                /* get F-Curves to take keyframes from */
775
 
                filter= ANIMFILTER_DATA_VISIBLE; // curves only
 
855
                filter = ANIMFILTER_DATA_VISIBLE;
776
856
                ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
777
857
                
778
858
                /* loop through each F-Curve, grabbing the keyframes */
779
 
                for (ale= anim_data.first; ale; ale= ale->next)
780
 
                        fcurve_to_keylist(ale->adt, ale->data, keys, blocks);
781
 
                
 
859
                for (ale = anim_data.first; ale; ale = ale->next) {
 
860
 
 
861
                        /* Why not use all #eAnim_KeyType here?
 
862
                         * All of the other key types are actually "summaries" themselves, and will just end up duplicating stuff
 
863
                         * that comes up through standard filtering of just F-Curves.
 
864
                         * Given the way that these work, there isn't really any benefit at all from including them. - Aligorith */
 
865
 
 
866
                        switch (ale->datatype) {
 
867
                                case ALE_FCURVE:
 
868
                                        fcurve_to_keylist(ale->adt, ale->data, keys, blocks);
 
869
                                        break;
 
870
                                case ALE_MASKLAY:
 
871
                                        mask_to_keylist(ac->ads, ale->data, keys);
 
872
                                        break;
 
873
                                case ALE_GPFRAME:
 
874
                                        gpl_to_keylist(ac->ads, ale->data, keys);
 
875
                                        break;
 
876
                                default:
 
877
                                        // printf("%s: datatype %d unhandled\n", __func__, ale->datatype);
 
878
                                        break;
 
879
                        }
 
880
                }
 
881
 
782
882
                BLI_freelistN(&anim_data);
783
883
        }
784
884
}
806
906
        ac.datatype = ANIMCONT_CHANNEL;
807
907
        
808
908
        /* get F-Curves to take keyframes from */
809
 
        filter= ANIMFILTER_DATA_VISIBLE; // curves only
 
909
        filter = ANIMFILTER_DATA_VISIBLE; // curves only
810
910
        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
811
911
        
812
912
        /* loop through each F-Curve, grabbing the keyframes */
813
 
        for (ale= anim_data.first; ale; ale= ale->next)
 
913
        for (ale = anim_data.first; ale; ale = ale->next)
814
914
                fcurve_to_keylist(ale->adt, ale->data, keys, blocks);
815
915
        
816
916
        BLI_freelistN(&anim_data);
842
942
        ac.datatype = ANIMCONT_CHANNEL;
843
943
        
844
944
        /* get F-Curves to take keyframes from */
845
 
        filter= ANIMFILTER_DATA_VISIBLE; // curves only
 
945
        filter = ANIMFILTER_DATA_VISIBLE; // curves only
846
946
        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
847
947
        
848
948
        /* loop through each F-Curve, grabbing the keyframes */
849
 
        for (ale= anim_data.first; ale; ale= ale->next)
 
949
        for (ale = anim_data.first; ale; ale = ale->next)
850
950
                fcurve_to_keylist(ale->adt, ale->data, keys, blocks);
851
951
        
852
952
        BLI_freelistN(&anim_data);
860
960
 
861
961
        if (fcu && fcu->totvert && fcu->bezt) {
862
962
                /* apply NLA-mapping (if applicable) */
863
 
                if (adt)        
 
963
                if (adt)
864
964
                        ANIM_nla_mapping_apply_fcurve(adt, fcu, 0, 0);
865
965
                
866
966
                /* if getting long keyframes too, grab the BezTriples in a BST for 
868
968
                 */
869
969
                if (blocks) {
870
970
                        /* init new tree */
871
 
                        beztTree= BLI_dlrbTree_new();
 
971
                        beztTree = BLI_dlrbTree_new();
872
972
                        
873
973
                        /* populate tree with the BezTriples */
874
 
                        for (v=0, bezt=fcu->bezt; v < fcu->totvert; v++, bezt++)
 
974
                        for (v = 0, bezt = fcu->bezt; v < fcu->totvert; v++, bezt++)
875
975
                                BLI_dlrbTree_add(beztTree, compare_abk_bezt, nalloc_abk_bezt, nupdate_abk_bezt, bezt);
876
976
                        
877
977
                        /* make sure that it is suitable for linked-list searching too */
879
979
                }
880
980
                
881
981
                /* loop through beztriples, making ActKeysColumns and ActKeyBlocks */
882
 
                for (v=0, bezt=fcu->bezt; v < fcu->totvert; v++, bezt++) {
 
982
                for (v = 0, bezt = fcu->bezt; v < fcu->totvert; v++, bezt++) {
883
983
                        add_bezt_to_keycolumns_list(keys, bezt);
884
984
                        if (blocks) add_bezt_to_keyblocks_list(blocks, beztTree, bezt);
885
985
                }
908
1008
 
909
1009
        if (agrp) {
910
1010
                /* loop through F-Curves */
911
 
                for (fcu= agrp->channels.first; fcu && fcu->grp==agrp; fcu= fcu->next) {
 
1011
                for (fcu = agrp->channels.first; fcu && fcu->grp == agrp; fcu = fcu->next) {
912
1012
                        fcurve_to_keylist(adt, fcu, keys, blocks);
913
1013
                }
914
1014
        }
920
1020
 
921
1021
        if (act) {
922
1022
                /* loop through F-Curves */
923
 
                for (fcu= act->curves.first; fcu; fcu= fcu->next) {
 
1023
                for (fcu = act->curves.first; fcu; fcu = fcu->next) {
924
1024
                        fcurve_to_keylist(adt, fcu, keys, blocks);
925
1025
                }
926
1026
        }
933
1033
        
934
1034
        if (gpl && keys) {
935
1035
                /* although the frames should already be in an ordered list, they are not suitable for displaying yet */
936
 
                for (gpf= gpl->frames.first; gpf; gpf= gpf->next)
 
1036
                for (gpf = gpl->frames.first; gpf; gpf = gpf->next)
937
1037
                        add_gpframe_to_keycolumns_list(keys, gpf);
938
1038
        }
939
1039
}
940
1040
 
 
1041
void mask_to_keylist(bDopeSheet *UNUSED(ads), MaskLayer *masklay, DLRBT_Tree *keys)
 
1042
{
 
1043
        MaskLayerShape *masklay_shape;
 
1044
 
 
1045
        if (masklay && keys) {
 
1046
                for (masklay_shape = masklay->splines_shapes.first;
 
1047
                     masklay_shape;
 
1048
                     masklay_shape = masklay_shape->next)
 
1049
                {
 
1050
                        add_masklay_to_keycolumns_list(keys, masklay_shape);
 
1051
                }
 
1052
        }
 
1053
}
 
1054