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