Tuesday merger of bf-blender into orange branch.
[blender-staging.git] / source / blender / src / header_info.c
1 /**
2  * header_info.c oct-2003
3  *
4  * Functions to draw the "User Preferences" 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 <math.h>
39 #include <stdlib.h>
40 #include <string.h>
41
42 #ifdef HAVE_CONFIG_H
43 #include <config.h>
44 #endif
45
46 #include "DNA_ID.h"
47 #include "DNA_image_types.h"
48 #include "DNA_lamp_types.h"
49 #include "DNA_object_types.h"
50 #include "DNA_packedFile_types.h"
51 #include "DNA_scene_types.h"
52 #include "DNA_screen_types.h"
53 #include "DNA_space_types.h"
54 #include "DNA_userdef_types.h"
55 #include "DNA_world_types.h"
56
57 #include "BDR_editcurve.h"
58 #include "BDR_editmball.h"
59 #include "BDR_editobject.h"
60
61 #include "BIF_editarmature.h"
62 #include "BIF_editfont.h"
63 #include "BIF_editmesh.h"
64 #include "BIF_gl.h"
65 #include "BIF_interface.h"
66 #include "BIF_language.h"
67 #include "BIF_mainqueue.h"
68 #include "BIF_previewrender.h"
69 #include "BIF_renderwin.h"
70 #include "BIF_resources.h"
71 #include "BIF_screen.h"
72 #include "BIF_space.h"
73 #include "BIF_toets.h"
74 #include "BIF_toolbox.h"
75 #include "BIF_usiblender.h"
76 #include "BIF_drawscene.h"
77
78 #include "BKE_blender.h"
79 #include "BKE_exotic.h"
80 #include "BKE_global.h"
81 #include "BKE_image.h"
82 #include "BKE_library.h"
83 #include "BKE_main.h"
84 #include "BKE_packedFile.h"
85 #include "BKE_scene.h"
86 #include "BKE_world.h"
87
88 #include "BLI_arithb.h"
89 #include "BLI_blenlib.h"
90 #include "BLO_writefile.h"
91
92 #include "BSE_editipo.h"
93 #include "BSE_filesel.h"
94 #include "BSE_headerbuttons.h"
95 #include "BSE_sequence.h"
96
97 #include "IMB_imbuf_types.h"
98
99 #include "MEM_guardedalloc.h"
100
101 #include "BPY_extern.h"
102 #include "BPY_menus.h"
103
104 #include "blendef.h"
105 #include "interface.h"
106 #include "mydevice.h"
107
108 extern char versionstr[]; /* from blender.c */
109
110 /*----------------------------------*/
111 /* Progress bar vars and functions: */
112
113 /* strubi shamelessly abused the status line as a progress bar...
114  * feel free to kill him after release */
115
116 static int g_progress_bar = 0;
117 static char *g_progress_info = 0;
118 static float g_done;
119
120 int start_progress_bar(void)
121 {
122         g_progress_bar = 1;
123         return 1;               // we never fail (yet)
124 }
125
126 void end_progress_bar(void)
127 {
128         g_progress_bar = 0;
129 }
130
131 static void update_progress_bar(float done, char *info)
132 {
133         g_done = done;
134         g_progress_info = info;
135 }
136
137 /** Progress bar
138         'done': a value between 0.0 and 1.0, showing progress
139         'info': a info text what is currently being done
140
141         Make sure that the progress bar is always called with:
142         done = 0.0 first
143                 and
144         done = 1.0 last -- or alternatively use:
145
146         start_progressbar();
147         do_stuff_and_callback_progress_bar();
148         end_progressbar();
149 */
150
151 int progress_bar(float done, char *busy_info)
152 {
153         ScrArea *sa;
154         short val; 
155
156         /* User break (ESC) */
157         while (qtest()) {
158                 if (extern_qread(&val) == ESCKEY) 
159                         return 0;
160         }
161         if (done == 0.0) {
162                 start_progress_bar();
163         } else if (done > 0.99) {
164                 end_progress_bar();
165         }
166
167         sa= G.curscreen->areabase.first;
168         while(sa) {
169                 if (sa->spacetype == SPACE_INFO) {
170                         update_progress_bar(done, busy_info);
171
172                         curarea = sa;
173
174                         scrarea_do_headdraw(curarea);
175                         areawinset(curarea->win);
176                         sa->head_swap= WIN_BACK_OK;
177                         screen_swapbuffers();
178                 }
179                 sa = sa->next;
180         }
181         return 1;
182 }
183 /* -- End of progress bar definitions ------- */
184
185 extern char videosc_dir[];      /* exotic.c */
186
187 void write_videoscape_fs()
188 {
189         if(G.obedit) {
190                 error("Can't save Videoscape. Press TAB to leave EditMode");
191         }
192         else {
193                 if(videosc_dir[0]==0) strcpy(videosc_dir, G.sce);
194                 activate_fileselect(FILE_SPECIAL, "Export Videoscape", videosc_dir,
195                                                                                 write_videoscape);
196         }
197 }
198
199 void write_vrml_fs()
200 {
201         if(G.obedit) {
202                 error("Can't save VRML. Press TAB to leave EditMode");
203         }
204         else {
205                 if(videosc_dir[0]==0) strcpy(videosc_dir, G.sce);
206         
207                 activate_fileselect(FILE_SPECIAL, "Export VRML 1.0", videosc_dir, write_vrml);
208         }  
209 }
210
211 void write_dxf_fs()
212 {
213         if(G.obedit) {
214                 error("Can't save DXF. Press TAB to leave EditMode");
215         }
216         else {
217
218                 if(videosc_dir[0]==0) strcpy(videosc_dir, G.sce);
219
220                 activate_fileselect(FILE_SPECIAL, "Export DXF", videosc_dir, write_dxf);        
221         }
222 }
223
224 void write_stl_fs()
225 {
226         if(G.obedit) {
227                 error("Can't save STL. Press TAB to leave EditMode");
228         }
229         else {
230
231                 if(videosc_dir[0]==0) strcpy(videosc_dir, G.sce);
232
233                 activate_fileselect(FILE_SPECIAL, "Export STL", videosc_dir, write_stl);
234         }
235 }
236 /* ------------ */
237
238 int buttons_do_unpack()
239 {
240         int how;
241         char menu[2048];
242         char line[128];
243         int ret_value = RET_OK, count = 0;
244
245         count = countPackedFiles();
246
247         if (count) {
248                 if (count == 1) {
249                         sprintf(menu, "Unpack 1 file%%t");
250                 } else {
251                         sprintf(menu, "Unpack %d files%%t", count);
252                 }
253                 
254                 sprintf(line, "|Use files in current directory (create when necessary)%%x%d", PF_USE_LOCAL);
255                 strcat(menu, line);
256         
257                 sprintf(line, "|Write files to current directory (overwrite existing files)%%x%d", PF_WRITE_LOCAL);
258                 strcat(menu, line);
259         
260                 sprintf(line, "|%%l|Use files in original location (create when necessary)%%x%d", PF_USE_ORIGINAL);
261                 strcat(menu, line);
262         
263                 sprintf(line, "|Write files to original location (overwrite existing files)%%x%d", PF_WRITE_ORIGINAL);
264                 strcat(menu, line);
265         
266                 sprintf(line, "|%%l|Disable AutoPack, keep all packed files %%x%d", PF_KEEP);
267                 strcat(menu, line);
268         
269                 sprintf(line, "|Ask for each file %%x%d", PF_ASK);
270                 strcat(menu, line);
271                 
272                 how = pupmenu(menu);
273                 
274                 if(how != -1) {
275                         if (how != PF_KEEP) {
276                                 unpackAll(how);
277                         }
278                         G.fileflags &= ~G_AUTOPACK;
279                 } else {
280                         ret_value = RET_CANCEL;
281                 }
282         } else {
283                 pupmenu("No packed files. Autopack disabled");
284         }
285         
286         return (ret_value);
287 }
288
289 /* here, because of all creator stuff */
290
291 Scene *copy_scene(Scene *sce, int level)
292 {
293         /* level 0: al objects shared
294          * level 1: al object-data shared
295          * level 2: full copy
296          */
297         Scene *scen;
298         Base *base, *obase;
299
300         /* level 0 */
301         scen= copy_libblock(sce);
302         duplicatelist(&(scen->base), &(sce->base));
303         
304         clear_id_newpoins();
305         
306         id_us_plus((ID *)scen->world);
307         id_us_plus((ID *)scen->set);
308
309         scen->ed= NULL;
310         scen->radio= NULL;
311         scen->theDag= NULL;
312         scen->toolsettings= MEM_dupallocN(sce->toolsettings);
313
314         duplicatelist(&(scen->markers), &(sce->markers));
315         
316         obase= sce->base.first;
317         base= scen->base.first;
318         while(base) {
319                 base->object->id.us++;
320                 if(obase==sce->basact) scen->basact= base;
321
322                 obase= obase->next;
323                 base= base->next;
324         }
325
326         if(level==0) return scen;
327
328         /* level 1 */
329         G.scene= scen;
330         
331         single_object_users(0);
332
333         /*      camera */
334         ID_NEW(G.scene->camera);
335
336         /* level 2 */
337         if(level>=2) {
338                 if(scen->world) {
339                         scen->world->id.us--;
340                         scen->world= copy_world(scen->world);
341                 }
342                 single_obdata_users(0);
343                 single_mat_users_expand();
344                 single_tex_users_expand();
345                 
346                 scen->radio= MEM_dupallocN(sce->radio);
347                 
348         }
349
350         clear_id_newpoins();
351
352         BPY_copy_scriptlink(&sce->scriptlink);
353         // make a private copy of the avicodecdata
354
355         if (sce->r.avicodecdata) {
356
357                 scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata);
358                 scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecdata->lpFormat);
359                 scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecdata->lpParms);
360         }
361
362         // make a private copy of the qtcodecdata
363
364         if (sce->r.qtcodecdata) {
365                 scen->r.qtcodecdata = MEM_dupallocN(sce->r.qtcodecdata);
366                 scen->r.qtcodecdata->cdParms = MEM_dupallocN(scen->r.qtcodecdata->cdParms);
367         }
368
369         return scen;
370 }
371
372 void do_info_buttons(unsigned short event)
373 {
374         bScreen *sc, *oldscreen;
375         Scene *sce, *sce1;
376         ScrArea *sa;
377         int nr;
378
379         switch(event) {
380         case B_INFOSCR:         /* menu select screen */
381
382                 if( G.curscreen->screennr== -2) {
383                         if(curarea->winy <50) {
384                                 sa= closest_bigger_area();
385                                 areawinset(sa->win);
386                         }
387                         activate_databrowse((ID *)G.curscreen, ID_SCR, 0, B_INFOSCR,
388                                                                                         &G.curscreen->screennr, do_info_buttons);
389                         return;
390                 }
391                 if( G.curscreen->screennr < 0) return;
392
393                 sc= G.main->screen.first;
394                 nr= 1;
395                 while(sc) {
396                         if(nr==G.curscreen->screennr) {
397                                 if(is_allowed_to_change_screen(sc)) setscreen(sc);
398                                 else error("Unable to perform function in EditMode");
399                                 break;
400                         }
401                         nr++;
402                         sc= sc->id.next;
403                 }
404                 /* last item: NEW SCREEN */
405                 if(sc==0) {
406                         duplicate_screen();
407                 }
408                 break;
409         case B_INFODELSCR:
410 /*do this event only with buttons, so it can never be called with full-window*/
411
412                 if(G.curscreen->id.prev) sc= G.curscreen->id.prev;
413                 else if(G.curscreen->id.next) sc= G.curscreen->id.next;
414                 else return;
415                 if(okee("Delete current screen")) {
416                         /* find new G.curscreen */
417
418                         oldscreen= G.curscreen;
419                         setscreen(sc);          /* this test if sc has a full */
420                         unlink_screen(oldscreen);
421                         free_libblock(&G.main->screen, oldscreen);
422                 }
423                 scrarea_queue_headredraw(curarea);
424
425                 break;
426         case B_INFOSCE:         /* menu select scene */
427
428                 if( G.curscreen->scenenr== -2) {
429                         if(curarea->winy <50) {
430                                 sa= closest_bigger_area();
431                                 areawinset(sa->win);
432                         }
433                         activate_databrowse((ID *)G.scene, ID_SCE, 0, B_INFOSCE,
434                                                                                         &G.curscreen->scenenr, do_info_buttons);
435                         return;
436                 }
437                 if( G.curscreen->scenenr < 0) return;
438
439                 sce= G.main->scene.first;
440                 nr= 1;
441                 while(sce) {
442                         if(nr==G.curscreen->scenenr) {
443                                 if(sce!=G.scene) set_scene(sce);
444                                 break;
445                         }
446                         nr++;
447                         sce= sce->id.next;
448                 }
449                 /* last item: NEW SCENE */
450                 if(sce==0) {
451                         nr= pupmenu("Add scene%t|Empty|Link Objects|Link ObData|Full Copy");
452                         if(nr<= 0) return;
453                         if(nr==1) {
454                                 sce= add_scene(G.scene->id.name+2);
455                                 sce->r= G.scene->r;
456 #ifdef _WIN32
457                                 if (sce->r.avicodecdata) {
458                                         sce->r.avicodecdata = MEM_dupallocN(G.scene->r.avicodecdata);
459                                         sce->r.avicodecdata->lpFormat = MEM_dupallocN(G.scene->r.avicodecdata->lpFormat);
460                                         sce->r.avicodecdata->lpParms = MEM_dupallocN(G.scene->r.avicodecdata->lpParms);
461                                 }
462 #endif
463 #ifdef WITH_QUICKTIME
464                                 if (sce->r.qtcodecdata) {
465                                         sce->r.qtcodecdata = MEM_dupallocN(G.scene->r.qtcodecdata);
466                                         sce->r.qtcodecdata->cdParms = MEM_dupallocN(G.scene->r.qtcodecdata->cdParms);
467                                 }
468 #endif
469                         }
470                         else sce= copy_scene(G.scene, nr-2);
471
472                         set_scene(sce);
473                 }
474                 BIF_preview_changed(ID_TE);
475
476                 break;
477         case B_INFODELSCE:
478
479                 if(G.scene->id.prev) sce= G.scene->id.prev;
480                 else if(G.scene->id.next) sce= G.scene->id.next;
481                 else return;
482                 if(okee("Delete current scene")) {
483
484                         /* check all sets */
485                         sce1= G.main->scene.first;
486                         while(sce1) {
487                                 if(sce1->set == G.scene) sce1->set= 0;
488                                 sce1= sce1->id.next;
489                         }
490
491                         /* check all sequences */
492                         clear_scene_in_allseqs(G.scene);
493
494                         /* al screens */
495                         sc= G.main->screen.first;
496                         while(sc) {
497                                 if(sc->scene == G.scene) sc->scene= sce;
498                                 sc= sc->id.next;
499                         }
500                         free_libblock(&G.main->scene, G.scene);
501                         set_scene(sce);
502                 }
503
504                 break;
505         }
506 }
507
508 static void check_packAll()
509 {
510         // first check for dirty images
511         Image *ima;
512
513         ima = G.main->image.first;
514         while (ima) {
515                 if (ima->ibuf && (ima->ibuf->userflags &= IB_BITMAPDIRTY)) {
516                         break;
517                 }
518                 ima= ima->id.next;
519                 }
520         
521         if (ima == 0 || okee("Some images are painted on. These changes will be lost. Continue ?")) {
522                 packAll();
523                 G.fileflags |= G_AUTOPACK;
524         }
525 }
526
527 static int write_runtime(char *str, char *exename)
528 {
529         char *freestr= NULL;
530         char *ext = 0;
531
532 #ifdef _WIN32
533         ext = ".exe";
534 #endif
535
536 #ifdef __APPLE__
537         ext = ".app";
538 #endif
539         if (ext && (!BLI_testextensie(str, ext))) {
540                 freestr= MEM_mallocN(strlen(str) + strlen(ext) + 1, "write_runtime_check");
541                 strcpy(freestr, str);
542                 strcat(freestr, ext);
543                 str= freestr;
544         }
545
546         if (!BLI_exists(str) || saveover(str))
547                 BLO_write_runtime(str, exename);
548
549         if (freestr)
550                 MEM_freeN(freestr);
551  
552         return 0;
553 }
554
555 static void write_runtime_check_dynamic(char *str) 
556 {
557         write_runtime(str, "blenderdynplayer.exe");
558 }
559
560 static void write_runtime_check(char *str) 
561 {
562         char player[128];
563
564         strcpy(player, "blenderplayer");
565
566 #ifdef _WIN32
567         strcat(player, ".exe");
568 #endif
569
570 #ifdef __APPLE__
571         strcat(player, ".app");
572 #endif
573
574         write_runtime(str, player);
575 }
576 /* end keyed functions */
577
578 /************************** MAIN MENU *****************************/
579 /************************** FILE *****************************/
580
581
582 static void do_info_file_importmenu(void *arg, int event)
583 {
584         ScrArea *sa;
585
586         if(curarea->spacetype==SPACE_INFO) {
587                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
588                 if (!sa) sa= closest_bigger_area();
589                 areawinset(sa->win);
590         }
591
592         /* events >=4 are registered bpython scripts */
593         if (event >= 4) {
594                 BPY_menu_do_python(PYMENU_IMPORT, event - 4);
595                 BIF_undo_push("Import file");
596         }
597         else {
598                 switch(event) {
599                                                                         
600                 case 0: /* DXF */
601                         activate_fileselect(FILE_BLENDER, "Import DXF", G.sce, BIF_read_file);
602                         break;
603                 case 1: /* VRML 1.0 */
604                         activate_fileselect(FILE_BLENDER, "Import VRML 1.0", G.sce, BIF_read_file);
605                         break;
606                 case 2: /* VideoScape */
607                         activate_fileselect(FILE_BLENDER, "Import VideoScape", G.sce, BIF_read_file);
608                         break;
609                 case 3: /* STL */
610                         activate_fileselect(FILE_BLENDER, "Import STL", G.sce, BIF_read_file);
611                         break;
612
613                 }
614         }
615         allqueue(REDRAWINFO, 0);
616 }
617
618 static uiBlock *info_file_importmenu(void *arg_unused)
619 {
620         uiBlock *block;
621         short yco = 20, menuwidth = 120;
622         BPyMenu *pym;
623         int i = 0;
624
625         block= uiNewBlock(&curarea->uiblocks, "importmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
626         uiBlockSetButmFunc(block, do_info_file_importmenu, NULL);
627         //uiBlockSetXOfs(block, -50);  // offset to parent button
628         
629         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...",
630                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "");
631         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...",
632                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "");
633         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VideoScape...",
634                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "");
635         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "STL...",
636                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 3, "");
637
638         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
639
640         for (pym = BPyMenuTable[PYMENU_IMPORT]; pym; pym = pym->next, i++) {
641                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i+4, pym->tooltip?pym->tooltip:pym->filename);
642         }
643
644         uiBlockSetDirection(block, UI_RIGHT);
645         uiTextBoundsBlock(block, 60);
646
647         return block;
648 }
649
650 static void do_info_file_exportmenu(void *arg, int event)
651 {
652         ScrArea *sa;
653
654         if(curarea->spacetype==SPACE_INFO) {
655                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
656                 if (!sa) sa= closest_bigger_area();
657                 areawinset(sa->win);
658         }
659
660         /* events >=4 are registered bpython scripts */
661         if (event >= 4) BPY_menu_do_python(PYMENU_EXPORT, event - 4);
662
663         else switch(event) {
664                                                                         
665         case 0:
666                 write_vrml_fs();
667                 break;
668         case 1:
669                 write_dxf_fs();
670                 break;
671         case 2:
672                 write_videoscape_fs();
673                 break;
674         case 3:
675                 write_stl_fs();
676                 break;
677         }
678         allqueue(REDRAWINFO, 0);
679 }
680
681 static uiBlock *info_file_exportmenu(void *arg_unused)
682 {
683         uiBlock *block;
684         short yco = 20, menuwidth = 120;
685         BPyMenu *pym;
686         int i = 0;
687
688         block= uiNewBlock(&curarea->uiblocks, "exportmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
689         uiBlockSetButmFunc(block, do_info_file_exportmenu, NULL);
690         //uiBlockSetXOfs(block, -50);  // offset to parent button
691
692         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...|Ctrl F2",
693                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "");
694         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...|Shift F2",
695                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "");
696         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Videoscape...|Alt W",
697                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "");
698         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "STL...",
699                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 3, "");
700
701         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
702
703         /* note that we acount for the 3 previous entries with i+3: */
704         for (pym = BPyMenuTable[PYMENU_EXPORT]; pym; pym = pym->next, i++) {
705                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
706                                  NULL, 0.0, 0.0, 1, i+4, 
707                                  pym->tooltip?pym->tooltip:pym->filename);
708         }
709
710
711         uiBlockSetDirection(block, UI_RIGHT);
712         uiTextBoundsBlock(block, 60);
713
714         return block;
715 }
716
717 static void do_info_filemenu(void *arg, int event)
718 {
719         ScrArea *sa;
720         char dir[FILE_MAXDIR];
721         
722         if(curarea->spacetype==SPACE_INFO) {
723                 sa= closest_bigger_area();
724                 areawinset(sa->win);
725         }
726
727         /* these are no defines, easier this way, the codes are in the function below */
728         switch(event) {
729         case 0:
730                 if (okee("Erase All")) {
731                         if (!BIF_read_homefile())
732                                 error("No file ~/.B.blend");
733                 }
734                 break;
735         case 1: /* open */
736                 activate_fileselect(FILE_BLENDER, "Open", G.sce, BIF_read_file);
737                 break;
738         case 2: /* reopen last */
739                 {
740                         char *s= MEM_mallocN(strlen(G.sce) + 11 + 1, "okee_reload");
741                         strcpy(s, "Open file: ");
742                         strcat(s, G.sce);
743                         if (okee(s)) BIF_read_file(G.sce);
744                         MEM_freeN(s);
745                 }
746                 break;
747         case 3: /* append */
748                 activate_fileselect(FILE_LOADLIB, "Load Library", G.lib, 0);
749                 break;
750         case 4: /* save */
751                 strcpy(dir, G.sce);
752                 untitled(dir);
753                 activate_fileselect(FILE_BLENDER, "Save As", dir, BIF_write_file);
754                 break;
755         case 5:
756                 strcpy(dir, G.sce);
757                 if (untitled(dir)) {
758                         activate_fileselect(FILE_BLENDER, "Save As", dir, BIF_write_file);
759                 } else {
760                         BIF_write_file(dir);
761                         free_filesel_spec(dir);
762                 }
763                 break;
764         case 6: /* save image */
765                 BIF_save_rendered_image();
766                 break;
767         case 22: /* save runtime */
768                 activate_fileselect(FILE_SPECIAL, "Save Runtime", "", write_runtime_check);
769                 break;
770         case 23: /* save dynamic runtime */
771                 activate_fileselect(FILE_SPECIAL, "Save Dynamic Runtime", "", write_runtime_check_dynamic);
772                 break;
773         case 24:
774                 BIF_screendump(0);
775                 break;
776         case 25:
777                 BIF_screendump(1);
778                 break;
779         case 10: /* pack data */
780                 check_packAll();
781                 break;
782         case 11: /* unpack to current dir */
783                 unpackAll(PF_WRITE_LOCAL);
784                 G.fileflags &= ~G_AUTOPACK;
785                 break;
786         case 12: /* unpack data */
787                 if (buttons_do_unpack() != RET_CANCEL) {
788                         /* Clear autopack bit only if user selected one of the unpack options */
789                         G.fileflags &= ~G_AUTOPACK;
790                 }
791                 break;
792         case 13:
793                 exit_usiblender();
794                 break;
795         case 15:        /* recover previous session */
796                 {
797                         extern short winqueue_break; /* editscreen.c */
798                         int save_over;
799                         char str[FILE_MAXDIR+FILE_MAXFILE];
800                         char scestr[FILE_MAXDIR+FILE_MAXFILE];
801                         
802                         strcpy(scestr, G.sce);  /* temporal store */
803                         save_over = G.save_over;
804                         BLI_make_file_string("/", str, U.tempdir, "quit.blend");
805                         BKE_read_file(str, NULL);
806                         G.save_over = save_over;
807                         strcpy(G.sce, scestr);
808
809                         winqueue_break= 1;      /* leave queues everywhere */
810                 
811                         BKE_reset_undo();
812                         BKE_write_undo("original");     /* save current state */
813                         refresh_interface_font();
814                 }
815                 break;
816         case 31: /* save default settings */
817                 BIF_write_homefile();
818                 break;
819
820         case 35: /* compress toggle */
821                 U.flag ^= (USER_FILECOMPRESS);
822                 break;
823         }
824         allqueue(REDRAWINFO, 0);
825 }
826
827 static uiBlock *info_filemenu(void *arg_unused)
828 {
829         uiBlock *block;
830         short yco=0;
831         short menuwidth=120;
832
833         block= uiNewBlock(&curarea->uiblocks, "info_filemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
834         uiBlockSetButmFunc(block, do_info_filemenu, NULL);
835         
836         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "New|Ctrl X",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
837         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Open...|F1",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
838         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reopen Last|Ctrl O",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
839         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Recover Last Session",                           0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 15, "");
840
841         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
842
843         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save|Ctrl W",                            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
844         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save As...|F2",                  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
845         
846         if(U.flag & USER_FILECOMPRESS) {
847                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Compress File",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 35, "Enable file compression");
848         } else {
849                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Compress File",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 35, "Enable file compression");
850         }
851
852         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
853
854         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Image...|F3",                       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
855         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Dump Subwindow|Ctrl F3",                 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 24, "");
856         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Dump Screen|Ctrl Shift F3",                      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 25, "");
857 #if GAMEBLENDER == 1
858         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Runtime...",                        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 22, "");
859 #ifdef _WIN32
860         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Dynamic Runtime...",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 23, "");
861 #endif
862 #endif
863         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
864
865         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Default Settings|Ctrl U",                   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 31, "");
866
867
868         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
869
870         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Append...|Shift F1",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
871         uiDefIconTextBlockBut(block, info_file_importmenu, NULL, ICON_RIGHTARROW_THIN, "Import", 0, yco-=20, menuwidth, 19, "");
872         uiDefIconTextBlockBut(block, info_file_exportmenu, NULL, ICON_RIGHTARROW_THIN, "Export", 0, yco-=20, menuwidth, 19, "");
873         
874         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
875
876         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Data",                              0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "");
877 //      uiDefBut(block, BUTM, 1, "Unpack Data to current dir",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 11, "Removes all packed files from the project and saves them to the current directory");
878         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpack Data...",                         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 12, "");
879
880         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
881
882         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Quit Blender| Q",                                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 13, "");
883
884         uiBlockSetDirection(block, UI_DOWN);
885         uiTextBoundsBlock(block, 80);
886
887         return block;
888 }
889
890 /**************************** ADD ******************************/
891
892 void do_info_add_meshmenu(void *arg, int event)
893 {
894
895         switch(event) {         
896                 case 0:
897                         /* Plane */
898                         add_primitiveMesh(0);
899                         break;
900                 case 1:
901                         /* Cube */
902                         add_primitiveMesh(1);
903                         break;
904                 case 2:
905                         /* Circle */
906                         add_primitiveMesh(4);
907                         break;
908                 case 3:
909                         /* UVsphere */
910                         add_primitiveMesh(11);
911                         break;
912                 case 4:
913                         /* IcoSphere */
914                         add_primitiveMesh(12);
915                         break;
916                 case 5:
917                         /* Cylinder */
918                         add_primitiveMesh(5);
919                         break;
920                 case 6:
921                         /* Tube */
922                         add_primitiveMesh(6);
923                         break;
924                 case 7:
925                         /* Cone */
926                         add_primitiveMesh(7);
927                         break;
928                 case 8:
929                         /* Grid */
930                         add_primitiveMesh(10);
931                         break;
932                 case 9:
933                         /* Monkey */
934                         add_primitiveMesh(13);
935                         break;
936                 default:
937                         break;
938         }
939         allqueue(REDRAWINFO, 0);
940 }
941
942 static uiBlock *info_add_meshmenu(void *arg_unused)
943 {
944 /*              static short tog=0; */
945         uiBlock *block;
946         short yco= 0;
947         
948         block= uiNewBlock(&curarea->uiblocks, "add_meshmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
949         uiBlockSetButmFunc(block, do_info_add_meshmenu, NULL);
950         
951         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Plane|",                         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
952         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cube|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
953         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Circle|",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
954         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "UVsphere",                       0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
955         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "IcoSphere|",                     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
956         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cylinder|",                      0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
957         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Tube|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 6, "");
958         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cone|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "");
959         uiDefIconTextBut(block, SEPR, 0, ICON_BLANK1, "",                                       0, yco-=6,      160, 6,  NULL, 0.0, 0.0, 0, 0, "");
960         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grid|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "");
961         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Monkey|",                        0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 9, "");
962
963         uiBlockSetDirection(block, UI_RIGHT);
964         uiTextBoundsBlock(block, 50);
965                 
966         return block;
967 }
968
969 void do_info_add_curvemenu(void *arg, int event)
970 {
971
972         switch(event) {         
973                 case 0:
974                         /* Bezier Curve */
975                         add_primitiveCurve(10);
976                         break;
977                 case 1:
978                         /* Bezier Circle */
979                         add_primitiveCurve(11);
980                         break;
981                 case 2:
982                         /* NURB Curve */
983                         add_primitiveCurve(40);
984                         break;
985                 case 3:
986                         /* NURB Circle */
987                         add_primitiveCurve(41);
988                         break;
989                 case 4:
990                         /* Path */
991                         add_primitiveCurve(46);
992                         break;
993                 default:
994                         break;
995         }
996         allqueue(REDRAWINFO, 0);
997 }
998
999 static uiBlock *info_add_curvemenu(void *arg_unused)
1000 {
1001 /*              static short tog=0; */
1002         uiBlock *block;
1003         short yco= 0;
1004         
1005         block= uiNewBlock(&curarea->uiblocks, "add_curvemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1006         uiBlockSetButmFunc(block, do_info_add_curvemenu, NULL);
1007         
1008         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Bezier Curve|",  0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1009         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Bezier Circle|", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1010         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Curve|",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1011         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Circle",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1012         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Path|",                  0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1013
1014         uiBlockSetDirection(block, UI_RIGHT);
1015         uiTextBoundsBlock(block, 50);
1016                 
1017         return block;
1018 }
1019
1020
1021 void do_info_add_surfacemenu(void *arg, int event)
1022 {
1023
1024         switch(event) {         
1025                 case 0:
1026                         /* Curve */
1027                         add_primitiveNurb(0);
1028                         break;
1029                 case 1:
1030                         /* Circle */
1031                         add_primitiveNurb(1);
1032                         break;
1033                 case 2:
1034                         /* Surface */
1035                         add_primitiveNurb(2);
1036                         break;
1037                 case 3:
1038                         /* Tube */
1039                         add_primitiveNurb(3);
1040                         break;
1041                 case 4:
1042                         /* Sphere */
1043                         add_primitiveNurb(4);
1044                         break;
1045                 case 5:
1046                         /* Donut */
1047                         add_primitiveNurb(5);
1048                         break;
1049                 default:
1050                         break;
1051         }
1052         allqueue(REDRAWINFO, 0);
1053 }
1054
1055 static uiBlock *info_add_surfacemenu(void *arg_unused)
1056 {
1057 /*              static short tog=0; */
1058         uiBlock *block;
1059         short yco= 0;
1060         
1061         block= uiNewBlock(&curarea->uiblocks, "add_surfacemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1062         uiBlockSetButmFunc(block, do_info_add_surfacemenu, NULL);
1063         
1064         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Curve|",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1065         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Circle|",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1066         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Surface|", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1067         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Tube",             0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1068         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Sphere|",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1069         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Donut|",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
1070         uiBlockSetDirection(block, UI_RIGHT);
1071         uiTextBoundsBlock(block, 50);
1072                 
1073         return block;
1074 }
1075
1076 void do_info_add_metamenu(void *arg, int event)
1077 {
1078
1079         switch(event) {         
1080                 case 0:
1081                         /* Ball */
1082                         add_primitiveMball(1);
1083                         break;
1084                 case 1:
1085                         /* Tube */
1086                         add_primitiveMball(2);
1087                         break;
1088                 case 2:
1089                         /* Plane */
1090                         add_primitiveMball(3);
1091                         break;
1092                 case 3:
1093                         /* Elipsoid */
1094                         add_primitiveMball(4);
1095                         break;
1096                 case 4:
1097                         /* Cube */
1098                         add_primitiveMball(5);
1099                         break;
1100                 default:
1101                         break;
1102         }
1103         allqueue(REDRAWINFO, 0);
1104 }
1105
1106
1107 static uiBlock *info_add_metamenu(void *arg_unused)
1108 {
1109 /*              static short tog=0; */
1110         uiBlock *block;
1111         short xco= 0;
1112         
1113         block= uiNewBlock(&curarea->uiblocks, "add_metamenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1114         uiBlockSetButmFunc(block, do_info_add_metamenu, NULL);
1115         
1116         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,"Meta Ball|",              0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1117         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Tube|",             0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1118         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Plane|",            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1119         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Ellipsoid|",        0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1120         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Cube|",             0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1121
1122         uiBlockSetDirection(block, UI_RIGHT);
1123         uiTextBoundsBlock(block, 50);
1124                 
1125         return block;
1126 }
1127
1128 void do_info_add_lampmenu(void *arg, int event)
1129 {
1130
1131         switch(event) {         
1132                 case 0: /* lamp */
1133                         add_objectLamp(LA_LOCAL);
1134                         break;
1135                 case 1: /* sun */
1136                         add_objectLamp(LA_SUN);
1137                         break;
1138                 case 2: /* spot */
1139                         add_objectLamp(LA_SPOT);
1140                         break;
1141                 case 3: /* hemi */
1142                         add_objectLamp(LA_HEMI);
1143                         break;
1144                 case 4: /* area */
1145                         add_objectLamp(LA_AREA);
1146                         break;
1147                 case 5: /* YafRay photon lamp */
1148                         if (G.scene->r.renderer==R_YAFRAY)
1149                                 add_objectLamp(LA_YF_PHOTON);
1150                         break;
1151                 default:
1152                         break;
1153         }
1154         allqueue(REDRAWINFO, 0);
1155 }
1156
1157 static uiBlock *info_add_lampmenu(void *arg_unused)
1158 {
1159 /*              static short tog=0; */
1160         uiBlock *block;
1161         short yco= 0;
1162         
1163         block= uiNewBlock(&curarea->uiblocks, "add_lampmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1164         uiBlockSetButmFunc(block, do_info_add_lampmenu, NULL);
1165         
1166         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Lamp|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1167         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Sun|",                           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1168         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Spot|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1169         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hemi|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1170         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Area|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1171         if (G.scene->r.renderer==R_YAFRAY)
1172                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Photon|",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
1173         
1174         uiBlockSetDirection(block, UI_RIGHT);
1175         uiTextBoundsBlock(block, 50);
1176                 
1177         return block;
1178 }
1179
1180 void do_info_addmenu(void *arg, int event)
1181 {
1182         switch(event) {         
1183                 case 0:
1184                         /* Mesh */
1185                         break;
1186                 case 1:
1187                         /* Curve */
1188                         break;
1189                 case 2:
1190                         /* Surface */
1191                         break;
1192                 case 3:
1193                         /* Metaball */
1194                         break;
1195                 case 4:
1196                         /* Text (argument is discarded) */
1197                         add_primitiveFont(event);
1198                         break;
1199                 case 5:
1200                         /* Empty */
1201                         add_object_draw(OB_EMPTY);
1202                         break;
1203                 case 6:
1204                         /* Camera */
1205                         add_object_draw(OB_CAMERA);
1206                         break;
1207                 case 8:
1208                         /* Armature */
1209                         add_primitiveArmature(OB_ARMATURE);
1210                         break;
1211                 case 9:
1212                         /* Lattice */
1213                         add_object_draw(OB_LATTICE);
1214                         break;
1215                 case 10:
1216                         /* group instance not yet */
1217                         break;
1218                 default:
1219                         break;
1220         }
1221         allqueue(REDRAWINFO, 0);
1222 }
1223
1224
1225 static uiBlock *info_addmenu(void *arg_unused)
1226 {
1227 /*              static short tog=0; */
1228         uiBlock *block;
1229         short yco= 0;
1230
1231         block= uiNewBlock(&curarea->uiblocks, "addmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1232         uiBlockSetButmFunc(block, do_info_addmenu, NULL);
1233         
1234         uiDefIconTextBlockBut(block, info_add_meshmenu, NULL, ICON_RIGHTARROW_THIN, "Mesh", 0, yco-=20, 120, 19, "");
1235         uiDefIconTextBlockBut(block, info_add_curvemenu, NULL, ICON_RIGHTARROW_THIN, "Curve", 0, yco-=20, 120, 19, "");
1236         uiDefIconTextBlockBut(block, info_add_surfacemenu, NULL, ICON_RIGHTARROW_THIN, "Surface", 0, yco-=20, 120, 19, "");
1237         uiDefIconTextBlockBut(block, info_add_metamenu, NULL, ICON_RIGHTARROW_THIN, "Meta", 0, yco-=20, 120, 19, "");
1238         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Text",                           0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 4, "");
1239         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Empty",                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 5, "");
1240         
1241         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1242         
1243         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Camera",                         0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 6, "");
1244         uiDefIconTextBlockBut(block, info_add_lampmenu, NULL, ICON_RIGHTARROW_THIN, "Lamp", 0, yco-=20, 120, 19, "");
1245         
1246         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1247         
1248         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Armature",                       0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 8, "");
1249         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Lattice",                        0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 9, "");
1250
1251         uiBlockSetDirection(block, UI_DOWN);
1252         uiTextBoundsBlock(block, 80);
1253                 
1254         return block;
1255 }
1256
1257 /************************** GAME *****************************/
1258
1259 static void do_info_gamemenu(void *arg, int event)
1260 {
1261         switch (event) {
1262         case G_FILE_ENABLE_ALL_FRAMES:
1263         case G_FILE_SHOW_FRAMERATE:
1264         case G_FILE_SHOW_DEBUG_PROPS:
1265         case G_FILE_AUTOPLAY:
1266         case G_FILE_GAME_TO_IPO:
1267         case G_FILE_GAME_MAT:
1268                 G.fileflags ^= event;
1269                 break;
1270         default:
1271                 ; /* ignore the rest */
1272         }
1273 }
1274
1275 static uiBlock *info_gamemenu(void *arg_unused)
1276 {
1277 /*              static short tog=0; */
1278         uiBlock *block;
1279         short yco= 0;
1280         short menuwidth=120;
1281         
1282         block= uiNewBlock(&curarea->uiblocks, "gamemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1283         uiBlockSetButmFunc(block, do_info_gamemenu, NULL);
1284         
1285         uiDefIconTextBut(block, BUTM, B_STARTGAME, ICON_BLANK1, "Start Game|P",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
1286         
1287         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 1, 0, "");
1288
1289
1290         if(G.fileflags & G_FILE_ENABLE_ALL_FRAMES) {
1291                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Enable All Frames",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_ENABLE_ALL_FRAMES, "");
1292         } else {
1293                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Enable All Frames",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_ENABLE_ALL_FRAMES, "");
1294         }
1295         
1296         if(G.fileflags & G_FILE_GAME_TO_IPO) {
1297                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Record Game Physics to IPO",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GAME_TO_IPO, "");
1298         } else {
1299                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Record Game Physics to IPO",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GAME_TO_IPO, "");
1300         }
1301         
1302         if(G.fileflags & G_FILE_GAME_MAT) {
1303                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Use Blender Materials",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GAME_MAT, "");
1304         } else {
1305                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Use Blender Materials",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GAME_MAT, "");
1306         }       
1307
1308
1309
1310         if(G.fileflags & G_FILE_SHOW_FRAMERATE) {
1311                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Show Framerate and Profile",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_SHOW_FRAMERATE, "");
1312         } else {
1313                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Show Framerate and Profile",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_SHOW_FRAMERATE, "");
1314         }
1315
1316         if(G.fileflags & G_FILE_SHOW_DEBUG_PROPS) {
1317                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Show Debug Properties",             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_SHOW_DEBUG_PROPS, "");
1318         } else {
1319                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Show Debug Properties",           0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_SHOW_DEBUG_PROPS, "");
1320         }
1321         
1322         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 1, 0, "");
1323
1324         if(G.fileflags & G_FILE_AUTOPLAY) {
1325                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Autostart",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_AUTOPLAY, "");
1326         } else {
1327                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Autostart",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_AUTOPLAY, "");
1328         }
1329
1330         uiBlockSetDirection(block, UI_DOWN);
1331         uiTextBoundsBlock(block, 70);
1332         
1333         return block;
1334 }
1335 /************************** TIMELINE *****************************/
1336
1337 static void do_info_timelinemenu(void *arg, int event)
1338 {
1339         /* needed to check for valid selected objects */
1340         Base *base=NULL;
1341         Object *ob=NULL;
1342         //char file[FILE_MAXDIR+FILE_MAXFILE];
1343
1344         base= BASACT;
1345         if (base) ob= base->object;
1346
1347         switch(event) {
1348         case 1:
1349                 /* Show Keyframes */
1350                 if (!ob) error("Select an object before showing its keyframes");
1351                 else set_ob_ipoflags();
1352                 break;
1353         case 2:
1354                 /* Show and select Keyframes */
1355                 if (!ob) error("Select an object before showing and selecting its keyframes");
1356                 else select_select_keys();
1357                         break;
1358                 case 3:
1359                 /* select next keyframe */
1360                 if (!ob) error("Select an object before selecting its next keyframe");
1361                 else nextkey_obipo(1);
1362                         break;
1363                 case 4:
1364                 /* select previous keyframe */
1365                 if (!ob) error("Select an object before selecting its previous keyframe");
1366                 else nextkey_obipo(-1);
1367                 break;
1368                 case 5:
1369                 /* next keyframe */
1370                 if (!ob) error("Select an object before going to its next keyframe");
1371                 else movekey_obipo(1);
1372                         break;
1373                 case 6:
1374                 /* previous keyframe */
1375                 if (!ob) error("Select an object before going to its previous keyframe");
1376                 else movekey_obipo(-1);
1377                 break;
1378         case 7:
1379                 /* next frame */
1380                 CFRA++;
1381                 update_for_newframe();
1382                 break;
1383                 case 8:
1384                 /* previous frame */
1385                 CFRA--;
1386                 if(CFRA<1) CFRA=1;
1387                 update_for_newframe();
1388                 break;
1389         case 9:
1390                 /* forward 10 frames */
1391                 CFRA+= 10;
1392                 update_for_newframe();
1393                 break;
1394         case 10:
1395                 /* back 10 frames */
1396                 CFRA-= 10;
1397                 if(CFRA<1) CFRA=1;
1398                 update_for_newframe();
1399                 break;
1400         case 11:
1401                 /* end frame */
1402                 CFRA= EFRA;
1403                 update_for_newframe();
1404                 break;
1405         case 12:
1406                 /* start frame */
1407                 CFRA= SFRA;
1408                 update_for_newframe();
1409                 break;
1410         }
1411         allqueue(REDRAWINFO, 0);
1412 }
1413
1414 static uiBlock *info_timelinemenu(void *arg_unused)
1415 {
1416 /*              static short tog=0; */
1417         uiBlock *block;
1418         short yco= 0;
1419         short menuwidth=120;
1420
1421         block= uiNewBlock(&curarea->uiblocks, "timelinemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1422         uiBlockSetButmFunc(block, do_info_timelinemenu, NULL);
1423         
1424         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Keyframes|K",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1425         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show and Select Keyframes|Shift K",0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1426         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Next Keyframe|PageUp",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1427         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Previous Keyframe|PageDown",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
1428
1429         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1430
1431         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Next Keyframe|Ctrl PageUp",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1432         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Previous Keyframe|Ctrl PageDown",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
1433
1434         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1435
1436         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Next Frame|RightArrow",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
1437         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Previous Frame|LeftArrow",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, "");
1438         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Forward 10 Frames|UpArrow",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, "");
1439         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Back 10 Frames|DownArrow",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
1440
1441         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1442
1443         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "End Frame|Shift RightArrow",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
1444         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Start Frame|Shift LeftArrow",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
1445
1446         uiBlockSetDirection(block, UI_DOWN);
1447         uiTextBoundsBlock(block, 80);
1448
1449         return block;
1450 }
1451
1452 /************************** RENDER *****************************/
1453
1454 static void do_info_rendermenu(void *arg, int event)
1455 {
1456
1457         extern void playback_anim();
1458
1459         switch(event) {
1460                 
1461         case 0:
1462                 BIF_do_render(0);
1463                 break;
1464         case 1:
1465                 BIF_do_render(1);
1466                 break;
1467
1468                 /* note: dont use select_area() for setting active areas for opengl render */
1469                 /* its hackish and instable... code here was removed */
1470         
1471         case 4:
1472                 BIF_toggle_render_display();
1473                 break;
1474         case 5:
1475                 playback_anim();
1476                 break;
1477         case 6:
1478                 /* dodgy hack turning on SHIFT key to do a proper render border select
1479                 set_render_border(); only works when 3d window active
1480                 
1481                 This code copied from toolbox.c, only works when 3d window is cameraview */
1482
1483                 if(select_area(SPACE_VIEW3D)) {
1484                         mainqenter(LEFTSHIFTKEY, 1);
1485                         mainqenter(BKEY, 1);
1486                         mainqenter(BKEY, 0);
1487                         mainqenter(EXECUTE, 1);
1488                         mainqenter(LEFTSHIFTKEY, 0);
1489                 }
1490
1491                 break;
1492
1493                 case 7:
1494                 extern_set_butspace(F10KEY);
1495                 break;
1496         }
1497         allqueue(REDRAWINFO, 0);
1498 }
1499
1500 static uiBlock *info_rendermenu(void *arg_unused)
1501 {
1502 /*              static short tog=0; */
1503         uiBlock *block;
1504         short yco= 0;
1505         short menuwidth=120;
1506         
1507         block= uiNewBlock(&curarea->uiblocks, "rendermenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1508         uiBlockSetButmFunc(block, do_info_rendermenu, NULL);
1509         
1510         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Current Frame|F12",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
1511         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Animation",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1512
1513         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1514
1515         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Render Buffer|F11",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
1516         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Rendered Animation",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1517
1518         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1519
1520         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Render Border|Shift B",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
1521
1522         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1523
1524         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Settings|F10",            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
1525
1526         uiBlockSetDirection(block, UI_DOWN);
1527         uiTextBoundsBlock(block, 80);
1528
1529         return block;
1530 }
1531
1532 /************************** HELP *****************************/
1533
1534 static void do_info_help_websitesmenu(void *arg, int event)
1535 {
1536         BPY_menu_do_python(PYMENU_HELPWEBSITES, event);
1537
1538         allqueue(REDRAWVIEW3D, 0);
1539 }
1540
1541
1542 static uiBlock *info_help_websitesmenu(void *arg_unused)
1543 {
1544         uiBlock *block;
1545         BPyMenu *pym;
1546         short yco = 20, menuwidth = 120;
1547         int i = 0;
1548
1549         block= uiNewBlock(&curarea->uiblocks, "info_help_websitesmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1550         uiBlockSetButmFunc(block, do_info_help_websitesmenu, NULL);
1551         
1552         for (pym = BPyMenuTable[PYMENU_HELPWEBSITES]; pym; pym = pym->next, i++) {
1553                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i, pym->tooltip?pym->tooltip:pym->filename);
1554         }
1555         
1556         uiBlockSetDirection(block, UI_RIGHT);
1557         uiTextBoundsBlock(block, 60);
1558                 
1559         return block;
1560 }
1561
1562 static void do_info_help_systemmenu(void *arg, int event)
1563 {
1564         /* events >=10 are registered bpython scripts */
1565         if (event >= 10) BPY_menu_do_python(PYMENU_HELPSYSTEM, event - 10);
1566         else {
1567                 switch(event) {
1568
1569                 case 1: /* Benchmark */
1570                         /* dodgy hack turning on CTRL ALT SHIFT key to do a benchmark 
1571                          *      rather than copying lines and lines of code from toets.c :( 
1572                          */
1573         
1574                         if(select_area(SPACE_VIEW3D)) {
1575                                 mainqenter(LEFTSHIFTKEY, 1);
1576                                 mainqenter(LEFTCTRLKEY, 1);
1577                                 mainqenter(LEFTALTKEY, 1);
1578                                 mainqenter(TKEY, 1);
1579                                 mainqenter(TKEY, 0);
1580                                 mainqenter(EXECUTE, 1);
1581                                 mainqenter(LEFTSHIFTKEY, 0);
1582                                 mainqenter(LEFTCTRLKEY, 0);
1583                                 mainqenter(LEFTALTKEY, 0);
1584                         }
1585                         break;
1586                 }
1587         }
1588
1589         allqueue(REDRAWVIEW3D, 0);
1590 }
1591
1592
1593 static uiBlock *info_help_systemmenu(void *arg_unused)
1594 {
1595         uiBlock *block;
1596         BPyMenu *pym;
1597         short yco = 20, menuwidth = 120;
1598         int i = 0;
1599
1600         block= uiNewBlock(&curarea->uiblocks, "info_help_systemmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1601         uiBlockSetButmFunc(block, do_info_help_systemmenu, NULL);
1602         
1603         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Benchmark",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1604         
1605         for (pym = BPyMenuTable[PYMENU_HELPSYSTEM]; pym; pym = pym->next, i++) {
1606                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i+10, pym->tooltip?pym->tooltip:pym->filename);
1607         }
1608         
1609         uiBlockSetDirection(block, UI_RIGHT);
1610         uiTextBoundsBlock(block, 60);
1611                 
1612         return block;
1613 }
1614
1615 static void do_info_helpmenu(void *arg, int event)
1616 {
1617         ScrArea *sa;
1618
1619         if(curarea->spacetype==SPACE_INFO) {
1620                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
1621                 if (!sa) sa= closest_bigger_area();
1622                 areawinset(sa->win);
1623         }
1624
1625         /* events >=10 are registered bpython scripts */
1626         if (event >= 10) BPY_menu_do_python(PYMENU_HELP, event - 10);
1627         else {
1628                 switch(event) {
1629                                                                         
1630                 case 0: /* About Blender */
1631                         break;
1632                 }
1633         }
1634
1635         allqueue(REDRAWINFO, 0);
1636 }
1637
1638 static uiBlock *info_helpmenu(void *arg_unused)
1639 {
1640 /*              static short tog=0; */
1641         uiBlock *block;
1642         short yco= 0;
1643         short menuwidth=120;
1644         BPyMenu *pym;
1645         int i = 0;
1646         
1647         block= uiNewBlock(&curarea->uiblocks, "info_helpmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1648         uiBlockSetButmFunc(block, do_info_helpmenu, NULL);
1649         
1650         uiDefIconTextBut(block, BUTM, B_SHOWSPLASH, ICON_BLANK1, "About Blender...",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
1651         
1652         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1653         
1654         for (pym = BPyMenuTable[PYMENU_HELP]; pym; pym = pym->next, i++) {
1655                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i+10, pym->tooltip?pym->tooltip:pym->filename);
1656         }
1657         
1658         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1659         
1660         uiDefIconTextBlockBut(block, info_help_websitesmenu, NULL, ICON_RIGHTARROW_THIN, "Websites", 0, yco-=20, 120, 19, "");
1661         
1662         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1663         
1664         uiDefIconTextBlockBut(block, info_help_systemmenu, NULL, ICON_RIGHTARROW_THIN, "System", 0, yco-=20, 120, 19, "");
1665
1666         uiBlockSetDirection(block, UI_DOWN);
1667         uiTextBoundsBlock(block, 80);
1668
1669         return block;
1670 }
1671
1672 /************************** END MAIN MENU *****************************/
1673 /* ugly global yes, for renderwin.c to write to */
1674 char info_time_str[32]="";
1675
1676 static void info_text(int x, int y)
1677 {
1678         Object *ob= OBACT;
1679         extern float hashvectf[];
1680         extern int mem_in_use;
1681         unsigned int swatch_color;
1682         float fac1, fac2, fac3;
1683         char infostr[300];
1684         char *headerstr;
1685         int hsize;
1686
1687         if(G.obedit) {
1688                 char *s = infostr;
1689
1690                 s+= sprintf(s, "%s", G.editModeTitleExtra);
1691                 if(G.obedit->type==OB_MESH) {
1692                         if(G.scene->selectmode & SCE_SELECT_VERTEX)
1693                                 s+= sprintf(s,"Ve:%d-%d | Ed:%d-%d | Fa:%d-%d",
1694                                                 G.totvertsel, G.totvert, G.totedgesel, G.totedge, G.totfacesel, G.totface);
1695                         else if(G.scene->selectmode & SCE_SELECT_EDGE)
1696                                 s+= sprintf(s,"Ed:%d-%d | Fa:%d-%d",
1697                                                 G.totedgesel, G.totedge, G.totfacesel, G.totface);
1698                         else 
1699                                 s+= sprintf(s,"Fa:%d-%d", G.totfacesel, G.totface);
1700                 }
1701                 else if(G.obedit->type==OB_ARMATURE) {
1702                         s+= sprintf(s,"Ve:%d-%d | Bo:%d-%d", G.totvertsel, G.totvert, G.totbonesel, G.totbone);
1703                 }
1704                 else {
1705                         s+= sprintf(s,"Ve:%d-%d", G.totvertsel, G.totvert);
1706                 }
1707
1708                 sprintf(s," | Mem:%.2fM ", (mem_in_use>>10)/1024.0);
1709         }
1710         else if(ob && (ob->flag & OB_POSEMODE)) {
1711                 sprintf(infostr,"Bo:%d-%d | Mem:%.2fM ",
1712                                         G.totbonesel, G.totbone, (mem_in_use>>10)/1024.0);
1713         }
1714         else {
1715                 sprintf(infostr,"Ve:%d | Fa:%d | Ob:%d-%d | La:%d | Mem:%.2fM | Time:%s | ",
1716                         G.totvert, G.totface, G.totobj, G.totobjsel, G.totlamp,  (mem_in_use>>10)/1024.0, info_time_str);
1717         }
1718         if(ob) {
1719                 strcat(infostr, ob->id.name+2);
1720         }
1721
1722         if (g_progress_bar && g_progress_info) {
1723                 headerstr= g_progress_info;
1724         } else {
1725                 headerstr= versionstr; 
1726         }
1727
1728         if      (g_progress_bar) {
1729                 hsize = 4 + (138.0 * g_done);
1730                 fac1 = 0.5 * g_done; // do some rainbow colours on progress
1731                 fac2 = 1.0;
1732                 fac3 = 0.9;
1733         } else {
1734                 hsize= 30+BIF_GetStringWidth(G.font, headerstr, (U.transopts & USER_TR_BUTTONS));
1735
1736                 /* promise! Never change these lines again! (zr & ton did!) */
1737                 fac1= fabs(hashvectf[ 2*G.version+4]);
1738                 fac2= 0.5+0.1*hashvectf[ G.version+3];
1739                 fac3= 0.7;
1740         }
1741         
1742         swatch_color= hsv_to_cpack(fac1, fac2, fac3);
1743
1744         cpack( swatch_color );
1745         glRecti(x-24,  y-6,  x-30+hsize,        y+14);
1746
1747         glColor3ub(0, 0, 0); /* makes text black colored rect */
1748         
1749         glRasterPos2i(x, y);
1750         BIF_RasterPos(x, y);
1751
1752         BIF_DrawString(G.font, headerstr, (U.transopts & USER_TR_MENUS));
1753         hsize= BIF_GetStringWidth(G.font, headerstr, (U.transopts & USER_TR_BUTTONS));
1754         
1755         BIF_ThemeColor(TH_MENU_TEXT); /* makes text readable on dark theme */
1756         
1757         glRasterPos2i(x+hsize+10,       y);
1758         BIF_RasterPos(x+hsize+10,       y);
1759         
1760         BIF_DrawString(G.font, infostr, (U.transopts & USER_TR_MENUS));
1761 }
1762
1763 void info_buttons(void)
1764 {
1765         uiBlock *block;
1766         short xco= 42;
1767         int xmax;
1768
1769         block= uiNewBlock(&curarea->uiblocks, "header info", UI_EMBOSSN, UI_HELV, curarea->headwin);
1770
1771         if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
1772         else uiBlockSetCol(block, TH_HEADERDESEL);
1773         
1774         if(curarea->flag & HEADER_NO_PULLDOWN) {
1775                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_RIGHT,
1776                                 xco,2,XIC,YIC-2,
1777                                 &(curarea->flag), 0, 0, 0, 0, "Enables display of pulldown menus");
1778         } else {
1779                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_DOWN,
1780                                 xco,2,XIC,YIC-2,
1781                                 &(curarea->flag), 0, 0, 0, 0, "Hides pulldown menus");
1782         }
1783         xco+=XIC;
1784
1785         if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
1786         
1787                 uiBlockSetEmboss(block, UI_EMBOSSP);
1788
1789                 /* the 'xmax - 3' rather than xmax is to prevent some weird flickering where the highlighted
1790                  * menu is drawn wider than it should be. The ypos of -1 is to make it properly fill the
1791                  * height of the header */
1792                 xmax= GetButStringLength("File");
1793                 uiDefPulldownBut(block, info_filemenu, NULL, "File",    xco, -1, xmax-3, 22, "");
1794                 xco+= xmax;
1795
1796                 xmax= GetButStringLength("Add");
1797                 uiDefPulldownBut(block, info_addmenu, NULL, "Add",      xco, -1, xmax-3, 22, "");
1798                 xco+= xmax;
1799
1800                 xmax= GetButStringLength("Timeline");
1801                 uiDefPulldownBut(block, info_timelinemenu, NULL, "Timeline",    xco, -1, xmax-3, 22, "");
1802                 xco+= xmax;
1803
1804                 xmax= GetButStringLength("Game");
1805                 uiDefPulldownBut(block, info_gamemenu, NULL, "Game",    xco, -1, xmax-3, 22, "");
1806                 xco+= xmax;
1807
1808                 xmax= GetButStringLength("Render");
1809                 uiDefPulldownBut(block, info_rendermenu, NULL, "Render",        xco, -1, xmax-3, 22, "");
1810                 xco+= xmax;
1811
1812                 xmax= GetButStringLength("Help");
1813                 uiDefPulldownBut(block, info_helpmenu, NULL, "Help",    xco, -1, xmax-3, 22, "");
1814                 xco+= xmax;
1815
1816         }
1817
1818         /* pack icon indicates a packed file */
1819         
1820         if (G.fileflags & G_AUTOPACK) {
1821                 uiBlockSetEmboss(block, UI_EMBOSSN);
1822                 uiDefIconBut(block, LABEL, 0, ICON_PACKAGE, xco, 0, XIC, YIC, &G.fileflags, 0.0, 0.0, 0, 0, "Indicates this is a Packed file. See File menu.");
1823                 xco += XIC;
1824         }
1825
1826         if (curarea->full == 0) {
1827                 curarea->butspacetype= SPACE_INFO;
1828                 uiBlockSetEmboss(block, UI_EMBOSS);
1829                 uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D, windowtype_pup(), 8,0,XIC+10,YIC, &(curarea->butspacetype), 1.0, SPACEICONMAX, 0, 0, "Displays Current Window Type. Click for menu of available types.");
1830                 
1831                 /* STD SCREEN BUTTONS */
1832                 xco= std_libbuttons(block, xco, 0, 0, NULL, B_INFOSCR, ID_SCR, 0, (ID *)G.curscreen, 0, &G.curscreen->screennr, 1, 1, B_INFODELSCR, 0, 0);
1833                 
1834                 xco +=8;
1835         
1836                 /* STD SCENE BUTTONS */
1837                 xco= std_libbuttons(block, xco, 0, 0, NULL, B_INFOSCE, ID_SCE, 0, (ID *)G.scene, 0, &G.curscreen->scenenr, 1, 1, B_INFODELSCE, 0, 0);
1838         }
1839         else xco= 430;
1840         
1841 BIF_SetScale(block->aspect);
1842         info_text(xco+24, 6);
1843         
1844         uiBlockSetEmboss(block, UI_EMBOSSN);
1845         uiDefIconBut(block, BUT, B_SHOWSPLASH, ICON_BLENDER, xco+2, 0,XIC,YIC, 0, 0, 0, 0, 0, "Click to display Splash Screen");
1846
1847         /* always do as last */
1848         curarea->headbutlen= xco+2*XIC;
1849
1850 #if 0
1851 // #ifdef _WIN32        // FULLSCREEN
1852         if(U.uiflag & USER_FLIPFULLSCREEN) {
1853                 uiDefIconBut(block, BUT, B_FLIPFULLSCREEN, ICON_WINDOW_WINDOW,
1854                                 (short)(curarea->winx-XIC-5), 0,XIC,YIC,
1855                                 0, 0, 0, 0, 0, "Toggles Blender to fullscreen mode");/* dir             */
1856         } else {
1857                 uiDefIconBut(block, BUT, B_FLIPFULLSCREEN, ICON_WINDOW_FULLSCREEN,
1858                                 (short)(curarea->winx-XIC-5), 0,XIC,YIC,
1859                                 0, 0, 0, 0, 0, "Toggles Blender to fullscreen mode");/* dir             */
1860         }
1861 #endif
1862         
1863         uiDrawBlock(block);
1864 }