2.5
[blender.git] / source / blender / editors / space_buttons / buttons_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_global.h"
42 #include "BKE_screen.h"
43
44 #include "ED_screen.h"
45 #include "ED_util.h"
46
47 #include "WM_api.h"
48 #include "WM_types.h"
49
50 #include "BIF_gl.h"
51 #include "BIF_glutil.h"
52
53 #include "UI_interface.h"
54 #include "UI_resources.h"
55 #include "UI_view2d.h"
56
57 #include "buttons_intern.h"
58
59
60 /* ************************ header area region *********************** */
61
62 static void do_viewmenu(bContext *C, void *arg, int event)
63 {
64         
65 }
66
67 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
68 {
69         ScrArea *curarea= C->area;
70         uiBlock *block;
71         short yco= 0, menuwidth=120;
72         
73         block= uiBeginBlock(C, handle->region, "dummy_viewmenu", UI_EMBOSSP, UI_HELV);
74         uiBlockSetButmFunc(block, do_viewmenu, NULL);
75         
76         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20, 
77                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
78         
79         if(curarea->headertype==HEADERTOP) {
80                 uiBlockSetDirection(block, UI_DOWN);
81         }
82         else {
83                 uiBlockSetDirection(block, UI_TOP);
84                 uiBlockFlipOrder(block);
85         }
86         
87         uiTextBoundsBlock(block, 50);
88         uiEndBlock(C, block);
89         
90         return block;
91 }
92
93 #define B_NEWSPACE                      100
94 #define B_CONTEXT_SWITCH        101
95 #define B_BUTSPREVIEW           102
96 #define B_NEWFRAME                      103
97
98 static void do_buttons_buttons(bContext *C, void *arg, int event)
99 {
100         switch(event) {
101                 case B_NEWSPACE:
102                         ED_newspace(C->area, C->area->butspacetype);
103                         WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
104                         break;
105                 case B_NEWFRAME:
106                         WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
107                         break;
108                 }
109 }
110
111
112 void buttons_header_buttons(const bContext *C, ARegion *ar)
113 {
114         ScrArea *sa= C->area;
115         SpaceButs *sbuts= sa->spacedata.first;
116         uiBlock *block;
117         int xco, yco= 3;
118         
119         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS, UI_HELV);
120         uiBlockSetHandleFunc(block, do_buttons_buttons, NULL);
121         
122         if(ED_screen_area_active(C)) uiBlockSetCol(block, TH_HEADER);
123         else uiBlockSetCol(block, TH_HEADERDESEL);
124
125         xco = 8;
126         
127         uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D, 
128                                           windowtype_pup(), xco, yco, XIC+10, YIC, 
129                                           &(C->area->butspacetype), 1.0, SPACEICONMAX, 0, 0, 
130                                           "Displays Current Window Type. "
131                                           "Click for menu of available types.");
132         
133         xco += XIC + 14;
134         
135         uiBlockSetEmboss(block, UI_EMBOSSN);
136         if (sa->flag & HEADER_NO_PULLDOWN) {
137                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0, 
138                                                  ICON_DISCLOSURE_TRI_RIGHT,
139                                                  xco,yco,XIC,YIC-2,
140                                                  &(sa->flag), 0, 0, 0, 0, 
141                                                  "Show pulldown menus");
142         }
143         else {
144                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0, 
145                                                  ICON_DISCLOSURE_TRI_DOWN,
146                                                  xco,yco,XIC,YIC-2,
147                                                  &(sa->flag), 0, 0, 0, 0, 
148                                                  "Hide pulldown menus");
149         }
150         uiBlockSetEmboss(block, UI_EMBOSS);
151         xco+=XIC;
152         
153         if((sa->flag & HEADER_NO_PULLDOWN)==0) {
154                 int xmax;
155                 
156                 /* pull down menus */
157                 uiBlockSetEmboss(block, UI_EMBOSSP);
158                 
159                 xmax= GetButStringLength("View");
160                 uiDefPulldownBut(block, dummy_viewmenu, C->area, 
161                                                  "View", xco, yco-2, xmax-3, 24, "");
162                 
163                 xco+=XIC+xmax;
164         }
165         
166         uiBlockSetEmboss(block, UI_EMBOSS);
167
168         uiBlockBeginAlign(block);
169         uiDefIconButS(block, ROW, B_CONTEXT_SWITCH,     ICON_GAME,                      xco, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)CONTEXT_LOGIC, 0, 0, "Logic (F4) ");
170         uiDefIconButS(block, ROW, B_CONTEXT_SWITCH,     ICON_SCRIPT,            xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)CONTEXT_SCRIPT, 0, 0, "Script ");
171         uiDefIconButS(block, ROW, B_BUTSPREVIEW,        ICON_MATERIAL_DEHLT,xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)CONTEXT_SHADING, 0, 0, "Shading (F5) ");
172         uiDefIconButS(block, ROW, B_CONTEXT_SWITCH,     ICON_OBJECT,            xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)CONTEXT_OBJECT, 0, 0, "Object (F7) ");
173         uiDefIconButS(block, ROW, B_CONTEXT_SWITCH,     ICON_EDIT,                      xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)CONTEXT_EDITING, 0, 0, "Editing (F9) ");
174         uiDefIconButS(block, ROW, B_CONTEXT_SWITCH,     ICON_SCENE_DEHLT,       xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)CONTEXT_SCENE, 0, 0, "Scene (F10) ");
175         
176         xco+= XIC;
177         
178         /* select the context to be drawn, per contex/tab the actual context is tested */
179         uiBlockSetEmboss(block, UI_EMBOSS);     // normal
180         switch(sbuts->mainb) {
181                 case CONTEXT_SCENE:
182                         uiBlockBeginAlign(block);
183                         uiDefIconButC(block, ROW, B_CONTEXT_SWITCH,             ICON_SCENE,     xco+=XIC, yco, XIC, YIC, &(sbuts->tab[CONTEXT_SCENE]), 1.0, (float)TAB_SCENE_RENDER, 0, 0, "Render buttons ");
184                         uiDefIconButC(block, ROW, B_CONTEXT_SWITCH,             ICON_SEQUENCE,  xco+=XIC, yco, XIC, YIC, &(sbuts->tab[CONTEXT_SCENE]), 1.0, (float)TAB_SCENE_SEQUENCER, 0, 0, "Sequencer buttons ");
185                         uiDefIconButC(block, ROW, B_CONTEXT_SWITCH,             ICON_ANIM,      xco+=XIC, yco, XIC, YIC, &(sbuts->tab[CONTEXT_SCENE]), 1.0, (float)TAB_SCENE_ANIM, 0, 0, "Anim/playback buttons");
186                         uiDefIconButC(block, ROW, B_CONTEXT_SWITCH,             ICON_SOUND,     xco+=XIC, yco, XIC, YIC, &(sbuts->tab[CONTEXT_SCENE]), 1.0, (float)TAB_SCENE_SOUND, 0, 0, "Sound block buttons");
187                         
188                         break;
189                 case CONTEXT_OBJECT:
190                         uiBlockBeginAlign(block);
191                         uiDefIconButC(block, ROW, B_CONTEXT_SWITCH,             ICON_OBJECT,    xco+=XIC, yco, XIC, YIC, &(sbuts->tab[CONTEXT_OBJECT]), 1.0, (float)TAB_OBJECT_OBJECT, 0, 0, "Object buttons ");
192                         uiDefIconButC(block, ROW, B_CONTEXT_SWITCH,             ICON_PHYSICS,   xco+=XIC, yco, XIC, YIC, &(sbuts->tab[CONTEXT_OBJECT]), 1.0, (float)TAB_OBJECT_PHYSICS, 0, 0, "Physics buttons");
193                         uiDefIconButC(block, ROW, B_CONTEXT_SWITCH,             ICON_PARTICLES, xco+=XIC, yco, XIC, YIC, &(sbuts->tab[CONTEXT_OBJECT]), 1.0, (float)TAB_OBJECT_PARTICLE, 0, 0, "Particle buttons");
194                         
195                         break;
196                 case CONTEXT_SHADING:
197                         uiBlockBeginAlign(block);
198                         uiDefIconButC(block, ROW, B_BUTSPREVIEW,        ICON_LAMP,      xco+=XIC, yco, XIC, YIC, &(sbuts->tab[CONTEXT_SHADING]), 1.0, (float)TAB_SHADING_LAMP, 0, 0, "Lamp buttons");
199                         uiDefIconButC(block, ROW, B_BUTSPREVIEW,        ICON_MATERIAL,  xco+=XIC, yco, XIC, YIC, &(sbuts->tab[CONTEXT_SHADING]), 1.0, (float)TAB_SHADING_MAT, 0, 0, "Material buttons");
200                         uiDefIconButC(block, ROW, B_BUTSPREVIEW,        ICON_TEXTURE,   xco+=XIC, yco, XIC, YIC, &(sbuts->tab[CONTEXT_SHADING]), 1.0, (float)TAB_SHADING_TEX, 0, 0, "Texture buttons(F6)");
201                         uiDefIconButC(block, ROW, B_CONTEXT_SWITCH,                     ICON_RADIO,xco+=XIC, yco, XIC, YIC, &(sbuts->tab[CONTEXT_SHADING]), 1.0, (float)TAB_SHADING_RAD, 0, 0, "Radiosity buttons");
202                         uiDefIconButC(block, ROW, B_BUTSPREVIEW,        ICON_WORLD,     xco+=XIC, yco, XIC, YIC, &(sbuts->tab[CONTEXT_SHADING]), 1.0, (float)TAB_SHADING_WORLD, 0, 0, "World buttons");
203                         
204                         break;
205                 case CONTEXT_EDITING:
206                         
207                         break;
208                 case CONTEXT_SCRIPT:
209                         
210                         break;
211                 case CONTEXT_LOGIC:
212                         
213                         break;
214         }
215         
216         uiBlockEndAlign(block);
217         
218         xco+=XIC;
219         uiDefButI(block, NUM, B_NEWFRAME, "",   (xco+20),yco,60,YIC, &(C->scene->r.cfra), 1.0, MAXFRAMEF, 0, 0, "Displays Current Frame of animation. Click to change.");
220         xco+= 80;
221         
222 // XXX  buttons_active_id(&id, &idfrom);
223 //      sbuts->lockpoin= id;
224         
225         
226         
227         /* always as last  */
228         sa->headbutlen= xco+XIC+80; // +80 because the last button is not an icon
229         
230         uiEndBlock(C, block);
231         uiDrawBlock(block);
232 }
233
234