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_object_types.h"
33 #include "DNA_space_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
37 #include "MEM_guardedalloc.h"
39 #include "BLI_blenlib.h"
40 #include "BLI_arithb.h"
43 #include "BKE_colortools.h"
44 #include "BKE_context.h"
45 #include "BKE_screen.h"
46 #include "BKE_sequence.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 "sequencer_intern.h" // own include
64 /* ******************** manage regions ********************* */
66 ARegion *sequencer_has_buttons_region(ScrArea *sa)
70 for(ar= sa->regionbase.first; ar; ar= ar->next)
71 if(ar->regiontype==RGN_TYPE_UI)
74 /* add subdiv level; after header */
75 for(ar= sa->regionbase.first; ar; ar= ar->next)
76 if(ar->regiontype==RGN_TYPE_HEADER)
80 if(ar==NULL) return NULL;
82 arnew= MEM_callocN(sizeof(ARegion), "buttons for sequencer");
84 BLI_insertlinkafter(&sa->regionbase, ar, arnew);
85 arnew->regiontype= RGN_TYPE_UI;
86 arnew->alignment= RGN_ALIGN_RIGHT;
88 arnew->flag = RGN_FLAG_HIDDEN;
94 /* ******************** default callbacks for sequencer space ***************** */
96 static SpaceLink *sequencer_new(const bContext *C)
98 Scene *scene= CTX_data_scene(C);
102 sseq= MEM_callocN(sizeof(SpaceSeq), "initsequencer");
103 sseq->spacetype= SPACE_SEQ;
109 ar= MEM_callocN(sizeof(ARegion), "header for sequencer");
111 BLI_addtail(&sseq->regionbase, ar);
112 ar->regiontype= RGN_TYPE_HEADER;
113 ar->alignment= RGN_ALIGN_BOTTOM;
115 /* buttons/list view */
116 ar= MEM_callocN(sizeof(ARegion), "buttons for sequencer");
118 BLI_addtail(&sseq->regionbase, ar);
119 ar->regiontype= RGN_TYPE_UI;
120 ar->alignment= RGN_ALIGN_RIGHT;
121 ar->flag = RGN_FLAG_HIDDEN;
124 ar= MEM_callocN(sizeof(ARegion), "main area for sequencer");
126 BLI_addtail(&sseq->regionbase, ar);
127 ar->regiontype= RGN_TYPE_WINDOW;
130 /* seq space goes from (0,8) to (0, efra) */
132 ar->v2d.tot.xmin= 0.0f;
133 ar->v2d.tot.ymin= 0.0f;
134 ar->v2d.tot.xmax= scene->r.efra;
135 ar->v2d.tot.ymax= 8.0f;
137 ar->v2d.cur= ar->v2d.tot;
139 ar->v2d.min[0]= 10.0f;
140 ar->v2d.min[1]= 4.0f;
142 ar->v2d.max[0]= MAXFRAMEF;
143 ar->v2d.max[1]= MAXSEQ;
145 ar->v2d.minzoom= 0.01f;
146 ar->v2d.maxzoom= 100.0f;
148 ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
149 ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
152 ar->v2d.align= V2D_ALIGN_NO_NEG_Y;
154 return (SpaceLink *)sseq;
157 /* not spacelink itself */
158 static void sequencer_free(SpaceLink *sl)
160 // SpaceSeq *sseq= (SpaceSequencer*) sl;
162 // XXX if(sseq->gpd) free_gpencil_data(sseq->gpd);
167 /* spacetype; init callback */
168 static void sequencer_init(struct wmWindowManager *wm, ScrArea *sa)
173 static SpaceLink *sequencer_duplicate(SpaceLink *sl)
175 SpaceSeq *sseqn= MEM_dupallocN(sl);
177 /* clear or remove stuff from old */
178 // XXX sseq->gpd= gpencil_data_duplicate(sseq->gpd);
180 return (SpaceLink *)sseqn;
185 /* add handlers, stuff you only do once or on area/region changes */
186 static void sequencer_main_area_init(wmWindowManager *wm, ARegion *ar)
190 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
193 keymap= WM_keymap_listbase(wm, "Sequencer", SPACE_SEQ, 0); /* XXX weak? */
194 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
198 /* add handlers, stuff you only do once or on area/region changes */
199 static void sequencer_header_area_init(wmWindowManager *wm, ARegion *ar)
201 ED_region_header_init(ar);
204 static void sequencer_header_area_draw(const bContext *C, ARegion *ar)
206 ED_region_header(C, ar);
209 static void sequencer_main_area_listener(ARegion *ar, wmNotifier *wmn)
211 /* context changes */
212 switch(wmn->category) {
218 ED_region_tag_redraw(ar);
225 /* *********************** buttons region ************************ */
227 /* add handlers, stuff you only do once or on area/region changes */
228 static void sequencer_buttons_area_init(wmWindowManager *wm, ARegion *ar)
231 ED_region_panels_init(wm, ar);
235 static void sequencer_buttons_area_draw(const bContext *C, ARegion *ar)
237 ED_region_panels(C, ar, 1, NULL, -1);
240 static void sequencer_buttons_area_listener(ARegion *ar, wmNotifier *wmn)
242 /* context changes */
243 switch(wmn->category) {
247 /* ************************************* */
249 /* only called once, from space/spacetypes.c */
250 void ED_spacetype_sequencer(void)
252 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype sequencer");
255 st->spaceid= SPACE_SEQ;
257 st->new= sequencer_new;
258 st->free= sequencer_free;
259 st->init= sequencer_init;
260 st->duplicate= sequencer_duplicate;
261 st->operatortypes= sequencer_operatortypes;
262 st->keymap= sequencer_keymap;
264 /* regions: main window */
265 art= MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
266 art->regionid = RGN_TYPE_WINDOW;
267 art->init= sequencer_main_area_init;
268 art->draw= drawseqspace;
269 art->listener= sequencer_main_area_listener;
270 art->keymapflag= ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES;
272 BLI_addhead(&st->regiontypes, art);
274 /* regions: listview/buttons */
275 art= MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
276 art->regionid = RGN_TYPE_UI;
277 art->minsizex= 220; // XXX
278 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_FRAMES;
279 art->listener= sequencer_buttons_area_listener;
280 art->init= sequencer_buttons_area_init;
281 art->draw= sequencer_buttons_area_draw;
282 BLI_addhead(&st->regiontypes, art);
284 /* Keep as python only for now
285 sequencer_buttons_register(art);
288 /* regions: header */
289 art= MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
290 art->regionid = RGN_TYPE_HEADER;
291 art->minsizey= HEADERY;
292 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES;
294 art->init= sequencer_header_area_init;
295 art->draw= sequencer_header_area_draw;
297 BLI_addhead(&st->regiontypes, art);
299 BKE_spacetype_register(st);