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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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_scene_types.h"
35 #include "MEM_guardedalloc.h"
37 #include "BLI_blenlib.h"
41 #include "BKE_colortools.h"
42 #include "BKE_context.h"
43 #include "BKE_screen.h"
45 #include "ED_screen.h"
52 #include "UI_resources.h"
53 #include "UI_view2d.h"
56 #include "sound_intern.h" // own include
58 /* ******************** default callbacks for sound space ***************** */
60 static SpaceLink *sound_new(const bContext *C)
65 ssound= MEM_callocN(sizeof(SpaceSound), "initsound");
66 ssound->spacetype= SPACE_SOUND;
69 ar= MEM_callocN(sizeof(ARegion), "header for sound");
71 BLI_addtail(&ssound->regionbase, ar);
72 ar->regiontype= RGN_TYPE_HEADER;
73 ar->alignment= RGN_ALIGN_BOTTOM;
76 ar= MEM_callocN(sizeof(ARegion), "main area for sound");
78 BLI_addtail(&ssound->regionbase, ar);
79 ar->regiontype= RGN_TYPE_WINDOW;
81 ar->v2d.tot.xmin= -4.0f;
82 ar->v2d.tot.ymin= -4.0f;
83 ar->v2d.tot.xmax= 250.0f;
84 ar->v2d.tot.ymax= 255.0f;
86 ar->v2d.cur.xmin= -4.0f;
87 ar->v2d.cur.ymin= -4.0f;
88 ar->v2d.cur.xmax= 50.0f;
89 ar->v2d.cur.ymax= 255.0f;
92 ar->v2d.min[1]= 259.0f;
94 ar->v2d.max[0]= MAXFRAMEF;
95 ar->v2d.max[1]= 259.0f;
97 ar->v2d.minzoom= 0.1f;
98 ar->v2d.maxzoom= 10.0f;
100 ar->v2d.scroll = (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
101 ar->v2d.scroll |= (V2D_SCROLL_LEFT);
104 ar->v2d.keepzoom = V2D_LOCKZOOM_Y;
107 return (SpaceLink *)ssound;
110 /* not spacelink itself */
111 static void sound_free(SpaceLink *sl)
113 // SpaceSound *ssound= (SpaceSound*) sl;
119 /* spacetype; init callback */
120 static void sound_init(struct wmWindowManager *wm, ScrArea *sa)
125 static SpaceLink *sound_duplicate(SpaceLink *sl)
127 SpaceSound *ssoundn= MEM_dupallocN(sl);
129 /* clear or remove stuff from old */
131 return (SpaceLink *)ssoundn;
136 /* add handlers, stuff you only do once or on area/region changes */
137 static void sound_main_area_init(wmWindowManager *wm, ARegion *ar)
141 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
144 keymap= WM_keymap_find(wm->defaultconf, "Sound", SPACE_SOUND, 0);
145 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
148 static void sound_main_area_draw(const bContext *C, ARegion *ar)
150 /* draw entirely, view changes should be handled here */
151 // SpaceSound *ssound= (SpaceSound*)CTX_wm_space_data(C);
152 View2D *v2d= &ar->v2d;
154 /* clear and setup matrix */
155 UI_ThemeClearColor(TH_BACK);
156 glClear(GL_COLOR_BUFFER_BIT);
158 UI_view2d_view_ortho(C, v2d);
163 /* reset view matrix */
164 UI_view2d_view_restore(C);
169 void sound_operatortypes(void)
174 void sound_keymap(struct wmKeyConfig *keyconf)
179 /* add handlers, stuff you only do once or on area/region changes */
180 static void sound_header_area_init(wmWindowManager *wm, ARegion *ar)
182 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
185 static void sound_header_area_draw(const bContext *C, ARegion *ar)
190 if(ED_screen_area_active(C))
191 UI_GetThemeColor3fv(TH_HEADER, col);
193 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
195 glClearColor(col[0], col[1], col[2], 0.0);
196 glClear(GL_COLOR_BUFFER_BIT);
198 /* set view2d view matrix for scrolling (without scrollers) */
199 UI_view2d_view_ortho(C, &ar->v2d);
201 sound_header_buttons(C, ar);
203 /* restore view matrix? */
204 UI_view2d_view_restore(C);
207 static void sound_main_area_listener(ARegion *ar, wmNotifier *wmn)
209 /* context changes */
212 /* only called once, from space/spacetypes.c */
213 void ED_spacetype_sound(void)
215 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype sound");
218 st->spaceid= SPACE_SOUND;
219 strncpy(st->name, "Sound", BKE_ST_MAXNAME);
222 st->free= sound_free;
223 st->init= sound_init;
224 st->duplicate= sound_duplicate;
225 st->operatortypes= sound_operatortypes;
226 st->keymap= sound_keymap;
228 /* regions: main window */
229 art= MEM_callocN(sizeof(ARegionType), "spacetype sound region");
230 art->regionid = RGN_TYPE_WINDOW;
231 art->init= sound_main_area_init;
232 art->draw= sound_main_area_draw;
233 art->listener= sound_main_area_listener;
234 art->keymapflag= ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES;
236 BLI_addhead(&st->regiontypes, art);
238 /* regions: header */
239 art= MEM_callocN(sizeof(ARegionType), "spacetype sound region");
240 art->regionid = RGN_TYPE_HEADER;
241 art->prefsizey= HEADERY;
242 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
244 art->init= sound_header_area_init;
245 art->draw= sound_header_area_draw;
247 BLI_addhead(&st->regiontypes, art);
249 /* regions: channels */
250 art= MEM_callocN(sizeof(ARegionType), "spacetype sound region");
251 art->regionid = RGN_TYPE_CHANNELS;
253 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
255 // art->init= sound_channel_area_init;
256 // art->draw= sound_channel_area_draw;
258 BLI_addhead(&st->regiontypes, art);
261 BKE_spacetype_register(st);