2.50: svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r19323...
[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 /* ******************** default callbacks for sequencer space ***************** */
65
66 static SpaceLink *sequencer_new(const bContext *C)
67 {
68         Scene *scene= CTX_data_scene(C);
69         ARegion *ar;
70         SpaceSeq *sseq;
71         
72         sseq= MEM_callocN(sizeof(SpaceSeq), "initsequencer");
73         sseq->spacetype= SPACE_SEQ;
74         sseq->zoom= 4;
75         sseq->chanshown = 0;
76         
77         
78         /* header */
79         ar= MEM_callocN(sizeof(ARegion), "header for sequencer");
80         
81         BLI_addtail(&sseq->regionbase, ar);
82         ar->regiontype= RGN_TYPE_HEADER;
83         ar->alignment= RGN_ALIGN_BOTTOM;
84         
85         /* main area */
86         ar= MEM_callocN(sizeof(ARegion), "main area for sequencer");
87         
88         BLI_addtail(&sseq->regionbase, ar);
89         ar->regiontype= RGN_TYPE_WINDOW;
90         
91         
92         /* seq space goes from (0,8) to (0, efra) */
93         
94         ar->v2d.tot.xmin= 0.0f;
95         ar->v2d.tot.ymin= 0.0f;
96         ar->v2d.tot.xmax= scene->r.efra;
97         ar->v2d.tot.ymax= 8.0f;
98         
99         ar->v2d.cur= ar->v2d.tot;
100         
101         ar->v2d.min[0]= 10.0f;
102         ar->v2d.min[1]= 4.0f;
103         
104         ar->v2d.max[0]= MAXFRAMEF;
105         ar->v2d.max[1]= MAXSEQ;
106         
107         ar->v2d.minzoom= 0.01f;
108         ar->v2d.maxzoom= 100.0f;
109         
110         ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
111         ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
112         ar->v2d.keepzoom= 0;
113         ar->v2d.keeptot= 0;
114         ar->v2d.align= V2D_ALIGN_NO_NEG_Y;
115         
116         return (SpaceLink *)sseq;
117 }
118
119 /* not spacelink itself */
120 static void sequencer_free(SpaceLink *sl)
121 {       
122 //      SpaceSeq *sseq= (SpaceSequencer*) sl;
123         
124 // XXX  if(sseq->gpd) free_gpencil_data(sseq->gpd);
125
126 }
127
128
129 /* spacetype; init callback */
130 static void sequencer_init(struct wmWindowManager *wm, ScrArea *sa)
131 {
132
133 }
134
135 static SpaceLink *sequencer_duplicate(SpaceLink *sl)
136 {
137         SpaceSeq *sseqn= MEM_dupallocN(sl);
138         
139         /* clear or remove stuff from old */
140 // XXX  sseq->gpd= gpencil_data_duplicate(sseq->gpd);
141
142         return (SpaceLink *)sseqn;
143 }
144
145
146
147 /* add handlers, stuff you only do once or on area/region changes */
148 static void sequencer_main_area_init(wmWindowManager *wm, ARegion *ar)
149 {
150         ListBase *keymap;
151         
152         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
153         
154         /* own keymap */
155         keymap= WM_keymap_listbase(wm, "Sequencer", SPACE_SEQ, 0);      /* XXX weak? */
156         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
157 }
158
159
160 /* add handlers, stuff you only do once or on area/region changes */
161 static void sequencer_header_area_init(wmWindowManager *wm, ARegion *ar)
162 {
163         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
164 }
165
166 static void sequencer_header_area_draw(const bContext *C, ARegion *ar)
167 {
168         float col[3];
169         
170         /* clear */
171         if(ED_screen_area_active(C))
172                 UI_GetThemeColor3fv(TH_HEADER, col);
173         else
174                 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
175         
176         glClearColor(col[0], col[1], col[2], 0.0);
177         glClear(GL_COLOR_BUFFER_BIT);
178         
179         /* set view2d view matrix for scrolling (without scrollers) */
180         UI_view2d_view_ortho(C, &ar->v2d);
181         
182         sequencer_header_buttons(C, ar);
183         
184         /* restore view matrix? */
185         UI_view2d_view_restore(C);
186 }
187
188 static void sequencer_main_area_listener(ARegion *ar, wmNotifier *wmn)
189 {
190         /* context changes */
191         switch(wmn->category) {
192                 case NC_SCENE:
193                         switch(wmn->data) {
194                                 case ND_FRAME:
195                                 case ND_MARKERS:
196                                 case ND_SEQUENCER:
197                                         ED_region_tag_redraw(ar);
198                                         break;
199                         }
200                         break;
201         }
202 }
203
204 /* only called once, from space/spacetypes.c */
205 void ED_spacetype_sequencer(void)
206 {
207         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype sequencer");
208         ARegionType *art;
209         
210         st->spaceid= SPACE_SEQ;
211         
212         st->new= sequencer_new;
213         st->free= sequencer_free;
214         st->init= sequencer_init;
215         st->duplicate= sequencer_duplicate;
216         st->operatortypes= sequencer_operatortypes;
217         st->keymap= sequencer_keymap;
218         
219         /* regions: main window */
220         art= MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
221         art->regionid = RGN_TYPE_WINDOW;
222         art->init= sequencer_main_area_init;
223         art->draw= drawseqspace;
224         art->listener= sequencer_main_area_listener;
225         art->keymapflag= ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES;
226
227         BLI_addhead(&st->regiontypes, art);
228         
229         /* regions: header */
230         art= MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
231         art->regionid = RGN_TYPE_HEADER;
232         art->minsizey= HEADERY;
233         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES;
234         
235         art->init= sequencer_header_area_init;
236         art->draw= sequencer_header_area_draw;
237         
238         BLI_addhead(&st->regiontypes, art);
239         
240         
241         BKE_spacetype_register(st);
242 }
243