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_sound_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_global.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 "sound_intern.h" // own include
64 /* ******************** default callbacks for sound space ***************** */
66 static SpaceLink *sound_new(void)
71 ssound= MEM_callocN(sizeof(SpaceSound), "initsound");
72 ssound->spacetype= SPACE_SOUND;
75 ar= MEM_callocN(sizeof(ARegion), "header for sound");
77 BLI_addtail(&ssound->regionbase, ar);
78 ar->regiontype= RGN_TYPE_HEADER;
79 ar->alignment= RGN_ALIGN_BOTTOM;
82 ar= MEM_callocN(sizeof(ARegion), "main area for sound");
84 BLI_addtail(&ssound->regionbase, ar);
85 ar->regiontype= RGN_TYPE_WINDOW;
87 ar->v2d.tot.xmin= -4.0f;
88 ar->v2d.tot.ymin= -4.0f;
89 ar->v2d.tot.xmax= 250.0f;
90 ar->v2d.tot.ymax= 255.0f;
92 ar->v2d.cur.xmin= -4.0f;
93 ar->v2d.cur.ymin= -4.0f;
94 ar->v2d.cur.xmax= 50.0f;
95 ar->v2d.cur.ymax= 255.0f;
98 ar->v2d.min[1]= 259.0f;
100 ar->v2d.max[0]= MAXFRAMEF;
101 ar->v2d.max[1]= 259.0f;
103 ar->v2d.minzoom= 0.1f;
104 ar->v2d.maxzoom= 10.0f;
106 ar->v2d.scroll = (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
107 ar->v2d.scroll |= (V2D_SCROLL_LEFT);
110 ar->v2d.keepzoom = V2D_LOCKZOOM_Y;
113 return (SpaceLink *)ssound;
116 /* not spacelink itself */
117 static void sound_free(SpaceLink *sl)
119 // SpaceSound *ssound= (SpaceSound*) sl;
125 /* spacetype; init callback */
126 static void sound_init(struct wmWindowManager *wm, ScrArea *sa)
131 static SpaceLink *sound_duplicate(SpaceLink *sl)
133 SpaceSound *ssoundn= MEM_dupallocN(sl);
135 /* clear or remove stuff from old */
137 return (SpaceLink *)ssoundn;
142 /* add handlers, stuff you only do once or on area/region changes */
143 static void sound_main_area_init(wmWindowManager *wm, ARegion *ar)
147 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_TIMELINE, ar->winx, ar->winy);
150 keymap= WM_keymap_listbase(wm, "Sound", SPACE_SOUND, 0); /* XXX weak? */
151 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
154 static void sound_main_area_draw(const bContext *C, ARegion *ar)
156 /* draw entirely, view changes should be handled here */
157 // SpaceSound *ssound= C->area->spacedata.first;
158 View2D *v2d= &ar->v2d;
161 /* clear and setup matrix */
162 UI_GetThemeColor3fv(TH_BACK, col);
163 glClearColor(col[0], col[1], col[2], 0.0);
164 glClear(GL_COLOR_BUFFER_BIT);
166 UI_view2d_view_ortho(C, v2d);
171 /* reset view matrix */
172 UI_view2d_view_restore(C);
177 void sound_operatortypes(void)
182 void sound_keymap(struct wmWindowManager *wm)
187 /* add handlers, stuff you only do once or on area/region changes */
188 static void sound_header_area_init(wmWindowManager *wm, ARegion *ar)
190 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
193 static void sound_header_area_draw(const bContext *C, ARegion *ar)
198 if(ED_screen_area_active(C))
199 UI_GetThemeColor3fv(TH_HEADER, col);
201 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
203 glClearColor(col[0], col[1], col[2], 0.0);
204 glClear(GL_COLOR_BUFFER_BIT);
206 /* set view2d view matrix for scrolling (without scrollers) */
207 UI_view2d_view_ortho(C, &ar->v2d);
209 sound_header_buttons(C, ar);
211 /* restore view matrix? */
212 UI_view2d_view_restore(C);
215 static void sound_main_area_listener(ARegion *ar, wmNotifier *wmn)
217 /* context changes */
220 /* only called once, from space/spacetypes.c */
221 void ED_spacetype_sound(void)
223 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype sound");
226 st->spaceid= SPACE_SOUND;
229 st->free= sound_free;
230 st->init= sound_init;
231 st->duplicate= sound_duplicate;
232 st->operatortypes= sound_operatortypes;
233 st->keymap= sound_keymap;
235 /* regions: main window */
236 art= MEM_callocN(sizeof(ARegionType), "spacetype sound region");
237 art->regionid = RGN_TYPE_WINDOW;
238 art->init= sound_main_area_init;
239 art->draw= sound_main_area_draw;
240 art->listener= sound_main_area_listener;
241 art->keymapflag= ED_KEYMAP_VIEW2D;
243 BLI_addhead(&st->regiontypes, art);
245 /* regions: header */
246 art= MEM_callocN(sizeof(ARegionType), "spacetype sound region");
247 art->regionid = RGN_TYPE_HEADER;
248 art->minsizey= HEADERY;
249 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
251 art->init= sound_header_area_init;
252 art->draw= sound_header_area_draw;
254 BLI_addhead(&st->regiontypes, art);
256 /* regions: channels */
257 art= MEM_callocN(sizeof(ARegionType), "spacetype sound region");
258 art->regionid = RGN_TYPE_CHANNELS;
260 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
262 // art->init= sound_channel_area_init;
263 // art->draw= sound_channel_area_draw;
265 BLI_addhead(&st->regiontypes, art);
268 BKE_spacetype_register(st);