4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2005 Blender Foundation.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
38 #include "BLI_blenlib.h"
39 #include "BLI_arithb.h"
41 #include "DNA_action_types.h"
42 #include "DNA_ipo_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_material_types.h"
45 #include "DNA_scene_types.h"
46 #include "DNA_space_types.h"
47 #include "DNA_screen_types.h"
50 #include "BKE_object.h"
51 #include "BKE_material.h"
52 #include "BKE_utildefines.h"
53 #include "BKE_global.h"
56 #include "BIF_mywindow.h"
57 #include "BIF_screen.h"
58 #include "BIF_resources.h"
60 #include "BSE_drawipo.h"
66 /* ---- prototypes ------ */
67 void drawtimespace(ScrArea *, void *);
70 static void draw_cfra_time(SpaceTime *stime)
74 vec[0]= (G.scene->r.cfra);
75 vec[0]*= G.scene->r.framelen;
77 vec[1]= G.v2d->cur.ymin;
78 glColor3ub(0x60, 0xc0, 0x40); // no theme, should be global color once...
83 vec[1]= G.v2d->cur.ymax;
89 if(stime->flag & TIME_CFRA_NUM) {
93 /* little box with frame */
95 glFlush(); // huhh... without this glColor won't work for the text...
96 getmouseco_areawin(mval);
98 if(mval[1]>curarea->winy-10) mval[1]= curarea->winy - 13;
100 if (curarea->winy < 25) {
101 if (mval[1]<17) mval[1]= 17;
102 } else if (mval[1]<22) mval[1]= 22;
104 areamouseco_to_ipoco(G.v2d, mval, &x, &y);
106 if(stime->flag & TIME_DRAWFRAMES)
107 sprintf(str, " %d\n", (G.scene->r.cfra));
108 else sprintf(str, " %.2f\n", (G.scene->r.cfra/(float)G.scene->r.frs_sec));
110 /* HACK! somehow the green color won't go away... */
111 glColor4ub(0, 0, 0, 0);
112 BIF_ThemeColor(TH_TEXT);
115 BMF_DrawString(G.fonts, str);
121 static void draw_marker(TimeMarker *marker)
123 float xpos, xspace, yspace, xpixels, ypixels;
125 xpos = marker->frame;
126 /* no time correction for framelen! space is drawn with old values */
128 xspace= G.v2d->cur.xmax - G.v2d->cur.xmin;
129 yspace= G.v2d->cur.ymax - G.v2d->cur.ymin;
130 xpixels= G.v2d->mask.xmax-G.v2d->mask.xmin;
131 ypixels= G.v2d->mask.ymax-G.v2d->mask.ymin;
134 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
136 /* 5 px to offset icon to align properly, space / pixels corrects for zoom */
137 if(marker->flag & SELECT)
138 BIF_draw_icon_blended(xpos-(5.0*(xspace/xpixels)), 12.0*yspace/ypixels, ICON_MARKER_HLT, TH_BACK, 0);
140 BIF_draw_icon_blended(xpos-(5.0*(xspace/xpixels)), 12.0*yspace/ypixels, ICON_MARKER, TH_BACK, 0);
142 glBlendFunc(GL_ONE, GL_ZERO);
145 /* and the marker name too, shifted slightly to the top-right */
146 if(marker->name && marker->name[0]) {
147 if(marker->flag & SELECT) {
148 BIF_ThemeColor(TH_TEXT_HI);
149 glRasterPos2f(xpos+(4.0*(xspace/xpixels)),
150 ((ypixels<=39.0)?(ypixels-10.0):29.0)*yspace/ypixels);
153 BIF_ThemeColor(TH_TEXT);
154 if((marker->frame <= G.scene->r.cfra) && (marker->frame+5 > G.scene->r.cfra))
155 glRasterPos2f(xpos+(4.0*(xspace/xpixels)),
156 ((ypixels<=39.0)?(ypixels-10.0):29.0)*yspace/ypixels);
158 glRasterPos2f(xpos+(4.0*(xspace/xpixels)), 17.0*yspace/ypixels);
160 BMF_DrawString(G.font, marker->name);
164 static void draw_markers_time( void )
168 /* unselected markers are drawn at the first time */
169 for(marker= G.scene->markers.first; marker; marker= marker->next) {
170 if(!(marker->flag & SELECT)) draw_marker(marker);
173 /* selected markers are drawn later ... selected markers have to cover unselected
174 * markers laying at the same position as selected markers
175 * (jiri: it is hack, it could be solved better) */
176 for(marker= G.scene->markers.first; marker; marker= marker->next) {
177 if(marker->flag & SELECT) draw_marker(marker);
181 static void draw_sfra_efra()
183 BIF_ThemeColorShade(TH_BACK, -25);
185 if (G.scene->r.sfra < G.scene->r.efra) {
186 glRectf(G.v2d->cur.xmin, G.v2d->cur.ymin, G.scene->r.sfra, G.v2d->cur.ymax);
188 glRectf(G.scene->r.efra, G.v2d->cur.ymin, G.v2d->cur.xmax, G.v2d->cur.ymax);
190 glRectf(G.v2d->cur.xmin, G.v2d->cur.ymin, G.v2d->cur.xmax, G.v2d->cur.ymax);
193 BIF_ThemeColorShade(TH_BACK, -60);
194 /* thin lines where the actual frames are */
195 fdrawline(G.scene->r.sfra, G.v2d->cur.ymin, G.scene->r.sfra, G.v2d->cur.ymax);
196 fdrawline(G.scene->r.efra, G.v2d->cur.ymin, G.scene->r.efra, G.v2d->cur.ymax);
201 /*draw all the keys in a list (elems) as lines */
202 static void draw_key_list(ListBase elems, char col[3])
209 drawframe = ce->cfra; //not correct for G.scene->r.framelen;
210 glColor3ub(col[0], col[1], col[2]);
212 fdrawline(drawframe, G.v2d->cur.ymin, drawframe, G.v2d->cur.ymax);
218 static void draw_ob_keys()
220 /*mostly copied from drawobject.c, draw_object() */
222 bActionChannel *achan;
234 /* convert the ipo to a list of 'current frame elements' */
236 elems.first= elems.last= NULL;
237 make_cfra_list(ob->ipo, &elems);
239 /* draw the list of current frame elements */
240 col[0] = 0xDD; col[1] = 0xD7; col[2] = 0x00;
241 draw_key_list(elems, col);
243 BLI_freelistN(&elems);
249 /* go through each channel in the action */
250 for (achan=act->chanbase.first; achan; achan=achan->next){
251 /* convert the ipo to a list of 'current frame elements' */
253 elems.first= elems.last= NULL;
254 make_cfra_list(achan->ipo, &elems);
256 col[0] = 0x00; col[1] = 0x82; col[2] = 0x8B;
257 draw_key_list(elems, col);
259 BLI_freelistN(&elems);
264 for(a=0; a<ob->totcol; a++) {
265 Material *ma= give_current_material(ob, a+1);
268 elems.first= elems.last= NULL;
269 make_cfra_list(ma->ipo, &elems);
271 col[0] = 0xDD; col[1] = 0xA7; col[2] = 0x00;
272 draw_key_list(elems, col);
274 BLI_freelistN(&elems);
283 void drawtimespace(ScrArea *sa, void *spacedata)
285 SpaceTime *stime= sa->spacedata.first;
288 BIF_GetThemeColor3fv(TH_BACK, col);
289 glClearColor(col[0], col[1], col[2], 0.0);
290 glClear(GL_COLOR_BUFFER_BIT);
292 calc_scrollrcts(sa, &(stime->v2d), curarea->winx, curarea->winy);
294 myortho2(stime->v2d.cur.xmin, stime->v2d.cur.xmax, stime->v2d.cur.ymin, stime->v2d.cur.ymax);
296 /* draw darkened area outside of active timeline */
299 /* boundbox_seq(); */
303 draw_cfra_time(spacedata);
307 /* restore viewport */
308 mywinset(curarea->win);
310 /* ortho at pixel level curarea */
311 myortho2(-0.375, curarea->winx-0.375, -0.375, curarea->winy-0.375);
313 /* the bottom with time values */
314 BIF_ThemeColor(TH_HEADER);
315 glRectf(0.0f, 0.0f, (float)curarea->winx, 12.0f);
316 BIF_ThemeColorShade(TH_HEADER, 50);
317 fdrawline(0.0f, 12.0f, (float)curarea->winx, 12.0f);
318 draw_view2d_numbers_horiz(stime->flag & TIME_DRAWFRAMES);
320 draw_area_emboss(sa);
321 curarea->win_swap= WIN_BACK_OK;