Long waited feature: Render Baking
[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         ima = G.main->image.first;
533         while (ima) {
534                 if (ima->ibuf && (ima->ibuf->userflags &= IB_BITMAPDIRTY)) {
535                         break;
536                 }
537                 ima= ima->id.next;
538                 }
539         
540         if (ima == 0 || okee("Some images are painted on. These changes will be lost. Continue ?")) {
541                 packAll();
542                 G.fileflags |= G_AUTOPACK;
543         }
544 }
545
546 static int write_runtime(char *str, char *exename)
547 {
548         char *freestr= NULL;
549         char *ext = 0;
550
551 #ifdef _WIN32
552         ext = ".exe";
553 #endif
554
555 #ifdef __APPLE__
556         ext = ".app";
557 #endif
558         if (ext && (!BLI_testextensie(str, ext))) {
559                 freestr= MEM_mallocN(strlen(str) + strlen(ext) + 1, "write_runtime_check");
560                 sprintf(freestr,"%s%s", str, ext);
561                 str= freestr;
562         }
563
564         if (!BLI_exists(str) || saveover(str))
565                 BLO_write_runtime(str, exename);
566
567         if (freestr)
568                 MEM_freeN(freestr);
569  
570         return 0;
571 }
572
573 static void write_runtime_check_dynamic(char *str) 
574 {
575         write_runtime(str, "blenderdynplayer.exe");
576 }
577
578 static void write_runtime_check(char *str) 
579 {
580         char player[128];
581
582         strcpy(player, "blenderplayer");
583
584 #ifdef _WIN32
585         strcat(player, ".exe");
586 #endif
587
588 #ifdef __APPLE__
589         strcat(player, ".app");
590 #endif
591
592         write_runtime(str, player);
593 }
594 /* end keyed functions */
595
596 /************************** MAIN MENU *****************************/
597 /************************** FILE *****************************/
598
599
600 static void do_info_file_importmenu(void *arg, int event)
601 {
602         ScrArea *sa;
603
604         if(curarea->spacetype==SPACE_INFO) {
605                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
606                 if (!sa) sa= closest_bigger_area();
607                 areawinset(sa->win);
608         }
609
610         /* events >=4 are registered bpython scripts */
611         if (event >= 4) {
612                 BPY_menu_do_python(PYMENU_IMPORT, event - 4);
613                 BIF_undo_push("Import file");
614         }
615         else {
616                 switch(event) {
617                                                                         
618                 case 0: /* DXF */
619                         activate_fileselect(FILE_BLENDER, "Import DXF", G.sce, BIF_read_file);
620                         break;
621                 case 1: /* VRML 1.0 */
622                         activate_fileselect(FILE_BLENDER, "Import VRML 1.0", G.sce, BIF_read_file);
623                         break;
624                 case 2: /* VideoScape */
625                         activate_fileselect(FILE_BLENDER, "Import VideoScape", G.sce, BIF_read_file);
626                         break;
627                 case 3: /* STL */
628                         activate_fileselect(FILE_BLENDER, "Import STL", G.sce, BIF_read_file);
629                         break;
630
631                 }
632         }
633         allqueue(REDRAWINFO, 0);
634 }
635
636 static uiBlock *info_file_importmenu(void *arg_unused)
637 {
638         uiBlock *block;
639         short yco = 20, menuwidth = 120;
640         BPyMenu *pym;
641         int i = 0;
642
643         block= uiNewBlock(&curarea->uiblocks, "importmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
644         uiBlockSetButmFunc(block, do_info_file_importmenu, NULL);
645         //uiBlockSetXOfs(block, -50);  // offset to parent button
646         
647         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...",
648                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "");
649         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...",
650                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "");
651         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VideoScape...",
652                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "");
653         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "STL...",
654                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 3, "");
655
656         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
657
658         for (pym = BPyMenuTable[PYMENU_IMPORT]; pym; pym = pym->next, i++) {
659                 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);
660         }
661
662         uiBlockSetDirection(block, UI_RIGHT);
663         uiTextBoundsBlock(block, 60);
664
665         return block;
666 }
667
668 static void do_info_file_exportmenu(void *arg, int event)
669 {
670         ScrArea *sa;
671
672         if(curarea->spacetype==SPACE_INFO) {
673                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
674                 if (!sa) sa= closest_bigger_area();
675                 areawinset(sa->win);
676         }
677
678         /* events >=4 are registered bpython scripts */
679         if (event >= 4) BPY_menu_do_python(PYMENU_EXPORT, event - 4);
680
681         else switch(event) {
682                                                                         
683         case 0:
684                 write_vrml_fs();
685                 break;
686         case 1:
687                 write_dxf_fs();
688                 break;
689         case 2:
690                 write_videoscape_fs();
691                 break;
692         case 3:
693                 write_stl_fs();
694                 break;
695         }
696         allqueue(REDRAWINFO, 0);
697 }
698
699 static uiBlock *info_file_exportmenu(void *arg_unused)
700 {
701         uiBlock *block;
702         short yco = 20, menuwidth = 120;
703         BPyMenu *pym;
704         int i = 0;
705
706         block= uiNewBlock(&curarea->uiblocks, "exportmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
707         uiBlockSetButmFunc(block, do_info_file_exportmenu, NULL);
708         //uiBlockSetXOfs(block, -50);  // offset to parent button
709
710         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...|Ctrl F2",
711                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "");
712         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...|Shift F2",
713                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "");
714         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Videoscape...|Alt W",
715                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "");
716         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "STL...",
717                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 3, "");
718
719         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
720
721         /* note that we acount for the 3 previous entries with i+3: */
722         for (pym = BPyMenuTable[PYMENU_EXPORT]; pym; pym = pym->next, i++) {
723                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
724                                  NULL, 0.0, 0.0, 1, i+4, 
725                                  pym->tooltip?pym->tooltip:pym->filename);
726         }
727
728
729         uiBlockSetDirection(block, UI_RIGHT);
730         uiTextBoundsBlock(block, 60);
731
732         return block;
733 }
734
735 #ifdef WITH_VERSE
736
737 extern ListBase session_list;
738
739 static void do_verse_filemenu(void *arg, int event)
740 {
741         char address[64];               /* lenght of domain name is 63 characters or less */
742         VerseSession *session = NULL;
743         ScrArea *sa;
744         
745         if(curarea->spacetype==SPACE_INFO) {
746                 sa= closest_bigger_area();
747                 areawinset(sa->win);
748         }
749
750         switch(event) {
751                 case 0:
752                         waitcursor(1);
753                         printf("Connecting to localhost!\n");
754                         b_verse_connect("localhost");
755                         waitcursor(0);
756                         break;
757                 case 1:
758                         address[0] = '\0';
759                         if(sbutton(address, 0, 63, "Server:")) {
760                                 waitcursor(1);
761                                 printf("Connecting to %s\n", address);
762                                 b_verse_connect(address);
763                                 waitcursor(0);
764                         }
765                         break;
766                 case 2:
767                         session = session_menu();
768                         if(session) {
769                                 printf("Disconnecting session: %s!\n", session->address);
770                                 end_verse_session(session);
771                         }
772                         break;
773                 case 3:
774                         printf("Disconnecting all sessions!\n");
775                         end_all_verse_sessions();
776                         break;
777         case 4:
778             printf("sending get to master server\n");
779             b_verse_ms_get();
780             break;
781         }
782 }
783
784 static uiBlock *verse_filemenu(void *unusedargs)
785 {
786         uiBlock *block;
787         short yco = 20, menuwidth = 120;
788
789         block= uiNewBlock(&curarea->uiblocks, "verse_filemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
790         uiBlockSetButmFunc(block, do_verse_filemenu, NULL);
791                 
792         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Connect to localhost", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
793         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Connect ...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
794         if(session_list.first != NULL) {
795                 if(session_list.first != session_list.last) {
796                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Disconnect ...",
797                                         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
798                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Disconnect all",
799                                         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
800                 }
801                 else {
802                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Disconnect",
803                                         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
804                 }
805                 
806         }
807         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Get Servers", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
808
809         uiBlockSetDirection(block, UI_RIGHT);
810         uiTextBoundsBlock(block, 60);
811
812         return block;
813 }
814 #endif
815
816 static void do_info_filemenu(void *arg, int event)
817 {
818         ScrArea *sa;
819         char dir[FILE_MAXDIR];
820         
821         if(curarea->spacetype==SPACE_INFO) {
822                 sa= closest_bigger_area();
823                 areawinset(sa->win);
824         }
825
826         /* these are no defines, easier this way, the codes are in the function below */
827         switch(event) {
828         case 0:
829                 if (okee("Erase All")) {
830                         if (!BIF_read_homefile())
831                                 error("No file ~/.B.blend");
832                 }
833                 break;
834         case 1: /* open */
835                 activate_fileselect(FILE_BLENDER, "Open", G.sce, BIF_read_file);
836                 break;
837         case 3: /* append */
838                 activate_fileselect(FILE_LOADLIB, "Load Library", G.lib, 0);
839                 break;
840         case 4: /* save */
841                 strcpy(dir, G.sce);
842                 untitled(dir);
843                 activate_fileselect(FILE_BLENDER, "Save As", dir, BIF_write_file);
844                 break;
845         case 5:
846                 strcpy(dir, G.sce);
847                 if (untitled(dir)) {
848                         activate_fileselect(FILE_BLENDER, "Save As", dir, BIF_write_file);
849                 } else {
850                         BIF_write_file(dir);
851                         free_filesel_spec(dir);
852                 }
853                 break;
854         case 6: /* save image */
855                 BIF_save_rendered_image_fs(0);
856                 break;
857         case 22: /* save runtime */
858                 activate_fileselect(FILE_SPECIAL, "Save Runtime", "", write_runtime_check);
859                 break;
860         case 23: /* save dynamic runtime */
861                 activate_fileselect(FILE_SPECIAL, "Save Dynamic Runtime", "", write_runtime_check_dynamic);
862                 break;
863         case 24:
864                 BIF_screendump(0);
865                 break;
866         case 25:
867                 BIF_screendump(1);
868                 break;
869         case 10: /* pack data */
870                 check_packAll();
871                 break;
872         case 11: /* unpack to current dir */
873                 unpackAll(PF_WRITE_LOCAL);
874                 G.fileflags &= ~G_AUTOPACK;
875                 break;
876         case 12: /* unpack data */
877                 if (buttons_do_unpack() != RET_CANCEL) {
878                         /* Clear autopack bit only if user selected one of the unpack options */
879                         G.fileflags &= ~G_AUTOPACK;
880                 }
881                 break;
882         case 13:
883                 exit_usiblender();
884                 break;
885         case 15:        /* recover previous session */
886                 {
887                         extern short winqueue_break; /* editscreen.c */
888                         int save_over;
889                         char str[FILE_MAXDIR+FILE_MAXFILE];
890                         char scestr[FILE_MAXDIR+FILE_MAXFILE];
891                         
892                         strcpy(scestr, G.sce);  /* temporal store */
893                         save_over = G.save_over;
894                         BLI_make_file_string("/", str, U.tempdir, "quit.blend");
895                         BKE_read_file(str, NULL);
896                         G.save_over = save_over;
897                         strcpy(G.sce, scestr);
898
899                         winqueue_break= 1;      /* leave queues everywhere */
900                 
901                         BKE_reset_undo();
902                         BKE_write_undo("original");     /* save current state */
903                         refresh_interface_font();
904                 }
905                 break;
906         case 31: /* save default settings */
907                 BIF_write_homefile();
908                 break;
909
910         case 35: /* compress toggle */
911                 U.flag ^= (USER_FILECOMPRESS);
912                 break;
913         }
914         allqueue(REDRAWINFO, 0);
915 }
916
917 static void do_info_operecentmenu(void *arg, int event)
918 {
919         struct RecentFile *recent;
920
921         if(event==0 && G.sce[0]) {
922                 BIF_read_file(G.sce);
923         }
924         else {  /* Global */
925                 recent = BLI_findlink(&(G.recent_files), event-1);
926                 BIF_read_file(recent->filename);
927         }
928 }
929
930 static uiBlock *info_openrecentmenu(void *arg_unused)
931 {
932         uiBlock *block;
933         short yco = 20, menuwidth = 120, i;
934         struct RecentFile *recent;
935
936         block= uiNewBlock(&curarea->uiblocks, "info_openrecentmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
937         uiBlockSetButmFunc(block, do_info_operecentmenu, NULL);
938
939         if (G.sce[0]) {
940                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, G.sce, 0, yco-=20,
941                                 menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
942         }
943
944         for (recent = G.recent_files.first, i=0; i<10 && recent; recent = recent->next, i++) {
945                 if (strcmp(recent->filename, G.sce)!=0) {
946                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, recent->filename, 0, yco-=20,
947                                         menuwidth, 19, NULL, 0.0, 0.0, 1, i+1, "");
948                 }
949         }
950
951         uiBlockSetDirection(block, UI_RIGHT);
952         uiTextBoundsBlock(block, 60);
953         return block;
954 }
955
956 static uiBlock *info_filemenu(void *arg_unused)
957 {
958         uiBlock *block;
959         short yco=0;
960         short menuwidth=120;
961
962         block= uiNewBlock(&curarea->uiblocks, "info_filemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
963         uiBlockSetButmFunc(block, do_info_filemenu, NULL);
964         
965         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "New|Ctrl X",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
966         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Open...|F1",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
967 #ifdef WITH_VERSE
968         uiDefIconTextBlockBut(block, verse_filemenu, NULL, ICON_RIGHTARROW_THIN, "Verse", 0, yco-=20, menuwidth, 19, "");
969 #endif
970         uiDefIconTextBlockBut(block, info_openrecentmenu, NULL, ICON_RIGHTARROW_THIN, "Open Recent",0, yco-=20, 120, 19, "");
971         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Recover Last Session",                           0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 15, "");
972
973         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
974
975         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save|Ctrl W",                            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
976         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save As...|F2",                  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
977         
978         if(U.flag & USER_FILECOMPRESS) {
979                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Compress File",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 35, "Enable file compression");
980         } else {
981                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Compress File",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 35, "Enable file compression");
982         }
983
984         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
985
986         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Image...|F3",                       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
987         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Dump Subwindow|Ctrl F3",                 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 24, "");
988         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Dump Screen|Ctrl Shift F3",                      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 25, "");
989 #if GAMEBLENDER == 1
990         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Runtime...",                        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 22, "");
991 #ifdef _WIN32
992         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Dynamic Runtime...",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 23, "");
993 #endif
994 #endif
995         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
996
997         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Default Settings|Ctrl U",                   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 31, "");
998
999
1000         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1001
1002         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Append\\Link|Shift F1",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1003         uiDefIconTextBlockBut(block, info_file_importmenu, NULL, ICON_RIGHTARROW_THIN, "Import", 0, yco-=20, menuwidth, 19, "");
1004         uiDefIconTextBlockBut(block, info_file_exportmenu, NULL, ICON_RIGHTARROW_THIN, "Export", 0, yco-=20, menuwidth, 19, "");
1005         
1006         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1007
1008         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Data",                              0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "");
1009 //      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");
1010         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpack Data...",                         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 12, "");
1011
1012         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1013
1014         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Quit Blender| Q",                                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 13, "");
1015
1016         uiBlockSetDirection(block, UI_DOWN);
1017         uiTextBoundsBlock(block, 80);
1018
1019         return block;
1020 }
1021
1022 /**************************** ADD ******************************/
1023
1024 void do_info_add_meshmenu(void *arg, int event)
1025 {
1026
1027         switch(event) {         
1028                 case 0:
1029                         /* Plane */
1030                         add_primitiveMesh(0);
1031                         break;
1032                 case 1:
1033                         /* Cube */
1034                         add_primitiveMesh(1);
1035                         break;
1036                 case 2:
1037                         /* Circle */
1038                         add_primitiveMesh(4);
1039                         break;
1040                 case 3:
1041                         /* UVsphere */
1042                         add_primitiveMesh(11);
1043                         break;
1044                 case 4:
1045                         /* IcoSphere */
1046                         add_primitiveMesh(12);
1047                         break;
1048                 case 5:
1049                         /* Cylinder */
1050                         add_primitiveMesh(5);
1051                         break;
1052                 case 6:
1053                         /* Tube */
1054                         add_primitiveMesh(6);
1055                         break;
1056                 case 7:
1057                         /* Cone */
1058                         add_primitiveMesh(7);
1059                         break;
1060                 case 8:
1061                         /* Grid */
1062                         add_primitiveMesh(10);
1063                         break;
1064                 case 9:
1065                         /* Monkey */
1066                         add_primitiveMesh(13);
1067                         break;
1068                 default:
1069                         break;
1070         }
1071         allqueue(REDRAWINFO, 0);
1072 }
1073
1074 static uiBlock *info_add_meshmenu(void *arg_unused)
1075 {
1076 /*              static short tog=0; */
1077         uiBlock *block;
1078         short yco= 0;
1079         
1080         block= uiNewBlock(&curarea->uiblocks, "add_meshmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1081         uiBlockSetButmFunc(block, do_info_add_meshmenu, NULL);
1082         
1083         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Plane|",                         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1084         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cube|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1085         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Circle|",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1086         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "UVsphere",                       0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1087         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "IcoSphere|",                     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1088         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cylinder|",                      0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
1089         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Tube|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 6, "");
1090         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cone|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "");
1091         uiDefIconTextBut(block, SEPR, 0, ICON_BLANK1, "",                                       0, yco-=6,      160, 6,  NULL, 0.0, 0.0, 0, 0, "");
1092         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grid|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "");
1093         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Monkey|",                        0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 9, "");
1094
1095         uiBlockSetDirection(block, UI_RIGHT);
1096         uiTextBoundsBlock(block, 50);
1097                 
1098         return block;
1099 }
1100
1101 void do_info_add_curvemenu(void *arg, int event)
1102 {
1103
1104         switch(event) {         
1105                 case 0:
1106                         /* Bezier Curve */
1107                         add_primitiveCurve(10);
1108                         break;
1109                 case 1:
1110                         /* Bezier Circle */
1111                         add_primitiveCurve(11);
1112                         break;
1113                 case 2:
1114                         /* NURB Curve */
1115                         add_primitiveCurve(40);
1116                         break;
1117                 case 3:
1118                         /* NURB Circle */
1119                         add_primitiveCurve(41);
1120                         break;
1121                 case 4:
1122                         /* Path */
1123                         add_primitiveCurve(46);
1124                         break;
1125                 default:
1126                         break;
1127         }
1128         allqueue(REDRAWINFO, 0);
1129 }
1130
1131 static uiBlock *info_add_curvemenu(void *arg_unused)
1132 {
1133 /*              static short tog=0; */
1134         uiBlock *block;
1135         short yco= 0;
1136         
1137         block= uiNewBlock(&curarea->uiblocks, "add_curvemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1138         uiBlockSetButmFunc(block, do_info_add_curvemenu, NULL);
1139         
1140         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Bezier Curve|",  0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1141         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Bezier Circle|", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1142         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Curve|",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1143         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Circle",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1144         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Path|",                  0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1145
1146         uiBlockSetDirection(block, UI_RIGHT);
1147         uiTextBoundsBlock(block, 50);
1148                 
1149         return block;
1150 }
1151
1152
1153 void do_info_add_surfacemenu(void *arg, int event)
1154 {
1155
1156         switch(event) {         
1157                 case 0:
1158                         /* Curve */
1159                         add_primitiveNurb(0);
1160                         break;
1161                 case 1:
1162                         /* Circle */
1163                         add_primitiveNurb(1);
1164                         break;
1165                 case 2:
1166                         /* Surface */
1167                         add_primitiveNurb(2);
1168                         break;
1169                 case 3:
1170                         /* Tube */
1171                         add_primitiveNurb(3);
1172                         break;
1173                 case 4:
1174                         /* Sphere */
1175                         add_primitiveNurb(4);
1176                         break;
1177                 case 5:
1178                         /* Donut */
1179                         add_primitiveNurb(5);
1180                         break;
1181                 default:
1182                         break;
1183         }
1184         allqueue(REDRAWINFO, 0);
1185 }
1186
1187 static uiBlock *info_add_surfacemenu(void *arg_unused)
1188 {
1189 /*              static short tog=0; */
1190         uiBlock *block;
1191         short yco= 0;
1192         
1193         block= uiNewBlock(&curarea->uiblocks, "add_surfacemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1194         uiBlockSetButmFunc(block, do_info_add_surfacemenu, NULL);
1195         
1196         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Curve|",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1197         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Circle|",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1198         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Surface|", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1199         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Tube",             0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1200         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Sphere|",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1201         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "NURBS Donut|",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
1202         uiBlockSetDirection(block, UI_RIGHT);
1203         uiTextBoundsBlock(block, 50);
1204                 
1205         return block;
1206 }
1207
1208 void do_info_add_metamenu(void *arg, int event)
1209 {
1210
1211         switch(event) {         
1212                 case 0:
1213                         /* Ball */
1214                         add_primitiveMball(1);
1215                         break;
1216                 case 1:
1217                         /* Tube */
1218                         add_primitiveMball(2);
1219                         break;
1220                 case 2:
1221                         /* Plane */
1222                         add_primitiveMball(3);
1223                         break;
1224                 case 3:
1225                         /* Elipsoid */
1226                         add_primitiveMball(4);
1227                         break;
1228                 case 4:
1229                         /* Cube */
1230                         add_primitiveMball(5);
1231                         break;
1232                 default:
1233                         break;
1234         }
1235         allqueue(REDRAWINFO, 0);
1236 }
1237
1238
1239 static uiBlock *info_add_metamenu(void *arg_unused)
1240 {
1241 /*              static short tog=0; */
1242         uiBlock *block;
1243         short xco= 0;
1244         
1245         block= uiNewBlock(&curarea->uiblocks, "add_metamenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1246         uiBlockSetButmFunc(block, do_info_add_metamenu, NULL);
1247         
1248         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,"Meta Ball|",              0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1249         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Tube|",             0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1250         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Plane|",            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1251         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Ellipsoid|",        0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1252         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Meta Cube|",             0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1253
1254         uiBlockSetDirection(block, UI_RIGHT);
1255         uiTextBoundsBlock(block, 50);
1256                 
1257         return block;
1258 }
1259
1260 void do_info_add_lampmenu(void *arg, int event)
1261 {
1262
1263         switch(event) {         
1264                 case 0: /* lamp */
1265                         add_objectLamp(LA_LOCAL);
1266                         break;
1267                 case 1: /* sun */
1268                         add_objectLamp(LA_SUN);
1269                         break;
1270                 case 2: /* spot */
1271                         add_objectLamp(LA_SPOT);
1272                         break;
1273                 case 3: /* hemi */
1274                         add_objectLamp(LA_HEMI);
1275                         break;
1276                 case 4: /* area */
1277                         add_objectLamp(LA_AREA);
1278                         break;
1279                 case 5: /* YafRay photon lamp */
1280                         if (G.scene->r.renderer==R_YAFRAY)
1281                                 add_objectLamp(LA_YF_PHOTON);
1282                         break;
1283                 default:
1284                         break;
1285         }
1286         allqueue(REDRAWINFO, 0);
1287 }
1288
1289 static uiBlock *info_add_lampmenu(void *arg_unused)
1290 {
1291 /*              static short tog=0; */
1292         uiBlock *block;
1293         short yco= 0;
1294         
1295         block= uiNewBlock(&curarea->uiblocks, "add_lampmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1296         uiBlockSetButmFunc(block, do_info_add_lampmenu, NULL);
1297         
1298         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Lamp|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1299         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Sun|",                           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1300         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Spot|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1301         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hemi|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1302         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Area|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1303         if (G.scene->r.renderer==R_YAFRAY)
1304                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Photon|",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
1305         
1306         uiBlockSetDirection(block, UI_RIGHT);
1307         uiTextBoundsBlock(block, 50);
1308                 
1309         return block;
1310 }
1311
1312 static void do_info_add_groupmenu(void *arg, int event)
1313 {
1314         Object *ob;
1315         
1316         add_object_draw(OB_EMPTY);
1317         ob= OBACT;
1318         
1319         ob->dup_group= BLI_findlink(&G.main->group, event);
1320         if(ob->dup_group) {
1321                 id_us_plus((ID *)ob->dup_group);
1322                 ob->transflag |= OB_DUPLIGROUP;
1323                 DAG_scene_sort(G.scene);
1324         }
1325 }
1326
1327
1328 static uiBlock *info_add_groupmenu(void *arg_unused)
1329 {
1330         Group *group;
1331         uiBlock *block;
1332         short yco= 0;
1333         int a;
1334         
1335         block= uiNewBlock(&curarea->uiblocks, "add_groupmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1336         uiBlockSetButmFunc(block, do_info_add_groupmenu, NULL);
1337         
1338         for(a=0, group= G.main->group.first; group; group= group->id.next, a++) {
1339                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, group->id.name+2,                         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, a, "");
1340         }
1341         
1342         uiBlockSetDirection(block, UI_RIGHT);
1343         uiTextBoundsBlock(block, 50);
1344                 
1345         return block;
1346 }
1347
1348 void do_info_addmenu(void *arg, int event)
1349 {
1350         switch(event) {         
1351                 case 0:
1352                         /* Mesh */
1353                         break;
1354                 case 1:
1355                         /* Curve */
1356                         break;
1357                 case 2:
1358                         /* Surface */
1359                         break;
1360                 case 3:
1361                         /* Metaball */
1362                         break;
1363                 case 4:
1364                         /* Text (argument is discarded) */
1365                         add_primitiveFont(event);
1366                         break;
1367                 case 5:
1368                         /* Empty */
1369                         add_object_draw(OB_EMPTY);
1370                         break;
1371                 case 6:
1372                         /* Camera */
1373                         add_object_draw(OB_CAMERA);
1374                         break;
1375                 case 8:
1376                         /* Armature */
1377                         add_primitiveArmature(OB_ARMATURE);
1378                         break;
1379                 case 9:
1380                         /* Lattice */
1381                         add_object_draw(OB_LATTICE);
1382                         break;
1383                 case 10:
1384                         /* group instance not yet */
1385                         break;
1386                 default:
1387                         break;
1388         }
1389         allqueue(REDRAWINFO, 0);
1390 }
1391
1392
1393 static uiBlock *info_addmenu(void *arg_unused)
1394 {
1395 /*              static short tog=0; */
1396         uiBlock *block;
1397         short yco= 0;
1398
1399         block= uiNewBlock(&curarea->uiblocks, "addmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1400         uiBlockSetButmFunc(block, do_info_addmenu, NULL);
1401         
1402         uiDefIconTextBlockBut(block, info_add_meshmenu, NULL, ICON_RIGHTARROW_THIN, "Mesh", 0, yco-=20, 120, 19, "");
1403         uiDefIconTextBlockBut(block, info_add_curvemenu, NULL, ICON_RIGHTARROW_THIN, "Curve", 0, yco-=20, 120, 19, "");
1404         uiDefIconTextBlockBut(block, info_add_surfacemenu, NULL, ICON_RIGHTARROW_THIN, "Surface", 0, yco-=20, 120, 19, "");
1405         uiDefIconTextBlockBut(block, info_add_metamenu, NULL, ICON_RIGHTARROW_THIN, "Meta", 0, yco-=20, 120, 19, "");
1406         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Text",                           0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 4, "");
1407         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Empty",                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 5, "");
1408         
1409         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1410         
1411         uiDefIconTextBlockBut(block, info_add_groupmenu, NULL, ICON_RIGHTARROW_THIN, "Group", 0, yco-=20, 120, 19, "");
1412         
1413         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1414         
1415         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Camera",                         0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 6, "");
1416         uiDefIconTextBlockBut(block, info_add_lampmenu, NULL, ICON_RIGHTARROW_THIN, "Lamp", 0, yco-=20, 120, 19, "");
1417         
1418         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1419         
1420         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Armature",                       0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 8, "");
1421         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Lattice",                        0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 9, "");
1422
1423         uiBlockSetDirection(block, UI_DOWN);
1424         uiTextBoundsBlock(block, 80);
1425                 
1426         return block;
1427 }
1428
1429 /************************** GAME *****************************/
1430
1431         
1432 static void do_info_gamemenu(void *arg, int event)
1433 {
1434         switch (event) {
1435         case G_FILE_ENABLE_ALL_FRAMES:
1436         case G_FILE_DIAPLAY_LISTS:
1437         case G_FILE_SHOW_FRAMERATE:
1438         case G_FILE_SHOW_DEBUG_PROPS:
1439         case G_FILE_AUTOPLAY:
1440         case G_FILE_GAME_TO_IPO:
1441         case G_FILE_GAME_MAT:
1442                 G.fileflags ^= event;
1443                 break;
1444         default:
1445                 ; /* ignore the rest */
1446         }
1447 }
1448
1449 static uiBlock *info_gamemenu(void *arg_unused)
1450 {
1451 /*              static short tog=0; */
1452         uiBlock *block;
1453         short yco= 0;
1454         short menuwidth=120;
1455         
1456         block= uiNewBlock(&curarea->uiblocks, "gamemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1457         uiBlockSetButmFunc(block, do_info_gamemenu, NULL);
1458         
1459         uiDefIconTextBut(block, BUTM, B_STARTGAME, ICON_BLANK1, "Start Game|P",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
1460         
1461         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 1, 0, "");
1462
1463
1464         if(G.fileflags & G_FILE_ENABLE_ALL_FRAMES) {
1465                 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, "");
1466         } else {
1467                 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, "");
1468         }
1469         
1470         if(G.fileflags & G_FILE_GAME_TO_IPO) {
1471                 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, "");
1472         } else {
1473
1474         if(G.fileflags & G_FILE_DIAPLAY_LISTS) {
1475                 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, "");
1476         } else {
1477                 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, "");
1478         }       
1479                 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, "");
1480         }
1481         
1482         if(G.fileflags & G_FILE_GAME_MAT) {
1483                 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, "");
1484         } else {
1485                 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, "");
1486         }       
1487
1488
1489
1490         if(G.fileflags & G_FILE_SHOW_FRAMERATE) {
1491                 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, "");
1492         } else {
1493                 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, "");
1494         }
1495
1496         if(G.fileflags & G_FILE_SHOW_DEBUG_PROPS) {
1497                 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, "");
1498         } else {
1499                 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, "");
1500         }
1501         
1502         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 1, 0, "");
1503
1504         if(G.fileflags & G_FILE_AUTOPLAY) {
1505                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Autostart",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_AUTOPLAY, "");
1506         } else {
1507                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Autostart",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_AUTOPLAY, "");
1508         }
1509
1510         uiBlockSetDirection(block, UI_DOWN);
1511         uiTextBoundsBlock(block, 70);
1512         
1513         return block;
1514 }
1515 /************************** TIMELINE *****************************/
1516
1517 static void do_info_timelinemenu(void *arg, int event)
1518 {
1519         /* needed to check for valid selected objects */
1520         Base *base=NULL;
1521         Object *ob=NULL;
1522         //char file[FILE_MAXDIR+FILE_MAXFILE];
1523
1524         base= BASACT;
1525         if (base) ob= base->object;
1526
1527         switch(event) {
1528         case 1:
1529                 /* Show Keyframes */
1530                 if (!ob) error("Select an object before showing its keyframes");
1531                 else set_ob_ipoflags();
1532                 break;
1533         case 2:
1534                 /* Show and select Keyframes */
1535                 if (!ob) error("Select an object before showing and selecting its keyframes");
1536                 else select_select_keys();
1537                         break;
1538                 case 3:
1539                 /* select next keyframe */
1540                 if (!ob) error("Select an object before selecting its next keyframe");
1541                 else nextkey_obipo(1);
1542                         break;
1543                 case 4:
1544                 /* select previous keyframe */
1545                 if (!ob) error("Select an object before selecting its previous keyframe");
1546                 else nextkey_obipo(-1);
1547                 break;
1548                 case 5:
1549                 /* next keyframe */
1550                 if (!ob) error("Select an object before going to its next keyframe");
1551                 else movekey_obipo(1);
1552                         break;
1553                 case 6:
1554                 /* previous keyframe */
1555                 if (!ob) error("Select an object before going to its previous keyframe");
1556                 else movekey_obipo(-1);
1557                 break;
1558         case 7:
1559                 /* next frame */
1560                 CFRA++;
1561                 update_for_newframe();
1562                 break;
1563                 case 8:
1564                 /* previous frame */
1565                 CFRA--;
1566                 if(CFRA<1) CFRA=1;
1567                 update_for_newframe();
1568                 break;
1569         case 9:
1570                 /* forward 10 frames */
1571                 CFRA+= 10;
1572                 update_for_newframe();
1573                 break;
1574         case 10:
1575                 /* back 10 frames */
1576                 CFRA-= 10;
1577                 if(CFRA<1) CFRA=1;
1578                 update_for_newframe();
1579                 break;
1580         case 11:
1581                 /* end frame */
1582                 CFRA= EFRA;
1583                 update_for_newframe();
1584                 break;
1585         case 12:
1586                 /* start frame */
1587                 CFRA= SFRA;
1588                 update_for_newframe();
1589                 break;
1590         }
1591         allqueue(REDRAWINFO, 0);
1592 }
1593
1594 static uiBlock *info_timelinemenu(void *arg_unused)
1595 {
1596 /*              static short tog=0; */
1597         uiBlock *block;
1598         short yco= 0;
1599         short menuwidth=120;
1600
1601         block= uiNewBlock(&curarea->uiblocks, "timelinemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1602         uiBlockSetButmFunc(block, do_info_timelinemenu, NULL);
1603         
1604         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Keyframes|K",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1605         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show and Select Keyframes|Shift K",0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1606         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Next Keyframe|PageUp",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1607         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Previous Keyframe|PageDown",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
1608
1609         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1610
1611         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Next Keyframe|Ctrl PageUp",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1612         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Previous Keyframe|Ctrl PageDown",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
1613
1614         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1615
1616         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Next Frame|RightArrow",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
1617         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Previous Frame|LeftArrow",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, "");
1618         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Forward 10 Frames|UpArrow",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, "");
1619         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Back 10 Frames|DownArrow",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
1620
1621         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1622
1623         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "End Frame|Shift RightArrow",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
1624         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Start Frame|Shift LeftArrow",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
1625
1626         uiBlockSetDirection(block, UI_DOWN);
1627         uiTextBoundsBlock(block, 80);
1628
1629         return block;
1630 }
1631
1632 /************************** RENDER *****************************/
1633
1634 static void do_info_rendermenu(void *arg, int event)
1635 {
1636
1637         extern void playback_anim();
1638
1639         switch(event) {
1640                 
1641         case 0:
1642                 BIF_do_render(0);
1643                 break;
1644         case 1:
1645                 BIF_do_render(1);
1646                 break;
1647
1648                 /* note: dont use select_area() for setting active areas for opengl render */
1649                 /* its hackish and instable... code here was removed */
1650         
1651         case 4:
1652                 BIF_toggle_render_display();
1653                 break;
1654         case 5:
1655                 playback_anim();
1656                 break;
1657         case 6:
1658                 /* dodgy hack turning on SHIFT key to do a proper render border select
1659                 set_render_border(); only works when 3d window active
1660                 
1661                 This code copied from toolbox.c, only works when 3d window is cameraview */
1662
1663                 if(select_area(SPACE_VIEW3D)) {
1664                         mainqenter(LEFTSHIFTKEY, 1);
1665                         mainqenter(BKEY, 1);
1666                         mainqenter(BKEY, 0);
1667                         mainqenter(EXECUTE, 1);
1668                         mainqenter(LEFTSHIFTKEY, 0);
1669                 }
1670
1671                 break;
1672
1673         case 7:
1674                 extern_set_butspace(F10KEY, 0);
1675                 break;
1676         case 8:
1677                 objects_bake_render();
1678                 break;
1679         }
1680         allqueue(REDRAWINFO, 0);
1681 }
1682
1683 static uiBlock *info_rendermenu(void *arg_unused)
1684 {
1685 /*              static short tog=0; */
1686         uiBlock *block;
1687         short yco= 0;
1688         short menuwidth=120;
1689         
1690         block= uiNewBlock(&curarea->uiblocks, "rendermenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1691         uiBlockSetButmFunc(block, do_info_rendermenu, NULL);
1692         
1693         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Current Frame|F12",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
1694         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Animation|Ctrl F12",              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1695         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Bake-Render Meshes|ALT+Ctrl B",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, "");
1696
1697         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1698
1699         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Render Buffer|F11",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
1700         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Rendered Animation|Ctrl F11",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1701
1702         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1703
1704         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Render Border|Shift B",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
1705
1706         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1707
1708         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Settings|F10",            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
1709
1710         uiBlockSetDirection(block, UI_DOWN);
1711         uiTextBoundsBlock(block, 80);
1712
1713         return block;
1714 }
1715
1716 /************************** HELP *****************************/
1717
1718 static void do_info_help_websitesmenu(void *arg, int event)
1719 {
1720         BPY_menu_do_python(PYMENU_HELPWEBSITES, event);
1721
1722         allqueue(REDRAWVIEW3D, 0);
1723 }
1724
1725
1726 static uiBlock *info_help_websitesmenu(void *arg_unused)
1727 {
1728         uiBlock *block;
1729         BPyMenu *pym;
1730         short yco = 20, menuwidth = 120;
1731         int i = 0;
1732
1733         block= uiNewBlock(&curarea->uiblocks, "info_help_websitesmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1734         uiBlockSetButmFunc(block, do_info_help_websitesmenu, NULL);
1735         
1736         for (pym = BPyMenuTable[PYMENU_HELPWEBSITES]; pym; pym = pym->next, i++) {
1737                 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);
1738         }
1739         
1740         uiBlockSetDirection(block, UI_RIGHT);
1741         uiTextBoundsBlock(block, 60);
1742                 
1743         return block;
1744 }
1745
1746 static void do_info_help_systemmenu(void *arg, int event)
1747 {
1748         /* events >=10 are registered bpython scripts */
1749         if (event >= 10) BPY_menu_do_python(PYMENU_HELPSYSTEM, event - 10);
1750         else {
1751                 switch(event) {
1752
1753                 case 1: /* Benchmark */
1754                         /* dodgy hack turning on CTRL ALT SHIFT key to do a benchmark 
1755                          *      rather than copying lines and lines of code from toets.c :( 
1756                          */
1757         
1758                         if(select_area(SPACE_VIEW3D)) {
1759                                 mainqenter(LEFTSHIFTKEY, 1);
1760                                 mainqenter(LEFTCTRLKEY, 1);
1761                                 mainqenter(LEFTALTKEY, 1);
1762                                 mainqenter(TKEY, 1);
1763                                 mainqenter(TKEY, 0);
1764                                 mainqenter(EXECUTE, 1);
1765                                 mainqenter(LEFTSHIFTKEY, 0);
1766                                 mainqenter(LEFTCTRLKEY, 0);
1767                                 mainqenter(LEFTALTKEY, 0);
1768                         }
1769                         break;
1770                 }
1771         }
1772
1773         allqueue(REDRAWVIEW3D, 0);
1774 }
1775
1776
1777 static uiBlock *info_help_systemmenu(void *arg_unused)
1778 {
1779         uiBlock *block;
1780         BPyMenu *pym;
1781         short yco = 20, menuwidth = 120;
1782         int i = 0;
1783
1784         block= uiNewBlock(&curarea->uiblocks, "info_help_systemmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1785         uiBlockSetButmFunc(block, do_info_help_systemmenu, NULL);
1786         
1787         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Benchmark",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1788         
1789         for (pym = BPyMenuTable[PYMENU_HELPSYSTEM]; pym; pym = pym->next, i++) {
1790                 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);
1791         }
1792         
1793         uiBlockSetDirection(block, UI_RIGHT);
1794         uiTextBoundsBlock(block, 60);
1795                 
1796         return block;
1797 }
1798
1799 static void do_info_helpmenu(void *arg, int event)
1800 {
1801         ScrArea *sa;
1802
1803         if(curarea->spacetype==SPACE_INFO) {
1804                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
1805                 if (!sa) sa= closest_bigger_area();
1806                 areawinset(sa->win);
1807         }
1808
1809         /* events >=10 are registered bpython scripts */
1810         if (event >= 10) BPY_menu_do_python(PYMENU_HELP, event - 10);
1811         else {
1812                 switch(event) {
1813                                                                         
1814                 case 0: /* About Blender */
1815                         break;
1816                 }
1817         }
1818
1819         allqueue(REDRAWINFO, 0);
1820 }
1821
1822 static uiBlock *info_helpmenu(void *arg_unused)
1823 {
1824 /*              static short tog=0; */
1825         uiBlock *block;
1826         short yco= 0;
1827         short menuwidth=120;
1828         BPyMenu *pym;
1829         int i = 0;
1830         
1831         block= uiNewBlock(&curarea->uiblocks, "info_helpmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1832         uiBlockSetButmFunc(block, do_info_helpmenu, NULL);
1833         
1834         uiDefIconTextBut(block, BUTM, B_SHOWSPLASH, ICON_BLANK1, "About Blender...",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
1835         
1836         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1837         
1838         for (pym = BPyMenuTable[PYMENU_HELP]; pym; pym = pym->next, i++) {
1839                 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);
1840         }
1841         
1842         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1843         
1844         uiDefIconTextBlockBut(block, info_help_websitesmenu, NULL, ICON_RIGHTARROW_THIN, "Websites", 0, yco-=20, 120, 19, "");
1845         
1846         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1847         
1848         uiDefIconTextBlockBut(block, info_help_systemmenu, NULL, ICON_RIGHTARROW_THIN, "System", 0, yco-=20, 120, 19, "");
1849
1850         uiBlockSetDirection(block, UI_DOWN);
1851         uiTextBoundsBlock(block, 80);
1852
1853         return block;
1854 }
1855
1856 /************************** END MAIN MENU *****************************/
1857 /* ugly global yes, for renderwin.c to write to */
1858 char info_time_str[32]="";
1859
1860 static void info_text(int x, int y)
1861 {
1862         Object *ob= OBACT;
1863         extern float hashvectf[];
1864         extern unsigned long mem_in_use, mmap_in_use;
1865         unsigned int swatch_color;
1866         float fac1, fac2, fac3;
1867         char infostr[300], memstr[64];
1868         char *headerstr, *s;
1869         int hsize;
1870
1871         s= memstr + sprintf(memstr," | Mem:%.2fM ", ((mem_in_use-mmap_in_use)>>10)/1024.0);
1872         if(mmap_in_use)
1873                 sprintf(s,"(%.2fM) ", ((mmap_in_use)>>10)/1024.0);
1874
1875         
1876         if(G.obedit) {
1877                 s = infostr;
1878
1879                 s+= sprintf(s, "%s", G.editModeTitleExtra);
1880                 if(G.obedit->type==OB_MESH) {
1881                         if(G.scene->selectmode & SCE_SELECT_VERTEX)
1882                                 s+= sprintf(s,"Ve:%d-%d | Ed:%d-%d | Fa:%d-%d",
1883                                                 G.totvertsel, G.totvert, G.totedgesel, G.totedge, G.totfacesel, G.totface);
1884                         else if(G.scene->selectmode & SCE_SELECT_EDGE)
1885                                 s+= sprintf(s,"Ed:%d-%d | Fa:%d-%d",
1886                                                 G.totedgesel, G.totedge, G.totfacesel, G.totface);
1887                         else 
1888                                 s+= sprintf(s,"Fa:%d-%d", G.totfacesel, G.totface);
1889                 }
1890                 else if(G.obedit->type==OB_ARMATURE) {
1891                         s+= sprintf(s,"Ve:%d-%d | Bo:%d-%d", G.totvertsel, G.totvert, G.totbonesel, G.totbone);
1892                 }
1893                 else {
1894                         s+= sprintf(s,"Ve:%d-%d", G.totvertsel, G.totvert);
1895                 }
1896
1897                 strcat(s, memstr);
1898         }
1899         else if(ob && (ob->flag & OB_POSEMODE)) {
1900                 sprintf(infostr,"Bo:%d-%d %s",
1901                                         G.totbonesel, G.totbone, memstr);
1902         }
1903         else {
1904                 sprintf(infostr,"Ve:%d | Fa:%d | Ob:%d-%d | La:%d %s | Time:%s | ",
1905                         G.totvert, G.totface, G.totobj, G.totobjsel, G.totlamp, memstr, info_time_str);
1906         }
1907         if(ob) {
1908                 strcat(infostr, ob->id.name+2);
1909         }
1910
1911         if (g_progress_bar && g_progress_info) {
1912                 headerstr= g_progress_info;
1913         } else {
1914                 headerstr= versionstr; 
1915         }
1916
1917         if      (g_progress_bar) {
1918                 hsize = 4 + (138.0 * g_done);
1919                 fac1 = 0.5 * g_done; // do some rainbow colours on progress
1920                 fac2 = 1.0;
1921                 fac3 = 0.9;
1922         } else {
1923                 hsize= 30+BIF_GetStringWidth(G.font, headerstr, (U.transopts & USER_TR_BUTTONS));
1924
1925                 /* promise! Never change these lines again! (zr & ton did!) */
1926                 fac1= fabs(hashvectf[ 2*G.version+4]);
1927                 fac2= 0.5+0.1*hashvectf[ G.version+3];
1928                 fac3= 0.7;
1929         }
1930         
1931         swatch_color= hsv_to_cpack(fac1, fac2, fac3);
1932
1933         cpack( swatch_color );
1934         glRecti(x-24,  y-6,  x-30+hsize,        y+14);
1935
1936         glColor3ub(0, 0, 0); /* makes text black colored rect */
1937         
1938         glRasterPos2i(x, y);
1939         BIF_RasterPos(x, y);
1940
1941         BIF_DrawString(G.font, headerstr, (U.transopts & USER_TR_MENUS));
1942         hsize= BIF_GetStringWidth(G.font, headerstr, (U.transopts & USER_TR_BUTTONS));
1943         
1944         BIF_ThemeColor(TH_MENU_TEXT); /* makes text readable on dark theme */
1945         
1946         glRasterPos2i(x+hsize+10,       y);
1947         BIF_RasterPos(x+hsize+10,       y);
1948         
1949         BIF_DrawString(G.font, infostr, (U.transopts & USER_TR_MENUS));
1950 }
1951
1952 void info_buttons(void)
1953 {
1954         uiBlock *block;
1955         short xco= 42;
1956         int xmax;
1957
1958         block= uiNewBlock(&curarea->uiblocks, "header info", UI_EMBOSSN, UI_HELV, curarea->headwin);
1959
1960         if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
1961         else uiBlockSetCol(block, TH_HEADERDESEL);
1962         
1963         if(curarea->flag & HEADER_NO_PULLDOWN) {
1964                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_RIGHT,
1965                                 xco,2,XIC,YIC-2,
1966                                 &(curarea->flag), 0, 0, 0, 0, "Enables display of pulldown menus");
1967         } else {
1968                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_DOWN,
1969                                 xco,2,XIC,YIC-2,
1970                                 &(curarea->flag), 0, 0, 0, 0, "Hides pulldown menus");
1971         }
1972         xco+=XIC;
1973
1974         if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
1975         
1976                 uiBlockSetEmboss(block, UI_EMBOSSP);
1977
1978                 /* the 'xmax - 3' rather than xmax is to prevent some weird flickering where the highlighted
1979                  * menu is drawn wider than it should be. The ypos of -1 is to make it properly fill the
1980                  * height of the header */
1981                 xmax= GetButStringLength("File");
1982                 uiDefPulldownBut(block, info_filemenu, NULL, "File",    xco, -1, xmax-3, 22, "");
1983                 xco+= xmax;
1984
1985                 xmax= GetButStringLength("Add");
1986                 uiDefPulldownBut(block, info_addmenu, NULL, "Add",      xco, -1, xmax-3, 22, "");
1987                 xco+= xmax;
1988
1989                 xmax= GetButStringLength("Timeline");
1990                 uiDefPulldownBut(block, info_timelinemenu, NULL, "Timeline",    xco, -1, xmax-3, 22, "");
1991                 xco+= xmax;
1992
1993                 xmax= GetButStringLength("Game");
1994                 uiDefPulldownBut(block, info_gamemenu, NULL, "Game",    xco, -1, xmax-3, 22, "");
1995                 xco+= xmax;
1996
1997                 xmax= GetButStringLength("Render");
1998                 uiDefPulldownBut(block, info_rendermenu, NULL, "Render",        xco, -1, xmax-3, 22, "");
1999                 xco+= xmax;
2000
2001                 xmax= GetButStringLength("Help");
2002                 uiDefPulldownBut(block, info_helpmenu, NULL, "Help",    xco, -1, xmax-3, 22, "");
2003                 xco+= xmax;
2004
2005         }
2006
2007         /* pack icon indicates a packed file */
2008         
2009         if (G.fileflags & G_AUTOPACK) {
2010                 uiBlockSetEmboss(block, UI_EMBOSSN);
2011                 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.");
2012                 xco += XIC;
2013         }
2014
2015         if (curarea->full == 0) {
2016                 curarea->butspacetype= SPACE_INFO;
2017                 uiBlockSetEmboss(block, UI_EMBOSS);
2018                 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.");
2019                 
2020                 /* STD SCREEN BUTTONS */
2021                 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);
2022                 
2023                 xco +=8;
2024         
2025                 /* STD SCENE BUTTONS */
2026                 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);
2027         }
2028         else xco= 430;
2029         
2030 BIF_SetScale(block->aspect);
2031         info_text(xco+24, 6);
2032         
2033         uiBlockSetEmboss(block, UI_EMBOSSN);
2034         uiDefIconBut(block, BUT, B_SHOWSPLASH, ICON_BLENDER, xco+2, 0,XIC,YIC, 0, 0, 0, 0, 0, "Click to display Splash Screen");
2035
2036         /* always do as last */
2037         curarea->headbutlen= xco+2*XIC;
2038
2039 #if 0
2040 // #ifdef _WIN32        // FULLSCREEN
2041         if(U.uiflag & USER_FLIPFULLSCREEN) {
2042                 uiDefIconBut(block, BUT, B_FLIPFULLSCREEN, ICON_WINDOW_WINDOW,
2043                                 (short)(curarea->winx-XIC-5), 0,XIC,YIC,
2044                                 0, 0, 0, 0, 0, "Toggles Blender to fullscreen mode");/* dir             */
2045         } else {
2046                 uiDefIconBut(block, BUT, B_FLIPFULLSCREEN, ICON_WINDOW_FULLSCREEN,
2047                                 (short)(curarea->winx-XIC-5), 0,XIC,YIC,
2048                                 0, 0, 0, 0, 0, "Toggles Blender to fullscreen mode");/* dir             */
2049         }
2050 #endif
2051         
2052         uiDrawBlock(block);
2053 }