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