View2D: Presets for Initialising Views
[blender-staging.git] / source / blender / editors / space_action / space_action.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_action_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"
37
38 #include "MEM_guardedalloc.h"
39
40 #include "BLI_blenlib.h"
41 #include "BLI_arithb.h"
42 #include "BLI_rand.h"
43
44 #include "BKE_colortools.h"
45 #include "BKE_global.h"
46 #include "BKE_screen.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 "action_intern.h"      // own include
63
64 /* ******************** default callbacks for action space ***************** */
65
66 static SpaceLink *action_new(void)
67 {
68         ARegion *ar;
69         SpaceAction *saction;
70         
71         saction= MEM_callocN(sizeof(SpaceAction), "initaction");
72         saction->spacetype= SPACE_ACTION;
73         saction->autosnap = SACTSNAP_FRAME;
74         
75         
76         /* header */
77         ar= MEM_callocN(sizeof(ARegion), "header for action");
78         
79         BLI_addtail(&saction->regionbase, ar);
80         ar->regiontype= RGN_TYPE_HEADER;
81         ar->alignment= RGN_ALIGN_BOTTOM;
82         
83         /* main area */
84         ar= MEM_callocN(sizeof(ARegion), "main area for action");
85         
86         BLI_addtail(&saction->regionbase, ar);
87         ar->regiontype= RGN_TYPE_WINDOW;
88         
89         ar->v2d.tot.xmin= 1.0f;
90         ar->v2d.tot.ymin= -1000.0f;
91         ar->v2d.tot.xmax= 1000.0f;
92         ar->v2d.tot.ymax= 0.0f;
93         
94         ar->v2d.min[1]= 0.0f;
95         ar->v2d.max[1]= 1000.0f;
96         
97         ar->v2d.scroll = V2D_SCROLL_RIGHT;
98         
99         ar->v2d.align= saction->v2d.align= V2D_ALIGN_NO_POS_Y;
100         ar->v2d.keepzoom= saction->v2d.keepzoom= V2D_LOCKZOOM_Y;
101         
102         /* channel list region XXX */
103         ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
104         BLI_addtail(&saction->regionbase, ar);
105         ar->regiontype= RGN_TYPE_CHANNELS;
106         ar->alignment= RGN_ALIGN_LEFT;
107                                 
108         
109         return (SpaceLink *)saction;
110 }
111
112 /* not spacelink itself */
113 static void action_free(SpaceLink *sl)
114 {       
115 //      SpaceAction *saction= (SpaceAction*) sl;
116         
117 }
118
119
120 /* spacetype; init callback */
121 static void action_init(struct wmWindowManager *wm, ScrArea *sa)
122 {
123
124 }
125
126 static SpaceLink *action_duplicate(SpaceLink *sl)
127 {
128         SpaceAction *sactionn= MEM_dupallocN(sl);
129         
130         /* clear or remove stuff from old */
131         
132         return (SpaceLink *)sactionn;
133 }
134
135
136
137 /* add handlers, stuff you only do once or on area/region changes */
138 static void action_main_area_init(wmWindowManager *wm, ARegion *ar)
139 {
140         ListBase *keymap;
141         
142         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_TIMELINE, ar->winx, ar->winy);
143         
144         /* own keymap */
145         keymap= WM_keymap_listbase(wm, "Action", SPACE_ACTION, 0);      /* XXX weak? */
146         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
147 }
148
149 static void action_main_area_draw(const bContext *C, ARegion *ar)
150 {
151         /* draw entirely, view changes should be handled here */
152         // SpaceAction *saction= C->area->spacedata.first;
153         View2D *v2d= &ar->v2d;
154         float col[3];
155         
156         /* clear and setup matrix */
157         UI_GetThemeColor3fv(TH_BACK, col);
158         glClearColor(col[0], col[1], col[2], 0.0);
159         glClear(GL_COLOR_BUFFER_BIT);
160         
161         UI_view2d_view_ortho(C, v2d);
162                 
163         /* data... */
164         
165         
166         /* reset view matrix */
167         UI_view2d_view_restore(C);
168         
169         /* scrollers? */
170 }
171
172 void action_operatortypes(void)
173 {
174         
175 }
176
177 void action_keymap(struct wmWindowManager *wm)
178 {
179         
180 }
181
182 /* add handlers, stuff you only do once or on area/region changes */
183 static void action_header_area_init(wmWindowManager *wm, ARegion *ar)
184 {
185         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
186 }
187
188 static void action_header_area_draw(const bContext *C, ARegion *ar)
189 {
190         float col[3];
191         
192         /* clear */
193         if(ED_screen_area_active(C))
194                 UI_GetThemeColor3fv(TH_HEADER, col);
195         else
196                 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
197         
198         glClearColor(col[0], col[1], col[2], 0.0);
199         glClear(GL_COLOR_BUFFER_BIT);
200         
201         /* set view2d view matrix for scrolling (without scrollers) */
202         UI_view2d_view_ortho(C, &ar->v2d);
203         
204         action_header_buttons(C, ar);
205         
206         /* restore view matrix? */
207         UI_view2d_view_restore(C);
208 }
209
210 static void action_main_area_listener(ARegion *ar, wmNotifier *wmn)
211 {
212         /* context changes */
213 }
214
215 /* only called once, from space/spacetypes.c */
216 void ED_spacetype_action(void)
217 {
218         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype action");
219         ARegionType *art;
220         
221         st->spaceid= SPACE_ACTION;
222         
223         st->new= action_new;
224         st->free= action_free;
225         st->init= action_init;
226         st->duplicate= action_duplicate;
227         st->operatortypes= action_operatortypes;
228         st->keymap= action_keymap;
229         
230         /* regions: main window */
231         art= MEM_callocN(sizeof(ARegionType), "spacetype action region");
232         art->regionid = RGN_TYPE_WINDOW;
233         art->init= action_main_area_init;
234         art->draw= action_main_area_draw;
235         art->listener= action_main_area_listener;
236         art->keymapflag= ED_KEYMAP_VIEW2D;
237
238         BLI_addhead(&st->regiontypes, art);
239         
240         /* regions: header */
241         art= MEM_callocN(sizeof(ARegionType), "spacetype action region");
242         art->regionid = RGN_TYPE_HEADER;
243         art->minsizey= HEADERY;
244         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
245         
246         art->init= action_header_area_init;
247         art->draw= action_header_area_draw;
248         
249         BLI_addhead(&st->regiontypes, art);
250         
251         /* regions: channels */
252         art= MEM_callocN(sizeof(ARegionType), "spacetype action region");
253         art->regionid = RGN_TYPE_CHANNELS;
254         art->minsizex = 200;
255         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
256         
257         //art->init= action_channel_area_init;
258         //art->draw= action_channel_area_draw;
259         
260         BLI_addhead(&st->regiontypes, art);
261         
262         
263         BKE_spacetype_register(st);
264 }
265