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