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_nla_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_colortools.h"
45 #include "BKE_global.h"
46 #include "BKE_screen.h"
48 #include "ED_space_api.h"
49 #include "ED_screen.h"
56 #include "UI_interface.h"
57 #include "UI_resources.h"
58 #include "UI_view2d.h"
60 #include "ED_markers.h"
62 #include "nla_intern.h" // own include
64 /* ******************** default callbacks for nla space ***************** */
66 static SpaceLink *nla_new(void)
71 snla= MEM_callocN(sizeof(SpaceNla), "initnla");
72 snla->spacetype= SPACE_NLA;
75 ar= MEM_callocN(sizeof(ARegion), "header for nla");
77 BLI_addtail(&snla->regionbase, ar);
78 ar->regiontype= RGN_TYPE_HEADER;
79 ar->alignment= RGN_ALIGN_BOTTOM;
82 ar= MEM_callocN(sizeof(ARegion), "main area for nla");
84 BLI_addtail(&snla->regionbase, ar);
85 ar->regiontype= RGN_TYPE_WINDOW;
87 ar->v2d.tot.xmin= 1.0f;
88 ar->v2d.tot.ymin= 0.0f;
89 ar->v2d.tot.xmax= 1000.0f;
90 ar->v2d.tot.ymax= 1000.0f;
92 ar->v2d.cur.xmin= -5.0f;
93 ar->v2d.cur.ymin= 0.0f;
94 ar->v2d.cur.xmax= 65.0f;
95 ar->v2d.cur.ymax= 1000.0f;
100 ar->v2d.max[0]= MAXFRAMEF;
101 ar->v2d.max[1]= 1000.0f;
103 ar->v2d.minzoom= 0.1f;
104 ar->v2d.maxzoom= 50.0f;
106 ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
107 ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
108 ar->v2d.keepzoom= V2D_LOCKZOOM_Y;
111 /* channel list region XXX */
112 ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
113 BLI_addtail(&snla->regionbase, ar);
114 ar->regiontype= RGN_TYPE_CHANNELS;
115 ar->alignment= RGN_ALIGN_LEFT;
118 return (SpaceLink *)snla;
121 /* not spacelink itself */
122 static void nla_free(SpaceLink *sl)
124 // SpaceNla *snla= (SpaceNla*) sl;
129 /* spacetype; init callback */
130 static void nla_init(struct wmWindowManager *wm, ScrArea *sa)
135 static SpaceLink *nla_duplicate(SpaceLink *sl)
137 SpaceNla *snlan= MEM_dupallocN(sl);
139 /* clear or remove stuff from old */
141 return (SpaceLink *)snlan;
146 /* add handlers, stuff you only do once or on area/region changes */
147 static void nla_main_area_init(wmWindowManager *wm, ARegion *ar)
151 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_TIMELINE, ar->winx, ar->winy);
154 keymap= WM_keymap_listbase(wm, "NLA", SPACE_NLA, 0); /* XXX weak? */
155 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
158 static void nla_main_area_draw(const bContext *C, ARegion *ar)
160 /* draw entirely, view changes should be handled here */
161 // SpaceNla *snla= C->area->spacedata.first;
162 View2D *v2d= &ar->v2d;
165 /* clear and setup matrix */
166 UI_GetThemeColor3fv(TH_BACK, col);
167 glClearColor(col[0], col[1], col[2], 0.0);
168 glClear(GL_COLOR_BUFFER_BIT);
170 UI_view2d_view_ortho(C, v2d);
175 /* reset view matrix */
176 UI_view2d_view_restore(C);
181 void nla_operatortypes(void)
186 void nla_keymap(struct wmWindowManager *wm)
191 /* add handlers, stuff you only do once or on area/region changes */
192 static void nla_header_area_init(wmWindowManager *wm, ARegion *ar)
194 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
197 static void nla_header_area_draw(const bContext *C, ARegion *ar)
202 if(ED_screen_area_active(C))
203 UI_GetThemeColor3fv(TH_HEADER, col);
205 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
207 glClearColor(col[0], col[1], col[2], 0.0);
208 glClear(GL_COLOR_BUFFER_BIT);
210 /* set view2d view matrix for scrolling (without scrollers) */
211 UI_view2d_view_ortho(C, &ar->v2d);
213 nla_header_buttons(C, ar);
215 /* restore view matrix? */
216 UI_view2d_view_restore(C);
219 static void nla_main_area_listener(ARegion *ar, wmNotifier *wmn)
221 /* context changes */
224 /* only called once, from space/spacetypes.c */
225 void ED_spacetype_nla(void)
227 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype nla");
230 st->spaceid= SPACE_NLA;
235 st->duplicate= nla_duplicate;
236 st->operatortypes= nla_operatortypes;
237 st->keymap= nla_keymap;
239 /* regions: main window */
240 art= MEM_callocN(sizeof(ARegionType), "spacetype nla region");
241 art->regionid = RGN_TYPE_WINDOW;
242 art->init= nla_main_area_init;
243 art->draw= nla_main_area_draw;
244 art->listener= nla_main_area_listener;
245 art->keymapflag= ED_KEYMAP_VIEW2D;
247 BLI_addhead(&st->regiontypes, art);
249 /* regions: header */
250 art= MEM_callocN(sizeof(ARegionType), "spacetype nla region");
251 art->regionid = RGN_TYPE_HEADER;
252 art->minsizey= HEADERY;
253 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
255 art->init= nla_header_area_init;
256 art->draw= nla_header_area_draw;
258 BLI_addhead(&st->regiontypes, art);
260 /* regions: channels */
261 art= MEM_callocN(sizeof(ARegionType), "spacetype nla region");
262 art->regionid = RGN_TYPE_CHANNELS;
264 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
266 //art->init= nla_channel_area_init;
267 //art->draw= nla_channel_area_draw;
269 BLI_addhead(&st->regiontypes, art);
272 BKE_spacetype_register(st);