2.5
[blender-staging.git] / source / blender / editors / space_info / info_header.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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 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 #include "DNA_space_types.h"
33 #include "DNA_scene_types.h"
34 #include "DNA_screen_types.h"
35 #include "DNA_windowmanager_types.h"
36
37 #include "MEM_guardedalloc.h"
38
39 #include "BLI_blenlib.h"
40
41 #include "BKE_context.h"
42 #include "BKE_global.h"
43 #include "BKE_screen.h"
44
45 #include "ED_screen.h"
46 #include "ED_types.h"
47 #include "ED_util.h"
48
49 #include "WM_api.h"
50 #include "WM_types.h"
51
52 #include "BIF_gl.h"
53 #include "BIF_glutil.h"
54
55 #include "UI_interface.h"
56 #include "UI_resources.h"
57 #include "UI_view2d.h"
58
59 #include "info_intern.h"
60
61
62 /* ************************ header area region *********************** */
63
64 #define B_STOPRENDER 1
65
66 static void do_viewmenu(bContext *C, void *arg, int event)
67 {
68 }
69
70 static uiBlock *dummy_viewmenu(bContext *C, ARegion *ar, void *arg_unused)
71 {
72         ScrArea *curarea= CTX_wm_area(C);
73         uiBlock *block;
74         short yco= 0, menuwidth=120;
75         
76         block= uiBeginBlock(C, ar, "dummy_viewmenu", UI_EMBOSSP, UI_HELV);
77         uiBlockSetButmFunc(block, do_viewmenu, NULL);
78         
79         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20, 
80                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
81         
82         if(curarea->headertype==HEADERTOP) {
83                 uiBlockSetDirection(block, UI_DOWN);
84         }
85         else {
86                 uiBlockSetDirection(block, UI_TOP);
87                 uiBlockFlipOrder(block);
88         }
89         
90         uiTextBoundsBlock(block, 50);
91         uiEndBlock(C, block);
92         
93         return block;
94 }
95
96
97 static void do_info_buttons(bContext *C, void *arg, int event)
98 {
99         switch(event) {
100                 case B_STOPRENDER:
101                         G.afbreek= 1;
102                         break;
103         }
104 }
105
106 static void screen_idpoin_handle(bContext *C, ID *id, int event)
107 {
108         
109         switch(event) {
110                 case UI_ID_BROWSE:
111                         /* exception: can't set screens inside of area/region handers */
112                         WM_event_add_notifier(C, NC_SCREEN|ND_SCREENBROWSE, id);
113                         break;
114                 case UI_ID_DELETE:
115                         ED_undo_push(C, "");
116                         break;
117                 case UI_ID_RENAME:
118                         break;
119                 case UI_ID_ADD_NEW:
120                         /* XXX not implemented */
121                         break;
122                 case UI_ID_OPEN:
123                         /* XXX not implemented */
124                         break;
125                 case UI_ID_ALONE:
126                         /* XXX not implemented */
127                         break;
128                 case UI_ID_PIN:
129                         break;
130         }
131 }
132
133 static void scene_idpoin_handle(bContext *C, ID *id, int event)
134 {
135         
136         switch(event) {
137                 case UI_ID_BROWSE:
138                         /* exception: can't set screens inside of area/region handers */
139                         WM_event_add_notifier(C, NC_SCENE|ND_SCENEBROWSE, id);
140                         break;
141                 case UI_ID_DELETE:
142                         ED_undo_push(C, "");
143                         break;
144                 case UI_ID_RENAME:
145                         break;
146                 case UI_ID_ADD_NEW:
147                         /* XXX not implemented */
148                         break;
149                 case UI_ID_OPEN:
150                         /* XXX not implemented */
151                         break;
152                 case UI_ID_ALONE:
153                         /* XXX not implemented */
154                         break;
155                 case UI_ID_PIN:
156                         break;
157         }
158 }
159
160
161 void info_header_buttons(const bContext *C, ARegion *ar)
162 {
163         wmWindow *win= CTX_wm_window(C);
164         bScreen *screen= CTX_wm_screen(C);
165         ScrArea *sa= CTX_wm_area(C);
166         SpaceInfo *si= sa->spacedata.first;
167         uiBlock *block;
168         int xco, yco= 3;
169         
170         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS, UI_HELV);
171         uiBlockSetHandleFunc(block, do_info_buttons, NULL);
172         
173         xco= ED_area_header_standardbuttons(C, block, yco);
174         
175         if((sa->flag & HEADER_NO_PULLDOWN)==0) {
176                 int xmax;
177                 
178                 /* pull down menus */
179                 uiBlockSetEmboss(block, UI_EMBOSSP);
180                 
181                 xmax= GetButStringLength("File");
182                 uiDefPulldownBut(block, dummy_viewmenu, sa, "File",     xco, yco, xmax-3, 22, "");
183                 xco+= xmax;
184                 
185                 xmax= GetButStringLength("Add");
186                 uiDefPulldownBut(block, dummy_viewmenu, sa, "Add",      xco, yco, xmax-3, 22, "");
187                 xco+= xmax;
188                 
189                 xmax= GetButStringLength("Timeline");
190                 uiDefPulldownBut(block, dummy_viewmenu, sa, "Timeline", xco, yco, xmax-3, 22, "");
191                 xco+= xmax;
192                 
193                 xmax= GetButStringLength("Game");
194                 uiDefPulldownBut(block, dummy_viewmenu, sa, "Game",     xco, yco, xmax-3, 22, "");
195                 xco+= xmax;
196                 
197                 xmax= GetButStringLength("Render");
198                 uiDefPulldownBut(block, dummy_viewmenu, sa, "Render",   xco, yco, xmax-3, 22, "");
199                 xco+= xmax;
200                 
201                 xmax= GetButStringLength("Help");
202                 uiDefPulldownBut(block, dummy_viewmenu, NULL, "Help",   xco, yco, xmax-3, 22, "");
203                 xco+= xmax;
204         }
205         
206         uiBlockSetEmboss(block, UI_EMBOSS);
207         
208         if(screen->full==NULL) {
209                 si->screen= win->screen;
210                 xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID**)&si->screen, ID_SCR, NULL, xco, yco,
211                                                  screen_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_DELETE);
212                 xco += 8;
213                 si->scene= screen->scene;
214                 xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID**)&si->scene, ID_SCE, NULL, xco, yco,
215                                                          scene_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_DELETE);
216                 xco += 8;
217         }       
218
219         if(WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C))) {
220                 uiDefIconTextBut(block, BUT, B_STOPRENDER, ICON_REC, "Render", xco+5,yco,75,19, NULL, 0.0f, 0.0f, 0, 0, "Stop rendering");
221         }
222         
223         /* always as last  */
224         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
225         
226         uiEndBlock(C, block);
227         uiDrawBlock(C, block);
228 }
229
230