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_object_types.h"
33 #include "DNA_space_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
37 #include "MEM_guardedalloc.h"
39 #include "BLI_blenlib.h"
40 #include "BLI_arithb.h"
43 #include "BKE_colortools.h"
44 #include "BKE_context.h"
45 #include "BKE_screen.h"
47 #include "ED_space_api.h"
48 #include "ED_screen.h"
55 #include "UI_interface.h"
56 #include "UI_resources.h"
57 #include "UI_view2d.h"
59 #include "ED_previewrender.h"
61 #include "buttons_intern.h" // own include
63 /* ******************** default callbacks for buttons space ***************** */
65 static SpaceLink *buttons_new(const bContext *C)
70 sbuts= MEM_callocN(sizeof(SpaceButs), "initbuts");
71 sbuts->spacetype= SPACE_BUTS;
72 sbuts->scaflag= BUTS_SENS_LINK|BUTS_SENS_ACT|BUTS_CONT_ACT|BUTS_ACT_ACT|BUTS_ACT_LINK;
75 ar= MEM_callocN(sizeof(ARegion), "header for buts");
77 BLI_addtail(&sbuts->regionbase, ar);
78 ar->regiontype= RGN_TYPE_HEADER;
79 ar->alignment= RGN_ALIGN_BOTTOM;
82 ar= MEM_callocN(sizeof(ARegion), "main area for buts");
84 BLI_addtail(&sbuts->regionbase, ar);
85 ar->regiontype= RGN_TYPE_WINDOW;
87 #if 0 // disabled, as this currently draws badly in new system
88 /* buts space goes from (0,0) to (1280, 228) */
89 ar->v2d.tot.xmin= 0.0f;
90 ar->v2d.tot.ymin= 0.0f;
91 ar->v2d.tot.xmax= 1279.0f;
92 ar->v2d.tot.ymax= 228.0f;
94 ar->v2d.cur= sbuts->v2d.tot;
96 ar->v2d.min[0]= 256.0f;
97 ar->v2d.min[1]= 42.0f;
99 ar->v2d.max[0]= 2048.0f;
100 ar->v2d.max[1]= 450.0f;
102 ar->v2d.minzoom= 0.5f;
103 ar->v2d.maxzoom= 1.21f;
105 ar->v2d.scroll= 0; // TODO: will we need scrollbars?
106 ar->v2d.align= V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y;
107 ar->v2d.keepzoom= V2D_KEEPZOOM|V2D_KEEPASPECT;
108 ar->v2d.keeptot= V2D_KEEPTOT_BOUNDS;
112 return (SpaceLink *)sbuts;
115 /* not spacelink itself */
116 static void buttons_free(SpaceLink *sl)
118 SpaceButs *sbuts= (SpaceButs*) sl;
121 if (sbuts->ri->rect) MEM_freeN(sbuts->ri->rect);
122 MEM_freeN(sbuts->ri);
128 /* spacetype; init callback */
129 static void buttons_init(struct wmWindowManager *wm, ScrArea *sa)
134 static SpaceLink *buttons_duplicate(SpaceLink *sl)
136 SpaceButs *sbutsn= MEM_dupallocN(sl);
138 /* clear or remove stuff from old */
141 return (SpaceLink *)sbutsn;
146 /* add handlers, stuff you only do once or on area/region changes */
147 static void buttons_main_area_init(wmWindowManager *wm, ARegion *ar)
151 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
154 keymap= WM_keymap_listbase(wm, "Buttons", SPACE_BUTS, 0); /* XXX weak? */
155 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
158 static void buttons_main_area_draw(const bContext *C, ARegion *ar)
160 /* draw entirely, view changes should be handled here */
161 // SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C);
162 View2D *v2d= &ar->v2d;
165 /* clear and setup matrix */
166 UI_GetThemeColor3fv(TH_BACK, col);
167 glClearColor(col[0], col[1], col[2], 0.0);
168 glClear(GL_COLOR_BUFFER_BIT);
170 UI_view2d_view_ortho(C, v2d);
172 /* swapbuffers indicator */
174 glColor3f(fac, fac, fac);
175 glRecti(20, 2, 30, 12);
180 /* reset view matrix */
181 UI_view2d_view_restore(C);
186 void buttons_operatortypes(void)
191 void buttons_keymap(struct wmWindowManager *wm)
196 /* add handlers, stuff you only do once or on area/region changes */
197 static void buttons_header_area_init(wmWindowManager *wm, ARegion *ar)
199 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
202 static void buttons_header_area_draw(const bContext *C, ARegion *ar)
207 if(ED_screen_area_active(C))
208 UI_GetThemeColor3fv(TH_HEADER, col);
210 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
212 glClearColor(col[0], col[1], col[2], 0.0);
213 glClear(GL_COLOR_BUFFER_BIT);
215 /* set view2d view matrix for scrolling (without scrollers) */
216 UI_view2d_view_ortho(C, &ar->v2d);
218 buttons_header_buttons(C, ar);
220 /* restore view matrix? */
221 UI_view2d_view_restore(C);
224 static void buttons_main_area_listener(ARegion *ar, wmNotifier *wmn)
226 /* context changes */
229 /* only called once, from space/spacetypes.c */
230 void ED_spacetype_buttons(void)
232 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype buttons");
235 st->spaceid= SPACE_BUTS;
237 st->new= buttons_new;
238 st->free= buttons_free;
239 st->init= buttons_init;
240 st->duplicate= buttons_duplicate;
241 st->operatortypes= buttons_operatortypes;
242 st->keymap= buttons_keymap;
244 /* regions: main window */
245 art= MEM_callocN(sizeof(ARegionType), "spacetype buttons region");
246 art->regionid = RGN_TYPE_WINDOW;
247 art->init= buttons_main_area_init;
248 art->draw= buttons_main_area_draw;
249 art->listener= buttons_main_area_listener;
250 art->keymapflag= ED_KEYMAP_VIEW2D;
252 BLI_addhead(&st->regiontypes, art);
254 /* regions: header */
255 art= MEM_callocN(sizeof(ARegionType), "spacetype buttons region");
256 art->regionid = RGN_TYPE_HEADER;
257 art->minsizey= HEADERY;
258 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
260 art->init= buttons_header_area_init;
261 art->draw= buttons_header_area_draw;
263 BLI_addhead(&st->regiontypes, art);
265 /* regions: channels */
266 art= MEM_callocN(sizeof(ARegionType), "spacetype buttons region");
267 art->regionid = RGN_TYPE_CHANNELS;
269 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
271 // art->init= buttons_channel_area_init;
272 // art->draw= buttons_channel_area_draw;
274 BLI_addhead(&st->regiontypes, art);
277 BKE_spacetype_register(st);