remove unused includes from editors/space_*
[blender.git] / source / blender / editors / space_logic / space_logic.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2009 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
33 #include "MEM_guardedalloc.h"
34
35 #include "BLI_blenlib.h"
36 #include "BLI_math.h"
37
38 #include "BKE_context.h"
39 #include "BKE_screen.h"
40
41 #include "ED_screen.h"
42
43 #include "BIF_gl.h"
44 #include "BIF_glutil.h"
45
46
47 #include "WM_api.h"
48 #include "WM_types.h"
49
50 #include "UI_resources.h"
51 #include "UI_view2d.h"
52
53 #include "logic_intern.h"
54
55 /* ******************** manage regions ********************* */
56
57 ARegion *logic_has_buttons_region(ScrArea *sa)
58 {
59         ARegion *ar, *arnew;
60         
61         for(ar= sa->regionbase.first; ar; ar= ar->next)
62                 if(ar->regiontype==RGN_TYPE_UI)
63                         return ar;
64         
65         /* add subdiv level; after header */
66         for(ar= sa->regionbase.first; ar; ar= ar->next)
67                 if(ar->regiontype==RGN_TYPE_HEADER)
68                         break;
69         
70         /* is error! */
71         if(ar==NULL) return NULL;
72         
73         arnew= MEM_callocN(sizeof(ARegion), "buttons for image");
74         
75         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
76         arnew->regiontype= RGN_TYPE_UI;
77         arnew->alignment= RGN_ALIGN_LEFT;
78         
79         arnew->flag = RGN_FLAG_HIDDEN;
80         
81         return arnew;
82 }
83
84 /* ******************** default callbacks for image space ***************** */
85
86 static SpaceLink *logic_new(const bContext *C)
87 {
88         ARegion *ar;
89         SpaceLogic *slogic;
90         
91         slogic= MEM_callocN(sizeof(SpaceLogic), "initlogic");
92         slogic->spacetype= SPACE_LOGIC;
93         
94         /* default options */
95         slogic->scaflag =       (BUTS_SENS_SEL|BUTS_SENS_ACT|BUTS_SENS_LINK)    |
96                                                 (BUTS_CONT_SEL|BUTS_CONT_ACT|BUTS_CONT_LINK)    |
97                                                 (BUTS_ACT_SEL|BUTS_ACT_ACT|BUTS_ACT_LINK)               |
98                                                 (BUTS_SENS_STATE|BUTS_ACT_STATE);
99         
100         
101         /* header */
102         ar= MEM_callocN(sizeof(ARegion), "header for logic");
103         
104         BLI_addtail(&slogic->regionbase, ar);
105         ar->regiontype= RGN_TYPE_HEADER;
106         ar->alignment= RGN_ALIGN_BOTTOM;
107         
108         /* buttons/list view */
109         ar= MEM_callocN(sizeof(ARegion), "buttons for logic");
110         
111         BLI_addtail(&slogic->regionbase, ar);
112         ar->regiontype= RGN_TYPE_UI;
113         ar->alignment= RGN_ALIGN_LEFT;
114         
115         /* main area */
116         ar= MEM_callocN(sizeof(ARegion), "main area for logic");
117         
118         BLI_addtail(&slogic->regionbase, ar);
119         ar->regiontype= RGN_TYPE_WINDOW;
120
121         ar->v2d.tot.xmin=  0.0f;
122         ar->v2d.tot.ymin=  0.0f;
123         ar->v2d.tot.xmax= 1280;
124         ar->v2d.tot.ymax= 240.0f;
125         
126         ar->v2d.cur.xmin=  0.0f;
127         ar->v2d.cur.ymin=  0.0f;
128         ar->v2d.cur.xmax= 1280.0f;
129         ar->v2d.cur.ymax= 240.0f;
130         
131         ar->v2d.min[0]= 1.0f;
132         ar->v2d.min[1]= 1.0f;
133         
134         ar->v2d.max[0]= 32000.0f;
135         ar->v2d.max[1]= 32000.0f;
136         
137         ar->v2d.minzoom= 0.5f;
138         ar->v2d.maxzoom= 1.21f;
139         
140         ar->v2d.scroll= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
141         ar->v2d.keepzoom= V2D_LIMITZOOM|V2D_KEEPASPECT;
142         ar->v2d.keeptot= 0;
143         
144         
145         return (SpaceLink *)slogic;
146 }
147
148 /* not spacelink itself */
149 static void logic_free(SpaceLink *sl)
150 {       
151 //      Spacelogic *slogic= (SpaceLogic*) sl;
152         
153 //      if(slogic->gpd)
154 // XXX          free_gpencil_data(slogic->gpd);
155         
156 }
157
158
159 /* spacetype; init callback */
160 static void logic_init(struct wmWindowManager *wm, ScrArea *sa)
161 {
162
163 }
164
165 static SpaceLink *logic_duplicate(SpaceLink *sl)
166 {
167         SpaceLogic *slogicn= MEM_dupallocN(sl);
168                 
169         return (SpaceLink *)slogicn;
170 }
171
172 void logic_operatortypes(void)
173 {
174         WM_operatortype_append(LOGIC_OT_properties);
175         WM_operatortype_append(LOGIC_OT_links_cut);
176 }
177
178 void logic_keymap(struct wmKeyConfig *keyconf)
179 {
180         wmKeyMap *keymap= WM_keymap_find(keyconf, "Logic Editor", SPACE_LOGIC, 0);
181         
182         WM_keymap_add_item(keymap, "LOGIC_OT_properties", NKEY, KM_PRESS, 0, 0);
183         WM_keymap_add_item(keymap, "LOGIC_OT_links_cut", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
184         WM_keymap_add_menu(keymap, "LOGIC_MT_logicbricks_add", AKEY, KM_PRESS, KM_SHIFT, 0);
185 }
186
187 static void logic_refresh(const bContext *C, ScrArea *sa)
188 {
189 //      SpaceLogic *slogic= CTX_wm_space_logic(C);
190 //      Object *obedit= CTX_data_edit_object(C);
191
192 }
193
194 static void logic_listener(ARegion *ar, wmNotifier *wmn)
195 {
196         /* context changes */
197         switch(wmn->category) {
198                 case NC_LOGIC:
199                         ED_region_tag_redraw(ar);
200                         break;
201                 case NC_SCENE:
202                         switch(wmn->data) {
203                                 case ND_FRAME:
204                                         ED_region_tag_redraw(ar);
205                                         break;
206                                         
207                                 case ND_OB_ACTIVE:
208                                         ED_region_tag_redraw(ar);
209                                         break;
210                                 }
211                                 break;
212                 case NC_OBJECT:
213                         break;
214                 case NC_ID:
215                         if(wmn->action == NA_RENAME)
216                                 ED_region_tag_redraw(ar);
217                         break;
218         }
219 }
220
221 static int logic_context(const bContext *C, const char *member, bContextDataResult *result)
222 {
223 //      SpaceLogic *slogic= CTX_wm_space_logic(C);
224
225
226         return 0;
227 }
228
229 /************************** main region ***************************/
230
231
232 /* add handlers, stuff you only do once or on area/region changes */
233 static void logic_main_area_init(wmWindowManager *wm, ARegion *ar)
234 {
235         wmKeyMap *keymap;
236         
237         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
238
239         /* own keymaps */
240         keymap= WM_keymap_find(wm->defaultconf, "Logic Editor", SPACE_LOGIC, 0);
241         WM_event_add_keymap_handler(&ar->handlers, keymap);
242 }
243
244 static void logic_main_area_draw(const bContext *C, ARegion *ar)
245 {
246         /* draw entirely, view changes should be handled here */
247 //      SpaceLogic *slogic= CTX_wm_space_logic(C);
248         View2D *v2d= &ar->v2d;
249         View2DScrollers *scrollers;
250         
251         /* clear and setup matrix */
252         UI_ThemeClearColor(TH_BACK);
253         glClear(GL_COLOR_BUFFER_BIT);
254         
255         UI_view2d_view_ortho(C, v2d);
256         
257         logic_buttons((bContext *)C, ar);
258         
259         /* reset view matrix */
260         UI_view2d_view_restore(C);
261         
262         /* scrollers */
263         scrollers= UI_view2d_scrollers_calc(C, v2d, 10, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
264         UI_view2d_scrollers_draw(C, v2d, scrollers);
265         UI_view2d_scrollers_free(scrollers);
266         
267 }
268
269
270 /* *********************** buttons region ************************ */
271
272 /* add handlers, stuff you only do once or on area/region changes */
273 static void logic_buttons_area_init(wmWindowManager *wm, ARegion *ar)
274 {
275         wmKeyMap *keymap;
276
277         ED_region_panels_init(wm, ar);
278         
279         keymap= WM_keymap_find(wm->defaultconf, "Logic Editor", SPACE_LOGIC, 0);
280         WM_event_add_keymap_handler(&ar->handlers, keymap);
281 }
282
283 static void logic_buttons_area_draw(const bContext *C, ARegion *ar)
284 {
285         ED_region_panels(C, ar, 1, NULL, -1);
286 }
287
288 /************************* header region **************************/
289
290 /* add handlers, stuff you only do once or on area/region changes */
291 static void logic_header_area_init(wmWindowManager *wm, ARegion *ar)
292 {
293         ED_region_header_init(ar);
294 }
295
296 static void logic_header_area_draw(const bContext *C, ARegion *ar)
297 {
298         ED_region_header(C, ar);
299 }
300
301 /**************************** spacetype *****************************/
302
303 /* only called once, from space/spacetypes.c */
304 void ED_spacetype_logic(void)
305 {
306         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype logic");
307         ARegionType *art;
308         
309         st->spaceid= SPACE_LOGIC;
310         strncpy(st->name, "Logic", BKE_ST_MAXNAME);
311         
312         st->new= logic_new;
313         st->free= logic_free;
314         st->init= logic_init;
315         st->duplicate= logic_duplicate;
316         st->operatortypes= logic_operatortypes;
317         st->keymap= logic_keymap;
318         st->refresh= logic_refresh;
319         st->context= logic_context;
320         
321         /* regions: main window */
322         art= MEM_callocN(sizeof(ARegionType), "spacetype logic region");
323         art->regionid = RGN_TYPE_WINDOW;
324         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_FRAMES|ED_KEYMAP_VIEW2D;
325         art->init= logic_main_area_init;
326         art->draw= logic_main_area_draw;
327         art->listener= logic_listener;
328
329         BLI_addhead(&st->regiontypes, art);
330         
331         /* regions: listview/buttons */
332         art= MEM_callocN(sizeof(ARegionType), "spacetype logic region");
333         art->regionid = RGN_TYPE_UI;
334         art->prefsizex= 220; // XXX
335         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_FRAMES;
336         art->listener= logic_listener;
337         art->init= logic_buttons_area_init;
338         art->draw= logic_buttons_area_draw;
339         BLI_addhead(&st->regiontypes, art);
340
341         logic_buttons_register(art);
342
343         /* regions: header */
344         art= MEM_callocN(sizeof(ARegionType), "spacetype logic region");
345         art->regionid = RGN_TYPE_HEADER;
346         art->prefsizey= HEADERY;
347         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES|ED_KEYMAP_HEADER;
348         art->init= logic_header_area_init;
349         art->draw= logic_header_area_draw;
350         
351         BLI_addhead(&st->regiontypes, art);
352         
353         BKE_spacetype_register(st);
354 }
355
356