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