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_context.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;
81 /* channel list region XXX */
82 ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
83 BLI_addtail(&snla->regionbase, ar);
84 ar->regiontype= RGN_TYPE_CHANNELS;
85 ar->alignment= RGN_ALIGN_LEFT;
87 ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
90 ar= MEM_callocN(sizeof(ARegion), "main area for nla");
92 BLI_addtail(&snla->regionbase, ar);
93 ar->regiontype= RGN_TYPE_WINDOW;
95 ar->v2d.tot.xmin= 1.0f;
96 ar->v2d.tot.ymin= 0.0f;
97 ar->v2d.tot.xmax= 1000.0f;
98 ar->v2d.tot.ymax= 1000.0f;
100 ar->v2d.cur.xmin= -5.0f;
101 ar->v2d.cur.ymin= 0.0f;
102 ar->v2d.cur.xmax= 65.0f;
103 ar->v2d.cur.ymax= 1000.0f;
105 ar->v2d.min[0]= 0.0f;
106 ar->v2d.min[1]= 0.0f;
108 ar->v2d.max[0]= MAXFRAMEF;
109 ar->v2d.max[1]= 1000.0f;
111 ar->v2d.minzoom= 0.1f;
112 ar->v2d.maxzoom= 50.0f;
114 ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
115 ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
116 ar->v2d.keepzoom= V2D_LOCKZOOM_Y;
119 return (SpaceLink *)snla;
122 /* not spacelink itself */
123 static void nla_free(SpaceLink *sl)
125 // SpaceNla *snla= (SpaceNla*) sl;
130 /* spacetype; init callback */
131 static void nla_init(struct wmWindowManager *wm, ScrArea *sa)
136 static SpaceLink *nla_duplicate(SpaceLink *sl)
138 SpaceNla *snlan= MEM_dupallocN(sl);
140 /* clear or remove stuff from old */
142 return (SpaceLink *)snlan;
147 /* add handlers, stuff you only do once or on area/region changes */
148 static void nla_main_area_init(wmWindowManager *wm, ARegion *ar)
152 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
155 keymap= WM_keymap_listbase(wm, "NLA", SPACE_NLA, 0); /* XXX weak? */
156 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
159 static void nla_main_area_draw(const bContext *C, ARegion *ar)
161 /* draw entirely, view changes should be handled here */
162 // SpaceNla *snla= (SpaceNla*)CTX_wm_space_data(C);
163 View2D *v2d= &ar->v2d;
166 /* clear and setup matrix */
167 UI_GetThemeColor3fv(TH_BACK, col);
168 glClearColor(col[0], col[1], col[2], 0.0);
169 glClear(GL_COLOR_BUFFER_BIT);
171 UI_view2d_view_ortho(C, v2d);
176 /* reset view matrix */
177 UI_view2d_view_restore(C);
182 void nla_operatortypes(void)
187 void nla_keymap(struct wmWindowManager *wm)
192 /* add handlers, stuff you only do once or on area/region changes */
193 static void nla_header_area_init(wmWindowManager *wm, ARegion *ar)
195 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
198 static void nla_header_area_draw(const bContext *C, ARegion *ar)
203 if(ED_screen_area_active(C))
204 UI_GetThemeColor3fv(TH_HEADER, col);
206 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
208 glClearColor(col[0], col[1], col[2], 0.0);
209 glClear(GL_COLOR_BUFFER_BIT);
211 /* set view2d view matrix for scrolling (without scrollers) */
212 UI_view2d_view_ortho(C, &ar->v2d);
214 nla_header_buttons(C, ar);
216 /* restore view matrix? */
217 UI_view2d_view_restore(C);
220 static void nla_main_area_listener(ARegion *ar, wmNotifier *wmn)
222 /* context changes */
225 /* only called once, from space/spacetypes.c */
226 void ED_spacetype_nla(void)
228 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype nla");
231 st->spaceid= SPACE_NLA;
236 st->duplicate= nla_duplicate;
237 st->operatortypes= nla_operatortypes;
238 st->keymap= nla_keymap;
240 /* regions: main window */
241 art= MEM_callocN(sizeof(ARegionType), "spacetype nla region");
242 art->regionid = RGN_TYPE_WINDOW;
243 art->init= nla_main_area_init;
244 art->draw= nla_main_area_draw;
245 art->listener= nla_main_area_listener;
246 art->keymapflag= ED_KEYMAP_VIEW2D;
248 BLI_addhead(&st->regiontypes, art);
250 /* regions: header */
251 art= MEM_callocN(sizeof(ARegionType), "spacetype nla region");
252 art->regionid = RGN_TYPE_HEADER;
253 art->minsizey= HEADERY;
254 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
256 art->init= nla_header_area_init;
257 art->draw= nla_header_area_draw;
259 BLI_addhead(&st->regiontypes, art);
261 /* regions: channels */
262 art= MEM_callocN(sizeof(ARegionType), "spacetype nla region");
263 art->regionid = RGN_TYPE_CHANNELS;
265 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
267 //art->init= nla_channel_area_init;
268 //art->draw= nla_channel_area_draw;
270 BLI_addhead(&st->regiontypes, art);
273 BKE_spacetype_register(st);