Blender  V2.59
space_sound.c
Go to the documentation of this file.
00001 /*
00002  * $Id: space_sound.c 35242 2011-02-27 20:29:51Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version. 
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2008 Blender Foundation.
00021  * All rights reserved.
00022  *
00023  * 
00024  * Contributor(s): Blender Foundation
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00034 #include <string.h>
00035 #include <stdio.h>
00036 
00037 #include "DNA_scene_types.h"
00038 
00039 #include "MEM_guardedalloc.h"
00040 
00041 #include "BLI_blenlib.h"
00042 #include "BLI_math.h"
00043 #include "BLI_rand.h"
00044 #include "BLI_utildefines.h"
00045 
00046 #include "BKE_context.h"
00047 #include "BKE_screen.h"
00048 
00049 #include "ED_space_api.h"
00050 #include "ED_screen.h"
00051 
00052 #include "BIF_gl.h"
00053 
00054 #include "WM_api.h"
00055 #include "WM_types.h"
00056 
00057 #include "UI_resources.h"
00058 #include "UI_view2d.h"
00059 
00060 
00061 #include "sound_intern.h"       // own include
00062 
00063 /* ******************** default callbacks for sound space ***************** */
00064 
00065 static SpaceLink *sound_new(const bContext *UNUSED(C))
00066 {
00067         ARegion *ar;
00068         SpaceSound *ssound;
00069         
00070         ssound= MEM_callocN(sizeof(SpaceSound), "initsound");
00071         ssound->spacetype= SPACE_SOUND;
00072         
00073         /* header */
00074         ar= MEM_callocN(sizeof(ARegion), "header for sound");
00075         
00076         BLI_addtail(&ssound->regionbase, ar);
00077         ar->regiontype= RGN_TYPE_HEADER;
00078         ar->alignment= RGN_ALIGN_BOTTOM;
00079         
00080         /* main area */
00081         ar= MEM_callocN(sizeof(ARegion), "main area for sound");
00082         
00083         BLI_addtail(&ssound->regionbase, ar);
00084         ar->regiontype= RGN_TYPE_WINDOW;
00085         
00086         ar->v2d.tot.xmin= -4.0f;
00087         ar->v2d.tot.ymin= -4.0f;
00088         ar->v2d.tot.xmax= 250.0f;
00089         ar->v2d.tot.ymax= 255.0f;
00090         
00091         ar->v2d.cur.xmin= -4.0f;
00092         ar->v2d.cur.ymin= -4.0f;
00093         ar->v2d.cur.xmax= 50.0f;
00094         ar->v2d.cur.ymax= 255.0f;
00095         
00096         ar->v2d.min[0]= 1.0f;
00097         ar->v2d.min[1]= 259.0f;
00098         
00099         ar->v2d.max[0]= MAXFRAMEF;
00100         ar->v2d.max[1]= 259.0f;
00101         
00102         ar->v2d.minzoom= 0.1f;
00103         ar->v2d.maxzoom= 10.0f;
00104         
00105         ar->v2d.scroll = (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
00106         ar->v2d.scroll |= (V2D_SCROLL_LEFT);
00107         ar->v2d.keepzoom= 0;
00108         ar->v2d.keeptot= 0;
00109         ar->v2d.keepzoom = V2D_LOCKZOOM_Y;
00110         
00111         
00112         return (SpaceLink *)ssound;
00113 }
00114 
00115 /* not spacelink itself */
00116 static void sound_free(SpaceLink *UNUSED(sl))
00117 {       
00118 //      SpaceSound *ssound= (SpaceSound*) sl;
00119         
00120         
00121 }
00122 
00123 
00124 /* spacetype; init callback */
00125 static void sound_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
00126 {
00127 
00128 }
00129 
00130 static SpaceLink *sound_duplicate(SpaceLink *sl)
00131 {
00132         SpaceSound *ssoundn= MEM_dupallocN(sl);
00133         
00134         /* clear or remove stuff from old */
00135         
00136         return (SpaceLink *)ssoundn;
00137 }
00138 
00139 
00140 
00141 /* add handlers, stuff you only do once or on area/region changes */
00142 static void sound_main_area_init(wmWindowManager *wm, ARegion *ar)
00143 {
00144         wmKeyMap *keymap;
00145         
00146         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
00147         
00148         /* own keymap */
00149         keymap= WM_keymap_find(wm->defaultconf, "Sound", SPACE_SOUND, 0);
00150         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
00151 }
00152 
00153 static void sound_main_area_draw(const bContext *C, ARegion *ar)
00154 {
00155         /* draw entirely, view changes should be handled here */
00156         // SpaceSound *ssound= (SpaceSound*)CTX_wm_space_data(C);
00157         View2D *v2d= &ar->v2d;
00158         
00159         /* clear and setup matrix */
00160         UI_ThemeClearColor(TH_BACK);
00161         glClear(GL_COLOR_BUFFER_BIT);
00162         
00163         UI_view2d_view_ortho(v2d);
00164                 
00165         /* data... */
00166         
00167         
00168         /* reset view matrix */
00169         UI_view2d_view_restore(C);
00170         
00171         /* scrollers? */
00172 }
00173 
00174 static void sound_operatortypes(void)
00175 {
00176         
00177 }
00178 
00179 static void sound_keymap(struct wmKeyConfig *UNUSED(keyconf))
00180 {
00181         
00182 }
00183 
00184 /* add handlers, stuff you only do once or on area/region changes */
00185 static void sound_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
00186 {
00187         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
00188 }
00189 
00190 static void sound_header_area_draw(const bContext *C, ARegion *ar)
00191 {
00192         float col[3];
00193         
00194         /* clear */
00195         if(ED_screen_area_active(C))
00196                 UI_GetThemeColor3fv(TH_HEADER, col);
00197         else
00198                 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
00199         
00200         glClearColor(col[0], col[1], col[2], 0.0);
00201         glClear(GL_COLOR_BUFFER_BIT);
00202         
00203         /* set view2d view matrix for scrolling (without scrollers) */
00204         UI_view2d_view_ortho(&ar->v2d);
00205         
00206         sound_header_buttons(C, ar);
00207         
00208         /* restore view matrix? */
00209         UI_view2d_view_restore(C);
00210 }
00211 
00212 static void sound_main_area_listener(ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn))
00213 {
00214         /* context changes */
00215 }
00216 
00217 /* only called once, from space/spacetypes.c */
00218 void ED_spacetype_sound(void)
00219 {
00220         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype sound");
00221         ARegionType *art;
00222         
00223         st->spaceid= SPACE_SOUND;
00224         strncpy(st->name, "Sound", BKE_ST_MAXNAME);
00225         
00226         st->new= sound_new;
00227         st->free= sound_free;
00228         st->init= sound_init;
00229         st->duplicate= sound_duplicate;
00230         st->operatortypes= sound_operatortypes;
00231         st->keymap= sound_keymap;
00232         
00233         /* regions: main window */
00234         art= MEM_callocN(sizeof(ARegionType), "spacetype sound region");
00235         art->regionid = RGN_TYPE_WINDOW;
00236         art->init= sound_main_area_init;
00237         art->draw= sound_main_area_draw;
00238         art->listener= sound_main_area_listener;
00239         art->keymapflag= ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES;
00240 
00241         BLI_addhead(&st->regiontypes, art);
00242         
00243         /* regions: header */
00244         art= MEM_callocN(sizeof(ARegionType), "spacetype sound region");
00245         art->regionid = RGN_TYPE_HEADER;
00246         art->prefsizey= HEADERY;
00247         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
00248         
00249         art->init= sound_header_area_init;
00250         art->draw= sound_header_area_draw;
00251         
00252         BLI_addhead(&st->regiontypes, art);
00253         
00254         /* regions: channels */
00255         art= MEM_callocN(sizeof(ARegionType), "spacetype sound region");
00256         art->regionid = RGN_TYPE_CHANNELS;
00257         art->prefsizex= 80;
00258         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
00259         
00260 //      art->init= sound_channel_area_init;
00261 //      art->draw= sound_channel_area_draw;
00262         
00263         BLI_addhead(&st->regiontypes, art);
00264         
00265         
00266         BKE_spacetype_register(st);
00267 }
00268