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_ipo_types.h"
33 #include "DNA_object_types.h"
34 #include "DNA_space_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_screen_types.h"
38 #include "MEM_guardedalloc.h"
40 #include "BLI_blenlib.h"
41 #include "BLI_arithb.h"
44 #include "BKE_context.h"
45 #include "BKE_screen.h"
47 #include "ED_space_api.h"
48 #include "ED_screen.h"
49 #include "ED_anim_api.h"
50 #include "ED_markers.h"
57 #include "UI_interface.h"
58 #include "UI_resources.h"
59 #include "UI_view2d.h"
61 #include "ipo_intern.h" // own include
63 /* ******************** default callbacks for ipo space ***************** */
65 static SpaceLink *ipo_new(void)
70 sipo= MEM_callocN(sizeof(SpaceIpo), "initipo");
71 sipo->spacetype= SPACE_IPO;
72 sipo->blocktype= ID_OB;
75 ar= MEM_callocN(sizeof(ARegion), "header for ipo");
77 BLI_addtail(&sipo->regionbase, ar);
78 ar->regiontype= RGN_TYPE_HEADER;
79 ar->alignment= RGN_ALIGN_BOTTOM;
82 ar= MEM_callocN(sizeof(ARegion), "main area for ipo");
84 BLI_addtail(&sipo->regionbase, ar);
85 ar->regiontype= RGN_TYPE_CHANNELS;
86 ar->alignment= RGN_ALIGN_LEFT;
88 ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
90 /* XXX view2d init for channels */
93 ar= MEM_callocN(sizeof(ARegion), "main area for ipo");
95 BLI_addtail(&sipo->regionbase, ar);
96 ar->regiontype= RGN_TYPE_WINDOW;
98 ar->v2d.tot.xmin= 0.0f;
99 ar->v2d.tot.ymin= -10.0f;
100 ar->v2d.tot.xmax= 250.0;
101 ar->v2d.tot.ymax= 10.0f;
103 ar->v2d.cur= ar->v2d.tot;
105 ar->v2d.min[0]= 0.01f;
106 ar->v2d.min[1]= 0.01f;
108 ar->v2d.max[0]= MAXFRAMEF;
109 ar->v2d.max[1]= 50000.0f;
111 ar->v2d.scroll= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
112 ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
116 /* channel list region XXX */
119 return (SpaceLink *)sipo;
122 /* not spacelink itself */
123 static void ipo_free(SpaceLink *sl)
125 SpaceIpo *si= (SpaceIpo*) sl;
127 if(si->editipo) MEM_freeN(si->editipo);
128 // XXX free_ipokey(&si->ipokey);
133 /* spacetype; init callback */
134 static void ipo_init(struct wmWindowManager *wm, ScrArea *sa)
139 static SpaceLink *ipo_duplicate(SpaceLink *sl)
141 SpaceIpo *sipon= MEM_dupallocN(sl);
143 /* clear or remove stuff from old */
144 sipon->editipo= NULL;
145 sipon->ipokey.first= sipon->ipokey.last= NULL;
147 return (SpaceLink *)sipon;
150 /* add handlers, stuff you only do once or on area/region changes */
151 static void ipo_main_area_init(wmWindowManager *wm, ARegion *ar)
155 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
158 keymap= WM_keymap_listbase(wm, "Ipo", SPACE_IPO, 0); /* XXX weak? */
159 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
162 static void ipo_main_area_draw(const bContext *C, ARegion *ar)
164 /* draw entirely, view changes should be handled here */
165 SpaceIpo *sipo= (SpaceIpo*)CTX_wm_space_data(C);
166 View2D *v2d= &ar->v2d;
168 View2DScrollers *scrollers;
170 short unit=0, flag=0;
172 /* clear and setup matrix */
173 UI_GetThemeColor3fv(TH_BACK, col);
174 glClearColor(col[0], col[1], col[2], 0.0);
175 glClear(GL_COLOR_BUFFER_BIT);
177 UI_view2d_view_ortho(C, v2d);
180 unit= (sipo->flag & SIPO_DRAWTIME)? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
181 grid= UI_view2d_grid_calc(C, v2d, unit, V2D_GRID_NOCLAMP, V2D_UNIT_VALUES/*unit-y*/, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
182 UI_view2d_grid_draw(C, v2d, grid, V2D_GRIDLINES_ALL);
183 UI_view2d_grid_free(grid);
188 if (sipo->flag & SIPO_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
189 if ((sipo->flag & SIPO_NODRAWCFRANUM)==0) flag |= DRAWCFRA_SHOW_NUMBOX;
190 ANIM_draw_cfra(C, v2d, flag);
193 UI_view2d_view_orthoSpecial(C, v2d, 1);
194 draw_markers_time(C, 0);
197 UI_view2d_view_ortho(C, v2d);
198 ANIM_draw_previewrange(C, v2d);
200 /* reset view matrix */
201 UI_view2d_view_restore(C);
204 // FIXME: args for scrollers depend on the type of data being shown...
205 scrollers= UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_NOCLAMP, V2D_UNIT_VALUES/*unit-y*/, V2D_GRID_NOCLAMP);
206 UI_view2d_scrollers_draw(C, v2d, scrollers);
207 UI_view2d_scrollers_free(scrollers);
210 void ipo_operatortypes(void)
214 void ipo_keymap(struct wmWindowManager *wm)
218 static void ipo_channel_area_init(wmWindowManager *wm, ARegion *ar)
220 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
223 static void ipo_channel_area_draw(const bContext *C, ARegion *ar)
225 //SpaceIpo *sipo= C->area->spacedata.first;
226 View2D *v2d= &ar->v2d;
227 View2DScrollers *scrollers;
230 /* clear and setup matrix */
231 UI_GetThemeColor3fv(TH_SHADE2, col);
232 glClearColor(col[0], col[1], col[2], 0.0);
233 glClear(GL_COLOR_BUFFER_BIT);
235 UI_view2d_view_ortho(C, v2d);
239 /* reset view matrix */
240 UI_view2d_view_restore(C);
243 scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
244 UI_view2d_scrollers_draw(C, v2d, scrollers);
245 UI_view2d_scrollers_free(scrollers);
248 /* add handlers, stuff you only do once or on area/region changes */
249 static void ipo_header_area_init(wmWindowManager *wm, ARegion *ar)
251 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
254 static void ipo_header_area_draw(const bContext *C, ARegion *ar)
259 if(ED_screen_area_active(C))
260 UI_GetThemeColor3fv(TH_HEADER, col);
262 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
264 glClearColor(col[0], col[1], col[2], 0.0);
265 glClear(GL_COLOR_BUFFER_BIT);
267 /* set view2d view matrix for scrolling (without scrollers) */
268 UI_view2d_view_ortho(C, &ar->v2d);
270 ipo_header_buttons(C, ar);
272 /* restore view matrix? */
273 UI_view2d_view_restore(C);
276 static void ipo_main_area_listener(ARegion *ar, wmNotifier *wmn)
278 /* context changes */
281 case WM_NOTE_MARKERS_CHANGED:
282 ED_region_tag_redraw(ar);
287 /* only called once, from space/spacetypes.c */
288 void ED_spacetype_ipo(void)
290 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype ipo");
293 st->spaceid= SPACE_IPO;
298 st->duplicate= ipo_duplicate;
299 st->operatortypes= ipo_operatortypes;
300 st->keymap= ipo_keymap;
302 /* regions: main window */
303 art= MEM_callocN(sizeof(ARegionType), "spacetype ipo region");
304 art->regionid = RGN_TYPE_WINDOW;
305 art->init= ipo_main_area_init;
306 art->draw= ipo_main_area_draw;
307 art->listener= ipo_main_area_listener;
308 art->keymapflag= ED_KEYMAP_VIEW2D|ED_KEYMAP_MARKERS|ED_KEYMAP_ANIMATION;
310 BLI_addhead(&st->regiontypes, art);
312 /* regions: header */
313 art= MEM_callocN(sizeof(ARegionType), "spacetype ipo region");
314 art->regionid = RGN_TYPE_HEADER;
315 art->minsizey= HEADERY;
316 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
318 art->init= ipo_header_area_init;
319 art->draw= ipo_header_area_draw;
321 BLI_addhead(&st->regiontypes, art);
323 /* regions: channels */
324 art= MEM_callocN(sizeof(ARegionType), "spacetype ipo region");
325 art->regionid = RGN_TYPE_CHANNELS;
327 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
329 art->init= ipo_channel_area_init;
330 art->draw= ipo_channel_area_draw;
332 BLI_addhead(&st->regiontypes, art);
335 BKE_spacetype_register(st);