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