1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
/**
* $Id:
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2005 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <math.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "DNA_action_types.h"
#include "DNA_ipo_types.h"
#include "DNA_object_types.h"
#include "DNA_material_types.h"
#include "DNA_scene_types.h"
#include "DNA_space_types.h"
#include "DNA_screen_types.h"
#include "DNA_sound_types.h"
#include "DNA_view2d_types.h"
#include "BKE_ipo.h"
#include "BKE_object.h"
#include "BKE_material.h"
#include "BKE_utildefines.h"
#include "BKE_global.h"
#include "BIF_gl.h"
#include "BIF_interface_icons.h"
#include "BIF_mywindow.h"
#include "BIF_screen.h"
#include "BIF_resources.h"
#include "BSE_drawipo.h"
#include "BSE_view.h"
#include "BMF_Api.h"
#include "blendef.h"
/* ---- prototypes ------ */
void drawtimespace(ScrArea *, void *);
static void draw_cfra_time(SpaceTime *stime)
{
float vec[2];
vec[0]= (G.scene->r.cfra);
vec[0]*= G.scene->r.framelen;
vec[1]= G.v2d->cur.ymin;
glColor3ub(0x60, 0xc0, 0x40); // no theme, should be global color once...
glLineWidth(3.0);
glBegin(GL_LINES);
glVertex2fv(vec);
vec[1]= G.v2d->cur.ymax;
glVertex2fv(vec);
glEnd();
glLineWidth(1.0);
if(stime->flag & TIME_CFRA_NUM) {
short mval[2];
float x, y;
char str[32];
/* little box with frame */
glFlush(); // huhh... without this glColor won't work for the text...
getmouseco_areawin(mval);
if(mval[1]>curarea->winy-10) mval[1]= curarea->winy - 13;
if (curarea->winy < 25) {
if (mval[1]<17) mval[1]= 17;
} else if (mval[1]<22) mval[1]= 22;
areamouseco_to_ipoco(G.v2d, mval, &x, &y);
if(stime->flag & TIME_DRAWFRAMES)
sprintf(str, " %d\n", (G.scene->r.cfra));
else sprintf(str, " %.2f\n", (G.scene->r.cfra/(float)G.scene->r.frs_sec));
/* HACK! somehow the green color won't go away... */
glColor4ub(0, 0, 0, 0);
BIF_ThemeColor(TH_TEXT);
glRasterPos2f(x, y);
BMF_DrawString(G.fonts, str);
}
}
static void draw_marker(TimeMarker *marker)
{
float xpos, xspace, yspace, xpixels, ypixels;
xpos = marker->frame;
/* no time correction for framelen! space is drawn with old values */
xspace= G.v2d->cur.xmax - G.v2d->cur.xmin;
yspace= G.v2d->cur.ymax - G.v2d->cur.ymin;
xpixels= G.v2d->mask.xmax-G.v2d->mask.xmin;
ypixels= G.v2d->mask.ymax-G.v2d->mask.ymin;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
/* 5 px to offset icon to align properly, space / pixels corrects for zoom */
if(marker->flag & SELECT)
BIF_icon_draw(xpos-(5.0*(xspace/xpixels)), 12.0*yspace/ypixels, ICON_MARKER_HLT);
else
BIF_icon_draw(xpos-(5.0*(xspace/xpixels)), 12.0*yspace/ypixels, ICON_MARKER);
glBlendFunc(GL_ONE, GL_ZERO);
glDisable(GL_BLEND);
/* and the marker name too, shifted slightly to the top-right */
if(marker->name && marker->name[0]) {
if(marker->flag & SELECT) {
BIF_ThemeColor(TH_TEXT_HI);
glRasterPos2f(xpos+(4.0*(xspace/xpixels)),
((ypixels<=39.0)?(ypixels-10.0):29.0)*yspace/ypixels);
}
else {
BIF_ThemeColor(TH_TEXT);
if((marker->frame <= G.scene->r.cfra) && (marker->frame+5 > G.scene->r.cfra))
glRasterPos2f(xpos+(4.0*(xspace/xpixels)),
((ypixels<=39.0)?(ypixels-10.0):29.0)*yspace/ypixels);
else
glRasterPos2f(xpos+(4.0*(xspace/xpixels)), 17.0*yspace/ypixels);
}
BMF_DrawString(G.font, marker->name);
}
}
static void draw_markers_time(void)
{
TimeMarker *marker;
/* unselected markers are drawn at the first time */
for(marker= G.scene->markers.first; marker; marker= marker->next) {
if(!(marker->flag & SELECT)) draw_marker(marker);
}
/* selected markers are drawn later ... selected markers have to cover unselected
* markers laying at the same position as selected markers
* (jiri: it is hack, it could be solved better) */
for(marker= G.scene->markers.first; marker; marker= marker->next) {
if(marker->flag & SELECT) draw_marker(marker);
}
}
void draw_markers_timespace()
{
TimeMarker *marker;
float yspace, ypixels;
/* move ortho view to align with slider in bottom */
glTranslatef(0.0f, G.v2d->cur.ymin, 0.0f);
/* bad hacks in drawing markers... inverse correct that as well */
yspace= G.v2d->cur.ymax - G.v2d->cur.ymin;
ypixels= G.v2d->mask.ymax - G.v2d->mask.ymin;
glTranslatef(0.0f, -11.0*yspace/ypixels, 0.0f);
/* unselected markers are drawn at the first time */
for(marker= G.scene->markers.first; marker; marker= marker->next) {
if(!(marker->flag & SELECT)) draw_marker(marker);
}
/* selected markers are drawn later ... selected markers have to cover unselected
* markers laying at the same position as selected markers */
for(marker= G.scene->markers.first; marker; marker= marker->next) {
if(marker->flag & SELECT) draw_marker(marker);
}
glTranslatef(0.0f, -G.v2d->cur.ymin, 0.0f);
glTranslatef(0.0f, 11.0*yspace/ypixels, 0.0f);
}
void draw_anim_preview_timespace()
{
/* only draw this if preview range is set */
if (G.scene->r.psfra) {
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable(GL_BLEND);
glColor4f(0, 0, 0, 0.4);
if (PSFRA < PEFRA) {
glRectf(G.v2d->cur.xmin, G.v2d->cur.ymin, PSFRA, G.v2d->cur.ymax);
glRectf(PEFRA, G.v2d->cur.ymin, G.v2d->cur.xmax, G.v2d->cur.ymax);
}
else {
glRectf(G.v2d->cur.xmin, G.v2d->cur.ymin, G.v2d->cur.xmax, G.v2d->cur.ymax);
}
glDisable(GL_BLEND);
}
}
static void draw_sfra_efra()
{
BIF_ThemeColorShade(TH_BACK, -25);
if (PSFRA < PEFRA) {
glRectf(G.v2d->cur.xmin, G.v2d->cur.ymin, PSFRA, G.v2d->cur.ymax);
glRectf(PEFRA, G.v2d->cur.ymin, G.v2d->cur.xmax, G.v2d->cur.ymax);
}
else {
glRectf(G.v2d->cur.xmin, G.v2d->cur.ymin, G.v2d->cur.xmax, G.v2d->cur.ymax);
}
BIF_ThemeColorShade(TH_BACK, -60);
/* thin lines where the actual frames are */
fdrawline(PSFRA, G.v2d->cur.ymin, PSFRA, G.v2d->cur.ymax);
fdrawline(PEFRA, G.v2d->cur.ymin, PEFRA, G.v2d->cur.ymax);
glDisable(GL_BLEND);
}
/*draw all the keys in a list (elems) as lines */
static void draw_key_list(ListBase elems, char col[3])
{
CfraElem *ce;
float drawframe;
ce= elems.first;
while(ce) {
drawframe = ce->cfra; //not correct for G.scene->r.framelen;
glColor3ub(col[0], col[1], col[2]);
fdrawline(drawframe, G.v2d->cur.ymin, drawframe, G.v2d->cur.ymax);
ce= ce->next;
}
}
static void draw_ob_keys()
{
/*mostly copied from drawobject.c, draw_object() */
Object *ob;
bActionChannel *achan;
bAction *act;
ListBase elems;
int a;
char col[3];
if (OBACT) {
ob = OBACT;
if(ob) {
if(ob!=G.obedit) {
if(ob->ipo) {
/* convert the ipo to a list of 'current frame elements' */
elems.first= elems.last= NULL;
make_cfra_list(ob->ipo, &elems);
/* draw the list of current frame elements */
col[0] = 0xDD; col[1] = 0xD7; col[2] = 0x00;
draw_key_list(elems, col);
BLI_freelistN(&elems);
}
if(ob->action) {
act = ob->action;
/* go through each channel in the action */
for (achan=act->chanbase.first; achan; achan=achan->next){
/* convert the ipo to a list of 'current frame elements' */
if(achan->ipo) {
elems.first= elems.last= NULL;
make_cfra_list(achan->ipo, &elems);
col[0] = 0x00; col[1] = 0x82; col[2] = 0x8B;
draw_key_list(elems, col);
BLI_freelistN(&elems);
}
}
}
for(a=0; a<ob->totcol; a++) {
Material *ma= give_current_material(ob, a+1);
if(ma && ma->ipo) {
elems.first= elems.last= NULL;
make_cfra_list(ma->ipo, &elems);
col[0] = 0xDD; col[1] = 0xA7; col[2] = 0x00;
draw_key_list(elems, col);
BLI_freelistN(&elems);
}
}
}
}
}
}
void drawtimespace(ScrArea *sa, void *spacedata)
{
SpaceTime *stime= sa->spacedata.first;
float col[3];
BIF_GetThemeColor3fv(TH_BACK, col);
glClearColor(col[0], col[1], col[2], 0.0);
glClear(GL_COLOR_BUFFER_BIT);
calc_scrollrcts(sa, &(stime->v2d), curarea->winx, curarea->winy);
myortho2(stime->v2d.cur.xmin, stime->v2d.cur.xmax, stime->v2d.cur.ymin, stime->v2d.cur.ymax);
/* draw darkened area outside of active timeline
* frame range used is preview range or scene range
*/
draw_sfra_efra();
/* boundbox_seq(); */
calc_ipogrid();
draw_ipogrid();
draw_cfra_time(spacedata);
draw_ob_keys();
draw_markers_time();
/* restore viewport */
mywinset(curarea->win);
/* ortho at pixel level curarea */
myortho2(-0.375, curarea->winx-0.375, -0.375, curarea->winy-0.375);
/* the bottom with time values */
BIF_ThemeColor(TH_HEADER);
glRectf(0.0f, 0.0f, (float)curarea->winx, 12.0f);
BIF_ThemeColorShade(TH_HEADER, 50);
fdrawline(0.0f, 12.0f, (float)curarea->winx, 12.0f);
draw_view2d_numbers_horiz(stime->flag & TIME_DRAWFRAMES);
draw_area_emboss(sa);
curarea->win_swap= WIN_BACK_OK;
}
|