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_anim_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 *graph_new(const bContext *C)
67 Scene *scene= CTX_data_scene(C);
71 sipo= MEM_callocN(sizeof(SpaceIpo), "init graphedit");
72 sipo->spacetype= SPACE_IPO;
74 /* allocate DopeSheet data for Graph Editor */
75 sipo->ads= MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
78 ar= MEM_callocN(sizeof(ARegion), "header for graphedit");
80 BLI_addtail(&sipo->regionbase, ar);
81 ar->regiontype= RGN_TYPE_HEADER;
82 ar->alignment= RGN_ALIGN_BOTTOM;
85 ar= MEM_callocN(sizeof(ARegion), "main area for graphedit");
87 BLI_addtail(&sipo->regionbase, ar);
88 ar->regiontype= RGN_TYPE_CHANNELS;
89 ar->alignment= RGN_ALIGN_LEFT;
91 ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
94 ar= MEM_callocN(sizeof(ARegion), "main area for graphedit");
96 BLI_addtail(&sipo->regionbase, ar);
97 ar->regiontype= RGN_TYPE_WINDOW;
99 ar->v2d.tot.xmin= 0.0f;
100 ar->v2d.tot.ymin= -10.0f;
101 ar->v2d.tot.xmax= (float)scene->r.efra;
102 ar->v2d.tot.ymax= 10.0f;
104 ar->v2d.cur= ar->v2d.tot;
106 ar->v2d.min[0]= 0.01f;
107 ar->v2d.min[1]= 0.01f;
109 ar->v2d.max[0]= MAXFRAMEF;
110 ar->v2d.max[1]= 50000.0f;
112 ar->v2d.scroll= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
113 ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
117 return (SpaceLink *)sipo;
120 /* not spacelink itself */
121 static void graph_free(SpaceLink *sl)
123 SpaceIpo *si= (SpaceIpo *)sl;
126 BLI_freelistN(&si->ads->chanbase);
132 /* spacetype; init callback */
133 static void graph_init(struct wmWindowManager *wm, ScrArea *sa)
135 //SpaceIpo *si= (SpaceIpo *)sa->spacedata.first;
139 static SpaceLink *graph_duplicate(SpaceLink *sl)
141 SpaceIpo *sipon= MEM_dupallocN(sl);
143 /* clear or remove stuff from old */
144 //sipon->ipokey.first= sipon->ipokey.last= NULL;
145 sipon->ads= MEM_dupallocN(sipon->ads);
147 return (SpaceLink *)sipon;
150 /* add handlers, stuff you only do once or on area/region changes */
151 static void graph_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, "GraphEdit Keys", SPACE_IPO, 0); /* XXX weak? */
159 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
162 static void graph_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);
167 View2D *v2d= &ar->v2d;
169 View2DScrollers *scrollers;
171 short unitx=0, unity=V2D_UNIT_VALUES, flag=0;
173 /* clear and setup matrix */
174 UI_GetThemeColor3fv(TH_BACK, col);
175 glClearColor(col[0], col[1], col[2], 0.0);
176 glClear(GL_COLOR_BUFFER_BIT);
178 UI_view2d_view_ortho(C, v2d);
181 unitx= (sipo->flag & SIPO_DRAWTIME)? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
182 grid= UI_view2d_grid_calc(C, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
183 UI_view2d_grid_draw(C, v2d, grid, V2D_GRIDLINES_ALL);
184 UI_view2d_grid_free(grid);
187 if (ANIM_animdata_get_context(C, &ac)) {
188 graph_draw_curves(&ac, sipo, ar);
192 if (sipo->flag & SIPO_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
193 if ((sipo->flag & SIPO_NODRAWCFRANUM)==0) flag |= DRAWCFRA_SHOW_NUMBOX;
194 ANIM_draw_cfra(C, v2d, flag);
197 UI_view2d_view_orthoSpecial(C, v2d, 1);
198 draw_markers_time(C, 0);
201 UI_view2d_view_ortho(C, v2d);
202 ANIM_draw_previewrange(C, v2d);
204 /* reset view matrix */
205 UI_view2d_view_restore(C);
208 // FIXME: args for scrollers depend on the type of data being shown...
209 scrollers= UI_view2d_scrollers_calc(C, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP);
210 UI_view2d_scrollers_draw(C, v2d, scrollers);
211 UI_view2d_scrollers_free(scrollers);
214 static void graph_channel_area_init(wmWindowManager *wm, ARegion *ar)
218 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
221 keymap= WM_keymap_listbase(wm, "Animation_Channels", 0, 0); /* XXX weak? */
222 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
225 static void graph_channel_area_draw(const bContext *C, ARegion *ar)
227 SpaceIpo *sipo= (SpaceIpo *)CTX_wm_space_data(C);
229 View2D *v2d= &ar->v2d;
230 View2DScrollers *scrollers;
233 /* clear and setup matrix */
234 UI_GetThemeColor3fv(TH_SHADE2, col);
235 glClearColor(col[0], col[1], col[2], 0.0);
236 glClear(GL_COLOR_BUFFER_BIT);
238 UI_view2d_view_ortho(C, v2d);
241 if (ANIM_animdata_get_context(C, &ac)) {
242 graph_draw_channel_names(&ac, sipo, ar);
245 /* reset view matrix */
246 UI_view2d_view_restore(C);
249 scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
250 UI_view2d_scrollers_draw(C, v2d, scrollers);
251 UI_view2d_scrollers_free(scrollers);
254 /* add handlers, stuff you only do once or on area/region changes */
255 static void graph_header_area_init(wmWindowManager *wm, ARegion *ar)
257 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
260 static void graph_header_area_draw(const bContext *C, ARegion *ar)
265 if(ED_screen_area_active(C))
266 UI_GetThemeColor3fv(TH_HEADER, col);
268 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
270 glClearColor(col[0], col[1], col[2], 0.0);
271 glClear(GL_COLOR_BUFFER_BIT);
273 /* set view2d view matrix for scrolling (without scrollers) */
274 UI_view2d_view_ortho(C, &ar->v2d);
276 graph_header_buttons(C, ar);
278 /* restore view matrix? */
279 UI_view2d_view_restore(C);
282 static void graph_region_listener(ARegion *ar, wmNotifier *wmn)
284 /* context changes */
285 switch(wmn->category) {
291 ED_region_tag_redraw(ar);
299 ED_region_tag_redraw(ar);
306 /* editor level listener */
307 static void graph_listener(ScrArea *sa, wmNotifier *wmn)
309 /* context changes */
310 switch (wmn->category) {
312 /*switch (wmn->data) {
315 ED_area_tag_refresh(sa);
318 ED_area_tag_refresh(sa);
321 /*switch (wmn->data) {
324 ED_area_tag_refresh(sa);
327 ED_area_tag_refresh(sa);
332 static void graph_refresh(const bContext *C, ScrArea *sa)
334 SpaceIpo *sipo = (SpaceIpo *)sa->spacedata.first;
336 /* updates to data needed depends on Graph Editor mode... */
337 switch (sipo->mode) {
338 case SIPO_MODE_ANIMATION: /* all animation */
344 case SIPO_MODE_DRIVERS: /* drivers only */
346 Object *ob= CTX_data_active_object(C);
348 /* sync changes to bones to the corresponding action channels */
349 ANIM_pose_to_action_sync(ob, sa);
354 /* region updates? */
355 // XXX resizing y-extents of tot should go here?
358 /* only called once, from space/spacetypes.c */
359 void ED_spacetype_ipo(void)
361 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype ipo");
364 st->spaceid= SPACE_IPO;
367 st->free= graph_free;
368 st->init= graph_init;
369 st->duplicate= graph_duplicate;
370 st->operatortypes= graphedit_operatortypes;
371 st->keymap= graphedit_keymap;
372 st->listener= graph_listener;
373 st->refresh= graph_refresh;
375 /* regions: main window */
376 art= MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
377 art->regionid = RGN_TYPE_WINDOW;
378 art->init= graph_main_area_init;
379 art->draw= graph_main_area_draw;
380 art->listener= graph_region_listener;
381 art->keymapflag= ED_KEYMAP_VIEW2D/*|ED_KEYMAP_MARKERS*/|ED_KEYMAP_ANIMATION|ED_KEYMAP_FRAMES;
383 BLI_addhead(&st->regiontypes, art);
385 /* regions: header */
386 art= MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
387 art->regionid = RGN_TYPE_HEADER;
388 art->minsizey= HEADERY;
389 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES;
390 art->listener= graph_region_listener;
391 art->init= graph_header_area_init;
392 art->draw= graph_header_area_draw;
394 BLI_addhead(&st->regiontypes, art);
396 /* regions: channels */
397 art= MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
398 art->regionid = RGN_TYPE_CHANNELS;
400 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES;
401 art->listener= graph_region_listener;
402 art->init= graph_channel_area_init;
403 art->draw= graph_channel_area_draw;
405 BLI_addhead(&st->regiontypes, art);
408 BKE_spacetype_register(st);