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