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