fix for #2592
[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 #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= 0;
310         scen->radio= 0;
311         scen->theDag= NULL;
312         scen->dagisvalid= 0;
313
314         obase= sce->base.first;
315         base= scen->base.first;
316         while(base) {
317                 base->object->id.us++;
318                 if(obase==sce->basact) scen->basact= base;
319
320                 obase= obase->next;
321                 base= base->next;
322         }
323
324         if(level==0) return scen;
325
326         /* level 1 */
327         G.scene= scen;
328         single_object_users(0);
329
330         /*      camera */
331         ID_NEW(G.scene->camera);
332
333         /* level 2 */
334         if(level>=2) {
335                 if(scen->world) {
336                         scen->world->id.us--;
337                         scen->world= copy_world(scen->world);
338                 }
339                 single_obdata_users(0);
340                 single_mat_users_expand();
341                 single_tex_users_expand();
342         }
343
344         clear_id_newpoins();
345
346         BPY_copy_scriptlink(&sce->scriptlink);
347
348         // make a private copy of the avicodecdata
349
350         if (sce->r.avicodecdata) {
351
352                 scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata);
353                 scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecdata->lpFormat);
354                 scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecdata->lpParms);
355         }
356
357         // make a private copy of the qtcodecdata
358
359         if (sce->r.qtcodecdata) {
360                 scen->r.qtcodecdata = MEM_dupallocN(sce->r.qtcodecdata);
361                 scen->r.qtcodecdata->cdParms = MEM_dupallocN(scen->r.qtcodecdata->cdParms);
362         }
363
364         return scen;
365 }
366
367 void do_info_buttons(unsigned short event)
368 {
369         bScreen *sc, *oldscreen;
370         Scene *sce, *sce1;
371         ScrArea *sa;
372         int nr;
373
374         switch(event) {
375         case B_INFOSCR:         /* menu select screen */
376
377                 if( G.curscreen->screennr== -2) {
378                         if(curarea->winy <50) {
379                                 sa= closest_bigger_area();
380                                 areawinset(sa->win);
381                         }
382                         activate_databrowse((ID *)G.curscreen, ID_SCR, 0, B_INFOSCR,
383                                                                                         &G.curscreen->screennr, do_info_buttons);
384                         return;
385                 }
386                 if( G.curscreen->screennr < 0) return;
387
388                 sc= G.main->screen.first;
389                 nr= 1;
390                 while(sc) {
391                         if(nr==G.curscreen->screennr) {
392                                 if(is_allowed_to_change_screen(sc)) setscreen(sc);
393                                 else error("Unable to perform function in EditMode");
394                                 break;
395                         }
396                         nr++;
397                         sc= sc->id.next;
398                 }
399                 /* last item: NEW SCREEN */
400                 if(sc==0) {
401                         duplicate_screen();
402                 }
403                 break;
404         case B_INFODELSCR:
405 /*do this event only with buttons, so it can never be called with full-window*/
406
407                 if(G.curscreen->id.prev) sc= G.curscreen->id.prev;
408                 else if(G.curscreen->id.next) sc= G.curscreen->id.next;
409                 else return;
410                 if(okee("Delete current screen")) {
411                         /* find new G.curscreen */
412
413                         oldscreen= G.curscreen;
414                         setscreen(sc);          /* this test if sc has a full */
415                         unlink_screen(oldscreen);
416                         free_libblock(&G.main->screen, oldscreen);
417                 }
418                 scrarea_queue_headredraw(curarea);
419
420                 break;
421         case B_INFOSCE:         /* menu select scene */
422
423                 if( G.curscreen->scenenr== -2) {
424                         if(curarea->winy <50) {
425                                 sa= closest_bigger_area();
426                                 areawinset(sa->win);
427                         }
428                         activate_databrowse((ID *)G.scene, ID_SCE, 0, B_INFOSCE,
429                                                                                         &G.curscreen->scenenr, do_info_buttons);
430                         return;
431                 }
432                 if( G.curscreen->scenenr < 0) return;
433
434                 sce= G.main->scene.first;
435                 nr= 1;
436                 while(sce) {
437                         if(nr==G.curscreen->scenenr) {
438                                 if(sce!=G.scene) set_scene(sce);
439                                 break;
440                         }
441                         nr++;
442                         sce= sce->id.next;
443                 }
444                 /* last item: NEW SCENE */
445                 if(sce==0) {
446                         nr= pupmenu("Add scene%t|Empty|Link Objects|Link ObData|Full Copy");
447                         if(nr<= 0) return;
448                         if(nr==1) {
449                                 sce= add_scene(G.scene->id.name+2);
450                                 sce->r= G.scene->r;
451 #ifdef _WIN32
452                                 if (sce->r.avicodecdata) {
453                                         sce->r.avicodecdata = MEM_dupallocN(G.scene->r.avicodecdata);
454                                         sce->r.avicodecdata->lpFormat = MEM_dupallocN(G.scene->r.avicodecdata->lpFormat);
455                                         sce->r.avicodecdata->lpParms = MEM_dupallocN(G.scene->r.avicodecdata->lpParms);
456                                 }
457 #endif
458 #ifdef WITH_QUICKTIME
459                                 if (sce->r.qtcodecdata) {
460                                         sce->r.qtcodecdata = MEM_dupallocN(G.scene->r.qtcodecdata);
461                                         sce->r.qtcodecdata->cdParms = MEM_dupallocN(G.scene->r.qtcodecdata->cdParms);
462                                 }
463 #endif
464                         }
465                         else sce= copy_scene(G.scene, nr-2);
466
467                         set_scene(sce);
468                 }
469                 BIF_preview_changed(G.buts);
470
471                 break;
472         case B_INFODELSCE:
473
474                 if(G.scene->id.prev) sce= G.scene->id.prev;
475                 else if(G.scene->id.next) sce= G.scene->id.next;
476                 else return;
477                 if(okee("Delete current scene")) {
478
479                         /* check all sets */
480                         sce1= G.main->scene.first;
481                         while(sce1) {
482                                 if(sce1->set == G.scene) sce1->set= 0;
483                                 sce1= sce1->id.next;
484                         }
485
486                         /* check all sequences */
487                         clear_scene_in_allseqs(G.scene);
488
489                         /* al screens */
490                         sc= G.main->screen.first;
491                         while(sc) {
492                                 if(sc->scene == G.scene) sc->scene= sce;
493                                 sc= sc->id.next;
494                         }
495                         free_libblock(&G.main->scene, G.scene);
496                         set_scene(sce);
497                 }
498
499                 break;
500         }
501 }
502
503 static void check_packAll()
504 {
505         // first check for dirty images
506         Image *ima;
507
508         ima = G.main->image.first;
509         while (ima) {
510                 if (ima->ibuf && (ima->ibuf->userflags &= IB_BITMAPDIRTY)) {
511                         break;
512                 }
513                 ima= ima->id.next;
514                 }
515         
516         if (ima == 0 || okee("Some images are painted on. These changes will be lost. Continue ?")) {
517                 packAll();
518                 G.fileflags |= G_AUTOPACK;
519         }
520 }
521
522 static int write_runtime(char *str, char *exename)
523 {
524         char *freestr= NULL;
525         char *ext = 0;
526
527 #ifdef _WIN32
528         ext = ".exe";
529 #endif
530
531 #ifdef __APPLE__
532         ext = ".app";
533 #endif
534         if (ext && (!BLI_testextensie(str, ext))) {
535                 freestr= MEM_mallocN(strlen(str) + strlen(ext) + 1, "write_runtime_check");
536                 strcpy(freestr, str);
537                 strcat(freestr, ext);
538                 str= freestr;
539         }
540
541         if (!BLI_exists(str) || saveover(str))
542                 BLO_write_runtime(str, exename);
543
544         if (freestr)
545                 MEM_freeN(freestr);
546  
547         return 0;
548 }
549
550 static void write_runtime_check_dynamic(char *str) 
551 {
552         write_runtime(str, "blenderdynplayer.exe");
553 }
554
555 static void write_runtime_check(char *str) 
556 {
557         char player[128];
558
559         strcpy(player, "blenderplayer");
560
561 #ifdef _WIN32
562         strcat(player, ".exe");
563 #endif
564
565 #ifdef __APPLE__
566         strcat(player, ".app");
567 #endif
568
569         write_runtime(str, player);
570 }
571 /* end keyed functions */
572
573 /************************** MAIN MENU *****************************/
574 /************************** FILE *****************************/
575
576 #if 0
577 static void do_info_file_optionsmenu(void *arg, int event)
578 {
579         G.fileflags ^= (1 << event);
580
581         // allqueue(REDRAWINFO, 0);
582 }
583 #endif
584
585 #if GAMEBLENDER == 1
586
587 #if 0
588 static uiBlock *info_file_optionsmenu(void *arg_unused)
589 {
590         uiBlock *block;
591         short yco= 0, xco = 20;
592
593         block= uiNewBlock(&curarea->uiblocks, "runtime_options", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
594         uiBlockSetButmFunc(block, do_info_file_optionsmenu, NULL);
595         uiBlockSetXOfs(block,-40);      // offset to parent button
596         
597         /* flags are case-values */
598         uiDefBut(block, BUTM, 1, "Compress File",       xco, yco-=20, 100, 19, NULL, 0.0, 0.0, 0, G_FILE_COMPRESS_BIT, "Enables file compression");
599 /*
600         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");
601         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");
602 */
603         uiTextBoundsBlock(block, 50);
604
605         /* Toggle buttons */
606         
607         yco= 0;
608         xco -= 20;
609         uiBlockSetEmboss(block, UI_EMBOSSM);
610         uiBlockSetButmFunc(block, NULL, NULL);
611         /* flags are defines */
612         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, "");
613 /*
614         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, "");
615         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, "");
616 */
617         uiBlockSetDirection(block, UI_RIGHT);
618                 
619         return block;
620 }
621
622 static uiBlock *info_runtime_optionsmenu(void *arg_unused)
623 {
624         uiBlock *block;
625         short yco= 0, xco = 20;
626
627         block= uiNewBlock(&curarea->uiblocks, "add_surfacemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
628         uiBlockSetXOfs(block, -40);  // offset to parent button
629         uiBlockSetEmboss(block, UI_EMBOSSM);
630
631         uiDefBut(block, LABEL, 0, "Size options:",              xco, yco-=20, 114, 19, 0, 0.0, 0.0, 0, 0, "");
632         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.");
633         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.");
634
635         uiDefBut(block, SEPR, 0, "",            xco, yco-=4, 114, 4, NULL, 0.0, 0.0, 0, 0, "");
636
637         uiDefBut(block, LABEL, 0, "Fullscreen options:",                xco, yco-=20, 114, 19, 0, 0.0, 0.0, 0, 0, "");
638         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");
639         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.");
640         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.");
641
642         uiDefBut(block, SEPR, 0, "",            xco, yco-=4, 114, 4, NULL, 0.0, 0.0, 0, 0, "");
643
644         /* stereo settings */
645         /* can't use any definition from the game engine here so hardcode it. Change it here when it changes there!
646          * RAS_IRasterizer has definitions:
647          * RAS_STEREO_NOSTEREO           1
648          * RAS_STEREO_QUADBUFFERED 2
649          * RAS_STEREO_ABOVEBELOW         3
650          * RAS_STEREO_INTERLACED         4       future
651          */
652         uiDefBut(block, LABEL, 0, "Stereo options", xco, yco-=20, 114, 19, 0, 0.0, 0.0, 0, 0, "");
653         uiDefButS(block, ROW, 0, "no stereo", xco+19, yco-=20, 95, 19, &(G.scene->r.stereomode), 6.0, 1.0, 0, 0, "Disables stereo");
654         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");
655         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");
656
657         uiBlockSetDirection(block, UI_RIGHT);
658         uiTextBoundsBlock(block, 50);
659                 
660         return block;
661 }
662 #endif
663
664 #endif
665
666 static void do_info_file_importmenu(void *arg, int event)
667 {
668         ScrArea *sa;
669
670         if(curarea->spacetype==SPACE_INFO) {
671                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
672                 if (!sa) sa= closest_bigger_area();
673                 areawinset(sa->win);
674         }
675
676         /* events >=4 are registered bpython scripts */
677         if (event >= 4) {
678                 BPY_menu_do_python(PYMENU_IMPORT, event - 4);
679                 BIF_undo_push("Import file");
680         }
681         else {
682                 switch(event) {
683                                                                         
684                 case 0: /* DXF */
685                         activate_fileselect(FILE_BLENDER, "Import DXF", G.sce, BIF_read_file);
686                         break;
687                 case 1: /* VRML 1.0 */
688                         activate_fileselect(FILE_BLENDER, "Import VRML 1.0", G.sce, BIF_read_file);
689                         break;
690                 case 2: /* VideoScape */
691                         activate_fileselect(FILE_BLENDER, "Import VideoScape", G.sce, BIF_read_file);
692                         break;
693                 case 3: /* STL */
694                         activate_fileselect(FILE_BLENDER, "Import STL", G.sce, BIF_read_file);
695                         break;
696
697                 }
698         }
699         allqueue(REDRAWINFO, 0);
700 }
701
702 static uiBlock *info_file_importmenu(void *arg_unused)
703 {
704         uiBlock *block;
705         short yco = 20, menuwidth = 120;
706         BPyMenu *pym;
707         int i = 0;
708
709         block= uiNewBlock(&curarea->uiblocks, "importmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
710         uiBlockSetButmFunc(block, do_info_file_importmenu, NULL);
711         //uiBlockSetXOfs(block, -50);  // offset to parent button
712         
713         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...",
714                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "");
715         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...",
716                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "");
717         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VideoScape...",
718                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "");
719         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "STL...",
720                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 3, "");
721
722         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
723
724         for (pym = BPyMenuTable[PYMENU_IMPORT]; pym; pym = pym->next, i++) {
725                 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);
726         }
727
728         uiBlockSetDirection(block, UI_RIGHT);
729         uiTextBoundsBlock(block, 60);
730
731         return block;
732 }
733
734 static void do_info_file_exportmenu(void *arg, int event)
735 {
736         ScrArea *sa;
737
738         if(curarea->spacetype==SPACE_INFO) {
739                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
740                 if (!sa) sa= closest_bigger_area();
741                 areawinset(sa->win);
742         }
743
744         /* events >=4 are registered bpython scripts */
745         if (event >= 4) BPY_menu_do_python(PYMENU_EXPORT, event - 4);
746
747         else switch(event) {
748                                                                         
749         case 0:
750                 write_vrml_fs();
751                 break;
752         case 1:
753                 write_dxf_fs();
754                 break;
755         case 2:
756                 write_videoscape_fs();
757                 break;
758         case 3:
759                 write_stl_fs();
760                 break;
761         }
762         allqueue(REDRAWINFO, 0);
763 }
764
765 static uiBlock *info_file_exportmenu(void *arg_unused)
766 {
767         uiBlock *block;
768         short yco = 20, menuwidth = 120;
769         BPyMenu *pym;
770         int i = 0;
771
772         block= uiNewBlock(&curarea->uiblocks, "exportmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
773         uiBlockSetButmFunc(block, do_info_file_exportmenu, NULL);
774         //uiBlockSetXOfs(block, -50);  // offset to parent button
775
776         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...|Ctrl F2",
777                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "");
778         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...|Shift F2",
779                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "");
780         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Videoscape...|Alt W",
781                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "");
782         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "STL...",
783                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 3, "");
784
785         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
786
787         /* note that we acount for the 3 previous entries with i+3: */
788         for (pym = BPyMenuTable[PYMENU_EXPORT]; pym; pym = pym->next, i++) {
789                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
790                                  NULL, 0.0, 0.0, 1, i+4, 
791                                  pym->tooltip?pym->tooltip:pym->filename);
792         }
793
794
795         uiBlockSetDirection(block, UI_RIGHT);
796         uiTextBoundsBlock(block, 60);
797
798         return block;
799 }
800
801 static void do_info_filemenu(void *arg, int event)
802 {
803         ScrArea *sa;
804         char dir[FILE_MAXDIR];
805         
806         if(curarea->spacetype==SPACE_INFO) {
807                 sa= closest_bigger_area();
808                 areawinset(sa->win);
809         }
810
811         /* these are no defines, easier this way, the codes are in the function below */
812         switch(event) {
813         case 0:
814                 if (okee("Erase All")) {
815                         if (!BIF_read_homefile())
816                                 error("No file ~/.B.blend");
817                 }
818                 break;
819         case 1: /* open */
820                 activate_fileselect(FILE_BLENDER, "Open", G.sce, BIF_read_file);
821                 break;
822         case 2: /* reopen last */
823                 {
824                         char *s= MEM_mallocN(strlen(G.sce) + 11 + 1, "okee_reload");
825                         strcpy(s, "Open file: ");
826                         strcat(s, G.sce);
827                         if (okee(s)) BIF_read_file(G.sce);
828                         MEM_freeN(s);
829                 }
830                 break;
831         case 3: /* append */
832                 activate_fileselect(FILE_LOADLIB, "Load Library", G.lib, 0);
833                 break;
834         case 4: /* save */
835                 strcpy(dir, G.sce);
836                 untitled(dir);
837                 activate_fileselect(FILE_BLENDER, "Save As", dir, BIF_write_file);
838                 break;
839         case 5:
840                 strcpy(dir, G.sce);
841                 if (untitled(dir)) {
842                         activate_fileselect(FILE_BLENDER, "Save As", dir, BIF_write_file);
843                 } else {
844                         BIF_write_file(dir);
845                         free_filesel_spec(dir);
846                 }
847                 break;
848         case 6: /* save image */
849                 BIF_save_rendered_image();
850                 break;
851         case 22: /* save runtime */
852                 activate_fileselect(FILE_SPECIAL, "Save Runtime", "", write_runtime_check);
853                 break;
854         case 23: /* save dynamic runtime */
855                 activate_fileselect(FILE_SPECIAL, "Save Dynamic Runtime", "", write_runtime_check_dynamic);
856                 break;
857         case 24:
858                 BIF_screendump(0);
859                 break;
860         case 25:
861                 BIF_screendump(1);
862                 break;
863         case 10: /* pack data */
864                 check_packAll();
865                 break;
866         case 11: /* unpack to current dir */
867                 unpackAll(PF_WRITE_LOCAL);
868                 G.fileflags &= ~G_AUTOPACK;
869                 break;
870         case 12: /* unpack data */
871                 if (buttons_do_unpack() != RET_CANCEL) {
872                         /* Clear autopack bit only if user selected one of the unpack options */
873                         G.fileflags &= ~G_AUTOPACK;
874                 }
875                 break;
876         case 13:
877                 exit_usiblender();
878                 break;
879         case 15:        /* recover previous session */
880                 {
881                         extern short winqueue_break; /* editscreen.c */
882                         int save_over;
883                         char str[FILE_MAXDIR+FILE_MAXFILE];
884                         char scestr[FILE_MAXDIR+FILE_MAXFILE];
885                         
886                         strcpy(scestr, G.sce);  /* temporal store */
887                         save_over = G.save_over;
888                         BLI_make_file_string("/", str, U.tempdir, "quit.blend");
889                         BKE_read_file(str, NULL);
890                         G.save_over = save_over;
891                         strcpy(G.sce, scestr);
892
893                         winqueue_break= 1;      /* leave queues everywhere */
894                 
895                         BKE_reset_undo();
896                         BKE_write_undo("original");     /* save current state */
897                         refresh_interface_font();
898                 }
899                 break;
900         case 31: /* save default settings */
901                 BIF_write_homefile();
902                 break;
903         }
904         allqueue(REDRAWINFO, 0);
905 }
906
907 static uiBlock *info_filemenu(void *arg_unused)
908 {
909         uiBlock *block;
910         short yco=0;
911         short menuwidth=120;
912
913         block= uiNewBlock(&curarea->uiblocks, "info_filemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
914         uiBlockSetButmFunc(block, do_info_filemenu, NULL);
915         
916         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "New|Ctrl X",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
917         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Open...|F1",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
918         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reopen Last|Ctrl O",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
919         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Recover Last Session",                           0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 15, "");
920
921         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
922
923         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save|Ctrl W",                            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
924         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save As...|F2",                  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
925
926         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
927
928         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Image...|F3",                       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
929         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Dump 3DView|Ctrl F3",                    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 24, "");
930         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Dump Screen|Ctrl Shift F3",                      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 25, "");
931 #if GAMEBLENDER == 1
932         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Runtime...",                        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 22, "");
933 #ifdef _WIN32
934         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Dynamic Runtime...",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 23, "");
935 #endif
936 #endif
937         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
938
939         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Default Settings|Ctrl U",                   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 31, "");
940
941
942         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
943
944         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Append...|Shift F1",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
945         uiDefIconTextBlockBut(block, info_file_importmenu, NULL, ICON_RIGHTARROW_THIN, "Import", 0, yco-=20, menuwidth, 19, "");
946         uiDefIconTextBlockBut(block, info_file_exportmenu, NULL, ICON_RIGHTARROW_THIN, "Export", 0, yco-=20, menuwidth, 19, "");
947         
948         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
949
950         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Data",                              0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "");
951 //      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");
952         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpack Data...",                         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 12, "");
953
954         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
955
956         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Quit Blender| Q",                                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 13, "");
957
958         uiBlockSetDirection(block, UI_DOWN);
959         uiTextBoundsBlock(block, 80);
960
961         return block;
962 }
963
964 /**************************** ADD ******************************/
965
966 void do_info_add_meshmenu(void *arg, int event)
967 {
968
969         switch(event) {         
970                 case 0:
971                         /* Plane */
972                         add_primitiveMesh(0);
973                         break;
974                 case 1:
975                         /* Cube */
976                         add_primitiveMesh(1);
977                         break;
978                 case 2:
979                         /* Circle */
980                         add_primitiveMesh(4);
981                         break;
982                 case 3:
983                         /* UVsphere */
984                         add_primitiveMesh(11);
985                         break;
986                 case 4:
987                         /* IcoSphere */
988                         add_primitiveMesh(12);
989                         break;
990                 case 5:
991                         /* Cylinder */
992                         add_primitiveMesh(5);
993                         break;
994                 case 6:
995                         /* Tube */
996                         add_primitiveMesh(6);
997                         break;
998                 case 7:
999                         /* Cone */
1000                         add_primitiveMesh(7);
1001                         break;
1002                 case 8:
1003                         /* Grid */
1004                         add_primitiveMesh(10);
1005                         break;
1006                 case 9:
1007                         /* Monkey */
1008                         add_primitiveMesh(13);
1009                         break;
1010                 default:
1011                         break;
1012         }
1013         allqueue(REDRAWINFO, 0);
1014 }
1015
1016 static uiBlock *info_add_meshmenu(void *arg_unused)
1017 {
1018 /*              static short tog=0; */
1019         uiBlock *block;
1020         short yco= 0;
1021         
1022         block= uiNewBlock(&curarea->uiblocks, "add_meshmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1023         uiBlockSetButmFunc(block, do_info_add_meshmenu, NULL);
1024         
1025         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Plane|",                         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1026         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cube|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1027         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Circle|",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1028         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "UVsphere",                       0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1029         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "IcoSphere|",                     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1030         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cylinder|",                      0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
1031         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Tube|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 6, "");
1032         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cone|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "");
1033         uiDefIconTextBut(block, SEPR, 0, ICON_BLANK1, "",                                       0, yco-=6,      160, 6,  NULL, 0.0, 0.0, 0, 0, "");
1034         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grid|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "");
1035         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Monkey|",                        0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 9, "");
1036
1037         uiBlockSetDirection(block, UI_RIGHT);
1038         uiTextBoundsBlock(block, 50);
1039                 
1040         return block;
1041 }
1042
1043 void do_info_add_curvemenu(void *arg, int event)
1044 {
1045
1046         switch(event) {         
1047                 case 0:
1048                         /* Bezier Curve */
1049                         add_primitiveCurve(10);
1050                         break;
1051                 case 1:
1052                         /* Bezier Circle */
1053                         add_primitiveCurve(11);
1054                         break;
1055                 case 2:
1056                         /* NURB Curve */
1057                         add_primitiveCurve(40);
1058                         break;
1059                 case 3:
1060                         /* NURB Circle */
1061                         add_primitiveCurve(41);
1062                         break;
1063                 case 4:
1064                         /* Path */
1065                         add_primitiveCurve(46);
1066                         break;
1067                 default:
1068                         break;
1069         }
1070         allqueue(REDRAWINFO, 0);
1071 }
1072
1073 static uiBlock *info_add_curvemenu(void *arg_unused)
1074 {
1075 /*              static short tog=0; */
1076         uiBlock *block;
1077         short yco= 0;
1078         
1079         block= uiNewBlock(&curarea->uiblocks, "add_curvemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1080         uiBlockSetButmFunc(block, do_info_add_curvemenu, NULL);
1081         
1082         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Bezier Curve|",  0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1083         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Bezier Circle|", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1084         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Curve|",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1085         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Circle",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1086         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Path|",                  0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1087
1088         uiBlockSetDirection(block, UI_RIGHT);
1089         uiTextBoundsBlock(block, 50);
1090                 
1091         return block;
1092 }
1093
1094
1095 void do_info_add_surfacemenu(void *arg, int event)
1096 {
1097
1098         switch(event) {         
1099                 case 0:
1100                         /* Curve */
1101                         add_primitiveNurb(0);
1102                         break;
1103                 case 1:
1104                         /* Circle */
1105                         add_primitiveNurb(1);
1106                         break;
1107                 case 2:
1108                         /* Surface */
1109                         add_primitiveNurb(2);
1110                         break;
1111                 case 3:
1112                         /* Tube */
1113                         add_primitiveNurb(3);
1114                         break;
1115                 case 4:
1116                         /* Sphere */
1117                         add_primitiveNurb(4);
1118                         break;
1119                 case 5:
1120                         /* Donut */
1121                         add_primitiveNurb(5);
1122                         break;
1123                 default:
1124                         break;
1125         }
1126         allqueue(REDRAWINFO, 0);
1127 }
1128
1129 static uiBlock *info_add_surfacemenu(void *arg_unused)
1130 {
1131 /*              static short tog=0; */
1132         uiBlock *block;
1133         short yco= 0;
1134         
1135         block= uiNewBlock(&curarea->uiblocks, "add_surfacemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1136         uiBlockSetButmFunc(block, do_info_add_surfacemenu, NULL);
1137         
1138         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Curve|",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1139         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Circle|",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1140         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Surface|", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1141         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Tube",             0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1142         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Sphere|",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1143         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Donut|",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
1144         uiBlockSetDirection(block, UI_RIGHT);
1145         uiTextBoundsBlock(block, 50);
1146                 
1147         return block;
1148 }
1149
1150 void do_info_add_metamenu(void *arg, int event)
1151 {
1152
1153         switch(event) {         
1154                 case 0:
1155                         /* Ball */
1156                         add_primitiveMball(1);
1157                         break;
1158                 case 1:
1159                         /* Tube */
1160                         add_primitiveMball(2);
1161                         break;
1162                 case 2:
1163                         /* Plane */
1164                         add_primitiveMball(3);
1165                         break;
1166                 case 3:
1167                         /* Elipsoid */
1168                         add_primitiveMball(4);
1169                         break;
1170                 case 4:
1171                         /* Cube */
1172                         add_primitiveMball(5);
1173                         break;
1174                 default:
1175                         break;
1176         }
1177         allqueue(REDRAWINFO, 0);
1178 }
1179
1180
1181 static uiBlock *info_add_metamenu(void *arg_unused)
1182 {
1183 /*              static short tog=0; */
1184         uiBlock *block;
1185         short xco= 0;
1186         
1187         block= uiNewBlock(&curarea->uiblocks, "add_metamenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1188         uiBlockSetButmFunc(block, do_info_add_metamenu, NULL);
1189         
1190         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,"Meta Ball|",              0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1191         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Tube|",             0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1192         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Plane|",            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1193         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Ellipsoid|",        0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1194         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Cube|",             0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1195
1196         uiBlockSetDirection(block, UI_RIGHT);
1197         uiTextBoundsBlock(block, 50);
1198                 
1199         return block;
1200 }
1201
1202 void do_info_add_lampmenu(void *arg, int event)
1203 {
1204
1205         switch(event) {         
1206                 case 0: /* lamp */
1207                         add_objectLamp(LA_LOCAL);
1208                         break;
1209                 case 1: /* sun */
1210                         add_objectLamp(LA_SUN);
1211                         break;
1212                 case 2: /* spot */
1213                         add_objectLamp(LA_SPOT);
1214                         break;
1215                 case 3: /* hemi */
1216                         add_objectLamp(LA_HEMI);
1217                         break;
1218                 case 4: /* area */
1219                         add_objectLamp(LA_AREA);
1220                         break;
1221                 case 5: /* YafRay photon lamp */
1222                         if (G.scene->r.renderer==R_YAFRAY)
1223                                 add_objectLamp(LA_YF_PHOTON);
1224                         break;
1225                 default:
1226                         break;
1227         }
1228         allqueue(REDRAWINFO, 0);
1229 }
1230
1231 static uiBlock *info_add_lampmenu(void *arg_unused)
1232 {
1233 /*              static short tog=0; */
1234         uiBlock *block;
1235         short yco= 0;
1236         
1237         block= uiNewBlock(&curarea->uiblocks, "add_lampmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1238         uiBlockSetButmFunc(block, do_info_add_lampmenu, NULL);
1239         
1240         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Lamp|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1241         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Sun|",                           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1242         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Spot|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1243         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hemi|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1244         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Area|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1245         if (G.scene->r.renderer==R_YAFRAY)
1246                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Photon|",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
1247         
1248         uiBlockSetDirection(block, UI_RIGHT);
1249         uiTextBoundsBlock(block, 50);
1250                 
1251         return block;
1252 }
1253
1254 void do_info_addmenu(void *arg, int event)
1255 {
1256         switch(event) {         
1257                 case 0:
1258                         /* Mesh */
1259                         break;
1260                 case 1:
1261                         /* Curve */
1262                         break;
1263                 case 2:
1264                         /* Surface */
1265                         break;
1266                 case 3:
1267                         /* Metaball */
1268                         break;
1269                 case 4:
1270                         /* Text (argument is discarded) */
1271                         add_primitiveFont(event);
1272                         break;
1273                 case 5:
1274                         /* Empty */
1275                         add_object_draw(OB_EMPTY);
1276                         break;
1277                 case 6:
1278                         /* Camera */
1279                         add_object_draw(OB_CAMERA);
1280                         break;
1281                 case 7:
1282                         /* Lamp */
1283                 //      add_object_draw(OB_LAMP);
1284                         break;
1285                 case 8:
1286                         /* Armature */
1287                         add_primitiveArmature(OB_ARMATURE);
1288                         break;
1289                 case 9:
1290                         /* Lattice */
1291                         add_object_draw(OB_LATTICE);
1292                         break;
1293                 default:
1294                         break;
1295         }
1296         allqueue(REDRAWINFO, 0);
1297 }
1298
1299
1300 static uiBlock *info_addmenu(void *arg_unused)
1301 {
1302 /*              static short tog=0; */
1303         uiBlock *block;
1304         short yco= 0;
1305
1306         block= uiNewBlock(&curarea->uiblocks, "addmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1307         uiBlockSetButmFunc(block, do_info_addmenu, NULL);
1308         
1309         uiDefIconTextBlockBut(block, info_add_meshmenu, NULL, ICON_RIGHTARROW_THIN, "Mesh", 0, yco-=20, 120, 19, "");
1310         uiDefIconTextBlockBut(block, info_add_curvemenu, NULL, ICON_RIGHTARROW_THIN, "Curve", 0, yco-=20, 120, 19, "");
1311         uiDefIconTextBlockBut(block, info_add_surfacemenu, NULL, ICON_RIGHTARROW_THIN, "Surface", 0, yco-=20, 120, 19, "");
1312         uiDefIconTextBlockBut(block, info_add_metamenu, NULL, ICON_RIGHTARROW_THIN, "Meta", 0, yco-=20, 120, 19, "");
1313         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Text",                           0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 4, "");
1314         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Empty",                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 5, "");
1315         
1316         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1317         
1318         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Camera",                         0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 6, "");
1319 //      uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Lamp",                           0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 7, "");
1320         uiDefIconTextBlockBut(block, info_add_lampmenu, NULL, ICON_RIGHTARROW_THIN, "Lamp", 0, yco-=20, 120, 19, "");
1321         
1322         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1323         
1324         /* armature needs 3d window to draw */
1325         //uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Armature",                     0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 8, "");
1326         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Lattice",                        0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 9, "");
1327
1328         uiBlockSetDirection(block, UI_DOWN);
1329         uiTextBoundsBlock(block, 80);
1330                 
1331         return block;
1332 }
1333
1334 /************************** GAME *****************************/
1335
1336 static void do_info_gamemenu(void *arg, int event)
1337 {
1338         switch (event) {
1339         case G_FILE_ENABLE_ALL_FRAMES_BIT:
1340         case G_FILE_SHOW_FRAMERATE_BIT:
1341         case G_FILE_SHOW_DEBUG_PROPS_BIT:
1342         case G_FILE_AUTOPLAY_BIT:
1343                 G.fileflags ^= (1 << event);
1344                 break;
1345         default:
1346                 ; /* ignore the rest */
1347         }
1348 }
1349
1350 static uiBlock *info_gamemenu(void *arg_unused)
1351 {
1352 /*              static short tog=0; */
1353         uiBlock *block;
1354         short yco= 0;
1355         short menuwidth=120;
1356         
1357         block= uiNewBlock(&curarea->uiblocks, "gamemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1358         uiBlockSetButmFunc(block, do_info_gamemenu, NULL);
1359         
1360         uiDefIconTextBut(block, BUTM, B_STARTGAME, ICON_BLANK1, "Start Game|P",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
1361         
1362         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 1, 0, "");
1363
1364
1365         if(G.fileflags & (1 << G_FILE_ENABLE_ALL_FRAMES_BIT)) {
1366                 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, "");
1367         } else {
1368                 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, "");
1369         }
1370
1371         if(G.fileflags & (1 << G_FILE_SHOW_FRAMERATE_BIT)) {
1372                 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, "");
1373         } else {
1374                 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, "");
1375         }
1376
1377         if(G.fileflags & (1 << G_FILE_SHOW_DEBUG_PROPS_BIT)) {
1378                 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, "");
1379         } else {
1380                 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, "");
1381         }
1382         
1383         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 1, 0, "");
1384
1385         if(G.fileflags & (1 << G_FILE_AUTOPLAY_BIT)) {
1386                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Autostart",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_AUTOPLAY_BIT, "");
1387         } else {
1388                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Autostart",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_AUTOPLAY_BIT, "");
1389         }
1390
1391         uiBlockSetDirection(block, UI_DOWN);
1392         uiTextBoundsBlock(block, 50);
1393         
1394         return block;
1395 }
1396 /************************** TIMELINE *****************************/
1397
1398 static void do_info_timelinemenu(void *arg, int event)
1399 {
1400         /* needed to check for valid selected objects */
1401         Base *base=NULL;
1402         Object *ob=NULL;
1403         //char file[FILE_MAXDIR+FILE_MAXFILE];
1404
1405         base= BASACT;
1406         if (base) ob= base->object;
1407
1408         switch(event) {
1409         case 1:
1410                 /* Show Keyframes */
1411                 if (!ob) error("Select an object before showing its keyframes");
1412                 else set_ob_ipoflags();
1413                 break;
1414         case 2:
1415                 /* Show and select Keyframes */
1416                 if (!ob) error("Select an object before showing and selecting its keyframes");
1417                 else select_select_keys();
1418                         break;
1419                 case 3:
1420                 /* select next keyframe */
1421                 if (!ob) error("Select an object before selecting its next keyframe");
1422                 else nextkey_obipo(1);
1423                         break;
1424                 case 4:
1425                 /* select previous keyframe */
1426                 if (!ob) error("Select an object before selecting its previous keyframe");
1427                 else nextkey_obipo(-1);
1428                 break;
1429                 case 5:
1430                 /* next keyframe */
1431                 if (!ob) error("Select an object before going to its next keyframe");
1432                 else movekey_obipo(1);
1433                         break;
1434                 case 6:
1435                 /* previous keyframe */
1436                 if (!ob) error("Select an object before going to its previous keyframe");
1437                 else movekey_obipo(-1);
1438                 break;
1439         case 7:
1440                 /* next frame */
1441                 CFRA++;
1442                 update_for_newframe();
1443                 break;
1444                 case 8:
1445                 /* previous frame */
1446                 CFRA--;
1447                 if(CFRA<1) CFRA=1;
1448                 update_for_newframe();
1449                 break;
1450         case 9:
1451                 /* forward 10 frames */
1452                 CFRA+= 10;
1453                 update_for_newframe();
1454                 break;
1455         case 10:
1456                 /* back 10 frames */
1457                 CFRA-= 10;
1458                 if(CFRA<1) CFRA=1;
1459                 update_for_newframe();
1460                 break;
1461         case 11:
1462                 /* end frame */
1463                 CFRA= EFRA;
1464                 update_for_newframe();
1465                 break;
1466         case 12:
1467                 /* start frame */
1468                 CFRA= SFRA;
1469                 update_for_newframe();
1470                 break;
1471         }
1472         allqueue(REDRAWINFO, 0);
1473 }
1474
1475 static uiBlock *info_timelinemenu(void *arg_unused)
1476 {
1477 /*              static short tog=0; */
1478         uiBlock *block;
1479         short yco= 0;
1480         short menuwidth=120;
1481
1482         block= uiNewBlock(&curarea->uiblocks, "timelinemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1483         uiBlockSetButmFunc(block, do_info_timelinemenu, NULL);
1484         
1485         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Keyframes|K",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1486         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show and Select Keyframes|Shift K",0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1487         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Next Keyframe|PageUp",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1488         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Previous Keyframe|PageDown",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
1489
1490         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1491
1492         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Next Keyframe|Ctrl PageUp",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1493         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Previous Keyframe|Ctrl PageDown",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
1494
1495         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1496
1497         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Next Frame|RightArrow",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
1498         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Previous Frame|LeftArrow",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, "");
1499         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Forward 10 Frames|UpArrow",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, "");
1500         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Back 10 Frames|DownArrow",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
1501
1502         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1503
1504         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "End Frame|Shift RightArrow",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
1505         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Start Frame|Shift LeftArrow",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
1506
1507         uiBlockSetDirection(block, UI_DOWN);
1508         uiTextBoundsBlock(block, 80);
1509
1510         return block;
1511 }
1512
1513 /************************** RENDER *****************************/
1514
1515 /* copied from buttons.c. .. probably not such a good idea!? */
1516 static void run_playanim(char *file)
1517 {
1518         extern char bprogname[];        /* usiblender.c */
1519         char str[FILE_MAXDIR+FILE_MAXFILE];
1520         int pos[2], size[2];
1521
1522         calc_renderwin_rectangle(G.winpos, pos, size);
1523
1524         sprintf(str, "%s -a -p %d %d \"%s\"", bprogname, pos[0], pos[1], file);
1525         system(str);
1526 }
1527
1528 static void do_info_rendermenu(void *arg, int event)
1529 {
1530         char file[FILE_MAXDIR+FILE_MAXFILE];
1531
1532         extern void makeavistring(char *string);
1533         extern void makeqtstring (char *string);
1534
1535         switch(event) {
1536                 
1537         case 0:
1538                 BIF_do_render(0);
1539                 break;
1540         case 1:
1541                 BIF_do_render(1);
1542                 break;
1543
1544                 /* note: dont use select_area() for setting active areas for opengl render */
1545                 /* its hackish and instable... code here was removed */
1546         
1547         case 4:
1548                 BIF_toggle_render_display();
1549                 break;
1550         case 5:
1551 #ifdef WITH_QUICKTIME
1552                 if(G.scene->r.imtype == R_QUICKTIME)
1553                         makeqtstring(file);
1554                 else
1555 #endif
1556                         makeavistring(file);
1557                 if(BLI_exist(file)) {
1558                         run_playanim(file);
1559                 }
1560                 else {
1561                         makepicstring(file, G.scene->r.sfra);
1562                         if(BLI_exist(file)) {
1563                                 run_playanim(file);
1564                         }
1565                         else error("Can't find image: %s", file);
1566                 }
1567                 break;
1568         case 6:
1569                 /* dodgy hack turning on SHIFT key to do a proper render border select
1570                 set_render_border(); only works when 3d window active
1571                 
1572                 This code copied from toolbox.c, only works when 3d window is cameraview */
1573
1574                 if(select_area(SPACE_VIEW3D)) {
1575                         mainqenter(LEFTSHIFTKEY, 1);
1576                         mainqenter(BKEY, 1);
1577                         mainqenter(BKEY, 0);
1578                         mainqenter(EXECUTE, 1);
1579                         mainqenter(LEFTSHIFTKEY, 0);
1580                 }
1581
1582                 break;
1583
1584                 case 7:
1585                 extern_set_butspace(F10KEY);
1586                 break;
1587         }
1588         allqueue(REDRAWINFO, 0);
1589 }
1590
1591 static uiBlock *info_rendermenu(void *arg_unused)
1592 {
1593 /*              static short tog=0; */
1594         uiBlock *block;
1595         short yco= 0;
1596         short menuwidth=120;
1597         
1598         block= uiNewBlock(&curarea->uiblocks, "rendermenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1599         uiBlockSetButmFunc(block, do_info_rendermenu, NULL);
1600         
1601         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Current Frame|F12",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
1602         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Animation",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1603
1604         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1605
1606         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Render Buffer|F11",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
1607         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Rendered Animation",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1608
1609         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1610
1611         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Render Border|Shift B",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
1612
1613         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1614
1615         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Settings|F10",            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
1616
1617         uiBlockSetDirection(block, UI_DOWN);
1618         uiTextBoundsBlock(block, 80);
1619
1620         return block;
1621 }
1622
1623 /************************** HELP *****************************/
1624
1625 static void do_info_help_websitesmenu(void *arg, int event)
1626 {
1627         BPY_menu_do_python(PYMENU_HELPWEBSITES, event);
1628
1629         allqueue(REDRAWVIEW3D, 0);
1630 }
1631
1632
1633 static uiBlock *info_help_websitesmenu(void *arg_unused)
1634 {
1635         uiBlock *block;
1636         BPyMenu *pym;
1637         short yco = 20, menuwidth = 120;
1638         int i = 0;
1639
1640         block= uiNewBlock(&curarea->uiblocks, "info_help_websitesmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1641         uiBlockSetButmFunc(block, do_info_help_websitesmenu, NULL);
1642         
1643         for (pym = BPyMenuTable[PYMENU_HELPWEBSITES]; pym; pym = pym->next, i++) {
1644                 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);
1645         }
1646         
1647         uiBlockSetDirection(block, UI_RIGHT);
1648         uiTextBoundsBlock(block, 60);
1649                 
1650         return block;
1651 }
1652
1653 static void do_info_help_systemmenu(void *arg, int event)
1654 {
1655         /* events >=10 are registered bpython scripts */
1656         if (event >= 10) BPY_menu_do_python(PYMENU_HELPSYSTEM, event - 10);
1657         else {
1658                 switch(event) {
1659
1660                 case 1: /* Benchmark */
1661                         /* dodgy hack turning on CTRL ALT SHIFT key to do a benchmark 
1662                          *      rather than copying lines and lines of code from toets.c :( 
1663                          */
1664         
1665                         if(select_area(SPACE_VIEW3D)) {
1666                                 mainqenter(LEFTSHIFTKEY, 1);
1667                                 mainqenter(LEFTCTRLKEY, 1);
1668                                 mainqenter(LEFTALTKEY, 1);
1669                                 mainqenter(TKEY, 1);
1670                                 mainqenter(TKEY, 0);
1671                                 mainqenter(EXECUTE, 1);
1672                                 mainqenter(LEFTSHIFTKEY, 0);
1673                                 mainqenter(LEFTCTRLKEY, 0);
1674                                 mainqenter(LEFTALTKEY, 0);
1675                         }
1676                         break;
1677                 }
1678         }
1679
1680         allqueue(REDRAWVIEW3D, 0);
1681 }
1682
1683
1684 static uiBlock *info_help_systemmenu(void *arg_unused)
1685 {
1686         uiBlock *block;
1687         BPyMenu *pym;
1688         short yco = 20, menuwidth = 120;
1689         int i = 0;
1690
1691         block= uiNewBlock(&curarea->uiblocks, "info_help_systemmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1692         uiBlockSetButmFunc(block, do_info_help_systemmenu, NULL);
1693         
1694         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Benchmark",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1695         
1696         for (pym = BPyMenuTable[PYMENU_HELPSYSTEM]; pym; pym = pym->next, i++) {
1697                 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);
1698         }
1699         
1700         uiBlockSetDirection(block, UI_RIGHT);
1701         uiTextBoundsBlock(block, 60);
1702                 
1703         return block;
1704 }
1705
1706 static void do_info_helpmenu(void *arg, int event)
1707 {
1708         ScrArea *sa;
1709
1710         if(curarea->spacetype==SPACE_INFO) {
1711                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
1712                 if (!sa) sa= closest_bigger_area();
1713                 areawinset(sa->win);
1714         }
1715
1716         /* events >=10 are registered bpython scripts */
1717         if (event >= 10) BPY_menu_do_python(PYMENU_HELP, event - 10);
1718         else {
1719                 switch(event) {
1720                                                                         
1721                 case 0: /* About Blender */
1722                         break;
1723                 }
1724         }
1725
1726         allqueue(REDRAWINFO, 0);
1727 }
1728
1729 static uiBlock *info_helpmenu(void *arg_unused)
1730 {
1731 /*              static short tog=0; */
1732         uiBlock *block;
1733         short yco= 0;
1734         short menuwidth=120;
1735         BPyMenu *pym;
1736         int i = 0;
1737         
1738         block= uiNewBlock(&curarea->uiblocks, "info_helpmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1739         uiBlockSetButmFunc(block, do_info_helpmenu, NULL);
1740         
1741         uiDefIconTextBut(block, BUTM, B_SHOWSPLASH, ICON_BLANK1, "About Blender...",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
1742         
1743         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1744         
1745         for (pym = BPyMenuTable[PYMENU_HELP]; pym; pym = pym->next, i++) {
1746                 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);
1747         }
1748         
1749         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1750         
1751         uiDefIconTextBlockBut(block, info_help_websitesmenu, NULL, ICON_RIGHTARROW_THIN, "Websites", 0, yco-=20, 120, 19, "");
1752         
1753         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1754         
1755         uiDefIconTextBlockBut(block, info_help_systemmenu, NULL, ICON_RIGHTARROW_THIN, "System", 0, yco-=20, 120, 19, "");
1756
1757         uiBlockSetDirection(block, UI_DOWN);
1758         uiTextBoundsBlock(block, 80);
1759
1760         return block;
1761 }
1762
1763 /************************** END MAIN MENU *****************************/
1764 /* ugly global yes, for renderwin.c to write to */
1765 char info_time_str[32]="";
1766
1767 static void info_text(int x, int y)
1768 {
1769         Object *ob;
1770         extern float hashvectf[];
1771         extern int mem_in_use;
1772         unsigned int swatch_color;
1773         float fac1, fac2, fac3;
1774         char infostr[300];
1775         char *headerstr;
1776         int hsize;
1777
1778         if(G.obedit) {
1779                 if(G.obedit->type==OB_MESH) {
1780                         if(G.scene->selectmode & SCE_SELECT_VERTEX)
1781                                 sprintf(infostr,"Ve:%d-%d | Ed:%d-%d | Fa:%d-%d | Mem:%.2fM ",
1782                                                 G.totvertsel, G.totvert, G.totedgesel, G.totedge, G.totfacesel, G.totface, (mem_in_use>>10)/1024.0);
1783                         else if(G.scene->selectmode & SCE_SELECT_EDGE)
1784                                 sprintf(infostr,"Ed:%d-%d | Fa:%d-%d | Mem:%.2fM ",
1785                                                 G.totedgesel, G.totedge, G.totfacesel, G.totface, (mem_in_use>>10)/1024.0);
1786                         else 
1787                                 sprintf(infostr,"Fa:%d-%d | Mem:%.2fM ",
1788                                                 G.totfacesel, G.totface, (mem_in_use>>10)/1024.0);
1789                 }
1790                 else {
1791                         sprintf(infostr,"Ve:%d-%d | Mem:%.2fM ",
1792                                         G.totvertsel, G.totvert, (mem_in_use>>10)/1024.0);
1793                 }
1794         }
1795         else {
1796                 sprintf(infostr,"Ve:%d | Fa:%d | Ob:%d-%d | La:%d | Mem:%.2fM | Time:%s | ",
1797                         G.totvert, G.totface, G.totobj, G.totobjsel, G.totlamp,  (mem_in_use>>10)/1024.0, info_time_str);
1798         }
1799         ob= OBACT;
1800         if(ob) {
1801                 strcat(infostr, ob->id.name+2);
1802         }
1803
1804         if (g_progress_bar && g_progress_info) {
1805                 headerstr= g_progress_info;
1806         } else {
1807                 headerstr= versionstr; 
1808         }
1809
1810         if      (g_progress_bar) {
1811                 hsize = 4 + (138.0 * g_done);
1812                 fac1 = 0.5 * g_done; // do some rainbow colours on progress
1813                 fac2 = 1.0;
1814                 fac3 = 0.9;
1815         } else {
1816                 hsize= 30+BIF_GetStringWidth(G.font, headerstr, (U.transopts & USER_TR_BUTTONS));
1817
1818                 /* promise! Never change these lines again! (zr & ton did!) */
1819                 fac1= fabs(hashvectf[ 2*G.version+4]);
1820                 fac2= 0.5+0.1*hashvectf[ G.version+3];
1821                 fac3= 0.7;
1822         }
1823         
1824         swatch_color= hsv_to_cpack(fac1, fac2, fac3);
1825
1826         cpack( swatch_color );
1827         glRecti(x-24,  y-6,  x-30+hsize,        y+14);
1828
1829         glColor3ub(0, 0, 0);
1830
1831         glRasterPos2i(x, y);
1832         BIF_RasterPos(x, y);
1833
1834         BIF_DrawString(G.font, headerstr, (U.transopts & USER_TR_MENUS));
1835         hsize= BIF_GetStringWidth(G.font, headerstr, (U.transopts & USER_TR_BUTTONS));
1836         
1837         glRasterPos2i(x+hsize+10,       y);
1838         BIF_RasterPos(x+hsize+10,       y);
1839
1840         BIF_DrawString(G.font, infostr, (U.transopts & USER_TR_MENUS));
1841 }
1842
1843 void info_buttons(void)
1844 {
1845         uiBlock *block;
1846         short xco= 42;
1847         int xmax;
1848
1849         block= uiNewBlock(&curarea->uiblocks, "header info", UI_EMBOSSN, UI_HELV, curarea->headwin);
1850
1851         if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
1852         else uiBlockSetCol(block, TH_HEADERDESEL);
1853         
1854         if(curarea->flag & HEADER_NO_PULLDOWN) {
1855                 uiDefIconButS(block, TOG|BIT|0, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_RIGHT,
1856                                 xco,2,XIC,YIC-2,
1857                                 &(curarea->flag), 0, 0, 0, 0, "Enables display of pulldown menus");
1858         } else {
1859                 uiDefIconButS(block, TOG|BIT|0, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_DOWN,
1860                                 xco,2,XIC,YIC-2,
1861                                 &(curarea->flag), 0, 0, 0, 0, "Hides pulldown menus");
1862         }
1863         xco+=XIC;
1864
1865         if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
1866         
1867                 uiBlockSetEmboss(block, UI_EMBOSSP);
1868
1869                 /* the 'xmax - 3' rather than xmax is to prevent some weird flickering where the highlighted
1870                  * menu is drawn wider than it should be. The ypos of -1 is to make it properly fill the
1871                  * height of the header */
1872                 xmax= GetButStringLength("File");
1873                 uiDefPulldownBut(block, info_filemenu, NULL, "File",    xco, -1, xmax-3, 22, "");
1874                 xco+= xmax;
1875
1876                 xmax= GetButStringLength("Add");
1877                 uiDefPulldownBut(block, info_addmenu, NULL, "Add",      xco, -1, xmax-3, 22, "");
1878                 xco+= xmax;
1879
1880                 xmax= GetButStringLength("Timeline");
1881                 uiDefPulldownBut(block, info_timelinemenu, NULL, "Timeline",    xco, -1, xmax-3, 22, "");
1882                 xco+= xmax;
1883
1884                 xmax= GetButStringLength("Game");
1885                 uiDefPulldownBut(block, info_gamemenu, NULL, "Game",    xco, -1, xmax-3, 22, "");
1886                 xco+= xmax;
1887
1888                 xmax= GetButStringLength("Render");
1889                 uiDefPulldownBut(block, info_rendermenu, NULL, "Render",        xco, -1, xmax-3, 22, "");
1890                 xco+= xmax;
1891
1892                 xmax= GetButStringLength("Help");
1893                 uiDefPulldownBut(block, info_helpmenu, NULL, "Help",    xco, -1, xmax-3, 22, "");
1894                 xco+= xmax;
1895
1896         }
1897
1898         /* pack icon indicates a packed file */
1899         
1900         if (G.fileflags & G_AUTOPACK) {
1901                 uiBlockSetEmboss(block, UI_EMBOSSN);
1902                 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.");
1903                 xco += XIC;
1904         }
1905
1906         if (curarea->full == 0) {
1907                 curarea->butspacetype= SPACE_INFO;
1908                 uiBlockSetEmboss(block, UI_EMBOSS);
1909                 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.");
1910                 
1911                 /* STD SCREEN BUTTONS */
1912                 xco= std_libbuttons(block, xco, 0, 0, NULL, B_INFOSCR, (ID *)G.curscreen, 0, &G.curscreen->screennr, 1, 1, B_INFODELSCR, 0, 0);
1913                 
1914                 xco +=8;
1915         
1916                 /* STD SCENE BUTTONS */
1917                 xco= std_libbuttons(block, xco, 0, 0, NULL, B_INFOSCE, (ID *)G.scene, 0, &G.curscreen->scenenr, 1, 1, B_INFODELSCE, 0, 0);
1918         }
1919         else xco= 430;
1920         
1921 BIF_SetScale(block->aspect);
1922         info_text(xco+24, 6);
1923         
1924         uiBlockSetEmboss(block, UI_EMBOSSN);
1925         uiDefIconBut(block, BUT, B_SHOWSPLASH, ICON_BLENDER, xco+2, 0,XIC,YIC, 0, 0, 0, 0, 0, "Click to display Splash Screen");
1926
1927         /* always do as last */
1928         curarea->headbutlen= xco+2*XIC;
1929
1930 #if 0
1931 // #ifdef _WIN32        // FULLSCREEN
1932         if(U.uiflag & USER_FLIPFULLSCREEN) {
1933                 uiDefIconBut(block, BUT, B_FLIPFULLSCREEN, ICON_WINDOW_WINDOW,
1934                                 (short)(curarea->winx-XIC-5), 0,XIC,YIC,
1935                                 0, 0, 0, 0, 0, "Toggles Blender to fullscreen mode");/* dir             */
1936         } else {
1937                 uiDefIconBut(block, BUT, B_FLIPFULLSCREEN, ICON_WINDOW_FULLSCREEN,
1938                                 (short)(curarea->winx-XIC-5), 0,XIC,YIC,
1939                                 0, 0, 0, 0, 0, "Toggles Blender to fullscreen mode");/* dir             */
1940         }
1941 #endif
1942         
1943         uiDrawBlock(block);
1944 }