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