Commenting out code from commit 22457 by Genscher for PointCache.
[blender-staging.git] / source / blender / editors / space_sequencer / space_sequencer.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
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. 
10  *
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.
15  *
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.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_object_types.h"
33 #include "DNA_space_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
36
37 #include "MEM_guardedalloc.h"
38
39 #include "BLI_blenlib.h"
40 #include "BLI_arithb.h"
41 #include "BLI_rand.h"
42
43 #include "BKE_colortools.h"
44 #include "BKE_context.h"
45 #include "BKE_screen.h"
46 #include "BKE_sequence.h"
47
48 #include "ED_space_api.h"
49 #include "ED_screen.h"
50
51 #include "BIF_gl.h"
52
53 #include "WM_api.h"
54 #include "WM_types.h"
55
56 #include "UI_interface.h"
57 #include "UI_resources.h"
58 #include "UI_view2d.h"
59
60 #include "ED_markers.h"
61
62 #include "sequencer_intern.h"   // own include
63
64 /* ******************** manage regions ********************* */
65
66 ARegion *sequencer_has_buttons_region(ScrArea *sa)
67 {
68         ARegion *ar, *arnew;
69         
70         for(ar= sa->regionbase.first; ar; ar= ar->next)
71                 if(ar->regiontype==RGN_TYPE_UI)
72                         return ar;
73         
74         /* add subdiv level; after header */
75         for(ar= sa->regionbase.first; ar; ar= ar->next)
76                 if(ar->regiontype==RGN_TYPE_HEADER)
77                         break;
78         
79         /* is error! */
80         if(ar==NULL) return NULL;
81         
82         arnew= MEM_callocN(sizeof(ARegion), "buttons for sequencer");
83         
84         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
85         arnew->regiontype= RGN_TYPE_UI;
86         arnew->alignment= RGN_ALIGN_RIGHT;
87         
88         arnew->flag = RGN_FLAG_HIDDEN;
89         
90         return arnew;
91 }
92
93
94 /* ******************** default callbacks for sequencer space ***************** */
95
96 static SpaceLink *sequencer_new(const bContext *C)
97 {
98         Scene *scene= CTX_data_scene(C);
99         ARegion *ar;
100         SpaceSeq *sseq;
101         
102         sseq= MEM_callocN(sizeof(SpaceSeq), "initsequencer");
103         sseq->spacetype= SPACE_SEQ;
104         sseq->zoom= 4;
105         sseq->chanshown = 0;
106         
107         
108         /* header */
109         ar= MEM_callocN(sizeof(ARegion), "header for sequencer");
110         
111         BLI_addtail(&sseq->regionbase, ar);
112         ar->regiontype= RGN_TYPE_HEADER;
113         ar->alignment= RGN_ALIGN_BOTTOM;
114         
115         /* buttons/list view */
116         ar= MEM_callocN(sizeof(ARegion), "buttons for sequencer");
117         
118         BLI_addtail(&sseq->regionbase, ar);
119         ar->regiontype= RGN_TYPE_UI;
120         ar->alignment= RGN_ALIGN_RIGHT;
121         ar->flag = RGN_FLAG_HIDDEN;
122         
123         /* main area */
124         ar= MEM_callocN(sizeof(ARegion), "main area for sequencer");
125         
126         BLI_addtail(&sseq->regionbase, ar);
127         ar->regiontype= RGN_TYPE_WINDOW;
128         
129         
130         /* seq space goes from (0,8) to (0, efra) */
131         
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;
136         
137         ar->v2d.cur= ar->v2d.tot;
138         
139         ar->v2d.min[0]= 10.0f;
140         ar->v2d.min[1]= 4.0f;
141         
142         ar->v2d.max[0]= MAXFRAMEF;
143         ar->v2d.max[1]= MAXSEQ;
144         
145         ar->v2d.minzoom= 0.01f;
146         ar->v2d.maxzoom= 100.0f;
147         
148         ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
149         ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
150         ar->v2d.keepzoom= 0;
151         ar->v2d.keeptot= 0;
152         ar->v2d.align= V2D_ALIGN_NO_NEG_Y;
153         
154         return (SpaceLink *)sseq;
155 }
156
157 /* not spacelink itself */
158 static void sequencer_free(SpaceLink *sl)
159 {       
160 //      SpaceSeq *sseq= (SpaceSequencer*) sl;
161         
162 // XXX  if(sseq->gpd) free_gpencil_data(sseq->gpd);
163
164 }
165
166
167 /* spacetype; init callback */
168 static void sequencer_init(struct wmWindowManager *wm, ScrArea *sa)
169 {
170
171 }
172
173 static SpaceLink *sequencer_duplicate(SpaceLink *sl)
174 {
175         SpaceSeq *sseqn= MEM_dupallocN(sl);
176         
177         /* clear or remove stuff from old */
178 // XXX  sseq->gpd= gpencil_data_duplicate(sseq->gpd);
179
180         return (SpaceLink *)sseqn;
181 }
182
183
184
185 /* add handlers, stuff you only do once or on area/region changes */
186 static void sequencer_main_area_init(wmWindowManager *wm, ARegion *ar)
187 {
188         ListBase *keymap;
189         
190         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
191         
192         /* own keymap */
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);
195 }
196
197
198 /* add handlers, stuff you only do once or on area/region changes */
199 static void sequencer_header_area_init(wmWindowManager *wm, ARegion *ar)
200 {
201         ED_region_header_init(ar);
202 }
203
204 static void sequencer_header_area_draw(const bContext *C, ARegion *ar)
205 {
206         ED_region_header(C, ar);
207 }
208
209 static void sequencer_main_area_listener(ARegion *ar, wmNotifier *wmn)
210 {
211         /* context changes */
212         switch(wmn->category) {
213                 case NC_SCENE:
214                         switch(wmn->data) {
215                                 case ND_FRAME:
216                                 case ND_MARKERS:
217                                 case ND_SEQUENCER:
218                                         ED_region_tag_redraw(ar);
219                                         break;
220                         }
221                         break;
222         }
223 }
224
225 /* *********************** buttons region ************************ */
226
227 /* add handlers, stuff you only do once or on area/region changes */
228 static void sequencer_buttons_area_init(wmWindowManager *wm, ARegion *ar)
229 {
230         
231         ED_region_panels_init(wm, ar);
232         
233 }
234
235 static void sequencer_buttons_area_draw(const bContext *C, ARegion *ar)
236 {
237         ED_region_panels(C, ar, 1, NULL, -1);
238 }
239
240 static void sequencer_buttons_area_listener(ARegion *ar, wmNotifier *wmn)
241 {
242         /* context changes */
243         switch(wmn->category) {
244                 
245         }
246 }
247 /* ************************************* */
248
249 /* only called once, from space/spacetypes.c */
250 void ED_spacetype_sequencer(void)
251 {
252         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype sequencer");
253         ARegionType *art;
254         
255         st->spaceid= SPACE_SEQ;
256         
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;
263         
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;
271
272         BLI_addhead(&st->regiontypes, art);
273         
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);
283         
284         /* Keep as python only for now
285         sequencer_buttons_register(art);
286         */
287
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;
293         
294         art->init= sequencer_header_area_init;
295         art->draw= sequencer_header_area_draw;
296         
297         BLI_addhead(&st->regiontypes, art);
298         
299         BKE_spacetype_register(st);
300 }
301