added scons option BF_WITH_PYTHON (defined as DISABLE_PYTHON)
[blender-staging.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  *
8  * ***** BEGIN GPL LICENSE BLOCK *****
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
23  *
24  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
25  * All rights reserved.
26  *
27  * The Original Code is: all of this file.
28  *
29  * Contributor(s): none yet.
30  *
31  * ***** END GPL LICENSE BLOCK *****
32  */
33  
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include "DNA_group_types.h"
43 #include "DNA_ID.h"
44 #include "DNA_image_types.h"
45 #include "DNA_lamp_types.h"
46 #include "DNA_object_types.h"
47 #include "DNA_packedFile_types.h"
48 #include "DNA_scene_types.h"
49 #include "DNA_screen_types.h"
50 #include "DNA_space_types.h"
51 #include "DNA_userdef_types.h"
52 #include "DNA_world_types.h"
53
54 #include "BDR_editcurve.h"
55 #include "BDR_editmball.h"
56 #include "BDR_editobject.h"
57 #include "BDR_editface.h"
58 #include "BDR_vpaint.h"
59
60 #include "BIF_editarmature.h"
61 #include "BIF_editfont.h"
62 #include "BIF_editmesh.h"
63 #include "BIF_gl.h"
64 #include "BIF_interface.h"
65 #include "BIF_language.h"
66 #include "BIF_mainqueue.h"
67 #include "BIF_meshtools.h"
68 #include "BIF_previewrender.h"
69 #include "BIF_renderwin.h"
70 #include "BIF_resources.h"
71 #include "BIF_screen.h"
72 #include "BIF_space.h"
73 #include "BIF_toets.h"
74 #include "BIF_toolbox.h"
75 #include "BIF_usiblender.h"
76 #include "BIF_writeimage.h"
77 #include "BIF_drawscene.h"
78
79 #ifdef WITH_VERSE
80 #include "BIF_verse.h"
81 #endif
82
83 #include "BKE_blender.h"
84 #include "BKE_colortools.h"
85 #include "BKE_depsgraph.h"
86 #include "BKE_exotic.h"
87 #include "BKE_global.h"
88 #include "BKE_image.h"
89 #include "BKE_library.h"
90 #include "BKE_main.h"
91 #include "BKE_node.h"
92 #include "BKE_packedFile.h"
93 #include "BKE_scene.h"
94 #include "BKE_world.h"
95
96 #ifdef WITH_VERSE
97 #include "BKE_verse.h"
98 #endif
99
100 #include "BLI_arithb.h"
101 #include "BLI_blenlib.h"
102 #include "BLI_bpath.h"
103 #include "BLO_writefile.h"
104
105 #include "BSE_editipo.h"
106 #include "BSE_filesel.h"
107 #include "BIF_imasel.h"
108 #include "BSE_headerbuttons.h"
109 #include "BSE_node.h"
110 #include "BSE_sequence.h"
111 #include "BSE_edit.h"
112 #include "BSE_time.h"
113
114 #include "IMB_imbuf_types.h"
115
116 #include "MEM_guardedalloc.h"
117
118 #ifndef DISABLE_PYTHON
119 #include "BPY_extern.h"
120 #include "BPY_menus.h"
121 #endif
122
123 #include "GPU_extensions.h"
124 #include "GPU_material.h"
125
126 #include "blendef.h"
127 #include "interface.h"
128 #include "mydevice.h"
129
130 extern char versionstr[]; /* from blender.c */
131
132 /*----------------------------------*/
133 /* Progress bar vars and functions: */
134
135 /* strubi shamelessly abused the status line as a progress bar...
136  * feel free to kill him after release */
137
138 static int g_progress_bar = 0;
139 static char *g_progress_info = 0;
140 static float g_done;
141
142 int start_progress_bar(void)
143 {
144         g_progress_bar = 1;
145         return 1;               // we never fail (yet)
146 }
147
148 void end_progress_bar(void)
149 {
150         g_progress_bar = 0;
151 }
152
153 static void update_progress_bar(float done, char *info)
154 {
155         g_done = done;
156         g_progress_info = info;
157 }
158
159 /** Progress bar
160         'done': a value between 0.0 and 1.0, showing progress
161         'info': a info text what is currently being done
162
163         Make sure that the progress bar is always called with:
164         done = 0.0 first
165                 and
166         done = 1.0 last -- or alternatively use:
167
168         start_progressbar();
169         do_stuff_and_callback_progress_bar();
170         end_progressbar();
171 */
172
173 int progress_bar(float done, char *busy_info)
174 {
175         ScrArea *sa;
176         short val; 
177
178         /* User break (ESC) */
179         while (qtest()) {
180                 if (extern_qread(&val) == ESCKEY) 
181                         return 0;
182         }
183         if (done == 0.0) {
184                 start_progress_bar();
185         } else if (done > 0.99) {
186                 end_progress_bar();
187         }
188
189         sa= G.curscreen->areabase.first;
190         while(sa) {
191                 if (sa->spacetype == SPACE_INFO) {
192                         update_progress_bar(done, busy_info);
193
194                         curarea = sa;
195
196                         scrarea_do_headdraw(curarea);
197                         areawinset(curarea->win);
198                         sa->head_swap= WIN_BACK_OK;
199                         screen_swapbuffers();
200                 }
201                 sa = sa->next;
202         }
203         return 1;
204 }
205 /* -- End of progress bar definitions ------- */
206
207 extern char temp_dir[]; /* XXXXX BAD BAD BAD from exotic.c */
208
209 void write_vrml_fs()
210 {
211         if(G.obedit) {
212                 error("Can't save VRML. Press TAB to leave EditMode");
213         }
214         else {
215                 if(temp_dir[0]==0) strcpy(temp_dir, G.sce);
216         
217                 activate_fileselect(FILE_SPECIAL, "Export VRML 1.0", temp_dir, write_vrml);
218         }  
219 }
220
221 void write_dxf_fs()
222 {
223         if(G.obedit) {
224                 error("Can't save DXF. Press TAB to leave EditMode");
225         }
226         else {
227
228                 if(temp_dir[0]==0) strcpy(temp_dir, G.sce);
229
230                 activate_fileselect(FILE_SPECIAL, "Export DXF", temp_dir, write_dxf);   
231         }
232 }
233
234 void write_stl_fs()
235 {
236         if(G.obedit) {
237                 error("Can't save STL. Press TAB to leave EditMode");
238         }
239         else {
240
241                 if(temp_dir[0]==0) strcpy(temp_dir, G.sce);
242
243                 activate_fileselect(FILE_SPECIAL, "Export STL", temp_dir, write_stl);
244         }
245 }
246 /* ------------ */
247
248 int buttons_do_unpack()
249 {
250         int how;
251         char menu[2048];
252         char *line = menu;
253         int ret_value = RET_OK, count = 0;
254
255         count = countPackedFiles();
256
257         if(!count) {
258                 pupmenu("No packed files. Autopack disabled");
259                 return ret_value;
260         }
261         if (count == 1)
262                 line += sprintf(line, "Unpack 1 file%%t");
263         else
264                 line += sprintf(line, "Unpack %d files%%t", count);
265         
266         line += sprintf(line, "|Use files in current directory (create when necessary)%%x%d", PF_USE_LOCAL);
267         line += sprintf(line, "|Write files to current directory (overwrite existing files)%%x%d", PF_WRITE_LOCAL);
268         line += sprintf(line, "|%%l|Use files in original location (create when necessary)%%x%d", PF_USE_ORIGINAL);
269         line += sprintf(line, "|Write files to original location (overwrite existing files)%%x%d", PF_WRITE_ORIGINAL);
270         line += sprintf(line, "|%%l|Disable AutoPack, keep all packed files %%x%d", PF_KEEP);
271         line += sprintf(line, "|Ask for each file %%x%d", PF_ASK);
272
273         how = pupmenu(menu);
274
275         if(how == -1)
276                 ret_value = RET_CANCEL;
277         else {
278                 if (how != PF_KEEP) unpackAll(how);
279                 G.fileflags &= ~G_AUTOPACK;
280         }
281         
282         return ret_value;
283 }
284
285 /* here, because of all creator stuff */
286
287 Scene *copy_scene(Scene *sce, int level)
288 {
289         /* 
290          * level 0: empty, only copy minimal stuff
291          * level 1: all objects shared
292          * level 2: all object-data shared
293          * level 3: full copy
294          */
295         
296         Scene *scen;
297         Base *base, *obase;
298         
299         if (level==0) { /* Add Empty, minimal copy */
300                 ListBase lb;
301                 scen= add_scene(sce->id.name+2);
302                 
303                 lb= scen->r.layers;
304                 scen->r= sce->r;
305                 scen->r.layers= lb;
306                 
307         } else {
308                 /* level 1+, but not level 0 */
309                 scen= copy_libblock(sce);
310                 duplicatelist(&(scen->base), &(sce->base));
311                 
312                 clear_id_newpoins();
313                 
314                 id_us_plus((ID *)scen->world);
315                 id_us_plus((ID *)scen->set);
316         
317                 scen->ed= NULL;
318                 scen->radio= NULL;
319                 scen->theDag= NULL;
320                 scen->toolsettings= MEM_dupallocN(sce->toolsettings);
321         
322                 duplicatelist(&(scen->markers), &(sce->markers));
323                 duplicatelist(&(scen->transform_spaces), &(sce->transform_spaces));
324                 duplicatelist(&(scen->r.layers), &(sce->r.layers));
325                 
326                 scen->nodetree= ntreeCopyTree(sce->nodetree, 0);
327                 
328                 obase= sce->base.first;
329                 base= scen->base.first;
330                 while(base) {
331                         id_us_plus(&base->object->id);
332                         if(obase==sce->basact) scen->basact= base;
333         
334                         obase= obase->next;
335                         base= base->next;
336                 }
337 #ifndef DISABLE_PYTHON
338                 BPY_copy_scriptlink(&sce->scriptlink);
339 #endif
340                 /* sculpt data */
341                 sce->sculptdata.session = NULL;
342                 if (sce->sculptdata.cumap) {
343                         int a;
344                         scen->sculptdata.cumap = curvemapping_copy(sce->sculptdata.cumap);
345                         scen->sculptdata.session = NULL; /* this is only for temp data storage anyway */
346                         for(a=0; a<MAX_MTEX; ++a) {
347                                 if (sce->sculptdata.mtex[a]) {
348                                         scen->sculptdata.mtex[a]= MEM_dupallocN(sce->sculptdata.mtex[a]);
349                                 }
350                         }
351                 }
352         }
353         
354         // make a private copy of the avicodecdata
355         
356         if (sce->r.avicodecdata) {
357         
358                 scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata);
359                 scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecdata->lpFormat);
360                 scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecdata->lpParms);
361         }
362         
363         // make a private copy of the qtcodecdata
364         
365         if (sce->r.qtcodecdata) {
366                 scen->r.qtcodecdata = MEM_dupallocN(sce->r.qtcodecdata);
367                 scen->r.qtcodecdata->cdParms = MEM_dupallocN(scen->r.qtcodecdata->cdParms);
368         }
369         
370         
371         if(level==0 || level==1) return scen;
372
373         /* level 2 */
374         G.scene= scen;
375         
376         single_object_users(0);
377
378         /*      camera */
379         ID_NEW(G.scene->camera);
380
381         /* level 3 */
382         if(level>=3) {
383                 if(scen->world) {
384                         id_us_plus(&scen->world->id);
385                         scen->world= copy_world(scen->world);
386                 }
387                 single_obdata_users(0);
388                 single_mat_users_expand();
389                 single_tex_users_expand();
390                 
391                 scen->radio= MEM_dupallocN(sce->radio);
392                 
393         }
394
395         clear_id_newpoins();
396         return scen;
397 }
398
399 void do_info_buttons(unsigned short event)
400 {
401         bScreen *sc, *oldscreen;
402         Scene *sce, *sce1;
403         ScrArea *sa;
404         int nr;
405
406         switch(event) {
407         case B_INFOSCR:         /* menu select screen */
408
409                 if( G.curscreen->screennr== -2) {
410                         if(curarea->winy <50) {
411                                 sa= closest_bigger_area();
412                                 areawinset(sa->win);
413                         }
414                         activate_databrowse((ID *)G.curscreen, ID_SCR, 0, B_INFOSCR,
415                                                                                         &G.curscreen->screennr, do_info_buttons);
416                         return;
417                 }
418                 if( G.curscreen->screennr < 0) return;
419
420                 sc= G.main->screen.first;
421                 nr= 1;
422                 while(sc) {
423                         if(nr==G.curscreen->screennr) {
424                                 if(is_allowed_to_change_screen(sc)) setscreen(sc);
425                                 else error("Unable to perform function in EditMode");
426                                 break;
427                         }
428                         nr++;
429                         sc= sc->id.next;
430                 }
431                 /* last item: NEW SCREEN */
432                 if(sc==0) {
433                         nr= pupmenu("New Screen%t|Empty%x1|Duplicate%x2");
434
435                         if(nr==1) default_twosplit();
436                         if(nr==2) duplicate_screen();
437                 }
438                 break;
439         case B_INFODELSCR:
440 /*do this event only with buttons, so it can never be called with full-window*/
441
442                 if(G.curscreen->id.prev) sc= G.curscreen->id.prev;
443                 else if(G.curscreen->id.next) sc= G.curscreen->id.next;
444                 else return;
445                 if(okee("Delete current screen")) {
446                         /* find new G.curscreen */
447
448                         oldscreen= G.curscreen;
449                         setscreen(sc);          /* this test if sc has a full */
450                         unlink_screen(oldscreen);
451                         free_libblock(&G.main->screen, oldscreen);
452                 }
453                 scrarea_queue_headredraw(curarea);
454
455                 break;
456         case B_INFOSCE:         /* menu select scene */
457
458                 if( G.curscreen->scenenr== -2) {
459                         if(curarea->winy <50) {
460                                 sa= closest_bigger_area();
461                                 areawinset(sa->win);
462                         }
463                         activate_databrowse((ID *)G.scene, ID_SCE, 0, B_INFOSCE,
464                                                                                         &G.curscreen->scenenr, do_info_buttons);
465                         return;
466                 }
467                 if( G.curscreen->scenenr < 0) return;
468
469                 sce= G.main->scene.first;
470                 nr= 1;
471                 while(sce) {
472                         if(nr==G.curscreen->scenenr) {
473                                 if(sce!=G.scene) set_scene(sce);
474                                 break;
475                         }
476                         nr++;
477                         sce= sce->id.next;
478                 }
479                 /* last item: NEW SCENE */
480                 if(sce==0) {
481                         nr= pupmenu("Add scene%t|Empty%x0|Link Objects%x1|Link ObData%x2|Full Copy%x3");
482                         if(nr<0) return;
483                         sce= copy_scene(G.scene, nr);
484                         set_scene(sce);
485                 }
486                 countall();
487                 BIF_preview_changed(ID_TE);
488
489                 break;
490         case B_INFODELSCE:
491
492                 if(G.scene->id.prev) sce= G.scene->id.prev;
493                 else if(G.scene->id.next) sce= G.scene->id.next;
494                 else return;
495                 if(okee("Delete current scene")) {
496                         /* Note, anything besides free_libblock needs to be added in
497                          * Python Scene.c for Blender.Scene.Unlink() */
498                         
499                         
500                         /* exit modes... could become single call once */
501                         exit_editmode(EM_FREEDATA|EM_WAITCURSOR);
502                         exit_paint_modes();
503                         
504                         /* check all sets */
505                         for (sce1= G.main->scene.first; sce1; sce1= sce1->id.next) {
506                                 if(sce1->set == G.scene) sce1->set= 0;
507                         }
508                         
509                         /* check all sequences */
510                         clear_scene_in_allseqs(G.scene);
511
512                         /* check render layer nodes in other scenes */
513                         clear_scene_in_nodes(G.scene);
514                         
515                         /* al screens */
516                         
517                         for (sc= G.main->screen.first; sc; sc= sc->id.next ) {
518                                 if(sc->scene == G.scene) sc->scene= sce;
519                         }
520                         free_libblock(&G.main->scene, G.scene);
521                         set_scene(sce);
522                         countall();
523                 }
524
525                 break;
526         }
527 }
528
529 static void check_packAll()
530 {
531         // first check for dirty images
532         Image *ima;
533
534         for(ima = G.main->image.first; ima; ima= ima->id.next) {
535                 if (ima->ibufs.first) { /* XXX FIX */
536                         ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
537
538                         if (ibuf && (ibuf->userflags &= IB_BITMAPDIRTY))
539                                 break;
540                 }
541         }
542         
543         if (ima == NULL || okee("Some images are painted on. These changes will be lost. Continue ?")) {
544                 packAll();
545                 G.fileflags |= G_AUTOPACK;
546         }
547 }
548
549 #ifdef _WIN32
550 static void copy_game_dll(char *dll_filename, char *source_dir, char *dest_dir)
551 {
552         char source_filename[FILE_MAX];
553         char dest_filename[FILE_MAX];
554
555         strcpy( source_filename, source_dir );
556         strcat( source_filename, dll_filename );
557
558         strcpy( dest_filename, dest_dir );
559         strcat( dest_filename, dll_filename );
560         
561         if(!BLI_exists(dest_filename)) {
562                 BLI_copy_fileops( source_filename, dest_filename );
563         }
564 }
565
566 static void copy_all_game_dlls(char *str)
567 {
568 #define GAME_DLL_COUNT          7
569         char *game_dll_list[GAME_DLL_COUNT]={"gnu_gettext.dll", "libpng.dll", "libtiff.dll", "pthreadVC2.dll", "python25.dll", "SDL.dll", "zlib.dll"};
570
571         char dest_dir[FILE_MAX];
572         char source_dir[FILE_MAX];
573         int i;
574
575         strcpy(source_dir, get_install_dir());
576         strcat(source_dir, "\\");
577         BLI_split_dirfile_basic(str, dest_dir, NULL);
578
579         for (i= 0; i< GAME_DLL_COUNT; i++) {
580                 copy_game_dll(game_dll_list[i], source_dir, dest_dir );
581         };
582 }
583 #endif
584
585 static int write_runtime(char *str, char *exename)
586 {
587         char *freestr= NULL;
588         char *ext = 0;
589
590 #ifdef _WIN32
591         ext = ".exe";
592 #endif
593
594 #ifdef __APPLE__
595         ext = ".app";
596 #endif
597         if (ext && (!BLI_testextensie(str, ext))) {
598                 freestr= MEM_mallocN(strlen(str) + strlen(ext) + 1, "write_runtime_check");
599                 sprintf(freestr,"%s%s", str, ext);
600                 str= freestr;
601         }
602
603         if (!BLI_exists(str) || saveover(str))
604                 BLO_write_runtime(str, exename);
605
606         if (freestr)
607                 MEM_freeN(freestr);
608  
609         return 0;
610 }
611
612 static void write_runtime_check_dynamic(char *str) 
613 {
614         write_runtime(str, "blenderdynplayer.exe");
615 }
616
617 static void write_runtime_check(char *str) 
618 {
619         char player[128];
620
621         strcpy(player, "blenderplayer");
622
623 #ifdef _WIN32
624         strcat(player, ".exe");
625 #endif
626
627 #ifdef __APPLE__
628         strcat(player, ".app");
629 #endif
630
631         write_runtime(str, player);
632
633 #ifdef _WIN32
634         // get a list of the .DLLs in the Blender folder and copy all of these to the destination folder if they don't exist
635         copy_all_game_dlls(str);
636 #endif
637 }
638
639
640 /* end keyed functions */
641
642 /************************** MAIN MENU *****************************/
643 /************************** FILE *****************************/
644
645
646 static void do_info_file_importmenu(void *arg, int event)
647 {
648         ScrArea *sa;
649
650         if(curarea->spacetype==SPACE_INFO) {
651                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
652                 if (!sa) sa= closest_bigger_area();
653                 areawinset(sa->win);
654         }
655
656 #ifndef DISABLE_PYTHON
657         /* events >=3 are registered bpython scripts */
658         if (event >= 3) {
659                 BPY_menu_do_python(PYMENU_IMPORT, event - 3);
660                 BIF_undo_push("Import file");
661         } else 
662 #endif
663         {
664                 switch(event) {
665                                                                         
666                 case 0: /* DXF */
667                         activate_fileselect(FILE_BLENDER, "Import DXF", G.sce, BIF_read_file);
668                         break;
669                 case 1: /* VRML 1.0 */
670                         activate_fileselect(FILE_BLENDER, "Import VRML 1.0", G.sce, BIF_read_file);
671                         break;
672                 case 2: /* STL */
673                         activate_fileselect(FILE_BLENDER, "Import STL", G.sce, BIF_read_file);
674                         break;
675
676                 }
677         }
678         allqueue(REDRAWINFO, 0);
679 }
680
681 static uiBlock *info_file_importmenu(void *arg_unused)
682 {
683         uiBlock *block;
684         short yco = 20, menuwidth = 120;
685 #ifndef DISABLE_PYTHON
686         BPyMenu *pym;
687 #endif
688         int i = 0;
689
690         block= uiNewBlock(&curarea->uiblocks, "importmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
691         uiBlockSetButmFunc(block, do_info_file_importmenu, NULL);
692         //uiBlockSetXOfs(block, -50);  // offset to parent button
693         
694         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...",
695                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "");
696         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...",
697                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "");
698         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "STL...",
699                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "");
700 #ifndef DISABLE_PYTHON
701         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
702
703         for (pym = BPyMenuTable[PYMENU_IMPORT]; pym; pym = pym->next, i++) {
704                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i+3, pym->tooltip?pym->tooltip:pym->filename);
705         }
706 #endif
707         uiBlockSetDirection(block, UI_RIGHT);
708         uiTextBoundsBlock(block, 60);
709
710         return block;
711 }
712
713 static void do_info_file_exportmenu(void *arg, int event)
714 {
715         ScrArea *sa;
716
717         if(curarea->spacetype==SPACE_INFO) {
718                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
719                 if (!sa) sa= closest_bigger_area();
720                 areawinset(sa->win);
721         }
722 #ifndef DISABLE_PYTHON
723         /* events >=3 are registered bpython scripts */
724         if (event >= 3) BPY_menu_do_python(PYMENU_EXPORT, event - 3);
725         else
726 #endif
727         switch(event) {
728                                                                         
729         case 0:
730                 write_vrml_fs();
731                 break;
732         case 1:
733                 write_dxf_fs();
734                 break;
735         case 2:
736                 write_stl_fs();
737                 break;
738         }
739         allqueue(REDRAWINFO, 0);
740 }
741
742 static uiBlock *info_file_exportmenu(void *arg_unused)
743 {
744         uiBlock *block;
745         short yco = 20, menuwidth = 120;
746 #ifndef DISABLE_PYTHON
747         BPyMenu *pym;
748 #endif
749         int i = 0;
750
751         block= uiNewBlock(&curarea->uiblocks, "exportmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
752         uiBlockSetButmFunc(block, do_info_file_exportmenu, NULL);
753         //uiBlockSetXOfs(block, -50);  // offset to parent button
754
755         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...|Ctrl F2",
756                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "");
757         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...|Shift F2",
758                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "");
759         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "STL...",
760                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "");
761
762 #ifndef DISABLE_PYTHON
763         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
764
765         /* note that we acount for the 3 previous entries with i+3: */
766         for (pym = BPyMenuTable[PYMENU_EXPORT]; pym; pym = pym->next, i++) {
767                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
768                                  NULL, 0.0, 0.0, 1, i+3, 
769                                  pym->tooltip?pym->tooltip:pym->filename);
770         }
771 #endif
772
773         uiBlockSetDirection(block, UI_RIGHT);
774         uiTextBoundsBlock(block, 60);
775
776         return block;
777 }
778
779 #ifdef WITH_VERSE
780
781 extern ListBase session_list;
782
783 static void do_verse_filemenu(void *arg, int event)
784 {
785         char address[64];               /* lenght of domain name is 63 characters or less */
786         VerseSession *session = NULL;
787         ScrArea *sa;
788         
789         if(curarea->spacetype==SPACE_INFO) {
790                 sa= closest_bigger_area();
791                 areawinset(sa->win);
792         }
793
794         switch(event) {
795                 case 0:
796                         waitcursor(1);
797                         printf("Connecting to localhost!\n");
798                         b_verse_connect("localhost");
799                         waitcursor(0);
800                         break;
801                 case 1:
802                         address[0] = '\0';
803                         if(sbutton(address, 0, 63, "Server:")) {
804                                 waitcursor(1);
805                                 printf("Connecting to %s\n", address);
806                                 b_verse_connect(address);
807                                 waitcursor(0);
808                         }
809                         break;
810                 case 2:
811                         session = session_menu();
812                         if(session) {
813                                 printf("Disconnecting session: %s!\n", session->address);
814                                 end_verse_session(session);
815                         }
816                         break;
817                 case 3:
818                         printf("Disconnecting all sessions!\n");
819                         end_all_verse_sessions();
820                         break;
821         case 4:
822             printf("sending get to master server\n");
823             b_verse_ms_get();
824             break;
825         }
826 }
827
828 static uiBlock *verse_filemenu(void *unusedargs)
829 {
830         uiBlock *block;
831         short yco = 20, menuwidth = 120;
832
833         block= uiNewBlock(&curarea->uiblocks, "verse_filemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
834         uiBlockSetButmFunc(block, do_verse_filemenu, NULL);
835                 
836         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Connect to localhost", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
837         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Connect ...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
838         if(session_list.first != NULL) {
839                 if(session_list.first != session_list.last) {
840                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Disconnect ...",
841                                         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
842                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Disconnect all",
843                                         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
844                 }
845                 else {
846                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Disconnect",
847                                         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
848                 }
849                 
850         }
851         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Get Servers", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
852
853         uiBlockSetDirection(block, UI_RIGHT);
854         uiTextBoundsBlock(block, 60);
855
856         return block;
857 }
858 #endif
859
860 static void do_info_filemenu(void *arg, int event)
861 {
862         ScrArea *sa;
863         char dir[FILE_MAX];
864         
865         if(curarea->spacetype==SPACE_INFO) {
866                 sa= closest_bigger_area();
867                 areawinset(sa->win);
868         }
869
870         /* these are no defines, easier this way, the codes are in the function below */
871         switch(event) {
872         case 0:
873                 if (okee("Erase All")) {
874                         if (!BIF_read_homefile(0))
875                                 error("No file ~/.B.blend");
876                 }
877                 break;
878         case 1: /* open */
879                 activate_fileselect(FILE_BLENDER, "Open", G.sce, BIF_read_file);
880                 break;
881         case 3: /* append */
882                 activate_fileselect(FILE_LOADLIB, "Load Library", G.lib, 0);
883                 break;
884         case 4: /* save */
885                 BLI_strncpy(dir, G.sce, FILE_MAX);
886                 untitled(dir);
887                 activate_fileselect(FILE_BLENDER, "Save As", dir, BIF_write_file);
888                 break;
889         case 5:
890                 BLI_strncpy(dir, G.sce, FILE_MAX);
891                 if (untitled(dir)) {
892                         activate_fileselect(FILE_BLENDER, "Save As", dir, BIF_write_file);
893                 } else {
894                         BIF_write_file(dir);
895                         free_filesel_spec(dir);
896                 }
897                 break;
898         case 6: /* save image */
899                 BIF_save_rendered_image_fs();
900                 break;
901         case 7:
902                 activate_imageselect(FILE_LOADLIB, "Load Library", G.lib, 0);
903                 break;
904         case 22: /* save runtime */
905                 activate_fileselect(FILE_SPECIAL, "Save Runtime", "", write_runtime_check);
906                 break;
907         case 23: /* save dynamic runtime */
908                 activate_fileselect(FILE_SPECIAL, "Save Dynamic Runtime", "", write_runtime_check_dynamic);
909                 break;
910         case 24:
911                 BIF_screendump(0);
912                 break;
913         case 25:
914                 BIF_screendump(1);
915                 break;
916         case 13:
917                 exit_usiblender();
918                 break;
919         case 15:        /* recover previous session */
920                 {
921                         extern short winqueue_break; /* editscreen.c */
922                         int save_over, retval = 0;
923                         char str[FILE_MAX];
924                         char scestr[FILE_MAX];
925                         
926                         BLI_strncpy(scestr, G.sce, FILE_MAX);   /* temporal store */
927                         save_over = G.save_over;
928                         BLI_make_file_string("/", str, btempdir, "quit.blend");
929                         retval = BKE_read_file(str, NULL);
930                         
931                         /*we successfully loaded a blend file, get sure that
932                         pointcache works */
933                         if (retval!=0) G.relbase_valid = 1;
934                         
935                         G.save_over = save_over;
936                         strcpy(G.sce, scestr);
937
938                         winqueue_break= 1;      /* leave queues everywhere */
939                 
940                         BKE_reset_undo();
941                         BKE_write_undo("Original");     /* save current state */
942                         refresh_interface_font();
943                 }
944                 break;
945         case 31: /* save default settings */
946                 BIF_write_homefile();
947                 break;
948         case 32:
949                 if (okee("Erase All")) {
950                         if (!BIF_read_homefile(1))
951                                 error("Can't read data from memory!");
952                 }
953                 break;
954         case 35: /* compress toggle */
955                 U.flag ^= (USER_FILECOMPRESS);
956                 break;
957         }
958         
959         allqueue(REDRAWINFO, 0);
960 }
961
962 static void do_info_operecentmenu(void *arg, int event)
963 {
964         struct RecentFile *recent;
965
966         if(event==0 && G.sce[0]) {
967                 BIF_read_file(G.sce);
968         }
969         else {  /* Global */
970                 recent = BLI_findlink(&(G.recent_files), event-1);
971                 BIF_read_file(recent->filename);
972         }
973 }
974
975 static uiBlock *info_openrecentmenu(void *arg_unused)
976 {
977         uiBlock *block;
978         short yco = 20, menuwidth = 120, i;
979         struct RecentFile *recent;
980
981         block= uiNewBlock(&curarea->uiblocks, "info_openrecentmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
982         uiBlockSetButmFunc(block, do_info_operecentmenu, NULL);
983
984         if (G.sce[0]) {
985                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, G.sce, 0, yco-=20,
986                                 menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
987         }
988
989         for (recent = G.recent_files.first, i=0; i<U.recent_files && recent; recent = recent->next, i++) {
990                 if (strcmp(recent->filename, G.sce)!=0) {
991                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, recent->filename, 0, yco-=20,
992                                         menuwidth, 19, NULL, 0.0, 0.0, 1, i+1, "");
993                 }
994         }
995
996         uiBlockSetDirection(block, UI_RIGHT);
997         uiTextBoundsBlock(block, 60);
998         return block;
999 }
1000
1001 static void do_info_externalfiles(void *arg, int event)
1002 {
1003         switch (event) {
1004                 
1005         case 1: /* pack data */
1006                 check_packAll();
1007                 break;
1008 #if 0
1009         case 2: /* unpack to current dir */
1010                 unpackAll(PF_WRITE_LOCAL);
1011                 G.fileflags &= ~G_AUTOPACK;
1012                 break;
1013 #endif
1014         case 3: /* unpack data */
1015                 if (buttons_do_unpack() != RET_CANCEL) {
1016                         /* Clear autopack bit only if user selected one of the unpack options */
1017                         G.fileflags &= ~G_AUTOPACK;
1018                 }
1019                 break;
1020         case 10: /* make all paths relative */
1021                 if (G.relbase_valid) {
1022                         int tot,changed,failed,linked;
1023                         char str[512];
1024                         char txtname[24]; /* text block name */
1025                         txtname[0] = '\0';
1026                         makeFilesRelative(txtname, &tot, &changed, &failed, &linked);
1027                         if (failed) sprintf(str, "Make Relative%%t|Total files %i|Changed %i|Failed %i, See Text \"%s\"|Linked %i", tot, changed, failed, txtname, linked);
1028                         else            sprintf(str, "Make Relative%%t|Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
1029                         pupmenu(str);
1030                 } else {
1031                         pupmenu("Can't set relative paths with an unsaved blend file");
1032                 }
1033                 break;
1034         case 11: /* make all paths absolute */
1035                 {
1036                         int tot,changed,failed,linked;
1037                         char str[512];
1038                         char txtname[24]; /* text block name */
1039                         txtname[0] = '\0';
1040                         makeFilesAbsolute(txtname, &tot, &changed, &failed, &linked);
1041                         sprintf(str, "Make Absolute%%t|Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
1042                         if (failed) sprintf(str, "Make Absolute%%t|Total files %i|Changed %i|Failed %i, See Text \"%s\"|Linked %i", tot, changed, failed, txtname, linked);
1043                         else            sprintf(str, "Make Absolute%%t|Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
1044                         
1045                         pupmenu(str);
1046                 }
1047                 break;
1048         case 12: /* check images exist */
1049                 {
1050                         char txtname[24]; /* text block name */
1051                         txtname[0] = '\0';
1052                         
1053                         /* run the missing file check */
1054                         checkMissingFiles( txtname );
1055                         
1056                         if (txtname[0] == '\0') {
1057                                 okee("No external files missing");
1058                         } else {
1059                                 char str[128];
1060                                 sprintf(str, "Missing files listed in Text \"%s\"", txtname );
1061                                 error(str);
1062                         }
1063                 }
1064                 break;
1065         case 13: /* search for referenced files that are not available  */
1066                 if(curarea->spacetype==SPACE_INFO) {
1067                         ScrArea *sa;
1068                         sa= closest_bigger_area();
1069                         areawinset(sa->win);
1070                 }
1071                 activate_fileselect(FILE_SPECIAL, "Find Missing Files", "", findMissingFiles);
1072                 break;
1073         }
1074         
1075         allqueue(REDRAWINFO, 0);
1076 }
1077
1078 static uiBlock *info_externalfiles(void *arg_unused)
1079 {
1080         uiBlock *block;
1081         short yco = 20, menuwidth = 120;
1082
1083         block= uiNewBlock(&curarea->uiblocks, "info_externalfiles", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1084         uiBlockSetButmFunc(block, do_info_externalfiles, NULL);
1085
1086         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack into .blend file",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1087 #if 0
1088         uiDefBut(block, BUTM, 1, "Unpack Data to current dir",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Removes all packed files from the project and saves them to the current directory");
1089 #endif
1090         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpack into Files...",                           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1091
1092         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1093         
1094         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Make all Paths Relative",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "");
1095         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Make all Paths Absolute",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 11, "");
1096         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Report Missing Files...",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 12, "");
1097         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Find Missing Files...",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 13, "");
1098
1099         uiBlockSetDirection(block, UI_RIGHT);
1100         uiTextBoundsBlock(block, 60);
1101         return block;
1102 }
1103
1104 static uiBlock *info_filemenu(void *arg_unused)
1105 {
1106         uiBlock *block;
1107         short yco=0;
1108         short menuwidth=120;
1109
1110         block= uiNewBlock(&curarea->uiblocks, "info_filemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1111         uiBlockSetButmFunc(block, do_info_filemenu, NULL);
1112         
1113         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "New|Ctrl X",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
1114         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Open...|F1",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1115 #ifdef WITH_VERSE
1116         uiDefIconTextBlockBut(block, verse_filemenu, NULL, ICON_RIGHTARROW_THIN, "Verse", 0, yco-=20, menuwidth, 19, "");
1117 #endif
1118         uiDefIconTextBlockBut(block, info_openrecentmenu, NULL, ICON_RIGHTARROW_THIN, "Open Recent",0, yco-=20, 120, 19, "");
1119         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Recover Last Session",                           0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 15, "");
1120
1121         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1122
1123         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save|Ctrl W",                            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1124         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save As...|F2",                  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
1125         
1126         if(U.flag & USER_FILECOMPRESS) {
1127                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Compress File",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 35, "Enable file compression");
1128         } else {
1129                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Compress File",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 35, "Enable file compression");
1130         }
1131
1132         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1133
1134         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Rendered Image...|F3",                      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
1135         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Screenshot Subwindow|Ctrl F3",                   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 24, "");
1136         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Screenshot All|Ctrl Shift F3",                   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 25, "");
1137 #if GAMEBLENDER == 1
1138         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Game As Runtime...",                        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 22, "");
1139 #ifdef _WIN32
1140 //       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Dynamic Runtime...",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 23, "");
1141 #endif
1142 #endif
1143         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1144
1145         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Default Settings|Ctrl U",                   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 31, "");
1146         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Load Factory Settings",                          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 32, "");
1147
1148
1149         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1150
1151         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Append or Link|Shift F1",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1152         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Append or Link (Image Browser)|Ctrl F1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
1153         uiDefIconTextBlockBut(block, info_file_importmenu, NULL, ICON_RIGHTARROW_THIN, "Import", 0, yco-=20, menuwidth, 19, "");
1154         uiDefIconTextBlockBut(block, info_file_exportmenu, NULL, ICON_RIGHTARROW_THIN, "Export", 0, yco-=20, menuwidth, 19, "");
1155         
1156         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1157         
1158         uiDefIconTextBlockBut(block, info_externalfiles, NULL, ICON_RIGHTARROW_THIN, "External Data",0, yco-=20, 120, 19, "");
1159         
1160         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1161         
1162         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Quit Blender|Ctrl Q",                            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 13, "");
1163
1164         uiBlockSetDirection(block, UI_DOWN);
1165         uiTextBoundsBlock(block, 80);
1166
1167         return block;
1168 }
1169
1170 /**************************** ADD ******************************/
1171
1172 void do_info_add_meshmenu(void *arg, int event)
1173 {
1174 #ifndef DISABLE_PYTHON
1175         if (event>=20) {
1176                 BPY_menu_do_python(PYMENU_ADDMESH, event - 20);
1177         } else
1178 #endif
1179         {
1180                 switch(event) {         
1181                         case 0:
1182                                 /* Plane */
1183                                 add_primitiveMesh(0);
1184                                 break;
1185                         case 1:
1186                                 /* Cube */
1187                                 add_primitiveMesh(1);
1188                                 break;
1189                         case 2:
1190                                 /* Circle */
1191                                 add_primitiveMesh(4);
1192                                 break;
1193                         case 3:
1194                                 /* UVsphere */
1195                                 add_primitiveMesh(11);
1196                                 break;
1197                         case 4:
1198                                 /* IcoSphere */
1199                                 add_primitiveMesh(12);
1200                                 break;
1201                         case 5:
1202                                 /* Cylinder */
1203                                 add_primitiveMesh(5);
1204                                 break;
1205                         case 7:
1206                                 /* Cone */
1207                                 add_primitiveMesh(7);
1208                                 break;
1209                         case 8:
1210                                 /* Grid */
1211                                 add_primitiveMesh(10);
1212                                 break;
1213                         case 9:
1214                                 /* Monkey */
1215                                 add_primitiveMesh(13);
1216                                 break;
1217                         default:
1218                                 break;
1219                 }
1220         }
1221         allqueue(REDRAWINFO, 0);
1222 }
1223
1224 static uiBlock *info_add_meshmenu(void *arg_unused)
1225 {
1226 /*              static short tog=0; */
1227         uiBlock *block;
1228         short yco= 0;
1229         
1230         /* Python Menu */
1231 #ifndef DISABLE_PYTHON
1232         BPyMenu *pym;
1233 #endif
1234         int i=0;
1235         
1236         block= uiNewBlock(&curarea->uiblocks, "add_meshmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1237         uiBlockSetButmFunc(block, do_info_add_meshmenu, NULL);
1238         
1239         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Plane|",                         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1240         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cube|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1241         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Circle|",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1242         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "UVsphere",                       0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1243         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "IcoSphere|",                     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1244         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cylinder|",                      0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
1245         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cone|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "");
1246         uiDefIconTextBut(block, SEPR, 0, ICON_BLANK1, "",                                       0, yco-=6,      160, 6,  NULL, 0.0, 0.0, 0, 0, "");
1247         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grid|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "");
1248         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Monkey|",                        0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 9, "");
1249
1250 #ifndef DISABLE_PYTHON
1251         pym = BPyMenuTable[PYMENU_ADDMESH];
1252         if (pym) {
1253                 uiDefIconTextBut(block, SEPR, 0, ICON_BLANK1, "",                                       0, yco-=6,      160, 6,  NULL, 0.0, 0.0, 0, 0, "");
1254                 
1255                 for (; pym; pym = pym->next, i++) {
1256                         uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, i+20, pym->tooltip?pym->tooltip:pym->filename);
1257                 }
1258         }
1259 #endif
1260
1261         uiBlockSetDirection(block, UI_RIGHT);
1262         uiTextBoundsBlock(block, 50);
1263                 
1264         return block;
1265 }
1266
1267 void do_info_add_curvemenu(void *arg, int event)
1268 {
1269
1270         switch(event) {         
1271                 case 0:
1272                         /* Bezier Curve */
1273                         add_primitiveCurve(10);
1274                         break;
1275                 case 1:
1276                         /* Bezier Circle */
1277                         add_primitiveCurve(11);
1278                         break;
1279                 case 2:
1280                         /* NURB Curve */
1281                         add_primitiveCurve(40);
1282                         break;
1283                 case 3:
1284                         /* NURB Circle */
1285                         add_primitiveCurve(41);
1286                         break;
1287                 case 4:
1288                         /* Path */
1289                         add_primitiveCurve(46);
1290                         break;
1291                 default:
1292                         break;
1293         }
1294         allqueue(REDRAWINFO, 0);
1295 }
1296
1297 static uiBlock *info_add_curvemenu(void *arg_unused)
1298 {
1299 /*              static short tog=0; */
1300         uiBlock *block;
1301         short yco= 0;
1302         
1303         block= uiNewBlock(&curarea->uiblocks, "add_curvemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1304         uiBlockSetButmFunc(block, do_info_add_curvemenu, NULL);
1305         
1306         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Bezier Curve|",  0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1307         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Bezier Circle|", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1308         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Curve|",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1309         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Circle",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1310         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Path|",                  0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1311
1312         uiBlockSetDirection(block, UI_RIGHT);
1313         uiTextBoundsBlock(block, 50);
1314                 
1315         return block;
1316 }
1317
1318
1319 void do_info_add_surfacemenu(void *arg, int event)
1320 {
1321
1322         switch(event) {         
1323                 case 0:
1324                         /* Curve */
1325                         add_primitiveNurb(0);
1326                         break;
1327                 case 1:
1328                         /* Circle */
1329                         add_primitiveNurb(1);
1330                         break;
1331                 case 2:
1332                         /* Surface */
1333                         add_primitiveNurb(2);
1334                         break;
1335                 case 3:
1336                         /* Tube */
1337                         add_primitiveNurb(3);
1338                         break;
1339                 case 4:
1340                         /* Sphere */
1341                         add_primitiveNurb(4);
1342                         break;
1343                 case 5:
1344                         /* Donut */
1345                         add_primitiveNurb(5);
1346                         break;
1347                 default:
1348                         break;
1349         }
1350         allqueue(REDRAWINFO, 0);
1351 }
1352
1353 static uiBlock *info_add_surfacemenu(void *arg_unused)
1354 {
1355 /*              static short tog=0; */
1356         uiBlock *block;
1357         short yco= 0;
1358         
1359         block= uiNewBlock(&curarea->uiblocks, "add_surfacemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1360         uiBlockSetButmFunc(block, do_info_add_surfacemenu, NULL);
1361         
1362         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Curve|",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1363         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Circle|",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1364         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Surface|", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1365         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Tube",             0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1366         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Sphere|",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1367         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Donut|",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
1368         uiBlockSetDirection(block, UI_RIGHT);
1369         uiTextBoundsBlock(block, 50);
1370                 
1371         return block;
1372 }
1373
1374 void do_info_add_metamenu(void *arg, int event)
1375 {
1376
1377         switch(event) {         
1378                 case 0:
1379                         /* Ball */
1380                         add_primitiveMball(1);
1381                         break;
1382                 case 1:
1383                         /* Tube */
1384                         add_primitiveMball(2);
1385                         break;
1386                 case 2:
1387                         /* Plane */
1388                         add_primitiveMball(3);
1389                         break;
1390                 case 3:
1391                         /* Elipsoid */
1392                         add_primitiveMball(4);
1393                         break;
1394                 case 4:
1395                         /* Cube */
1396                         add_primitiveMball(5);
1397                         break;
1398                 default:
1399                         break;
1400         }
1401         allqueue(REDRAWINFO, 0);
1402 }
1403
1404
1405 static uiBlock *info_add_metamenu(void *arg_unused)
1406 {
1407 /*              static short tog=0; */
1408         uiBlock *block;
1409         short xco= 0;
1410         
1411         block= uiNewBlock(&curarea->uiblocks, "add_metamenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1412         uiBlockSetButmFunc(block, do_info_add_metamenu, NULL);
1413         
1414         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,"Meta Ball|",              0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1415         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Tube|",             0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1416         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Plane|",            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1417         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Ellipsoid|",        0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1418         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Cube|",             0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1419
1420         uiBlockSetDirection(block, UI_RIGHT);
1421         uiTextBoundsBlock(block, 50);
1422                 
1423         return block;
1424 }
1425
1426 void do_info_add_lampmenu(void *arg, int event)
1427 {
1428
1429         switch(event) {         
1430                 case 0: /* lamp */
1431                         add_objectLamp(LA_LOCAL);
1432                         break;
1433                 case 1: /* sun */
1434                         add_objectLamp(LA_SUN);
1435                         break;
1436                 case 2: /* spot */
1437                         add_objectLamp(LA_SPOT);
1438                         break;
1439                 case 3: /* hemi */
1440                         add_objectLamp(LA_HEMI);
1441                         break;
1442                 case 4: /* area */
1443                         add_objectLamp(LA_AREA);
1444                         break;
1445                 case 5: /* YafRay photon lamp */
1446                         if (G.scene->r.renderer==R_YAFRAY)
1447                                 add_objectLamp(LA_YF_PHOTON);
1448                         break;
1449                 default:
1450                         break;
1451         }
1452         allqueue(REDRAWINFO, 0);
1453 }
1454
1455 static uiBlock *info_add_lampmenu(void *arg_unused)
1456 {
1457 /*              static short tog=0; */
1458         uiBlock *block;
1459         short yco= 0;
1460         
1461         block= uiNewBlock(&curarea->uiblocks, "add_lampmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1462         uiBlockSetButmFunc(block, do_info_add_lampmenu, NULL);
1463         
1464         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Lamp|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1465         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Sun|",                           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1466         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Spot|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1467         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hemi|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1468         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Area|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1469         if (G.scene->r.renderer==R_YAFRAY)
1470                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Photon|",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
1471         
1472         uiBlockSetDirection(block, UI_RIGHT);
1473         uiTextBoundsBlock(block, 50);
1474                 
1475         return block;
1476 }
1477
1478 static void do_info_add_groupmenu(void *arg, int event)
1479 {
1480         Object *ob;
1481         
1482         add_object_draw(OB_EMPTY);
1483         ob= OBACT;
1484         
1485         ob->dup_group= BLI_findlink(&G.main->group, event);
1486         if(ob->dup_group) {
1487                 id_us_plus((ID *)ob->dup_group);
1488                 ob->transflag |= OB_DUPLIGROUP;
1489                 DAG_scene_sort(G.scene);
1490         }
1491 }
1492
1493
1494 static uiBlock *info_add_groupmenu(void *arg_unused)
1495 {
1496         Group *group;
1497         uiBlock *block;
1498         short yco= 0;
1499         int a;
1500         
1501         block= uiNewBlock(&curarea->uiblocks, "add_groupmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1502         uiBlockSetButmFunc(block, do_info_add_groupmenu, NULL);
1503         
1504         for(a=0, group= G.main->group.first; group; group= group->id.next, a++) {
1505                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, group->id.name+2,                         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, a, "");
1506         }
1507         
1508         uiBlockSetDirection(block, UI_RIGHT);
1509         uiTextBoundsBlock(block, 50);
1510                 
1511         return block;
1512 }
1513
1514 void do_info_addmenu(void *arg, int event)
1515 {
1516 #ifndef DISABLE_PYTHON
1517         if (event>=20) {
1518                 BPY_menu_do_python(PYMENU_ADD, event - 20);
1519         } else
1520 #endif
1521         {
1522                 switch(event) {         
1523                         case 0:
1524                                 /* Mesh */
1525                                 break;
1526                         case 1:
1527                                 /* Curve */
1528                                 break;
1529                         case 2:
1530                                 /* Surface */
1531                                 break;
1532                         case 3:
1533                                 /* Metaball */
1534                                 break;
1535                         case 4:
1536                                 /* Text (argument is discarded) */
1537                                 add_primitiveFont(event);
1538                                 break;
1539                         case 5:
1540                                 /* Empty */
1541                                 add_object_draw(OB_EMPTY);
1542                                 break;
1543                         case 6:
1544                                 /* Camera */
1545                                 add_object_draw(OB_CAMERA);
1546                                 break;
1547                         case 8:
1548                                 /* Armature */
1549                                 add_primitiveArmature(OB_ARMATURE);
1550                                 break;
1551                         case 9:
1552                                 /* Lattice */
1553                                 add_object_draw(OB_LATTICE);
1554                                 break;
1555                         case 10:
1556                                 /* group instance not yet */
1557                                 break;
1558                         default:
1559                                 break;
1560                 }
1561         }
1562         allqueue(REDRAWINFO, 0);
1563 }
1564
1565
1566 static uiBlock *info_addmenu(void *arg_unused)
1567 {
1568 /*              static short tog=0; */
1569         uiBlock *block;
1570 #ifndef DISABLE_PYTHON
1571         BPyMenu *pym;
1572 #endif
1573         int i=0;
1574         short yco= 0;
1575
1576         block= uiNewBlock(&curarea->uiblocks, "addmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1577         uiBlockSetButmFunc(block, do_info_addmenu, NULL);
1578         
1579         uiDefIconTextBlockBut(block, info_add_meshmenu, NULL, ICON_RIGHTARROW_THIN, "Mesh", 0, yco-=20, 120, 19, "");
1580         uiDefIconTextBlockBut(block, info_add_curvemenu, NULL, ICON_RIGHTARROW_THIN, "Curve", 0, yco-=20, 120, 19, "");
1581         uiDefIconTextBlockBut(block, info_add_surfacemenu, NULL, ICON_RIGHTARROW_THIN, "Surface", 0, yco-=20, 120, 19, "");
1582         uiDefIconTextBlockBut(block, info_add_metamenu, NULL, ICON_RIGHTARROW_THIN, "Meta", 0, yco-=20, 120, 19, "");
1583         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Text",                           0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 4, "");
1584         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Empty",                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 5, "");
1585         
1586         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1587         
1588         uiDefIconTextBlockBut(block, info_add_groupmenu, NULL, ICON_RIGHTARROW_THIN, "Group", 0, yco-=20, 120, 19, "");
1589         
1590         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1591         
1592         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Camera",                         0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 6, "");
1593         uiDefIconTextBlockBut(block, info_add_lampmenu, NULL, ICON_RIGHTARROW_THIN, "Lamp", 0, yco-=20, 120, 19, "");
1594         
1595         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1596         
1597         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Armature",                       0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 8, "");
1598         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Lattice",                        0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 9, "");
1599
1600 #ifndef DISABLE_PYTHON
1601         pym = BPyMenuTable[PYMENU_ADD];
1602         if (pym) {
1603                 uiDefIconTextBut(block, SEPR, 0, ICON_BLANK1, "",                                       0, yco-=6,      1620, 6,  NULL, 0.0, 0.0, 0, 0, "");
1604                 
1605                 for (; pym; pym = pym->next, i++) {
1606                         uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, i+20, pym->tooltip?pym->tooltip:pym->filename);
1607                 }
1608         }
1609 #endif
1610         
1611         uiBlockSetDirection(block, UI_DOWN);
1612         uiTextBoundsBlock(block, 80);
1613                 
1614         return block;
1615 }
1616
1617 /************************** GAME *****************************/
1618
1619 void do_info_game_glslmenu(void *arg, int event)
1620 {
1621         switch (event) {
1622         case G_FILE_GLSL_NO_LIGHTS:
1623         case G_FILE_GLSL_NO_SHADERS:
1624         case G_FILE_GLSL_NO_SHADOWS:
1625         case G_FILE_GLSL_NO_RAMPS:
1626         case G_FILE_GLSL_NO_NODES:
1627         case G_FILE_GLSL_NO_EXTRA_TEX:
1628                 G.fileflags ^= event;
1629                 GPU_materials_free();
1630                 allqueue(REDRAWINFO, 0);
1631                 allqueue(REDRAWVIEW3D, 0);
1632                 break;
1633         default:
1634                 break;
1635         }       
1636 }
1637
1638 static uiBlock *info_game_glslmenu(void *arg_unused)
1639 {
1640         uiBlock *block;
1641         short yco= 0, menuwidth=160;
1642         int check;
1643         
1644         block= uiNewBlock(&curarea->uiblocks, "game_glslmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1645         uiBlockSetButmFunc(block, do_info_game_glslmenu, NULL);
1646
1647         check = (G.fileflags & G_FILE_GLSL_NO_LIGHTS)? ICON_CHECKBOX_DEHLT: ICON_CHECKBOX_HLT;
1648         uiDefIconTextBut(block, BUTM, 1, check, "Enable Lights",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GLSL_NO_LIGHTS,
1649                 "Enable using lights in GLSL materials.");
1650         check = (G.fileflags & G_FILE_GLSL_NO_SHADERS)? ICON_CHECKBOX_DEHLT: ICON_CHECKBOX_HLT;
1651         uiDefIconTextBut(block, BUTM, 1, check, "Enable Shaders",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GLSL_NO_SHADERS,
1652                 "Enable using shaders other than Lambert in GLSL materials");
1653         check = (G.fileflags & G_FILE_GLSL_NO_SHADOWS)? ICON_CHECKBOX_DEHLT: ICON_CHECKBOX_HLT;
1654         uiDefIconTextBut(block, BUTM, 1, check, "Enable Shadows",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GLSL_NO_SHADOWS,
1655                 "Enable using shadows in GLSL materials");
1656         check = (G.fileflags & G_FILE_GLSL_NO_RAMPS)? ICON_CHECKBOX_DEHLT: ICON_CHECKBOX_HLT;
1657         uiDefIconTextBut(block, BUTM, 1, check, "Enable Ramps",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GLSL_NO_RAMPS,
1658                 "Enable using ramps in GLSL materials");
1659         check = (G.fileflags & G_FILE_GLSL_NO_NODES)? ICON_CHECKBOX_DEHLT: ICON_CHECKBOX_HLT;
1660         uiDefIconTextBut(block, BUTM, 1, check, "Enable Nodes",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GLSL_NO_NODES,
1661                 "Enable using nodes in GLSL materials.");
1662         check = (G.fileflags & G_FILE_GLSL_NO_EXTRA_TEX)? ICON_CHECKBOX_DEHLT: ICON_CHECKBOX_HLT;
1663         uiDefIconTextBut(block, BUTM, 1, check, "Enable Extra Textures",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GLSL_NO_EXTRA_TEX,
1664                 "Enable using texture channels other than Col and Alpha in GLSL materials.");
1665
1666         uiBlockSetDirection(block, UI_RIGHT);
1667         uiTextBoundsBlock(block, 50);
1668                 
1669         return block;
1670 }
1671
1672 static void do_info_gamemenu(void *arg, int event)
1673 {
1674         switch (event) {
1675         case G_FILE_ENABLE_ALL_FRAMES:
1676         case G_FILE_DISPLAY_LISTS:
1677         case G_FILE_SHOW_FRAMERATE:
1678         case G_FILE_SHOW_DEBUG_PROPS:
1679         case G_FILE_AUTOPLAY:
1680         case G_FILE_GAME_TO_IPO:
1681         case G_FILE_SHOW_PHYSICS:
1682                 G.fileflags ^= event;
1683                 break;
1684         case G_FILE_GAME_MAT|G_FILE_GAME_MAT_GLSL:
1685                 G.fileflags &= ~(G_FILE_GAME_MAT|G_FILE_GAME_MAT_GLSL);
1686                 break;
1687         case G_FILE_GAME_MAT:
1688                 G.fileflags |= G_FILE_GAME_MAT;
1689                 G.fileflags &= ~G_FILE_GAME_MAT_GLSL;
1690                 break;
1691         case G_FILE_GAME_MAT_GLSL:
1692                 if(!GPU_extensions_minimum_support())
1693                         error("GLSL not supported with this graphics card or driver.");
1694                 G.fileflags |= (G_FILE_GAME_MAT|G_FILE_GAME_MAT_GLSL);
1695                 break;
1696         default:
1697                 ; /* ignore the rest */
1698         }
1699 }
1700
1701 static uiBlock *info_gamemenu(void *arg_unused)
1702 {
1703 /*              static short tog=0; */
1704         uiBlock *block;
1705         short yco= 0;
1706         short menuwidth=120;
1707         
1708         block= uiNewBlock(&curarea->uiblocks, "gamemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1709         uiBlockSetButmFunc(block, do_info_gamemenu, NULL);
1710         
1711         uiDefIconTextBut(block, BUTM, B_STARTGAME, ICON_BLANK1, "Start Game|P",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
1712         
1713         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 1, 0, "");
1714
1715
1716         if(G.fileflags & G_FILE_ENABLE_ALL_FRAMES) {
1717                 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, "");
1718         } else {
1719                 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, "");
1720         }
1721         
1722         if(G.fileflags & G_FILE_GAME_TO_IPO) {
1723                 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, "");
1724         } else {
1725
1726         if(G.fileflags & G_FILE_DISPLAY_LISTS) {
1727                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Generate Display Lists",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_DISPLAY_LISTS, "");
1728         } else {
1729                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Generate Display Lists",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_DISPLAY_LISTS, "");
1730         }       
1731                 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, "");
1732         }
1733         
1734         if(G.fileflags & G_FILE_SHOW_FRAMERATE) {
1735                 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, "");
1736         } else {
1737                 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, "");
1738         }
1739
1740
1741         if(G.fileflags & G_FILE_SHOW_PHYSICS) {
1742                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Show Physics Visualization",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_SHOW_PHYSICS, "");
1743         } else {
1744                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Show Physics Visualization",              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_SHOW_PHYSICS, "");
1745         }
1746         
1747         if(G.fileflags & G_FILE_SHOW_DEBUG_PROPS) {
1748                 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, "");
1749         } else {
1750                 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, "");
1751         }
1752
1753         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 1, 0, "");
1754
1755         if(!(G.fileflags & G_FILE_GAME_MAT)) {
1756                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Texture Face Materials",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
1757         } else {
1758                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Texture Face Materials",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GAME_MAT|G_FILE_GAME_MAT_GLSL, "");
1759         }       
1760
1761         if((G.fileflags & G_FILE_GAME_MAT) && !(G.fileflags & G_FILE_GAME_MAT_GLSL)) {
1762                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Blender Multitexture Materials",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
1763         } else {
1764                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Blender Multitexture Materials",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GAME_MAT, "");
1765         }       
1766
1767         if((G.fileflags & G_FILE_GAME_MAT) && (G.fileflags & G_FILE_GAME_MAT_GLSL)) {
1768                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Blender GLSL Materials",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
1769         } else {
1770                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Blender GLSL Materials",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_GAME_MAT_GLSL, "");
1771         }       
1772
1773         uiDefIconTextBlockBut(block, info_game_glslmenu, NULL, ICON_RIGHTARROW_THIN, "GLSL Material Settings", 0, yco-=20, menuwidth, 19, "");
1774         
1775         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 1, 0, "");
1776
1777         if(G.fileflags & G_FILE_AUTOPLAY) {
1778                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Autostart",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_AUTOPLAY, "");
1779         } else {
1780                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Autostart",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_AUTOPLAY, "");
1781         }
1782
1783         uiBlockSetDirection(block, UI_DOWN);
1784         uiTextBoundsBlock(block, 70);
1785         
1786         return block;
1787 }
1788 /************************** TIMELINE *****************************/
1789
1790 static void do_info_timelinemenu(void *arg, int event)
1791 {
1792         /* needed to check for valid selected objects */
1793         Base *base=NULL;
1794         Object *ob=NULL;
1795         //char file[FILE_MAXDIR+FILE_MAXFILE];
1796
1797         base= BASACT;
1798         if (base) ob= base->object;
1799
1800         switch(event) {
1801         case 1:
1802                 /* Show Keyframes */
1803                 if (!ob) error("Select an object before showing its keyframes");
1804                 else set_ob_ipoflags();
1805                 break;
1806         case 2:
1807                 /* Show and select Keyframes */
1808                 if (!ob) error("Select an object before showing and selecting its keyframes");
1809                 else select_select_keys();
1810                         break;
1811         case 3:
1812                 /* select next keyframe */
1813                 if (!ob) error("Select an object before selecting its next keyframe");
1814                 else nextkey_obipo(1);
1815                         break;
1816         case 4:
1817                 /* select previous keyframe */
1818                 if (!ob) error("Select an object before selecting its previous keyframe");
1819                 else nextkey_obipo(-1);
1820                 break;
1821                 case 5:
1822         /* next keyframe */
1823                 if (!ob) error("Select an object before going to its next keyframe");
1824                 else movekey_obipo(1);
1825                         break;
1826                 case 6:
1827         /* previous keyframe */
1828                 if (!ob) error("Select an object before going to its previous keyframe");
1829                 else movekey_obipo(-1);
1830                 break;
1831         case 7:
1832                 /* next frame */
1833                 CFRA++;
1834                 update_for_newframe();
1835                 break;
1836                 case 8:
1837                 /* previous frame */
1838                 CFRA--;
1839                 if(CFRA<1) CFRA=1;
1840                 update_for_newframe();
1841                 break;
1842         case 9:
1843                 /* forward 10 frames */
1844                 CFRA+= 10;
1845                 update_for_newframe();
1846                 break;
1847         case 10:
1848                 /* back 10 frames */
1849                 CFRA-= 10;
1850                 if(CFRA<1) CFRA=1;
1851                 update_for_newframe();
1852                 break;
1853         case 11:
1854                 /* end frame */
1855                 CFRA= EFRA;
1856                 update_for_newframe();
1857                 break;
1858         case 12:
1859                 /* start frame */
1860                 CFRA= SFRA;
1861                 update_for_newframe();
1862                 break;
1863         case 13: 
1864                 /* previous keyframe */
1865                 nextprev_timeline_key(-1);
1866                 break;
1867         case 14:
1868                 /* next keyframe */
1869                 nextprev_timeline_key(1);
1870                 break;
1871         }
1872         allqueue(REDRAWINFO, 0);
1873 }
1874
1875 static uiBlock *info_timelinemenu(void *arg_unused)
1876 {
1877 /*              static short tog=0; */
1878         uiBlock *block;
1879         char str[26];
1880         short yco= 0;
1881         short menuwidth=120;
1882
1883         block= uiNewBlock(&curarea->uiblocks, "timelinemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1884         uiBlockSetButmFunc(block, do_info_timelinemenu, NULL);
1885         
1886         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Keyframes|K",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1887         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show and Select Keyframes|Shift K",0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1888         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Next Keyframe|PageUp",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1889         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Previous Keyframe|PageDown",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
1890
1891         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1892
1893         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Next Ob-Keyframe|Shift PageUp",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1894         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Previous Ob-Keyframe|Shift PageDown",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
1895
1896         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Next Keyframe|Ctrl PageUp",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 13, "");
1897         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Previous Keyframe|Ctrl PageDown",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 14, "");
1898         
1899         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1900
1901         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Next Frame|RightArrow",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
1902         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Previous Frame|LeftArrow",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, "");
1903         
1904         sprintf(str, "Forward %d Frames|UpArrow", G.scene->jumpframe);
1905         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, str,      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, "");
1906         sprintf(str, "Back %d Frames|DownArrow", G.scene->jumpframe);
1907         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, str,      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
1908
1909         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1910
1911         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "End Frame|Shift RightArrow",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
1912         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Start Frame|Shift LeftArrow",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
1913
1914         uiBlockSetDirection(block, UI_DOWN);
1915         uiTextBoundsBlock(block, 80);
1916
1917         return block;
1918 }
1919
1920 /************************** RENDER *****************************/
1921
1922 void do_info_render_bakemenu(void *arg, int event)
1923 {
1924         switch (event) {
1925         case 6:
1926                 G.scene->r.bake_flag ^= event;
1927                 break;
1928         default:
1929                 objects_bake_render_ui(event);
1930         }       
1931         
1932         allqueue(REDRAWINFO, 0);
1933 }
1934
1935 static uiBlock *info_render_bakemenu(void *arg_unused)
1936 {
1937         uiBlock *block;
1938         short yco= 0, menuwidth=160;
1939         
1940         block= uiNewBlock(&curarea->uiblocks, "render_bakemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1941         uiBlockSetButmFunc(block, do_info_render_bakemenu, NULL);
1942         
1943         if(G.scene->r.bake_flag & R_BAKE_TO_ACTIVE) {
1944                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Selected to Active",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
1945         } else {
1946                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Selected to Active",              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
1947         }
1948         
1949         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1950         
1951         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Full Render|Ctrl Alt B, 1",                              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1952         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Ambient Occlusion|Ctrl Alt B, 2",                                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1953         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Normals|Ctrl Alt B, 3",                          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1954         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Texture Only|Ctrl Alt B, 4",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
1955         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Displacement|Ctrl Alt B, 5",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");   
1956
1957         uiBlockSetDirection(block, UI_RIGHT);
1958         uiTextBoundsBlock(block, 50);
1959                 
1960         return block;
1961 }
1962
1963 static void do_info_rendermenu(void *arg, int event)
1964 {
1965         ScrArea *sa;
1966         extern void playback_anim();
1967
1968         /* events >=10 are registered bpython scripts */
1969         if (event >= 10) {
1970                 if(curarea->spacetype==SPACE_INFO) {
1971                         sa= find_biggest_area_of_type(SPACE_SCRIPT);
1972                         if (!sa) sa= closest_bigger_area();
1973                         areawinset(sa->win);
1974                 }
1975 #ifndef DISABLE_PYTHON
1976                 BPY_menu_do_python(PYMENU_RENDER, event - 10);
1977                 BIF_undo_push("Rendering Script");
1978 #endif
1979         }
1980         else {
1981         switch(event) {
1982                         
1983                 case 0:
1984                         BIF_do_render(0);
1985                         break;
1986                 case 1:
1987                         BIF_do_render(1);
1988                         break;
1989
1990                         /* note: dont use select_area() for setting active areas for opengl render */
1991                         /* its hackish and instable... code here was removed */
1992                 
1993                 case 4:
1994                         BIF_toggle_render_display();
1995                         break;
1996                 case 5:
1997                         playback_anim();
1998                         break;
1999                 case 6:
2000                         /* dodgy hack turning on SHIFT key to do a proper render border select
2001                         set_render_border(); only works when 3d window active
2002                         
2003                         This code copied from toolbox.c, only works when 3d window is cameraview */
2004
2005                         if(select_area(SPACE_VIEW3D)) {
2006                                 mainqenter(LEFTSHIFTKEY, 1);
2007                                 mainqenter(BKEY, 1);
2008                                 mainqenter(BKEY, 0);
2009                                 mainqenter(EXECUTE, 1);
2010                                 mainqenter(LEFTSHIFTKEY, 0);
2011                         }
2012
2013                         break;
2014
2015                 case 7:
2016                         extern_set_butspace(F10KEY, 0);
2017                         break;
2018                 }
2019         }
2020         allqueue(REDRAWINFO, 0);
2021 }
2022
2023 static uiBlock *info_rendermenu(void *arg_unused)
2024 {
2025         uiBlock *block;
2026 #ifndef DISABLE_PYTHON
2027         BPyMenu *pym;
2028 #endif
2029         short yco= 0;
2030         short menuwidth=120;
2031         int i=0;
2032         
2033         block= uiNewBlock(&curarea->uiblocks, "rendermenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
2034         uiBlockSetButmFunc(block, do_info_rendermenu, NULL);
2035         
2036         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Current Frame|F12",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
2037         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Animation|Ctrl F12",              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
2038         
2039         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
2040         
2041         uiDefIconTextBlockBut(block, info_render_bakemenu, NULL, ICON_RIGHTARROW_THIN, "Bake Render Meshes", 0, yco-=20, 120, 19, "");
2042
2043         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
2044
2045         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Render Buffer|F11",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
2046         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Rendered Animation|Ctrl F11",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
2047
2048         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
2049
2050         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Render Border|Shift B",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
2051
2052         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
2053
2054         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Settings|F10",            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
2055
2056 #ifndef DISABLE_PYTHON
2057         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
2058
2059         for (pym = BPyMenuTable[PYMENU_RENDER]; pym; pym = pym->next, i++) {
2060                 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);
2061         }
2062 #endif
2063         
2064         uiBlockSetDirection(block, UI_DOWN);
2065         uiTextBoundsBlock(block, 80);
2066
2067         return block;
2068 }
2069
2070 /************************** HELP *****************************/
2071
2072 static void do_info_help_websitesmenu(void *arg, int event)
2073 {
2074 #ifndef DISABLE_PYTHON
2075         BPY_menu_do_python(PYMENU_HELPWEBSITES, event);
2076 #endif
2077         allqueue(REDRAWVIEW3D, 0);
2078 }
2079
2080
2081 static uiBlock *info_help_websitesmenu(void *arg_unused)
2082 {
2083         uiBlock *block;
2084 #ifndef DISABLE_PYTHON
2085         BPyMenu *pym;
2086 #endif
2087         short yco = 20, menuwidth = 120;
2088         int i = 0;
2089
2090         block= uiNewBlock(&curarea->uiblocks, "info_help_websitesmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2091         uiBlockSetButmFunc(block, do_info_help_websitesmenu, NULL);
2092 #ifndef DISABLE_PYTHON
2093         for (pym = BPyMenuTable[PYMENU_HELPWEBSITES]; pym; pym = pym->next, i++) {
2094                 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);
2095         }
2096 #endif
2097         uiBlockSetDirection(block, UI_RIGHT);
2098         uiTextBoundsBlock(block, 60);
2099                 
2100         return block;
2101 }
2102
2103 static void do_info_help_systemmenu(void *arg, int event)
2104 {
2105         /* events >=10 are registered bpython scripts */
2106 #ifndef DISABLE_PYTHON
2107         if (event >= 10) BPY_menu_do_python(PYMENU_HELPSYSTEM, event - 10);
2108         else
2109 #endif
2110         {
2111                 switch(event) {
2112
2113                 case 1: /* Benchmark */
2114                         /* dodgy hack turning on CTRL ALT SHIFT key to do a benchmark 
2115                          *      rather than copying lines and lines of code from toets.c :( 
2116                          */
2117         
2118                         if(select_area(SPACE_VIEW3D)) {
2119                                 mainqenter(LEFTSHIFTKEY, 1);
2120                                 mainqenter(LEFTCTRLKEY, 1);
2121                                 mainqenter(LEFTALTKEY, 1);
2122                                 mainqenter(TKEY, 1);
2123                                 mainqenter(TKEY, 0);
2124                                 mainqenter(EXECUTE, 1);
2125                                 mainqenter(LEFTSHIFTKEY, 0);
2126                                 mainqenter(LEFTCTRLKEY, 0);
2127                                 mainqenter(LEFTALTKEY, 0);
2128                         }
2129                         break;
2130                 }
2131         }
2132
2133         allqueue(REDRAWVIEW3D, 0);
2134 }
2135
2136
2137 static uiBlock *info_help_systemmenu(void *arg_unused)
2138 {
2139         uiBlock *block;
2140 #ifndef DISABLE_PYTHON
2141         BPyMenu *pym;
2142 #endif
2143         short yco = 20, menuwidth = 120;
2144         int i = 0;
2145
2146         block= uiNewBlock(&curarea->uiblocks, "info_help_systemmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2147         uiBlockSetButmFunc(block, do_info_help_systemmenu, NULL);
2148         
2149         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Benchmark",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
2150 #ifndef DISABLE_PYTHON
2151         for (pym = BPyMenuTable[PYMENU_HELPSYSTEM]; pym; pym = pym->next, i++) {
2152                 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);
2153         }
2154 #endif
2155         uiBlockSetDirection(block, UI_RIGHT);
2156         uiTextBoundsBlock(block, 60);
2157                 
2158         return block;
2159 }
2160
2161 static void do_info_helpmenu(void *arg, int event)
2162 {
2163         ScrArea *sa;
2164
2165         if(curarea->spacetype==SPACE_INFO) {
2166                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
2167                 if (!sa) sa= closest_bigger_area();
2168                 areawinset(sa->win);
2169         }
2170
2171         /* events >=10 are registered bpython scripts */
2172 #ifndef DISABLE_PYTHON
2173         if (event >= 10) BPY_menu_do_python(PYMENU_HELP, event - 10);
2174         else
2175 #endif
2176         {
2177                 switch(event) {
2178                                                                         
2179                 case 0: /* About Blender */
2180                         break;
2181                 }
2182         }
2183
2184         allqueue(REDRAWINFO, 0);
2185 }
2186
2187 static uiBlock *info_helpmenu(void *arg_unused)
2188 {
2189 /*              static short tog=0; */
2190         uiBlock *block;
2191         short yco= 0;
2192         short menuwidth=120;
2193 #ifndef DISABLE_PYTHON
2194         BPyMenu *pym;
2195 #endif
2196         int i = 0;
2197         
2198         block= uiNewBlock(&curarea->uiblocks, "info_helpmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
2199         uiBlockSetButmFunc(block, do_info_helpmenu, NULL);
2200         
2201         uiDefIconTextBut(block, BUTM, B_SHOWSPLASH, ICON_BLANK1, "About Blender...",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
2202 #ifndef DISABLE_PYTHON
2203         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
2204         
2205         for (pym = BPyMenuTable[PYMENU_HELP]; pym; pym = pym->next, i++) {
2206                 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);
2207         }
2208 #endif
2209         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
2210         
2211         uiDefIconTextBlockBut(block, info_help_websitesmenu, NULL, ICON_RIGHTARROW_THIN, "Websites", 0, yco-=20, 120, 19, "");
2212         
2213         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
2214         
2215         uiDefIconTextBlockBut(block, info_help_systemmenu, NULL, ICON_RIGHTARROW_THIN, "System", 0, yco-=20, 120, 19, "");
2216
2217         uiBlockSetDirection(block, UI_DOWN);
2218         uiTextBoundsBlock(block, 80);
2219
2220         return block;
2221 }
2222
2223 /************************** END MAIN MENU *****************************/
2224 /* ugly global yes, for renderwin.c to write to */
2225 char info_time_str[32]="";
2226
2227 static void info_text(int x, int y)
2228 {
2229         Object *ob= OBACT;
2230         extern float hashvectf[];
2231         uintptr_t mem_in_use, mmap_in_use;
2232         unsigned int swatch_color;
2233         float fac1, fac2, fac3;
2234         char infostr[300], memstr[64];
2235         char *headerstr, *s;
2236         int hsize;
2237
2238         mem_in_use= MEM_get_memory_in_use();
2239         mmap_in_use= MEM_get_mapped_memory_in_use();
2240
2241         s= memstr + sprintf(memstr," | Mem:%.2fM ", ((mem_in_use-mmap_in_use)>>10)/1024.0);
2242         if(mmap_in_use)
2243                 sprintf(s,"(%.2fM) ", ((mmap_in_use)>>10)/1024.0);
2244
2245         
2246         if(G.obedit) {
2247                 s = infostr;
2248
2249                 s+= sprintf(s, "%s", G.editModeTitleExtra);
2250                 if(G.obedit->type==OB_MESH) {
2251                         if(G.scene->selectmode & SCE_SELECT_VERTEX)
2252                                 s+= sprintf(s,"Ve:%d-%d | Ed:%d-%d | Fa:%d-%d",
2253                                                 G.totvertsel, G.totvert, G.totedgesel, G.totedge, G.totfacesel, G.totface);
2254                         else if(G.scene->selectmode & SCE_SELECT_EDGE)
2255                                 s+= sprintf(s,"Ed:%d-%d | Fa:%d-%d",
2256                                                 G.totedgesel, G.totedge, G.totfacesel, G.totface);
2257                         else 
2258                                 s+= sprintf(s,"Fa:%d-%d", G.totfacesel, G.totface);
2259                 }
2260                 else if(G.obedit->type==OB_ARMATURE) {
2261                         s+= sprintf(s,"Ve:%d-%d | Bo:%d-%d", G.totvertsel, G.totvert, G.totbonesel, G.totbone);
2262                 }
2263                 else {
2264                         s+= sprintf(s,"Ve:%d-%d", G.totvertsel, G.totvert);
2265                 }
2266
2267                 strcat(s, memstr);
2268         }
2269         else if(ob && (ob->flag & OB_POSEMODE)) {
2270                 sprintf(infostr,"Bo:%d-%d %s",
2271                                         G.totbonesel, G.totbone, memstr);
2272         }
2273         else {
2274                 sprintf(infostr,"Ve:%d | Fa:%d | Ob:%d-%d | La:%d %s | Time:%s | ",
2275                         G.totvert, G.totface, G.totobj, G.totobjsel, G.totlamp, memstr, info_time_str);
2276         }
2277         if(ob) {
2278                 strcat(infostr, ob->id.name+2);
2279         }
2280
2281         if (g_progress_bar && g_progress_info) {
2282                 headerstr= g_progress_info;
2283         } else {
2284                 headerstr= versionstr; 
2285         }
2286
2287         if      (g_progress_bar) {
2288                 hsize = 4 + (138.0 * g_done);
2289                 fac1 = 0.5 * g_done; /* do some rainbow colors on progress */
2290                 fac2 = 1.0;
2291                 fac3 = 0.9;
2292         } else {
2293                 hsize= 30+BIF_GetStringWidth(G.font, headerstr, (U.transopts & USER_TR_BUTTONS));
2294
2295                 /* promise! Never change these lines again! (zr & ton did!) */
2296                 fac1= fabs(hashvectf[ 2*G.version+4]);
2297                 fac2= 0.5+0.1*hashvectf[ G.version+3];
2298                 fac3= 0.7;
2299         }
2300         
2301         swatch_color= hsv_to_cpack(fac1, fac2, fac3);
2302
2303         cpack( swatch_color );
2304         glRecti(x-24,  y-6,  x-30+hsize,        y+14);
2305
2306         glColor3ub(0, 0, 0); /* makes text black colored rect */
2307         
2308         glRasterPos2i(x, y);
2309         BIF_RasterPos(x, y);
2310
2311         BIF_DrawString(G.font, headerstr, (U.transopts & USER_TR_MENUS));
2312         hsize= BIF_GetStringWidth(G.font, headerstr, (U.transopts & USER_TR_BUTTONS));
2313         
2314         BIF_ThemeColor(TH_MENU_TEXT); /* makes text readable on dark theme */
2315         
2316         glRasterPos2i(x+hsize+10,       y);
2317         BIF_RasterPos(x+hsize+10,       y);
2318         
2319         BIF_DrawString(G.font, infostr, (U.transopts & USER_TR_MENUS));
2320 }
2321
2322 void info_buttons(void)
2323 {
2324         uiBlock *block;
2325         short xco= 42;
2326         int xmax;
2327
2328         block= uiNewBlock(&curarea->uiblocks, "header info", UI_EMBOSSN, UI_HELV, curarea->headwin);
2329
2330         if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
2331         else uiBlockSetCol(block, TH_HEADERDESEL);
2332         
2333         if(curarea->flag & HEADER_NO_PULLDOWN) {
2334                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_RIGHT,
2335                                 xco,2,XIC,YIC-2,
2336                                 &(curarea->flag), 0, 0, 0, 0, "Enables display of pulldown menus");
2337         } else {
2338                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_DOWN,
2339                                 xco,2,XIC,YIC-2,
2340                                 &(curarea->flag), 0, 0, 0, 0, "Hides pulldown menus");
2341         }
2342         xco+=XIC;
2343
2344         if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
2345         
2346                 uiBlockSetEmboss(block, UI_EMBOSSP);
2347
2348                 /* the 'xmax - 3' rather than xmax is to prevent some weird flickering where the highlighted
2349                  * menu is drawn wider than it should be. The ypos of -1 is to make it properly fill the
2350                  * height of the header */
2351                 xmax= GetButStringLength("File");
2352                 uiDefPulldownBut(block, info_filemenu, NULL, "File",    xco, -1, xmax-3, 22, "");
2353                 xco+= xmax;
2354
2355                 xmax= GetButStringLength("Add");
2356                 uiDefPulldownBut(block, info_addmenu, NULL, "Add",      xco, -1, xmax-3, 22, "");
2357                 xco+= xmax;
2358
2359                 xmax= GetButStringLength("Timeline");
2360                 uiDefPulldownBut(block, info_timelinemenu, NULL, "Timeline",    xco, -1, xmax-3, 22, "");
2361                 xco+= xmax;
2362
2363                 xmax= GetButStringLength("Game");
2364                 uiDefPulldownBut(block, info_gamemenu, NULL, "Game",    xco, -1, xmax-3, 22, "");
2365                 xco+= xmax;
2366
2367                 xmax= GetButStringLength("Render");
2368                 uiDefPulldownBut(block, info_rendermenu, NULL, "Render",        xco, -1, xmax-3, 22, "");
2369                 xco+= xmax;
2370
2371                 xmax= GetButStringLength("Help");
2372                 uiDefPulldownBut(block, info_helpmenu, NULL, "Help",    xco, -1, xmax-3, 22, "");
2373                 xco+= xmax;
2374
2375         }
2376
2377         /* pack icon indicates a packed file */
2378         
2379         if (G.fileflags & G_AUTOPACK) {
2380                 uiBlockSetEmboss(block, UI_EMBOSSN);
2381                 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.");
2382                 xco += XIC;
2383         }
2384
2385         if (curarea->full == 0) {
2386                 curarea->butspacetype= SPACE_INFO;
2387                 uiBlockSetEmboss(block, UI_EMBOSS);
2388                 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.");
2389                 
2390                 /* STD SCREEN BUTTONS */
2391                 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);
2392                 
2393                 xco +=8;
2394         
2395                 /* STD SCENE BUTTONS */
2396                 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);
2397         }
2398         else xco= 430;
2399         
2400 BIF_SetScale(block->aspect);
2401         info_text(xco+24, 6);
2402         
2403         uiBlockSetEmboss(block, UI_EMBOSSN);
2404         uiDefIconBut(block, BUT, B_SHOWSPLASH, ICON_BLENDER, xco+2, 0,XIC,YIC, 0, 0, 0, 0, 0, "Click to display Splash Screen");
2405
2406         /* always do as last */
2407         curarea->headbutlen= xco+2*XIC;
2408
2409 #if 0
2410 // #ifdef _WIN32        // FULLSCREEN
2411         if(U.uiflag & USER_FLIPFULLSCREEN) {
2412                 uiDefIconBut(block, BUT, B_FLIPFULLSCREEN, ICON_WINDOW_WINDOW,
2413                                 (short)(curarea->winx-XIC-5), 0,XIC,YIC,
2414                                 0, 0, 0, 0, 0, "Toggles Blender to fullscreen mode");/* dir             */
2415         } else {
2416                 uiDefIconBut(block, BUT, B_FLIPFULLSCREEN, ICON_WINDOW_FULLSCREEN,
2417                                 (short)(curarea->winx-XIC-5), 0,XIC,YIC,
2418                                 0, 0, 0, 0, 0, "Toggles Blender to fullscreen mode");/* dir             */
2419         }
2420 #endif
2421         
2422         uiDrawBlock(block);
2423 }