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) 2008 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
32 #include "DNA_space_types.h"
33 #include "DNA_scene_types.h"
34 #include "DNA_screen_types.h"
35 #include "DNA_windowmanager_types.h"
37 #include "MEM_guardedalloc.h"
39 #include "BLI_blenlib.h"
41 #include "BKE_global.h"
42 #include "BKE_screen.h"
44 #include "ED_space_api.h"
45 #include "ED_screen.h"
52 #include "BIF_glutil.h"
54 #include "UI_interface.h"
55 #include "UI_resources.h"
56 #include "UI_view2d.h"
58 #include "ED_markers.h"
60 #include "time_intern.h"
62 /* ************************ main time area region *********************** */
64 /* draws a current frame indicator for the TimeLine */
65 static void time_draw_cfra_time(const bContext *C, SpaceTime *stime, ARegion *ar)
67 Scene *scene= C->scene;
70 vec[0]= scene->r.cfra*scene->r.framelen;
72 UI_ThemeColor(TH_CFRAME); // no theme, should be global color once...
76 vec[1]= ar->v2d.cur.ymin;
78 vec[1]= ar->v2d.cur.ymax;
85 static void time_draw_sfra_efra(const bContext *C, SpaceTime *stime, ARegion *ar)
87 View2D *v2d= UI_view2d_fromcontext(C);
89 /* draw darkened area outside of active timeline
90 * frame range used is preview range or scene range */
91 UI_ThemeColorShade(TH_BACK, -25);
94 glRectf(v2d->cur.xmin, v2d->cur.ymin, PSFRA, v2d->cur.ymax);
95 glRectf(PEFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
98 glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
101 UI_ThemeColorShade(TH_BACK, -60);
102 /* thin lines where the actual frames are */
103 fdrawline(PSFRA, v2d->cur.ymin, PSFRA, v2d->cur.ymax);
104 fdrawline(PEFRA, v2d->cur.ymin, PEFRA, v2d->cur.ymax);
107 /* add handlers, stuff you only do once or on area/region changes */
108 static void time_main_area_init(wmWindowManager *wm, ARegion *ar)
112 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_TIMELINE, ar->winx, ar->winy);
115 keymap= WM_keymap_listbase(wm, "TimeLine", SPACE_TIME, 0); /* XXX weak? */
116 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
120 static void time_main_area_draw(const bContext *C, ARegion *ar)
122 /* draw entirely, view changes should be handled here */
123 SpaceTime *stime= C->area->spacedata.first;
124 View2D *v2d= &ar->v2d;
126 View2DScrollers *scrollers;
130 /* clear and setup matrix */
131 UI_GetThemeColor3fv(TH_BACK, col);
132 glClearColor(col[0], col[1], col[2], 0.0);
133 glClear(GL_COLOR_BUFFER_BIT);
135 UI_view2d_view_ortho(C, v2d);
137 /* start and end frame */
138 time_draw_sfra_efra(C, stime, ar);
141 unit= (stime->flag & TIME_DRAWFRAMES)? V2D_UNIT_FRAMES: V2D_UNIT_SECONDS;
142 grid= UI_view2d_grid_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
143 UI_view2d_grid_draw(C, v2d, grid, (V2D_VERTICAL_LINES|V2D_VERTICAL_AXIS));
144 UI_view2d_grid_free(grid);
147 time_draw_cfra_time(C, stime, ar);
150 UI_view2d_view_orthoSpecial(C, v2d, 1);
151 draw_markers_time(C, 0);
153 /* reset view matrix */
154 UI_view2d_view_restore(C);
157 scrollers= UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
158 UI_view2d_scrollers_draw(C, v2d, scrollers);
159 UI_view2d_scrollers_free(scrollers);
162 static void time_main_area_listener(ARegion *ar, wmNotifier *wmn)
164 /* context changes */
167 case WM_NOTE_TIMELINE_SYNC:
168 if(ar->v2d.flag & V2D_VIEWSYNC_X) {
169 ar->do_draw= 1; /* XXX GAH! */
170 UI_view2d_sync(&ar->v2d, wmn->data, wmn->value);
176 /* ************************ header time area region *********************** */
178 /* add handlers, stuff you only do once or on area/region changes */
179 static void time_header_area_init(wmWindowManager *wm, ARegion *ar)
181 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
184 static void time_header_area_draw(const bContext *C, ARegion *ar)
189 if(ED_screen_area_active(C))
190 UI_GetThemeColor3fv(TH_HEADER, col);
192 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
194 glClearColor(col[0], col[1], col[2], 0.0);
195 glClear(GL_COLOR_BUFFER_BIT);
197 /* set view2d view matrix for scrolling (without scrollers) */
198 UI_view2d_view_ortho(C, &ar->v2d);
200 time_header_buttons(C, ar);
202 /* restore view matrix? */
203 UI_view2d_view_restore(C);
207 /* ******************** default callbacks for time space ***************** */
209 static SpaceLink *time_new(void)
214 stime= MEM_callocN(sizeof(SpaceTime), "inittime");
216 stime->spacetype= SPACE_TIME;
217 stime->redraws= TIME_ALL_3D_WIN|TIME_ALL_ANIM_WIN;
218 stime->flag |= TIME_DRAWFRAMES;
221 ar= MEM_callocN(sizeof(ARegion), "header for time");
223 BLI_addtail(&stime->regionbase, ar);
224 ar->regiontype= RGN_TYPE_HEADER;
225 ar->alignment= RGN_ALIGN_BOTTOM;
228 ar= MEM_callocN(sizeof(ARegion), "main area for time");
230 BLI_addtail(&stime->regionbase, ar);
231 ar->regiontype= RGN_TYPE_WINDOW;
233 /* only need to set y-locks for view2d of main area,
234 * as the rest is taken care of by View2D preset for TimeGrids
236 ar->v2d.min[1]= 20.0;
237 ar->v2d.max[1]= 20.0;
239 ar->v2d.cur.ymin= ar->v2d.tot.ymin= 0.0f;
240 ar->v2d.cur.ymax= ar->v2d.tot.ymax= 20.0f;
242 ar->v2d.align = V2D_ALIGN_NO_NEG_Y;
243 ar->v2d.keepofs = V2D_LOCKOFS_Y;
244 ar->v2d.keepzoom = V2D_LOCKZOOM_Y;
246 return (SpaceLink*)stime;
249 /* not spacelink itself */
250 static void time_free(SpaceLink *sl)
255 /* spacetype; init callback in ED_area_initialize() */
256 /* init is called to (re)initialize an existing editor (file read, screen changes) */
257 /* validate spacedata, add own area level handlers */
258 static void time_init(wmWindowManager *wm, ScrArea *sa)
263 static SpaceLink *time_duplicate(SpaceLink *sl)
265 SpaceTime *stime= (SpaceTime *)sl;
266 SpaceTime *stimen= MEM_dupallocN(stime);
268 return (SpaceLink *)stimen;
271 /* only called once, from space_api/spacetypes.c */
272 /* it defines all callbacks to maintain spaces */
273 void ED_spacetype_time(void)
275 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype time");
278 st->spaceid= SPACE_TIME;
279 strncpy(st->name, "Timeline", BKE_ST_MAXNAME);
284 st->duplicate= time_duplicate;
285 st->operatortypes= time_operatortypes;
288 /* regions: main window */
289 art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
290 art->regionid = RGN_TYPE_WINDOW;
291 art->keymapflag= ED_KEYMAP_VIEW2D|ED_KEYMAP_MARKERS;
293 art->init= time_main_area_init;
294 art->draw= time_main_area_draw;
295 art->listener= time_main_area_listener;
296 art->keymap= time_keymap;
297 BLI_addhead(&st->regiontypes, art);
299 /* regions: header */
300 art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
301 art->regionid = RGN_TYPE_HEADER;
302 art->minsizey= HEADERY;
303 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
305 art->init= time_header_area_init;
306 art->draw= time_header_area_draw;
307 BLI_addhead(&st->regiontypes, art);
309 BKE_spacetype_register(st);