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 "BKE_global.h"
40 #include "BKE_screen.h"
48 #include "BIF_glutil.h"
50 #include "UI_interface.h"
51 #include "UI_resources.h"
52 #include "UI_view2d.h"
54 #include "ED_markers.h"
56 #include "time_intern.h"
58 /* ************************ main time area region *********************** */
60 /* draws a current frame indicator for the TimeLine */
61 static void time_draw_cfra_time(const bContext *C, SpaceTime *stime, ARegion *ar)
63 Scene *scene= C->scene;
66 vec[0]= scene->r.cfra*scene->r.framelen;
68 UI_ThemeColor(TH_CFRAME); // no theme, should be global color once...
72 vec[1]= ar->v2d.cur.ymin;
74 vec[1]= ar->v2d.cur.ymax;
81 static void time_draw_sfra_efra(const bContext *C, SpaceTime *stime, ARegion *ar)
83 View2D *v2d= UI_view2d_fromcontext(C);
85 /* draw darkened area outside of active timeline
86 * frame range used is preview range or scene range */
87 UI_ThemeColorShade(TH_BACK, -25);
90 glRectf(v2d->cur.xmin, v2d->cur.ymin, PSFRA, v2d->cur.ymax);
91 glRectf(PEFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
94 glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
97 UI_ThemeColorShade(TH_BACK, -60);
98 /* thin lines where the actual frames are */
99 fdrawline(PSFRA, v2d->cur.ymin, PSFRA, v2d->cur.ymax);
100 fdrawline(PEFRA, v2d->cur.ymin, PEFRA, v2d->cur.ymax);
103 static void time_main_area_init(const bContext *C, ARegion *ar)
105 /* add handlers, stuff you only do once or on area/region changes */
108 static void time_main_area_refresh(const bContext *C, ARegion *ar)
110 /* refresh to match contextual changes */
113 static void time_main_area_draw(const bContext *C, ARegion *ar)
115 /* draw entirely, windowsize changes should be handled here */
116 SpaceTime *stime= C->area->spacedata.first;
117 View2D *v2d= &ar->v2d;
119 View2DScrollers *scrollers;
121 int unit, winx, winy;
123 // XXX this should become stored in regions too...
124 winx= ar->winrct.xmax - ar->winrct.xmin + 1;
125 winy= ar->winrct.ymax - ar->winrct.ymin + 1;
127 UI_view2d_update_size(v2d, winx, winy);
129 /* clear and setup matrix */
130 UI_GetThemeColor3fv(TH_BACK, col);
131 glClearColor(col[0], col[1], col[2], 0.0);
132 glClear(GL_COLOR_BUFFER_BIT);
134 UI_view2d_view_ortho(C, v2d);
136 /* start and end frame */
137 time_draw_sfra_efra(C, stime, ar);
140 unit= (stime->flag & TIME_DRAWFRAMES)? V2D_UNIT_FRAMES: V2D_UNIT_SECONDS;
141 grid= UI_view2d_calc_grid(C, v2d, unit, V2D_GRID_CLAMP, winx, winy);
142 UI_view2d_draw_grid(C, v2d, grid, (V2D_VERTICAL_LINES|V2D_VERTICAL_AXIS));
143 UI_view2d_free_grid(grid);
146 time_draw_cfra_time(C, stime, ar);
149 UI_view2d_view_orthospecial(C, v2d, 1);
150 draw_markers_time(C, 0);
152 /* reset view matrix */
153 UI_view2d_view_restore(C);
156 scrollers= UI_view2d_calc_scrollers(C, v2d, unit, V2D_GRID_CLAMP, 0, 0);
157 UI_view2d_draw_scrollers(C, v2d, scrollers);
158 UI_view2d_free_scrollers(scrollers);
161 static void time_main_area_listener(ARegion *ar, wmNotifier *wmn)
163 /* draw entirely, windowsize changes should be handled here */
166 /* ************************ header time area region *********************** */
168 static void time_header_area_draw(const bContext *C, ARegion *ar)
173 UI_GetThemeColor3fv(TH_HEADER, col);
174 glClearColor(col[0], col[1], col[2], 0.0);
175 glClear(GL_COLOR_BUFFER_BIT);
180 static void time_header_area_free(ARegion *ar)
182 uiFreeBlocks(&ar->uiblocks);
185 /* ******************** default callbacks for time space ***************** */
187 static SpaceLink *time_new(void)
191 stime= MEM_callocN(sizeof(SpaceTime), "inittime");
193 stime->spacetype= SPACE_TIME;
194 stime->blockscale= 0.7;
195 stime->redraws= TIME_ALL_3D_WIN|TIME_ALL_ANIM_WIN;
197 // XXX move to region!
198 stime->v2d.tot.xmin= -4.0;
199 stime->v2d.tot.ymin= 0.0;
200 stime->v2d.tot.xmax= (float)EFRA + 4.0;
201 //stime->v2d.tot.ymax= (float)stime->winy;
203 stime->v2d.cur= stime->v2d.tot;
205 stime->v2d.min[0]= 1.0;
206 //stime->v2d.min[1]= (float)stime->winy;
208 stime->v2d.max[0]= 32000.0;
209 //stime->v2d.max[1]= (float)stime->winy;
211 stime->v2d.minzoom= 0.1f;
212 stime->v2d.maxzoom= 10.0;
214 stime->v2d.scroll= 0;
215 stime->v2d.keepaspect= 0;
216 stime->v2d.keepzoom= 0;
217 stime->v2d.keeptot= 0;
219 stime->flag |= TIME_DRAWFRAMES;
221 return (SpaceLink*)stime;
224 /* not spacelink itself */
225 static void time_free(SpaceLink *sl)
229 /* spacetype; init callback */
230 static void time_init(wmWindowManager *wm, ScrArea *sa)
234 /* link area to SpaceXXX struct */
236 /* add handlers to area */
237 /* define how many regions, the order and types */
239 /* add types to regions */
240 for(ar= sa->regionbase.first; ar; ar= ar->next) {
241 if(ar->regiontype == RGN_TYPE_WINDOW) {
242 static ARegionType mainart={NULL, NULL, NULL, NULL, NULL};
244 mainart.init= time_main_area_init;
245 mainart.refresh= time_main_area_refresh;
246 mainart.draw= time_main_area_draw;
247 mainart.listener= time_main_area_listener;
251 /* XXX the windowmanager may not be the best place to keep these
252 * keymaps, and this function callback may not be the best one
253 * to add the keymap handler, also will need to take care of
254 * area type changes, etc, basically space callbacks need to
255 * be looked at further */
256 WM_event_remove_keymap_handler(&ar->handlers, &wm->timekeymap);
257 WM_event_add_keymap_handler(&ar->handlers, &wm->timekeymap);
258 WM_event_add_keymap_handler(&ar->handlers, &wm->view2dkeymap); // XXX this should be added automatically!
260 else if(ar->regiontype == RGN_TYPE_HEADER) {
261 static ARegionType headerart={NULL, NULL, NULL, NULL, NULL};
263 headerart.draw= time_header_area_draw;
264 headerart.free= time_header_area_free;
266 ar->type= &headerart;
267 WM_event_add_keymap_handler(&ar->handlers, &wm->uikeymap);
268 WM_event_add_keymap_handler(&ar->handlers, &wm->view2dkeymap); // XXX this should be added automatically!
271 static ARegionType art={NULL, NULL, NULL, NULL, NULL};
273 /* for time being; register 1 type */
279 /* spacetype; context changed */
280 static void time_refresh(bContext *C, ScrArea *sa)
285 static SpaceLink *time_duplicate(SpaceLink *sl)
287 SpaceTime *stime= (SpaceTime *)sl;
288 SpaceTime *stimen= MEM_dupallocN(stime);
290 return (SpaceLink *)stimen;
293 /* only called once, from screen/spacetypes.c */
294 void ED_spacetype_time(void)
298 st.spaceid= SPACE_TIME;
303 st.refresh= time_refresh;
304 st.duplicate= time_duplicate;
305 st.operatortypes= time_operatortypes;
306 st.keymap= time_keymap;
308 BKE_spacetype_register(&st);