Modified interface texture font support, which should work nicely with the freshly...
[blender.git] / source / blender / src / header_buttonswin.c
1 /**
2  * header_buttonswin.c oct-2003
3  *
4  * Functions to draw the "Buttons Window" window header
5  * and handle user events sent to it.
6  * 
7  * $Id$
8  *
9  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version. The Blender
15  * Foundation also sells licenses for use in proprietary software under
16  * the Blender License.  See http://www.blender.org/BL/ for information
17  * about this.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software Foundation,
26  * Inc., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
27  *
28  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
29  * All rights reserved.
30  *
31  * The Original Code is: all of this file.
32  *
33  * Contributor(s): none yet.
34  *
35  * ***** END GPL/BL DUAL LICENSE BLOCK *****
36  */
37
38 #include <stdlib.h>
39 #include <string.h>
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 #ifdef WIN32
46 #include "BLI_winstuff.h"
47 #endif
48
49 #include "DNA_ID.h"
50 #include "DNA_armature_types.h"
51 #include "DNA_lamp_types.h"
52 #include "DNA_material_types.h"
53 #include "DNA_object_types.h"
54 #include "DNA_scene_types.h"
55 #include "DNA_screen_types.h"
56 #include "DNA_space_types.h"
57 #include "DNA_texture_types.h"
58 #include "DNA_world_types.h"
59
60 #include "BIF_editconstraint.h"
61 #include "BIF_interface.h"
62 #include "BIF_previewrender.h"
63 #include "BIF_resources.h"
64 #include "BIF_screen.h"
65 #include "BIF_space.h"
66 #include "BIF_butspace.h"
67
68 #include "BKE_armature.h"
69 #include "BKE_global.h"
70 #include "BKE_library.h"
71 #include "BKE_main.h"
72 #include "BKE_material.h"
73 #include "BKE_texture.h"
74 #include "BKE_utildefines.h"
75 #include "BSE_drawipo.h"
76 #include "BSE_headerbuttons.h"
77
78 #include "MEM_guardedalloc.h"
79
80 #include "blendef.h"
81 #include "mydevice.h"
82 #include "butspace.h"
83
84 Material matcopybuf;
85
86 void clear_matcopybuf(void)
87 {
88         memset(&matcopybuf, 0, sizeof(Material));
89 }
90
91 void free_matcopybuf(void)
92 {
93         extern MTex mtexcopybuf;        /* buttons.c */
94         int a;
95
96         for(a=0; a<MAX_MTEX; a++) {
97                 if(matcopybuf.mtex[a]) {
98                         MEM_freeN(matcopybuf.mtex[a]);
99                         matcopybuf.mtex[a]= NULL;
100                 }
101         }
102  
103         if(matcopybuf.ramp_col) MEM_freeN(matcopybuf.ramp_col);
104         if(matcopybuf.ramp_spec) MEM_freeN(matcopybuf.ramp_spec);
105         matcopybuf.ramp_col= NULL;
106         matcopybuf.ramp_spec= NULL;
107         
108         default_mtex(&mtexcopybuf);
109 }
110
111 void do_buts_buttons(short event)
112 {
113         static short matcopied=0;
114         MTex *mtex;
115         Material *ma;
116         ID id;
117         int a;
118         float dx, dy;
119         if(curarea->win==0) return;
120
121         switch(event) {
122         case B_BUTSHOME:
123                 uiSetPanel_view2d(curarea);
124                 G.v2d->cur= G.v2d->tot;
125                 test_view2d(G.v2d, curarea->winx, curarea->winy);
126                 
127                 /* we always put in left/top */
128                 dy= G.v2d->tot.ymax - G.v2d->cur.ymax;
129                 G.v2d->cur.ymin += dy;
130                 G.v2d->cur.ymax += dy;
131                 dx= G.v2d->tot.xmin - G.v2d->cur.xmin;
132                 G.v2d->cur.xmin += dx;
133                 G.v2d->cur.xmax += dx;
134                 
135                 scrarea_queue_winredraw(curarea);
136                 break;
137         case B_BUTSPREVIEW:
138                 BIF_preview_changed(G.buts);
139                 scrarea_queue_headredraw(curarea);
140                 scrarea_queue_winredraw(curarea);
141                 break;
142         case B_MATCOPY:
143                 if(G.buts->lockpoin) {
144                         if(matcopied) free_matcopybuf();
145
146                         memcpy(&matcopybuf, G.buts->lockpoin, sizeof(Material));
147                         if(matcopybuf.ramp_col) matcopybuf.ramp_col= MEM_dupallocN(matcopybuf.ramp_col);
148                         if(matcopybuf.ramp_spec) matcopybuf.ramp_spec= MEM_dupallocN(matcopybuf.ramp_spec);
149
150                         for(a=0; a<MAX_MTEX; a++) {
151                                 mtex= matcopybuf.mtex[a];
152                                 if(mtex) {
153                                         matcopybuf.mtex[a]= MEM_dupallocN(mtex);
154                                 }
155                         }
156                         matcopied= 1;
157                 }
158                 break;
159         case B_MATPASTE:
160                 if(matcopied && G.buts->lockpoin) {
161                         ma= G.buts->lockpoin;
162                         /* free current mat */
163                         if(ma->ramp_col) MEM_freeN(ma->ramp_col);
164                         if(ma->ramp_spec) MEM_freeN(ma->ramp_spec);
165                         for(a=0; a<MAX_MTEX; a++) {
166                                 mtex= ma->mtex[a];
167                                 if(mtex && mtex->tex) mtex->tex->id.us--;
168                                 if(mtex) MEM_freeN(mtex);
169                         }
170                         
171                         id= (ma->id);
172                         memcpy(G.buts->lockpoin, &matcopybuf, sizeof(Material));
173                         (ma->id)= id;
174                         
175                         if(matcopybuf.ramp_col) ma->ramp_col= MEM_dupallocN(matcopybuf.ramp_col);
176                         if(matcopybuf.ramp_spec) ma->ramp_spec= MEM_dupallocN(matcopybuf.ramp_spec);
177                         
178                         for(a=0; a<MAX_MTEX; a++) {
179                                 mtex= ma->mtex[a];
180                                 if(mtex) {
181                                         ma->mtex[a]= MEM_dupallocN(mtex);
182                                         if(mtex->tex) id_us_plus((ID *)mtex->tex);
183                                 }
184                         }
185                         BIF_preview_changed(G.buts);
186                         BIF_undo_push("Paste material settings");
187                         scrarea_queue_winredraw(curarea);
188                 }
189                 break;
190         case B_MESHTYPE:
191                 allqueue(REDRAWBUTSEDIT, 0);
192                 allqueue(REDRAWVIEW3D, 0);
193                 break;
194         }
195 }
196
197 void buttons_active_id(ID **id, ID **idfrom)
198 {
199         Object *ob= OBACT;
200         Material *ma;
201
202         *id= NULL;
203         *idfrom= (ID *)ob;
204         
205         if(G.buts->mainb==CONTEXT_SCENE) {
206                 int tab= G.buts->tab[CONTEXT_SCENE];
207                 
208                 if(tab==TAB_SCENE_RENDER) *id= (ID *)G.scene;
209                 else if(tab==TAB_SCENE_SOUND) {
210                         ID *search;
211                         
212                         // validate lockpoin, maybe its not a sound
213                         if (G.buts->lockpoin) {
214                                 search = G.main->sound.first;
215                                 while (search) {
216                                         if (search == G.buts->lockpoin) {
217                                                 break;
218                                         }
219                                         search = search->next;
220                                 }
221                                 if (search == NULL) {
222                                         *id = G.main->sound.first;
223                                 } else {
224                                         *id = search;
225                                 }
226                         }
227                         else {
228                                 *id = G.main->sound.first;
229                         }
230                 
231                 }
232         }
233         else if(G.buts->mainb==CONTEXT_SHADING) {
234                 int tab= G.buts->tab[CONTEXT_SHADING];
235                 
236                 if(tab==TAB_SHADING_LAMP) {
237                         if(ob && ob->type==OB_LAMP) {
238                                 *id= ob->data;
239                         }
240                 }
241                 else if(tab==TAB_SHADING_MAT) {
242                         if(ob && (ob->type<OB_LAMP) && ob->type) {
243                                 *id= (ID *)give_current_material(ob, ob->actcol);
244                                 *idfrom= material_from(ob, ob->actcol);
245                         }
246                 }
247                 else if(tab==TAB_SHADING_WORLD) {
248                         *id= (ID *)G.scene->world;
249                         *idfrom= (ID *)G.scene;
250                 }
251                 else if(tab==TAB_SHADING_TEX) {
252                         MTex *mtex;
253                         
254                         if(G.buts->mainbo==G.buts->mainb && G.buts->tabo!=tab) {
255                                 if(G.buts->tabo==TAB_SHADING_LAMP) G.buts->texfrom= 2;
256                                 else if(G.buts->tabo==TAB_SHADING_WORLD) G.buts->texfrom= 1;
257                                 else if(G.buts->tabo==TAB_SHADING_MAT) G.buts->texfrom= 0;
258                         }
259
260                         if(G.buts->texfrom==0) {
261                                 if(ob && ob->type<OB_LAMP && ob->type) {
262                                         ma= give_current_material(ob, ob->actcol);
263                                         *idfrom= (ID *)ma;
264                                         if(ma) {
265                                                 mtex= ma->mtex[ ma->texact ];
266                                                 if(mtex) *id= (ID *)mtex->tex;
267                                         }
268                                 }
269                         }
270                         else if(G.buts->texfrom==1) {
271                                 World *wrld= G.scene->world;
272                                 *idfrom= (ID *)wrld;
273                                 if(wrld) {
274                                         mtex= wrld->mtex[ wrld->texact];
275                                         if(mtex) *id= (ID *)mtex->tex;
276                                 }
277                         }
278                         else if(G.buts->texfrom==2) {
279                                 Lamp *la;
280                                 if(ob && ob->type==OB_LAMP) {
281                                         la= ob->data;
282                                         *idfrom= (ID *)la;
283                                         mtex= la->mtex[ la->texact];
284                                         if(mtex) *id= (ID *)mtex->tex;
285                                 }
286                         }
287                 }
288         }
289         else if(G.buts->mainb==CONTEXT_OBJECT || G.buts->mainb==CONTEXT_LOGIC) {
290                 if(ob) {
291                         *idfrom= (ID *)G.scene;
292                         *id= (ID *)ob;
293                 }
294         }
295         else if(G.buts->mainb==CONTEXT_EDITING) {
296                 if(ob && ob->data) {
297                         *id= ob->data;
298                 }
299         }
300 }
301
302 #if 0
303 static void validate_bonebutton(void *bonev, void *data2_unused){
304         Bone *bone= bonev;
305         bArmature *arm;
306
307         arm = get_armature(G.obpose);
308         unique_bone_name(bone, arm);
309 }
310
311
312 static int bonename_exists(Bone *orig, char *name, ListBase *list)
313 {
314         Bone *curbone;
315         
316         for (curbone=list->first; curbone; curbone=curbone->next){
317                 /* Check this bone */
318                 if (orig!=curbone){
319                         if (!strcmp(curbone->name, name))
320                                 return 1;
321                 }
322                 
323                 /* Check Children */
324                 if (bonename_exists(orig, name, &curbone->childbase))
325                         return 1;
326         }
327         
328         return 0;
329
330 }
331
332 static void unique_bone_name (Bone *bone, bArmature *arm)
333 {
334         char            tempname[64];
335         char            oldname[64];
336         int                     number;
337         char            *dot;
338
339         if (!arm)
340                 return;
341
342         strcpy(oldname, bone->name);
343
344         /* See if we even need to do this */
345         if (!bonename_exists(bone, bone->name, &arm->bonebase))
346                 return;
347
348         /* Strip off the suffix */
349         dot=strchr(bone->name, '.');
350         if (dot)
351                 *dot=0;
352         
353         for (number = 1; number <=999; number++){
354                 sprintf (tempname, "%s.%03d", bone->name, number);
355                 
356                 if (!bonename_exists(bone, tempname, &arm->bonebase)){
357                         strcpy (bone->name, tempname);
358                         return;
359                 }
360         }
361 }
362
363 static uiBlock *sbuts_context_menu(void *arg_unused)
364 {
365         uiBlock *block;
366         short yco = 0;
367
368         block= uiNewBlock(&curarea->uiblocks, "context_options", UI_EMBOSSP, UI_HELV, curarea->headwin);
369
370         /* should be branches from tree */
371         uiDefIconTextButS(block, BUTM, B_REDR, ICON_SCENE_DEHLT, "Scene|F10", 0, yco-=22, 100, 20, &G.buts->mainb, 0.0, 0.0, 0, 0, "");
372         uiDefIconTextButS(block, BUTM, B_REDR, ICON_EDIT, "Editing|F9", 0, yco-=22, 100, 20, &G.buts->mainb, 4.0, 0.0, 0, 0, "");
373         uiDefIconTextButS(block, BUTM, B_REDR, ICON_OBJECT, "Object|F6", 0, yco-=22, 100, 20, &G.buts->mainb, 1.0, 0.0, 0, 0, "");
374         uiDefIconTextButS(block, BUTM, B_REDR, ICON_MATERIAL_DEHLT, "Shading|F5", 0, yco-=22, 100, 20, &G.buts->mainb, 3.0, 0.0, 0, 0, "");
375         uiDefIconTextButS(block, BUTM, B_REDR, ICON_GAME, "Logic|F4", 0, yco-=22, 100, 20, &G.buts->mainb, 6.0, 0.0, 0, 0, "");
376         uiDefIconTextButS(block, BUTM, B_REDR, ICON_SCRIPT, "Script", 0, yco-=22, 100, 20, &G.buts->mainb, 5.0, 0.0, 0, 0, "");
377         
378         if(curarea->headertype==HEADERTOP) {
379                 uiBlockSetDirection(block, UI_DOWN);
380         }
381         else {
382                 uiBlockSetDirection(block, UI_TOP);
383                 uiBlockFlipOrder(block);
384         }
385
386         return block;
387 }
388 #endif
389
390 static void do_buts_view_shadingmenu(void *arg, int event)
391 {
392         G.buts->mainb = CONTEXT_SHADING;
393         
394         allqueue(REDRAWBUTSALL, 0);
395 }
396
397
398 static uiBlock *buts_view_shadingmenu(void *arg_unused)
399 {
400         uiBlock *block;
401         short yco = 20, menuwidth = 120;
402
403         block= uiNewBlock(&curarea->uiblocks, "buts_view_shadingmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
404         uiBlockSetButmFunc(block, do_buts_view_shadingmenu, NULL);
405         
406         if((G.buts->mainb == CONTEXT_SHADING) && (G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_LAMP)) {
407                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_HLT, "Lamp|F5",
408                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SHADING]), (float)TAB_SHADING_LAMP, 0.0, 0, 10, "");
409         } else {
410                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_DEHLT, "Lamp|F5",
411                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SHADING]), (float)TAB_SHADING_LAMP, 0.0, 0, 10, "");
412         }
413         
414         if((G.buts->mainb == CONTEXT_SHADING) && (G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_MAT)) {
415                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_HLT, "Material|F5",
416                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SHADING]), (float)TAB_SHADING_MAT, 0.0, 0, 10, "");
417         } else {
418                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_DEHLT, "Material|F5",
419                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SHADING]), (float)TAB_SHADING_MAT, 0.0, 0, 10, "");
420         }
421         
422         if((G.buts->mainb == CONTEXT_SHADING) && (G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_TEX)) {
423                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_HLT, "Texture|F6",
424                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SHADING]), (float)TAB_SHADING_TEX, 0.0, 0, 10, "");
425         } else {
426                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_DEHLT, "Texture|F6",
427                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SHADING]), (float)TAB_SHADING_TEX, 0.0, 0, 10, "");
428         }
429         
430         if((G.buts->mainb == CONTEXT_SHADING) && (G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_RAD)) {
431                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_HLT, "Radiosity",
432                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SHADING]), (float)TAB_SHADING_RAD, 0.0, 0, 10, "");
433         } else {
434                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_DEHLT, "Radiosity",
435                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SHADING]), (float)TAB_SHADING_RAD, 0.0, 0, 10, "");
436         }
437         
438         if((G.buts->mainb == CONTEXT_SHADING) && (G.buts->tab[CONTEXT_SHADING]==TAB_SHADING_WORLD)) {
439                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_HLT, "World|F8",
440                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SHADING]), (float)TAB_SHADING_WORLD, 1.0, 0, 10, "");
441         } else {
442                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_DEHLT, "World|F8",
443                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SHADING]), (float)TAB_SHADING_WORLD, 1.0, 0, 10, "");
444         }
445         
446         uiBlockSetDirection(block, UI_RIGHT);
447         uiTextBoundsBlock(block, 60);
448                 
449         return block;
450 }
451
452 static void do_buts_view_scenemenu(void *arg, int event)
453 {
454         G.buts->mainb = CONTEXT_SCENE;
455         
456         allqueue(REDRAWBUTSALL, 0);
457 }
458
459
460 static uiBlock *buts_view_scenemenu(void *arg_unused)
461 {
462         uiBlock *block;
463         short yco = 20, menuwidth = 120;
464
465         block= uiNewBlock(&curarea->uiblocks, "buts_view_scenemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
466         uiBlockSetButmFunc(block, do_buts_view_scenemenu, NULL);
467         
468         if((G.buts->mainb == CONTEXT_SCENE) && (G.buts->tab[CONTEXT_SCENE]==TAB_SCENE_RENDER)) {
469                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_HLT, "Render|F10",
470                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SCENE]), (float)TAB_SCENE_RENDER, 0.0, 0, 10, "");
471         } else {
472                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_DEHLT, "Render|F10",
473                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SCENE]), (float)TAB_SCENE_RENDER, 0.0, 0, 10, "");
474         }
475         
476         if((G.buts->mainb == CONTEXT_SCENE) && (G.buts->tab[CONTEXT_SCENE]==TAB_SCENE_ANIM)) {
477                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_HLT, "Animation",
478                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SCENE]), (float)TAB_SCENE_ANIM, 0.0, 0, 10, "");
479         } else {
480                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_DEHLT, "Animation",
481                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SCENE]), (float)TAB_SCENE_ANIM, 0.0, 0, 10, "");
482         }
483         
484         if((G.buts->mainb == CONTEXT_SCENE) && (G.buts->tab[CONTEXT_SCENE]==TAB_SCENE_SOUND)) {
485                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_HLT, "Sound",
486                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SCENE]), (float)TAB_SCENE_SOUND, 0.0, 0, 10, "");
487         } else {
488                 uiDefIconTextButC(block, BUTM, B_REDR, ICON_CHECKBOX_DEHLT, "Sound",
489                 0, yco-=20, menuwidth, 19, &(G.buts->tab[CONTEXT_SCENE]), (float)TAB_SCENE_SOUND, 0.0, 0, 10, "");
490         }
491                 
492         uiBlockSetDirection(block, UI_RIGHT);
493         uiTextBoundsBlock(block, 60);
494                 
495         return block;
496 }
497
498 static void do_buts_view_alignmenu(void *arg, int event)
499 {
500         SpaceButs *sbuts= curarea->spacedata.first;
501         
502         switch(event) {
503                 case 0: /* panel alignment */
504                 case 1:
505                 case 2:
506                         sbuts->align= event;
507                         if(event) {
508                                 uiAlignPanelStep(curarea, 1.0);
509                                 do_buts_buttons(B_BUTSHOME);
510                         }
511                         break;
512         }
513         
514         allqueue(REDRAWBUTSALL, 0);
515 }
516
517
518 static uiBlock *buts_view_alignmenu(void *arg_unused)
519 {
520         SpaceButs *sbuts= curarea->spacedata.first;
521         uiBlock *block;
522         short yco = 20, menuwidth = 120;
523
524         block= uiNewBlock(&curarea->uiblocks, "buts_view_alignmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
525         uiBlockSetButmFunc(block, do_buts_view_alignmenu, NULL);
526         
527         if (sbuts->align == 1) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Horizontal", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
528         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Horizontal", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
529
530         if (sbuts->align == 2) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Vertical", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
531         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Vertical", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
532         
533         if (sbuts->align == 0) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Free", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
534         else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Free", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
535         
536         uiBlockSetDirection(block, UI_RIGHT);
537         uiTextBoundsBlock(block, 60);
538                 
539         return block;
540 }
541
542 static void do_buts_viewmenu(void *arg, int event)
543 {       
544         switch(event) {
545                 case 3: /* View All */
546                         do_buts_buttons(B_BUTSHOME);
547                         break;
548                 case 4: /* Maximize Window */
549                         /* using event B_FULL */
550                         break;
551                 case 10: /* empty for the context events */
552                         break;  
553         }
554         allqueue(REDRAWBUTSALL, 0);
555 }
556
557 static uiBlock *buts_viewmenu(void *arg_unused)
558 {
559         uiBlock *block;
560         short yco= 0, menuwidth=120;
561         
562         block= uiNewBlock(&curarea->uiblocks, "buts_viewmenu", 
563                                           UI_EMBOSSP, UI_HELV, curarea->headwin);
564         uiBlockSetButmFunc(block, do_buts_viewmenu, NULL);
565         
566         if(G.buts->mainb==CONTEXT_LOGIC) {
567                 uiDefIconTextButS(block, BUTM, B_REDR, ICON_CHECKBOX_HLT, "Logic|F4",
568                 0, yco-=20, menuwidth, 19, &(G.buts->mainb), CONTEXT_LOGIC, 0.0, 0, 10, "");
569         } else {
570                 uiDefIconTextButS(block, BUTM, B_REDR, ICON_CHECKBOX_DEHLT, "Logic|F4",
571                 0, yco-=20, menuwidth, 19, &(G.buts->mainb), CONTEXT_LOGIC, 0.0, 0, 10, "");
572         }
573         
574         if(G.buts->mainb==CONTEXT_SCRIPT) {
575                 uiDefIconTextButS(block, BUTM, B_REDR, ICON_CHECKBOX_HLT, "Script",
576                 0, yco-=20, menuwidth, 19, &(G.buts->mainb), (float)CONTEXT_SCRIPT, 0.0, 0, 10, "");
577         } else {
578                 uiDefIconTextButS(block, BUTM, B_REDR, ICON_CHECKBOX_DEHLT, "Script",
579                 0, yco-=20, menuwidth, 19, &(G.buts->mainb), (float)CONTEXT_SCRIPT, 0.0, 0, 10, "");
580         }
581         
582         uiDefIconTextBlockBut(block, buts_view_shadingmenu, NULL, ICON_RIGHTARROW_THIN, "Shading", 0, yco-=20, 120, 19, "");
583
584         if(G.buts->mainb==CONTEXT_OBJECT) {
585                 uiDefIconTextButS(block, BUTM, B_REDR, ICON_CHECKBOX_HLT, "Object|F7",
586                 0, yco-=20, menuwidth, 19, &(G.buts->mainb), (float)CONTEXT_OBJECT, 0.0, 0, 10, "");
587         } else {
588                 uiDefIconTextButS(block, BUTM, B_REDR, ICON_CHECKBOX_DEHLT, "Object|F7",
589                 0, yco-=20, menuwidth, 19, &(G.buts->mainb), (float)CONTEXT_OBJECT, 0.0, 0, 10, "");
590         }
591         
592         if(G.buts->mainb==CONTEXT_EDITING) {
593                 uiDefIconTextButS(block, BUTM, B_REDR, ICON_CHECKBOX_HLT, "Editing|F9",
594                 0, yco-=20, menuwidth, 19, &(G.buts->mainb), (float)CONTEXT_EDITING, 0.0, 0, 10, "");
595         } else {
596                 uiDefIconTextButS(block, BUTM, B_REDR, ICON_CHECKBOX_DEHLT, "Editing|F9",
597                 0, yco-=20, menuwidth, 19, &(G.buts->mainb), (float)CONTEXT_EDITING, 0.0, 0, 10, "");
598         }
599         
600         uiDefIconTextBlockBut(block, buts_view_scenemenu, NULL, ICON_RIGHTARROW_THIN, "Scene", 0, yco-=20, 120, 19, "");
601         
602         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
603         
604         uiDefIconTextBlockBut(block, buts_view_alignmenu, NULL, ICON_RIGHTARROW_THIN, "Align", 0, yco-=20, 120, 19, "");
605
606         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
607         
608         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
609                 
610         if (!curarea->full) 
611                 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
612         else 
613                 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
614         
615         if(curarea->headertype==HEADERTOP) {
616                 uiBlockSetDirection(block, UI_DOWN);
617         }
618         else {
619                 uiBlockSetDirection(block, UI_TOP);
620                 uiBlockFlipOrder(block);
621         }
622
623         uiTextBoundsBlock(block, 50);
624         
625         return block;
626 }
627
628 void buts_buttons(void)
629 {
630         uiBlock *block;
631         ID *id, *idfrom;
632         short xco, xmax, t_base= 0;
633         char naam[20];
634
635         sprintf(naam, "header %d", curarea->headwin);
636         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->headwin);
637
638         if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
639         else uiBlockSetCol(block, TH_HEADERDESEL);
640
641         curarea->butspacetype= SPACE_BUTS;
642         
643         xco = 8;
644         
645         uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D, 
646                                           windowtype_pup(), xco, 0, XIC+10, YIC, 
647                                           &(curarea->butspacetype), 1.0, SPACEICONMAX, 0, 0, 
648                                           "Displays Current Window Type. "
649                                           "Click for menu of available types.");
650
651         xco += XIC + 14;
652
653         uiBlockSetEmboss(block, UI_EMBOSSN);
654         if (curarea->flag & HEADER_NO_PULLDOWN) {
655                 uiDefIconButS(block, TOG|BIT|0, B_FLIPINFOMENU, 
656                                           ICON_DISCLOSURE_TRI_RIGHT,
657                                           xco,2,XIC,YIC-2,
658                                           &(curarea->flag), 0, 0, 0, 0, 
659                                           "Show pulldown menus");
660         }
661         else {
662                 uiDefIconButS(block, TOG|BIT|0, B_FLIPINFOMENU, 
663                                           ICON_DISCLOSURE_TRI_DOWN,
664                                           xco,2,XIC,YIC-2,
665                                           &(curarea->flag), 0, 0, 0, 0, 
666                                           "Hide pulldown menus");
667         }
668         uiBlockSetEmboss(block, UI_EMBOSS);
669         xco+=XIC;
670
671         if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
672                 /* pull down menus */
673                 uiBlockSetEmboss(block, UI_EMBOSSP);
674         
675                 xmax= GetButStringLength("Panels");
676                 uiDefPulldownBut(block, buts_viewmenu, NULL, 
677                                           "Panels", xco, -2, xmax-3, 24, "");
678                 xco+= xmax;
679
680         }
681
682         uiBlockSetEmboss(block, UI_EMBOSSX);
683
684         
685         /* FULL WINDOW */
686 //      if(curarea->full) uiDefIconBut(block, BUT,B_FULL, ICON_SPLITSCREEN,     xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Returns to multiple views window (CTRL+Up arrow)");
687 //      else uiDefIconBut(block, BUT,B_FULL, ICON_FULLSCREEN,   xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Makes current window full screen (CTRL+Down arrow)");
688
689         /* HOME */
690 //      uiDefIconBut(block, BUT, B_BUTSHOME, ICON_HOME, xco+=XIC,0,XIC,YIC, 0, 0, 0, 0, 0, "Zooms window to home view showing all items (HOMEKEY)");
691 //      xco+=XIC;
692         
693         /* mainb menu*/
694         /* (this could be done later with a dynamic tree and branches, also for python) */
695         //{
696         //      char mainbname[8][12]= {" Scene", " Object", " Types", " Shading", " Editing", " Script", " Logic"};
697         //      char mainbicon[8]= {ICON_SCENE_DEHLT, ICON_OBJECT, ICON_BBOX, ICON_MATERIAL_DEHLT, ICON_EDIT, ICON_SCRIPT, ICON_GAME};
698         //      uiBut *but= uiDefIconTextBlockBut(block, sbuts_context_menu, NULL, mainbicon[G.buts->mainb], mainbname[G.buts->mainb], xco, 0, 90, YIC, "Set main context for button panels");
699         //      uiButClearFlag(but, UI_ICON_RIGHT); // this type has both flags set, and draws icon right.. uhh
700         //      xco+= 90-XIC+10;
701         //}
702         uiBlockBeginAlign(block);
703         uiDefIconButS(block, ROW, B_REDR,       ICON_GAME,                      xco, 0, XIC, YIC, &(G.buts->mainb), 0.0, (float)CONTEXT_LOGIC, 0, 0, "Logic (F4) ");
704         uiDefIconButS(block, ROW, B_REDR,       ICON_SCRIPT,            xco+=XIC, 0, XIC, YIC, &(G.buts->mainb), 0.0, (float)CONTEXT_SCRIPT, 0, 0, "Script ");
705         uiDefIconButS(block, ROW, B_REDR,       ICON_MATERIAL_DEHLT,xco+=XIC, 0, XIC, YIC, &(G.buts->mainb), 0.0, (float)CONTEXT_SHADING, 0, 0, "Shading (F5) ");
706         uiDefIconButS(block, ROW, B_REDR,       ICON_OBJECT,            xco+=XIC, 0, XIC, YIC, &(G.buts->mainb), 0.0, (float)CONTEXT_OBJECT, 0, 0, "Object (F7) ");
707         uiDefIconButS(block, ROW, B_REDR,       ICON_EDIT,                      xco+=XIC, 0, XIC, YIC, &(G.buts->mainb), 0.0, (float)CONTEXT_EDITING, 0, 0, "Editing (F9) ");
708         uiDefIconButS(block, ROW, B_REDR,       ICON_SCENE_DEHLT,       xco+=XIC, 0, XIC, YIC, &(G.buts->mainb), 0.0, (float)CONTEXT_SCENE, 0, 0, "Scene (F10) ");
709         
710         xco+= XIC;
711         
712         // if(curarea->headertype==HEADERTOP)  t_base= -3; else t_base= 4;
713         
714         /* select the context to be drawn, per contex/tab the actual context is tested */
715         uiBlockSetEmboss(block, UI_EMBOSS);     // normal
716         switch(G.buts->mainb) {
717         case CONTEXT_SCENE:
718                 uiBlockBeginAlign(block);
719                 uiDefIconButC(block, ROW, B_REDR,               ICON_SCENE,     xco+=XIC, t_base, XIC, YIC, &(G.buts->tab[CONTEXT_SCENE]), 1.0, (float)TAB_SCENE_RENDER, 0, 0, "Render buttons ");
720                 uiDefIconButC(block, ROW, B_REDR,               ICON_ANIM,      xco+=XIC, t_base, XIC, YIC, &(G.buts->tab[CONTEXT_SCENE]), 1.0, (float)TAB_SCENE_ANIM, 0, 0, "Anim/playback buttons");
721                 uiDefIconButC(block, ROW, B_REDR,               ICON_SOUND,     xco+=XIC, t_base, XIC, YIC, &(G.buts->tab[CONTEXT_SCENE]), 1.0, (float)TAB_SCENE_SOUND, 0, 0, "Sound block buttons");
722                 
723                 break;
724         case CONTEXT_OBJECT:
725
726                 break;
727         case CONTEXT_SHADING:
728                 uiBlockBeginAlign(block);
729                 uiDefIconButC(block, ROW, B_BUTSPREVIEW,        ICON_LAMP,      xco+=XIC, t_base, XIC, YIC, &(G.buts->tab[CONTEXT_SHADING]), 1.0, (float)TAB_SHADING_LAMP, 0, 0, "Lamp buttons");
730                 uiDefIconButC(block, ROW, B_BUTSPREVIEW,        ICON_MATERIAL,  xco+=XIC, t_base, XIC, YIC, &(G.buts->tab[CONTEXT_SHADING]), 1.0, (float)TAB_SHADING_MAT, 0, 0, "Material buttons");
731                 uiDefIconButC(block, ROW, B_BUTSPREVIEW,        ICON_TEXTURE,   xco+=XIC, t_base, XIC, YIC, &(G.buts->tab[CONTEXT_SHADING]), 1.0, (float)TAB_SHADING_TEX, 0, 0, "Texture buttons(F6)");
732                 uiDefIconButC(block, ROW, B_REDR,                       ICON_RADIO,xco+=XIC, t_base, XIC, YIC, &(G.buts->tab[CONTEXT_SHADING]), 1.0, (float)TAB_SHADING_RAD, 0, 0, "Radiosity buttons");
733                 uiDefIconButC(block, ROW, B_BUTSPREVIEW,        ICON_WORLD,     xco+=XIC, t_base, XIC, YIC, &(G.buts->tab[CONTEXT_SHADING]), 1.0, (float)TAB_SHADING_WORLD, 0, 0, "World buttons");
734                 
735                 break;
736         case CONTEXT_EDITING:
737                 
738                 break;
739         case CONTEXT_SCRIPT:
740
741                 break;
742         case CONTEXT_LOGIC:
743                 
744                 break;
745         }
746         
747         uiBlockEndAlign(block);
748         
749         xco+=XIC;
750         uiDefButS(block, NUM, B_NEWFRAME, "",   (short)(xco+20),0,60,YIC, &(G.scene->r.cfra), 1.0, 18000.0, 0, 0, "Displays Current Frame of animation. Click to change.");
751         xco+= 80;
752
753         buttons_active_id(&id, &idfrom);
754         G.buts->lockpoin= id;
755
756         /* always do as last */
757         uiDrawBlock(block);
758         curarea->headbutlen= xco;
759 }