2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): Joshua Leung
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file blender/editors/space_action/action_draw.c
33 /* System includes ----------------------------------------------------- */
40 #include "BLI_blenlib.h"
41 #include "BLI_utildefines.h"
43 /* Types --------------------------------------------------------------- */
45 #include "DNA_anim_types.h"
46 #include "DNA_screen_types.h"
48 #include "BKE_action.h"
49 #include "BKE_context.h"
52 /* Everything from source (BIF, BDR, BSE) ------------------------------ */
56 #include "UI_interface.h"
57 #include "UI_resources.h"
58 #include "UI_view2d.h"
60 #include "ED_anim_api.h"
61 #include "ED_keyframes_draw.h"
63 #include "action_intern.h"
65 /* ************************************************************************* */
69 void draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar)
71 ListBase anim_data = {NULL, NULL};
75 View2D *v2d = &ar->v2d;
80 /* build list of channels to draw */
81 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
82 items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
84 height = ((items * ACHANNEL_STEP(ac)) + (ACHANNEL_HEIGHT(ac)));
85 if (height > BLI_rcti_size_y(&v2d->mask)) {
86 /* don't use totrect set, as the width stays the same
87 * (NOTE: this is ok here, the configuration is pretty straightforward)
89 v2d->tot.ymin = (float)(-height);
91 /* need to do a view-sync here, so that the keys area doesn't jump around (it must copy this) */
92 UI_view2d_sync(NULL, ac->sa, v2d, V2D_LOCK_COPY);
94 /* loop through channels, and set up drawing depending on their type */
95 { /* first pass: just the standard GL-drawing for backdrop + text */
96 size_t channel_index = 0;
98 y = (float)ACHANNEL_FIRST(ac);
100 for (ale = anim_data.first; ale; ale = ale->next) {
101 float yminc = (float)(y - ACHANNEL_HEIGHT_HALF(ac));
102 float ymaxc = (float)(y + ACHANNEL_HEIGHT_HALF(ac));
104 /* check if visible */
105 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
106 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) )
108 /* draw all channels using standard channel-drawing API */
109 ANIM_channel_draw(ac, ale, yminc, ymaxc, channel_index);
112 /* adjust y-position for next one */
113 y -= ACHANNEL_STEP(ac);
117 { /* second pass: widgets */
118 uiBlock *block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
119 size_t channel_index = 0;
121 y = (float)ACHANNEL_FIRST(ac);
123 for (ale = anim_data.first; ale; ale = ale->next) {
124 float yminc = (float)(y - ACHANNEL_HEIGHT_HALF(ac));
125 float ymaxc = (float)(y + ACHANNEL_HEIGHT_HALF(ac));
127 /* check if visible */
128 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
129 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) )
131 /* draw all channels using standard channel-drawing API */
132 ANIM_channel_draw_widgets(C, ac, ale, block, yminc, ymaxc, channel_index);
135 /* adjust y-position for next one */
136 y -= ACHANNEL_STEP(ac);
140 UI_block_end(C, block);
141 UI_block_draw(C, block);
144 /* free tempolary channels */
145 ANIM_animdata_freelist(&anim_data);
148 /* ************************************************************************* */
151 /* extra padding for lengths (to go under scrollers) */
152 #define EXTRA_SCROLL_PAD 100.0f
154 /* draw keyframes in each channel */
155 void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar)
157 ListBase anim_data = {NULL, NULL};
161 View2D *v2d = &ar->v2d;
162 bDopeSheet *ads = &saction->ads;
163 AnimData *adt = NULL;
165 float act_start, act_end, y;
169 unsigned char col1[3], col2[3];
170 unsigned char col1a[3], col2a[3];
171 unsigned char col1b[3], col2b[3];
173 const bool show_group_colors = !(saction->flag & SACTION_NODRAWGCOLORS);
176 /* get theme colors */
177 UI_GetThemeColor3ubv(TH_BACK, col2);
178 UI_GetThemeColor3ubv(TH_HILITE, col1);
180 UI_GetThemeColor3ubv(TH_GROUP, col2a);
181 UI_GetThemeColor3ubv(TH_GROUP_ACTIVE, col1a);
183 UI_GetThemeColor3ubv(TH_DOPESHEET_CHANNELOB, col1b);
184 UI_GetThemeColor3ubv(TH_DOPESHEET_CHANNELSUBOB, col2b);
186 /* set view-mapping rect (only used for x-axis), for NLA-scaling mapping with less calculation */
188 /* if in NLA there's a strip active, map the view */
189 if (ac->datatype == ANIMCONT_ACTION) {
190 /* adt = ANIM_nla_mapping_get(ac, NULL); */ /* UNUSED */
192 /* start and end of action itself */
193 calc_action_range(ac->data, &act_start, &act_end, 0);
196 /* build list of channels to draw */
197 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
198 items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
200 height = ((items * ACHANNEL_STEP(ac)) + (ACHANNEL_HEIGHT(ac)));
201 /* don't use totrect set, as the width stays the same
202 * (NOTE: this is ok here, the configuration is pretty straightforward)
204 v2d->tot.ymin = (float)(-height);
206 /* first backdrop strips */
207 y = (float)(-ACHANNEL_HEIGHT(ac));
210 for (ale = anim_data.first; ale; ale = ale->next) {
211 const float yminc = (float)(y - ACHANNEL_HEIGHT_HALF(ac));
212 const float ymaxc = (float)(y + ACHANNEL_HEIGHT_HALF(ac));
214 /* check if visible */
215 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
216 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) )
218 const bAnimChannelType *acf = ANIM_channel_get_typeinfo(ale);
221 /* determine if any need to draw channel */
222 if (ale->datatype != ALE_NONE) {
223 /* determine if channel is selected */
224 if (acf->has_setting(ac, ale, ACHANNEL_SETTING_SELECT))
225 sel = ANIM_channel_setting_get(ac, ale, ACHANNEL_SETTING_SELECT);
227 if (ELEM(ac->datatype, ANIMCONT_ACTION, ANIMCONT_DOPESHEET, ANIMCONT_SHAPEKEY)) {
229 case ANIMTYPE_SUMMARY:
231 /* reddish color from NLA */
232 UI_ThemeColor4(TH_ANIM_ACTIVE);
236 case ANIMTYPE_OBJECT:
238 if (sel) glColor4ub(col1b[0], col1b[1], col1b[2], 0x45);
239 else glColor4ub(col1b[0], col1b[1], col1b[2], 0x22);
242 case ANIMTYPE_FILLACTD:
243 case ANIMTYPE_DSSKEY:
246 if (sel) glColor4ub(col2b[0], col2b[1], col2b[2], 0x45);
247 else glColor4ub(col2b[0], col2b[1], col2b[2], 0x22);
252 bActionGroup *agrp = ale->data;
253 if (show_group_colors && agrp->customCol) {
255 unsigned char *cp = (unsigned char *)agrp->cs.select;
256 glColor4ub(cp[0], cp[1], cp[2], 0x45);
259 unsigned char *cp = (unsigned char *)agrp->cs.solid;
260 glColor4ub(cp[0], cp[1], cp[2], 0x1D);
264 if (sel) glColor4ub(col1a[0], col1a[1], col1a[2], 0x22);
265 else glColor4ub(col2a[0], col2a[1], col2a[2], 0x22);
269 case ANIMTYPE_FCURVE:
271 FCurve *fcu = ale->data;
272 if (show_group_colors && fcu->grp && fcu->grp->customCol) {
273 unsigned char *cp = (unsigned char *)fcu->grp->cs.active;
275 if (sel) glColor4ub(cp[0], cp[1], cp[2], 0x65);
276 else glColor4ub(cp[0], cp[1], cp[2], 0x0B);
279 if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x22);
280 else glColor4ub(col2[0], col2[1], col2[2], 0x22);
286 if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x22);
287 else glColor4ub(col2[0], col2[1], col2[2], 0x22);
292 /* draw region twice: firstly backdrop, then the current range */
293 glRectf(v2d->cur.xmin, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmax + EXTRA_SCROLL_PAD, (float)y + ACHANNEL_HEIGHT_HALF(ac));
295 if (ac->datatype == ANIMCONT_ACTION)
296 glRectf(act_start, (float)y - ACHANNEL_HEIGHT_HALF(ac), act_end, (float)y + ACHANNEL_HEIGHT_HALF(ac));
298 else if (ac->datatype == ANIMCONT_GPENCIL) {
299 /* frames less than one get less saturated background */
300 if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x22);
301 else glColor4ub(col2[0], col2[1], col2[2], 0x22);
302 glRectf(0.0f, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmin, (float)y + ACHANNEL_HEIGHT_HALF(ac));
304 /* frames one and higher get a saturated background */
305 if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x44);
306 else glColor4ub(col2[0], col2[1], col2[2], 0x44);
307 glRectf(v2d->cur.xmin, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmax + EXTRA_SCROLL_PAD, (float)y + ACHANNEL_HEIGHT_HALF(ac));
309 else if (ac->datatype == ANIMCONT_MASK) {
310 /* TODO --- this is a copy of gpencil */
311 /* frames less than one get less saturated background */
312 if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x22);
313 else glColor4ub(col2[0], col2[1], col2[2], 0x22);
314 glRectf(0.0f, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmin, (float)y + ACHANNEL_HEIGHT_HALF(ac));
316 /* frames one and higher get a saturated background */
317 if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x44);
318 else glColor4ub(col2[0], col2[1], col2[2], 0x44);
319 glRectf(v2d->cur.xmin, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmax + EXTRA_SCROLL_PAD, (float)y + ACHANNEL_HEIGHT_HALF(ac));
324 /* Increment the step */
325 y -= ACHANNEL_STEP(ac);
330 * 1) Only channels that are visible in the Action Editor get drawn/evaluated.
331 * This is to try to optimize this for heavier data sets
332 * 2) Keyframes which are out of view horizontally are disregarded
334 y = (float)(-ACHANNEL_HEIGHT(ac));
336 for (ale = anim_data.first; ale; ale = ale->next) {
337 const float yminc = (float)(y - ACHANNEL_HEIGHT_HALF(ac));
338 const float ymaxc = (float)(y + ACHANNEL_HEIGHT_HALF(ac));
340 /* check if visible */
341 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
342 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) )
344 /* check if anything to show for this channel */
345 if (ale->datatype != ALE_NONE) {
346 adt = ANIM_nla_mapping_get(ac, ale);
348 /* draw 'keyframes' for each specific datatype */
349 switch (ale->datatype) {
351 draw_summary_channel(v2d, ale->data, y, ac->yscale_fac);
354 draw_scene_channel(v2d, ads, ale->key_data, y, ac->yscale_fac);
357 draw_object_channel(v2d, ads, ale->key_data, y, ac->yscale_fac);
360 draw_action_channel(v2d, adt, ale->key_data, y, ac->yscale_fac);
363 draw_agroup_channel(v2d, adt, ale->data, y, ac->yscale_fac);
366 draw_fcurve_channel(v2d, adt, ale->key_data, y, ac->yscale_fac);
369 draw_gpl_channel(v2d, ads, ale->data, y, ac->yscale_fac);
372 draw_masklay_channel(v2d, ads, ale->data, y, ac->yscale_fac);
378 y -= ACHANNEL_STEP(ac);
381 /* free tempolary channels used for drawing */
382 ANIM_animdata_freelist(&anim_data);
384 /* black line marking 'current frame' for Time-Slide transform mode */
385 if (saction->flag & SACTION_MOVING) {
386 glColor3f(0.0f, 0.0f, 0.0f);
389 glVertex2f(saction->timeslide, v2d->cur.ymin - EXTRA_SCROLL_PAD);
390 glVertex2f(saction->timeslide, v2d->cur.ymax);