096374a82c485b4cd4fb6b3e05713eed3bf040b7
[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                         WM_event_add_notifier(C, NC_SCREEN|ND_SCENEBROWSE, CTX_wm_screen(C));
139                         break;
140                 case UI_ID_DELETE:
141                         ED_undo_push(C, "");
142                         break;
143                 case UI_ID_RENAME:
144                         break;
145                 case UI_ID_ADD_NEW:
146                         /* XXX not implemented */
147                         break;
148                 case UI_ID_OPEN:
149                         /* XXX not implemented */
150                         break;
151                 case UI_ID_ALONE:
152                         /* XXX not implemented */
153                         break;
154                 case UI_ID_PIN:
155                         break;
156         }
157 }
158
159
160 void info_header_buttons(const bContext *C, ARegion *ar)
161 {
162         wmWindow *win= CTX_wm_window(C);
163         bScreen *screen= CTX_wm_screen(C);
164         ScrArea *sa= CTX_wm_area(C);
165         SpaceInfo *si= sa->spacedata.first;
166         uiBlock *block;
167         int xco, yco= 3;
168         
169         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS, UI_HELV);
170         uiBlockSetHandleFunc(block, do_info_buttons, NULL);
171         
172         xco= ED_area_header_standardbuttons(C, block, yco);
173         
174         if((sa->flag & HEADER_NO_PULLDOWN)==0) {
175                 int xmax;
176                 
177                 /* pull down menus */
178                 uiBlockSetEmboss(block, UI_EMBOSSP);
179                 
180                 xmax= GetButStringLength("File");
181                 uiDefPulldownBut(block, dummy_viewmenu, sa, "File",     xco, yco, xmax-3, 22, "");
182                 xco+= xmax;
183                 
184                 xmax= GetButStringLength("Add");
185                 uiDefPulldownBut(block, dummy_viewmenu, sa, "Add",      xco, yco, xmax-3, 22, "");
186                 xco+= xmax;
187                 
188                 xmax= GetButStringLength("Timeline");
189                 uiDefPulldownBut(block, dummy_viewmenu, sa, "Timeline", xco, yco, xmax-3, 22, "");
190                 xco+= xmax;
191                 
192                 xmax= GetButStringLength("Game");
193                 uiDefPulldownBut(block, dummy_viewmenu, sa, "Game",     xco, yco, xmax-3, 22, "");
194                 xco+= xmax;
195                 
196                 xmax= GetButStringLength("Render");
197                 uiDefPulldownBut(block, dummy_viewmenu, sa, "Render",   xco, yco, xmax-3, 22, "");
198                 xco+= xmax;
199                 
200                 xmax= GetButStringLength("Help");
201                 uiDefPulldownBut(block, dummy_viewmenu, NULL, "Help",   xco, yco, xmax-3, 22, "");
202                 xco+= xmax;
203         }
204         
205         uiBlockSetEmboss(block, UI_EMBOSS);
206         
207         if(screen->full==NULL) {
208                 si->screen= win->screen;
209                 xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID**)&si->screen, ID_SCR, NULL, xco, yco,
210                                                  screen_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_DELETE);
211                 xco += 8;
212                 si->scene= screen->scene;
213                 xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID**)&si->scene, ID_SCE, NULL, xco, yco,
214                                                          scene_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_DELETE);
215                 xco += 8;
216         }       
217
218         if(WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C))) {
219                 uiDefIconTextBut(block, BUT, B_STOPRENDER, ICON_REC, "Render", xco+5,yco,75,19, NULL, 0.0f, 0.0f, 0, 0, "Stop rendering");
220         }
221         
222         /* always as last  */
223         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
224         
225         uiEndBlock(C, block);
226         uiDrawBlock(C, block);
227 }
228
229