This is patch #6833
[blender-staging.git] / source / blender / src / header_info.c
1 /**
2  * header_info.c oct-2003
3  *
4  * Functions to draw the "User Preferences" window header
5  * and handle user events sent to it.
6  * 
7  *
8  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version. The Blender
14  * Foundation also sells licenses for use in proprietary software under
15  * the Blender License.  See http://www.blender.org/BL/ for information
16  * about this.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
26  *
27  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
28  * All rights reserved.
29  *
30  * The Original Code is: all of this file.
31  *
32  * Contributor(s): none yet.
33  *
34  * ***** END GPL/BL DUAL LICENSE BLOCK *****
35  */
36  
37 #include <math.h>
38 #include <stdlib.h>
39 #include <string.h>
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 #include "DNA_group_types.h"
46 #include "DNA_ID.h"
47 #include "DNA_image_types.h"
48 #include "DNA_lamp_types.h"
49 #include "DNA_object_types.h"
50 #include "DNA_packedFile_types.h"
51 #include "DNA_scene_types.h"
52 #include "DNA_screen_types.h"
53 #include "DNA_space_types.h"
54 #include "DNA_userdef_types.h"
55 #include "DNA_world_types.h"
56
57 #include "BDR_editcurve.h"
58 #include "BDR_editmball.h"
59 #include "BDR_editobject.h"
60 #include "BDR_editface.h"
61 #include "BDR_vpaint.h"
62
63 #include "BIF_editarmature.h"
64 #include "BIF_editfont.h"
65 #include "BIF_editmesh.h"
66 #include "BIF_gl.h"
67 #include "BIF_interface.h"
68 #include "BIF_language.h"
69 #include "BIF_mainqueue.h"
70 #include "BIF_meshtools.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 temp_dir[]; /* XXXXX BAD BAD BAD from exotic.c */
201
202 void write_vrml_fs()
203 {
204         if(G.obedit) {
205                 error("Can't save VRML. Press TAB to leave EditMode");
206         }
207         else {
208                 if(temp_dir[0]==0) strcpy(temp_dir, G.sce);
209         
210                 activate_fileselect(FILE_SPECIAL, "Export VRML 1.0", temp_dir, write_vrml);
211         }  
212 }
213
214 void write_dxf_fs()
215 {
216         if(G.obedit) {
217                 error("Can't save DXF. Press TAB to leave EditMode");
218         }
219         else {
220
221                 if(temp_dir[0]==0) strcpy(temp_dir, G.sce);
222
223                 activate_fileselect(FILE_SPECIAL, "Export DXF", temp_dir, write_dxf);   
224         }
225 }
226
227 void write_stl_fs()
228 {
229         if(G.obedit) {
230                 error("Can't save STL. Press TAB to leave EditMode");
231         }
232         else {
233
234                 if(temp_dir[0]==0) strcpy(temp_dir, G.sce);
235
236                 activate_fileselect(FILE_SPECIAL, "Export STL", temp_dir, write_stl);
237         }
238 }
239 /* ------------ */
240
241 int buttons_do_unpack()
242 {
243         int how;
244         char menu[2048];
245         char *line = menu;
246         int ret_value = RET_OK, count = 0;
247
248         count = countPackedFiles();
249
250         if(!count) {
251                 pupmenu("No packed files. Autopack disabled");
252                 return ret_value;
253         }
254         if (count == 1)
255                 line += sprintf(line, "Unpack 1 file%%t");
256         else
257                 line += sprintf(line, "Unpack %d files%%t", count);
258         
259         line += sprintf(line, "|Use files in current directory (create when necessary)%%x%d", PF_USE_LOCAL);
260         line += sprintf(line, "|Write files to current directory (overwrite existing files)%%x%d", PF_WRITE_LOCAL);
261         line += sprintf(line, "|%%l|Use files in original location (create when necessary)%%x%d", PF_USE_ORIGINAL);
262         line += sprintf(line, "|Write files to original location (overwrite existing files)%%x%d", PF_WRITE_ORIGINAL);
263         line += sprintf(line, "|%%l|Disable AutoPack, keep all packed files %%x%d", PF_KEEP);
264         line += sprintf(line, "|Ask for each file %%x%d", PF_ASK);
265
266         how = pupmenu(menu);
267
268         if(how == -1)
269                 ret_value = RET_CANCEL;
270         else {
271                 if (how != PF_KEEP) unpackAll(how);
272                 G.fileflags &= ~G_AUTOPACK;
273         }
274         
275         return ret_value;
276 }
277
278 /* here, because of all creator stuff */
279
280 Scene *copy_scene(Scene *sce, int level)
281 {
282         /* level 0: al objects shared
283          * level 1: al object-data shared
284          * level 2: full copy
285          */
286         Scene *scen;
287         Base *base, *obase;
288
289         /* level 0 */
290         scen= copy_libblock(sce);
291         duplicatelist(&(scen->base), &(sce->base));
292         
293         clear_id_newpoins();
294         
295         id_us_plus((ID *)scen->world);
296         id_us_plus((ID *)scen->set);
297
298         scen->ed= NULL;
299         scen->radio= NULL;
300         scen->theDag= NULL;
301         scen->toolsettings= MEM_dupallocN(sce->toolsettings);
302
303         duplicatelist(&(scen->markers), &(sce->markers));
304         duplicatelist(&(scen->r.layers), &(sce->r.layers));
305         
306         scen->nodetree= ntreeCopyTree(sce->nodetree, 0);
307         
308         obase= sce->base.first;
309         base= scen->base.first;
310         while(base) {
311                 id_us_plus(&base->object->id);
312                 if(obase==sce->basact) scen->basact= base;
313
314                 obase= obase->next;
315                 base= base->next;
316         }
317
318         if(level==0) return scen;
319
320         /* level 1 */
321         G.scene= scen;
322         
323         single_object_users(0);
324
325         /*      camera */
326         ID_NEW(G.scene->camera);
327
328         /* level 2 */
329         if(level>=2) {
330                 if(scen->world) {
331                         id_us_plus(&scen->world->id);
332                         scen->world= copy_world(scen->world);
333                 }
334                 single_obdata_users(0);
335                 single_mat_users_expand();
336                 single_tex_users_expand();
337                 
338                 scen->radio= MEM_dupallocN(sce->radio);
339                 
340         }
341
342         clear_id_newpoins();
343
344         BPY_copy_scriptlink(&sce->scriptlink);
345         // make a private copy of the avicodecdata
346
347         if (sce->r.avicodecdata) {
348
349                 scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata);
350                 scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecdata->lpFormat);
351                 scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecdata->lpParms);
352         }
353
354         // make a private copy of the qtcodecdata
355
356         if (sce->r.qtcodecdata) {
357                 scen->r.qtcodecdata = MEM_dupallocN(sce->r.qtcodecdata);
358                 scen->r.qtcodecdata->cdParms = MEM_dupallocN(scen->r.qtcodecdata->cdParms);
359         }
360
361         return scen;
362 }
363
364 void do_info_buttons(unsigned short event)
365 {
366         bScreen *sc, *oldscreen;
367         Scene *sce, *sce1;
368         ScrArea *sa;
369         int nr;
370
371         switch(event) {
372         case B_INFOSCR:         /* menu select screen */
373
374                 if( G.curscreen->screennr== -2) {
375                         if(curarea->winy <50) {
376                                 sa= closest_bigger_area();
377                                 areawinset(sa->win);
378                         }
379                         activate_databrowse((ID *)G.curscreen, ID_SCR, 0, B_INFOSCR,
380                                                                                         &G.curscreen->screennr, do_info_buttons);
381                         return;
382                 }
383                 if( G.curscreen->screennr < 0) return;
384
385                 sc= G.main->screen.first;
386                 nr= 1;
387                 while(sc) {
388                         if(nr==G.curscreen->screennr) {
389                                 if(is_allowed_to_change_screen(sc)) setscreen(sc);
390                                 else error("Unable to perform function in EditMode");
391                                 break;
392                         }
393                         nr++;
394                         sc= sc->id.next;
395                 }
396                 /* last item: NEW SCREEN */
397                 if(sc==0) {
398                         nr= pupmenu("New Screen%t|Empty%x1|Duplicate%x2");
399
400                         if(nr==1) default_twosplit();
401                         if(nr==2) duplicate_screen();
402                 }
403                 break;
404         case B_INFODELSCR:
405 /*do this event only with buttons, so it can never be called with full-window*/
406
407                 if(G.curscreen->id.prev) sc= G.curscreen->id.prev;
408                 else if(G.curscreen->id.next) sc= G.curscreen->id.next;
409                 else return;
410                 if(okee("Delete current screen")) {
411                         /* find new G.curscreen */
412
413                         oldscreen= G.curscreen;
414                         setscreen(sc);          /* this test if sc has a full */
415                         unlink_screen(oldscreen);
416                         free_libblock(&G.main->screen, oldscreen);
417                 }
418                 scrarea_queue_headredraw(curarea);
419
420                 break;
421         case B_INFOSCE:         /* menu select scene */
422
423                 if( G.curscreen->scenenr== -2) {
424                         if(curarea->winy <50) {
425                                 sa= closest_bigger_area();
426                                 areawinset(sa->win);
427                         }
428                         activate_databrowse((ID *)G.scene, ID_SCE, 0, B_INFOSCE,
429                                                                                         &G.curscreen->scenenr, do_info_buttons);
430                         return;
431                 }
432                 if( G.curscreen->scenenr < 0) return;
433
434                 sce= G.main->scene.first;
435                 nr= 1;
436                 while(sce) {
437                         if(nr==G.curscreen->scenenr) {
438                                 if(sce!=G.scene) set_scene(sce);
439                                 break;
440                         }
441                         nr++;
442                         sce= sce->id.next;
443                 }
444                 /* last item: NEW SCENE */
445                 if(sce==0) {
446                         nr= pupmenu("Add scene%t|Empty|Link Objects|Link ObData|Full Copy");
447                         if(nr<= 0) return;
448                         if(nr==1) {
449                                 ListBase lb;
450                                 
451                                 sce= add_scene(G.scene->id.name+2);
452                                 /* pretty bad ass copying here. we should use copy_scene to do all (ton) */
453                                 lb= sce->r.layers;
454                                 sce->r= G.scene->r;
455                                 sce->r.layers= lb;
456 #ifdef _WIN32
457                                 if (sce->r.avicodecdata) {
458                                         sce->r.avicodecdata = MEM_dupallocN(G.scene->r.avicodecdata);
459                                         sce->r.avicodecdata->lpFormat = MEM_dupallocN(G.scene->r.avicodecdata->lpFormat);
460                                         sce->r.avicodecdata->lpParms = MEM_dupallocN(G.scene->r.avicodecdata->lpParms);
461                                 }
462 #endif
463 #ifdef WITH_QUICKTIME
464                                 if (sce->r.qtcodecdata) {
465                                         sce->r.qtcodecdata = MEM_dupallocN(G.scene->r.qtcodecdata);
466                                         sce->r.qtcodecdata->cdParms = MEM_dupallocN(G.scene->r.qtcodecdata->cdParms);
467                                 }
468 #endif
469                         }
470                         else sce= copy_scene(G.scene, nr-2);
471
472                         set_scene(sce);
473                 }
474                 countall();
475                 BIF_preview_changed(ID_TE);
476
477                 break;
478         case B_INFODELSCE:
479
480                 if(G.scene->id.prev) sce= G.scene->id.prev;
481                 else if(G.scene->id.next) sce= G.scene->id.next;
482                 else return;
483                 if(okee("Delete current scene")) {
484                         
485                         /* exit modes... could become single call once */
486                         exit_editmode(EM_FREEDATA|EM_WAITCURSOR);
487                         if(G.f & G_VERTEXPAINT) set_vpaint(); /* Switch off vertex paint */
488                         if(G.f & G_TEXTUREPAINT) set_texturepaint(); /* Switch off tex paint */
489                         if(G.f & G_WEIGHTPAINT) set_wpaint();           /* Switch off weight paint */
490                         if(G.f & G_FACESELECT) set_faceselect(); /* Switch off face select */
491                         
492                         /* check all sets */
493                         sce1= G.main->scene.first;
494                         while(sce1) {
495                                 if(sce1->set == G.scene) sce1->set= 0;
496                                 sce1= sce1->id.next;
497                         }
498
499                         /* check all sequences */
500                         clear_scene_in_allseqs(G.scene);
501
502                         /* al screens */
503                         sc= G.main->screen.first;
504                         while(sc) {
505                                 if(sc->scene == G.scene) sc->scene= sce;
506                                 sc= sc->id.next;
507                         }
508                         free_libblock(&G.main->scene, G.scene);
509                         set_scene(sce);
510                         countall();
511                 }
512
513                 break;
514         }
515 }
516
517 static void check_packAll()
518 {
519         // first check for dirty images
520         Image *ima;
521
522         for(ima = G.main->image.first; ima; ima= ima->id.next) {
523                 if (ima->ibufs.first) { /* XXX FIX */
524                         ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
525
526                         if (ibuf && (ibuf->userflags &= IB_BITMAPDIRTY))
527                                 break;
528                 }
529         }
530         
531         if (ima == NULL || okee("Some images are painted on. These changes will be lost. Continue ?")) {
532                 packAll();
533                 G.fileflags |= G_AUTOPACK;
534         }
535 }
536
537 static int write_runtime(char *str, char *exename)
538 {
539         char *freestr= NULL;
540         char *ext = 0;
541
542 #ifdef _WIN32
543         ext = ".exe";
544 #endif
545
546 #ifdef __APPLE__
547         ext = ".app";
548 #endif
549         if (ext && (!BLI_testextensie(str, ext))) {
550                 freestr= MEM_mallocN(strlen(str) + strlen(ext) + 1, "write_runtime_check");
551                 sprintf(freestr,"%s%s", str, ext);
552                 str= freestr;
553         }
554
555         if (!BLI_exists(str) || saveover(str))
556                 BLO_write_runtime(str, exename);
557
558         if (freestr)
559                 MEM_freeN(freestr);
560  
561         return 0;
562 }
563
564 static void write_runtime_check_dynamic(char *str) 
565 {
566         write_runtime(str, "blenderdynplayer.exe");
567 }
568
569 static void write_runtime_check(char *str) 
570 {
571         char player[128];
572
573         strcpy(player, "blenderplayer");
574
575 #ifdef _WIN32
576         strcat(player, ".exe");
577 #endif
578
579 #ifdef __APPLE__
580         strcat(player, ".app");
581 #endif
582
583         write_runtime(str, player);
584 }
585 /* end keyed functions */
586
587 /************************** MAIN MENU *****************************/
588 /************************** FILE *****************************/
589
590
591 static void do_info_file_importmenu(void *arg, int event)
592 {
593         ScrArea *sa;
594
595         if(curarea->spacetype==SPACE_INFO) {
596                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
597                 if (!sa) sa= closest_bigger_area();
598                 areawinset(sa->win);
599         }
600
601         /* events >=3 are registered bpython scripts */
602         if (event >= 3) {
603                 BPY_menu_do_python(PYMENU_IMPORT, event - 3);
604                 BIF_undo_push("Import file");
605         }
606         else {
607                 switch(event) {
608                                                                         
609                 case 0: /* DXF */
610                         activate_fileselect(FILE_BLENDER, "Import DXF", G.sce, BIF_read_file);
611                         break;
612                 case 1: /* VRML 1.0 */
613                         activate_fileselect(FILE_BLENDER, "Import VRML 1.0", G.sce, BIF_read_file);
614                         break;
615                 case 2: /* STL */
616                         activate_fileselect(FILE_BLENDER, "Import STL", G.sce, BIF_read_file);
617                         break;
618
619                 }
620         }
621         allqueue(REDRAWINFO, 0);
622 }
623
624 static uiBlock *info_file_importmenu(void *arg_unused)
625 {
626         uiBlock *block;
627         short yco = 20, menuwidth = 120;
628         BPyMenu *pym;
629         int i = 0;
630
631         block= uiNewBlock(&curarea->uiblocks, "importmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
632         uiBlockSetButmFunc(block, do_info_file_importmenu, NULL);
633         //uiBlockSetXOfs(block, -50);  // offset to parent button
634         
635         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...",
636                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "");
637         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...",
638                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "");
639         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "STL...",
640                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "");
641
642         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
643
644         for (pym = BPyMenuTable[PYMENU_IMPORT]; pym; pym = pym->next, i++) {
645                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i+3, pym->tooltip?pym->tooltip:pym->filename);
646         }
647
648         uiBlockSetDirection(block, UI_RIGHT);
649         uiTextBoundsBlock(block, 60);
650
651         return block;
652 }
653
654 static void do_info_file_exportmenu(void *arg, int event)
655 {
656         ScrArea *sa;
657
658         if(curarea->spacetype==SPACE_INFO) {
659                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
660                 if (!sa) sa= closest_bigger_area();
661                 areawinset(sa->win);
662         }
663
664         /* events >=3 are registered bpython scripts */
665         if (event >= 3) BPY_menu_do_python(PYMENU_EXPORT, event - 3);
666
667         else switch(event) {
668                                                                         
669         case 0:
670                 write_vrml_fs();
671                 break;
672         case 1:
673                 write_dxf_fs();
674                 break;
675         case 2:
676                 write_stl_fs();
677                 break;
678         }
679         allqueue(REDRAWINFO, 0);
680 }
681
682 static uiBlock *info_file_exportmenu(void *arg_unused)
683 {
684         uiBlock *block;
685         short yco = 20, menuwidth = 120;
686         BPyMenu *pym;
687         int i = 0;
688
689         block= uiNewBlock(&curarea->uiblocks, "exportmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
690         uiBlockSetButmFunc(block, do_info_file_exportmenu, NULL);
691         //uiBlockSetXOfs(block, -50);  // offset to parent button
692
693         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...|Ctrl F2",
694                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "");
695         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...|Shift F2",
696                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "");
697         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "STL...",
698                          0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "");
699
700         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
701
702         /* note that we acount for the 3 previous entries with i+3: */
703         for (pym = BPyMenuTable[PYMENU_EXPORT]; pym; pym = pym->next, i++) {
704                 uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, 
705                                  NULL, 0.0, 0.0, 1, i+3, 
706                                  pym->tooltip?pym->tooltip:pym->filename);
707         }
708
709
710         uiBlockSetDirection(block, UI_RIGHT);
711         uiTextBoundsBlock(block, 60);
712
713         return block;
714 }
715
716 #ifdef WITH_VERSE
717
718 extern ListBase session_list;
719
720 static void do_verse_filemenu(void *arg, int event)
721 {
722         char address[64];               /* lenght of domain name is 63 characters or less */
723         VerseSession *session = NULL;
724         ScrArea *sa;
725         
726         if(curarea->spacetype==SPACE_INFO) {
727                 sa= closest_bigger_area();
728                 areawinset(sa->win);
729         }
730
731         switch(event) {
732                 case 0:
733                         waitcursor(1);
734                         printf("Connecting to localhost!\n");
735                         b_verse_connect("localhost");
736                         waitcursor(0);
737                         break;
738                 case 1:
739                         address[0] = '\0';
740                         if(sbutton(address, 0, 63, "Server:")) {
741                                 waitcursor(1);
742                                 printf("Connecting to %s\n", address);
743                                 b_verse_connect(address);
744                                 waitcursor(0);
745                         }
746                         break;
747                 case 2:
748                         session = session_menu();
749                         if(session) {
750                                 printf("Disconnecting session: %s!\n", session->address);
751                                 end_verse_session(session);
752                         }
753                         break;
754                 case 3:
755                         printf("Disconnecting all sessions!\n");
756                         end_all_verse_sessions();
757                         break;
758         case 4:
759             printf("sending get to master server\n");
760             b_verse_ms_get();
761             break;
762         }
763 }
764
765 static uiBlock *verse_filemenu(void *unusedargs)
766 {
767         uiBlock *block;
768         short yco = 20, menuwidth = 120;
769
770         block= uiNewBlock(&curarea->uiblocks, "verse_filemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
771         uiBlockSetButmFunc(block, do_verse_filemenu, NULL);
772                 
773         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Connect to localhost", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
774         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Connect ...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
775         if(session_list.first != NULL) {
776                 if(session_list.first != session_list.last) {
777                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Disconnect ...",
778                                         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
779                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Disconnect all",
780                                         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
781                 }
782                 else {
783                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Disconnect",
784                                         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
785                 }
786                 
787         }
788         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Get Servers", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
789
790         uiBlockSetDirection(block, UI_RIGHT);
791         uiTextBoundsBlock(block, 60);
792
793         return block;
794 }
795 #endif
796
797 static void do_info_filemenu(void *arg, int event)
798 {
799         ScrArea *sa;
800         char dir[FILE_MAXDIR];
801         
802         if(curarea->spacetype==SPACE_INFO) {
803                 sa= closest_bigger_area();
804                 areawinset(sa->win);
805         }
806
807         /* these are no defines, easier this way, the codes are in the function below */
808         switch(event) {
809         case 0:
810                 if (okee("Erase All")) {
811                         if (!BIF_read_homefile(0))
812                                 error("No file ~/.B.blend");
813                 }
814                 break;
815         case 1: /* open */
816                 activate_fileselect(FILE_BLENDER, "Open", G.sce, BIF_read_file);
817                 break;
818         case 3: /* append */
819                 activate_fileselect(FILE_LOADLIB, "Load Library", G.lib, 0);
820                 break;
821         case 4: /* save */
822                 strcpy(dir, G.sce);
823                 untitled(dir);
824                 activate_fileselect(FILE_BLENDER, "Save As", dir, BIF_write_file);
825                 break;
826         case 5:
827                 strcpy(dir, G.sce);
828                 if (untitled(dir)) {
829                         activate_fileselect(FILE_BLENDER, "Save As", dir, BIF_write_file);
830                 } else {
831                         BIF_write_file(dir);
832                         free_filesel_spec(dir);
833                 }
834                 break;
835         case 6: /* save image */
836                 BIF_save_rendered_image_fs();
837                 break;
838         case 22: /* save runtime */
839                 activate_fileselect(FILE_SPECIAL, "Save Runtime", "", write_runtime_check);
840                 break;
841         case 23: /* save dynamic runtime */
842                 activate_fileselect(FILE_SPECIAL, "Save Dynamic Runtime", "", write_runtime_check_dynamic);
843                 break;
844         case 24:
845                 BIF_screendump(0);
846                 break;
847         case 25:
848                 BIF_screendump(1);
849                 break;
850         case 10: /* pack data */
851                 check_packAll();
852                 break;
853         case 11: /* unpack to current dir */
854                 unpackAll(PF_WRITE_LOCAL);
855                 G.fileflags &= ~G_AUTOPACK;
856                 break;
857         case 12: /* unpack data */
858                 if (buttons_do_unpack() != RET_CANCEL) {
859                         /* Clear autopack bit only if user selected one of the unpack options */
860                         G.fileflags &= ~G_AUTOPACK;
861                 }
862                 break;
863         case 13:
864                 exit_usiblender();
865                 break;
866         case 15:        /* recover previous session */
867                 {
868                         extern short winqueue_break; /* editscreen.c */
869                         int save_over;
870                         char str[FILE_MAXDIR+FILE_MAXFILE];
871                         char scestr[FILE_MAXDIR+FILE_MAXFILE];
872                         
873                         strcpy(scestr, G.sce);  /* temporal store */
874                         save_over = G.save_over;
875                         BLI_make_file_string("/", str, U.tempdir, "quit.blend");
876                         BKE_read_file(str, NULL);
877                         G.save_over = save_over;
878                         strcpy(G.sce, scestr);
879
880                         winqueue_break= 1;      /* leave queues everywhere */
881                 
882                         BKE_reset_undo();
883                         BKE_write_undo("original");     /* save current state */
884                         refresh_interface_font();
885                 }
886                 break;
887         case 31: /* save default settings */
888                 BIF_write_homefile();
889                 break;
890         case 32:
891                 if (okee("Erase All")) {
892                         if (!BIF_read_homefile(1))
893                                 error("Can't read data from memory!");
894                 }
895                 break;
896         case 35: /* compress toggle */
897                 U.flag ^= (USER_FILECOMPRESS);
898                 break;
899         }
900         allqueue(REDRAWINFO, 0);
901 }
902
903 static void do_info_operecentmenu(void *arg, int event)
904 {
905         struct RecentFile *recent;
906
907         if(event==0 && G.sce[0]) {
908                 BIF_read_file(G.sce);
909         }
910         else {  /* Global */
911                 recent = BLI_findlink(&(G.recent_files), event-1);
912                 BIF_read_file(recent->filename);
913         }
914 }
915
916 static uiBlock *info_openrecentmenu(void *arg_unused)
917 {
918         uiBlock *block;
919         short yco = 20, menuwidth = 120, i;
920         struct RecentFile *recent;
921
922         block= uiNewBlock(&curarea->uiblocks, "info_openrecentmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
923         uiBlockSetButmFunc(block, do_info_operecentmenu, NULL);
924
925         if (G.sce[0]) {
926                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, G.sce, 0, yco-=20,
927                                 menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
928         }
929
930         for (recent = G.recent_files.first, i=0; i<U.recent_files && recent; recent = recent->next, i++) {
931                 if (strcmp(recent->filename, G.sce)!=0) {
932                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, recent->filename, 0, yco-=20,
933                                         menuwidth, 19, NULL, 0.0, 0.0, 1, i+1, "");
934                 }
935         }
936
937         uiBlockSetDirection(block, UI_RIGHT);
938         uiTextBoundsBlock(block, 60);
939         return block;
940 }
941
942 static uiBlock *info_filemenu(void *arg_unused)
943 {
944         uiBlock *block;
945         short yco=0;
946         short menuwidth=120;
947
948         block= uiNewBlock(&curarea->uiblocks, "info_filemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
949         uiBlockSetButmFunc(block, do_info_filemenu, NULL);
950         
951         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "New|Ctrl X",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
952         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Open...|F1",                             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
953 #ifdef WITH_VERSE
954         uiDefIconTextBlockBut(block, verse_filemenu, NULL, ICON_RIGHTARROW_THIN, "Verse", 0, yco-=20, menuwidth, 19, "");
955 #endif
956         uiDefIconTextBlockBut(block, info_openrecentmenu, NULL, ICON_RIGHTARROW_THIN, "Open Recent",0, yco-=20, 120, 19, "");
957         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Recover Last Session",                           0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 15, "");
958
959         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
960
961         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save|Ctrl W",                            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
962         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save As...|F2",                  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
963         
964         if(U.flag & USER_FILECOMPRESS) {
965                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Compress File",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 35, "Enable file compression");
966         } else {
967                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Compress File",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 35, "Enable file compression");
968         }
969
970         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
971
972         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Image...|F3",                       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
973         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Dump Subwindow|Ctrl F3",                 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 24, "");
974         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Dump Screen|Ctrl Shift F3",                      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 25, "");
975 #if GAMEBLENDER == 1
976         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Runtime...",                        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 22, "");
977 #ifdef _WIN32
978         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Dynamic Runtime...",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 23, "");
979 #endif
980 #endif
981         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
982
983         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Default Settings|Ctrl U",                   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 31, "");
984         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Load Factory Settings",                          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 32, "");
985
986
987         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
988
989         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Append or Link|Shift F1",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
990         uiDefIconTextBlockBut(block, info_file_importmenu, NULL, ICON_RIGHTARROW_THIN, "Import", 0, yco-=20, menuwidth, 19, "");
991         uiDefIconTextBlockBut(block, info_file_exportmenu, NULL, ICON_RIGHTARROW_THIN, "Export", 0, yco-=20, menuwidth, 19, "");
992         
993         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
994
995         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack Data",                              0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "");
996 //      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");
997         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Unpack Data...",                         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 12, "");
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, "Quit Blender|Ctrl Q",                            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 13, "");
1002
1003         uiBlockSetDirection(block, UI_DOWN);
1004         uiTextBoundsBlock(block, 80);
1005
1006         return block;
1007 }
1008
1009 /**************************** ADD ******************************/
1010
1011 void do_info_add_meshmenu(void *arg, int event)
1012 {
1013         if (event>=20) {
1014                 BPY_menu_do_python(PYMENU_ADDMESH, event - 20);
1015         } else {
1016                 switch(event) {         
1017                         case 0:
1018                                 /* Plane */
1019                                 add_primitiveMesh(0);
1020                                 break;
1021                         case 1:
1022                                 /* Cube */
1023                                 add_primitiveMesh(1);
1024                                 break;
1025                         case 2:
1026                                 /* Circle */
1027                                 add_primitiveMesh(4);
1028                                 break;
1029                         case 3:
1030                                 /* UVsphere */
1031                                 add_primitiveMesh(11);
1032                                 break;
1033                         case 4:
1034                                 /* IcoSphere */
1035                                 add_primitiveMesh(12);
1036                                 break;
1037                         case 5:
1038                                 /* Cylinder */
1039                                 add_primitiveMesh(5);
1040                                 break;
1041                         case 7:
1042                                 /* Cone */
1043                                 add_primitiveMesh(7);
1044                                 break;
1045                         case 8:
1046                                 /* Grid */
1047                                 add_primitiveMesh(10);
1048                                 break;
1049                         case 9:
1050                                 /* Monkey */
1051                                 add_primitiveMesh(13);
1052                                 break;
1053                         default:
1054                                 break;
1055                 }
1056         }
1057         allqueue(REDRAWINFO, 0);
1058 }
1059
1060 static uiBlock *info_add_meshmenu(void *arg_unused)
1061 {
1062 /*              static short tog=0; */
1063         uiBlock *block;
1064         short yco= 0;
1065         
1066         /* Python Menu */
1067         BPyMenu *pym;
1068         int i=0;
1069         
1070         block= uiNewBlock(&curarea->uiblocks, "add_meshmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1071         uiBlockSetButmFunc(block, do_info_add_meshmenu, NULL);
1072         
1073         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Plane|",                         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1074         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cube|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1075         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Circle|",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1076         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "UVsphere",                       0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1077         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "IcoSphere|",                     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1078         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cylinder|",                      0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "");
1079         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Cone|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "");
1080         uiDefIconTextBut(block, SEPR, 0, ICON_BLANK1, "",                                       0, yco-=6,      160, 6,  NULL, 0.0, 0.0, 0, 0, "");
1081         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grid|",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "");
1082         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Monkey|",                        0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 9, "");
1083
1084
1085         pym = BPyMenuTable[PYMENU_ADDMESH];
1086         if (pym) {
1087                 uiDefIconTextBut(block, SEPR, 0, ICON_BLANK1, "",                                       0, yco-=6,      160, 6,  NULL, 0.0, 0.0, 0, 0, "");
1088                 
1089                 for (; pym; pym = pym->next, i++) {
1090                         uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, i+20, pym->tooltip?pym->tooltip:pym->filename);
1091                 }
1092         }
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         case G_FILE_SHOW_PHYSICS:
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
1497         if(G.fileflags & G_FILE_SHOW_PHYSICS) {
1498                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Show Physics Visualization",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_SHOW_PHYSICS, "");
1499         } else {
1500                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Show Physics Visualization",              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_SHOW_PHYSICS, "");
1501         }
1502         
1503         if(G.fileflags & G_FILE_SHOW_DEBUG_PROPS) {
1504                 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, "");
1505         } else {
1506                 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, "");
1507         }
1508         
1509         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 1, 0, "");
1510
1511         if(G.fileflags & G_FILE_AUTOPLAY) {
1512                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Autostart",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_AUTOPLAY, "");
1513         } else {
1514                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Autostart",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, G_FILE_AUTOPLAY, "");
1515         }
1516
1517         uiBlockSetDirection(block, UI_DOWN);
1518         uiTextBoundsBlock(block, 70);
1519         
1520         return block;
1521 }
1522 /************************** TIMELINE *****************************/
1523
1524 static void do_info_timelinemenu(void *arg, int event)
1525 {
1526         /* needed to check for valid selected objects */
1527         Base *base=NULL;
1528         Object *ob=NULL;
1529         //char file[FILE_MAXDIR+FILE_MAXFILE];
1530
1531         base= BASACT;
1532         if (base) ob= base->object;
1533
1534         switch(event) {
1535         case 1:
1536                 /* Show Keyframes */
1537                 if (!ob) error("Select an object before showing its keyframes");
1538                 else set_ob_ipoflags();
1539                 break;
1540         case 2:
1541                 /* Show and select Keyframes */
1542                 if (!ob) error("Select an object before showing and selecting its keyframes");
1543                 else select_select_keys();
1544                         break;
1545                 case 3:
1546                 /* select next keyframe */
1547                 if (!ob) error("Select an object before selecting its next keyframe");
1548                 else nextkey_obipo(1);
1549                         break;
1550                 case 4:
1551                 /* select previous keyframe */
1552                 if (!ob) error("Select an object before selecting its previous keyframe");
1553                 else nextkey_obipo(-1);
1554                 break;
1555                 case 5:
1556                 /* next keyframe */
1557                 if (!ob) error("Select an object before going to its next keyframe");
1558                 else movekey_obipo(1);
1559                         break;
1560                 case 6:
1561                 /* previous keyframe */
1562                 if (!ob) error("Select an object before going to its previous keyframe");
1563                 else movekey_obipo(-1);
1564                 break;
1565         case 7:
1566                 /* next frame */
1567                 CFRA++;
1568                 update_for_newframe();
1569                 break;
1570                 case 8:
1571                 /* previous frame */
1572                 CFRA--;
1573                 if(CFRA<1) CFRA=1;
1574                 update_for_newframe();
1575                 break;
1576         case 9:
1577                 /* forward 10 frames */
1578                 CFRA+= 10;
1579                 update_for_newframe();
1580                 break;
1581         case 10:
1582                 /* back 10 frames */
1583                 CFRA-= 10;
1584                 if(CFRA<1) CFRA=1;
1585                 update_for_newframe();
1586                 break;
1587         case 11:
1588                 /* end frame */
1589                 CFRA= EFRA;
1590                 update_for_newframe();
1591                 break;
1592         case 12:
1593                 /* start frame */
1594                 CFRA= SFRA;
1595                 update_for_newframe();
1596                 break;
1597         }
1598         allqueue(REDRAWINFO, 0);
1599 }
1600
1601 static uiBlock *info_timelinemenu(void *arg_unused)
1602 {
1603 /*              static short tog=0; */
1604         uiBlock *block;
1605         char str[26];
1606         short yco= 0;
1607         short menuwidth=120;
1608
1609         block= uiNewBlock(&curarea->uiblocks, "timelinemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1610         uiBlockSetButmFunc(block, do_info_timelinemenu, NULL);
1611         
1612         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Keyframes|K",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1613         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show and Select Keyframes|Shift K",0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
1614         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Next Keyframe|PageUp",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
1615         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Previous Keyframe|PageDown",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
1616
1617         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1618
1619         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Next Keyframe|Ctrl PageUp",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1620         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Previous Keyframe|Ctrl PageDown",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
1621
1622         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1623
1624         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Next Frame|RightArrow",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
1625         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Previous Frame|LeftArrow",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, "");
1626         
1627         sprintf(str, "Forward %d Frames|UpArrow", G.scene->jumpframe);
1628         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, str,      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, "");
1629         sprintf(str, "Back %d Frames|DownArrow", G.scene->jumpframe);
1630         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, str,      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
1631
1632         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1633
1634         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "End Frame|Shift RightArrow",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
1635         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Start Frame|Shift LeftArrow",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
1636
1637         uiBlockSetDirection(block, UI_DOWN);
1638         uiTextBoundsBlock(block, 80);
1639
1640         return block;
1641 }
1642
1643 /************************** RENDER *****************************/
1644
1645 void do_info_render_bakemenu(void *arg, int event)
1646 {
1647
1648         objects_bake_render(event);
1649         
1650         allqueue(REDRAWINFO, 0);
1651 }
1652
1653 static uiBlock *info_render_bakemenu(void *arg_unused)
1654 {
1655         uiBlock *block;
1656         short yco= 0;
1657         
1658         block= uiNewBlock(&curarea->uiblocks, "render_bakemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1659         uiBlockSetButmFunc(block, do_info_render_bakemenu, NULL);
1660         
1661         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Full Render|Ctrl Alt B, 1",                              0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "");
1662         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Ambient Occlusion|Ctrl Alt B, 2",                                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "");
1663         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Normals|Ctrl Alt B, 3",                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "");
1664         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Texture Only|Ctrl Alt B, 4",                             0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "");
1665
1666         uiBlockSetDirection(block, UI_RIGHT);
1667         uiTextBoundsBlock(block, 50);
1668                 
1669         return block;
1670 }
1671
1672 static void do_info_rendermenu(void *arg, int event)
1673 {
1674         ScrArea *sa;
1675         extern void playback_anim();
1676
1677         /* events >=10 are registered bpython scripts */
1678         if (event >= 10) {
1679                 if(curarea->spacetype==SPACE_INFO) {
1680                         sa= find_biggest_area_of_type(SPACE_SCRIPT);
1681                         if (!sa) sa= closest_bigger_area();
1682                         areawinset(sa->win);
1683                 }
1684
1685                 BPY_menu_do_python(PYMENU_RENDER, event - 10);
1686                 BIF_undo_push("Rendering Script");
1687         }
1688         else {
1689         switch(event) {
1690                         
1691                 case 0:
1692                         BIF_do_render(0);
1693                         break;
1694                 case 1:
1695                         BIF_do_render(1);
1696                         break;
1697
1698                         /* note: dont use select_area() for setting active areas for opengl render */
1699                         /* its hackish and instable... code here was removed */
1700                 
1701                 case 4:
1702                         BIF_toggle_render_display();
1703                         break;
1704                 case 5:
1705                         playback_anim();
1706                         break;
1707                 case 6:
1708                         /* dodgy hack turning on SHIFT key to do a proper render border select
1709                         set_render_border(); only works when 3d window active
1710                         
1711                         This code copied from toolbox.c, only works when 3d window is cameraview */
1712
1713                         if(select_area(SPACE_VIEW3D)) {
1714                                 mainqenter(LEFTSHIFTKEY, 1);
1715                                 mainqenter(BKEY, 1);
1716                                 mainqenter(BKEY, 0);
1717                                 mainqenter(EXECUTE, 1);
1718                                 mainqenter(LEFTSHIFTKEY, 0);
1719                         }
1720
1721                         break;
1722
1723                 case 7:
1724                         extern_set_butspace(F10KEY, 0);
1725                         break;
1726                 }
1727         }
1728         allqueue(REDRAWINFO, 0);
1729 }
1730
1731 static uiBlock *info_rendermenu(void *arg_unused)
1732 {
1733         uiBlock *block;
1734         BPyMenu *pym;
1735         short yco= 0;
1736         short menuwidth=120;
1737         int i=0;
1738         
1739         block= uiNewBlock(&curarea->uiblocks, "rendermenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1740         uiBlockSetButmFunc(block, do_info_rendermenu, NULL);
1741         
1742         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Current Frame|F12",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
1743         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Animation|Ctrl F12",              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1744         
1745         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1746         
1747         uiDefIconTextBlockBut(block, info_render_bakemenu, NULL, ICON_RIGHTARROW_THIN, "Bake Render Meshes", 0, yco-=20, 120, 19, "");
1748
1749         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1750
1751         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Render Buffer|F11",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
1752         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Rendered Animation|Ctrl F11",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
1753
1754         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1755
1756         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Render Border|Shift B",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
1757
1758         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1759
1760         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Render Settings|F10",            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
1761
1762         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1763
1764         for (pym = BPyMenuTable[PYMENU_RENDER]; pym; pym = pym->next, i++) {
1765                 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);
1766         }
1767
1768         uiBlockSetDirection(block, UI_DOWN);
1769         uiTextBoundsBlock(block, 80);
1770
1771         return block;
1772 }
1773
1774 /************************** HELP *****************************/
1775
1776 static void do_info_help_websitesmenu(void *arg, int event)
1777 {
1778         BPY_menu_do_python(PYMENU_HELPWEBSITES, event);
1779
1780         allqueue(REDRAWVIEW3D, 0);
1781 }
1782
1783
1784 static uiBlock *info_help_websitesmenu(void *arg_unused)
1785 {
1786         uiBlock *block;
1787         BPyMenu *pym;
1788         short yco = 20, menuwidth = 120;
1789         int i = 0;
1790
1791         block= uiNewBlock(&curarea->uiblocks, "info_help_websitesmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1792         uiBlockSetButmFunc(block, do_info_help_websitesmenu, NULL);
1793         
1794         for (pym = BPyMenuTable[PYMENU_HELPWEBSITES]; pym; pym = pym->next, i++) {
1795                 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);
1796         }
1797         
1798         uiBlockSetDirection(block, UI_RIGHT);
1799         uiTextBoundsBlock(block, 60);
1800                 
1801         return block;
1802 }
1803
1804 static void do_info_help_systemmenu(void *arg, int event)
1805 {
1806         /* events >=10 are registered bpython scripts */
1807         if (event >= 10) BPY_menu_do_python(PYMENU_HELPSYSTEM, event - 10);
1808         else {
1809                 switch(event) {
1810
1811                 case 1: /* Benchmark */
1812                         /* dodgy hack turning on CTRL ALT SHIFT key to do a benchmark 
1813                          *      rather than copying lines and lines of code from toets.c :( 
1814                          */
1815         
1816                         if(select_area(SPACE_VIEW3D)) {
1817                                 mainqenter(LEFTSHIFTKEY, 1);
1818                                 mainqenter(LEFTCTRLKEY, 1);
1819                                 mainqenter(LEFTALTKEY, 1);
1820                                 mainqenter(TKEY, 1);
1821                                 mainqenter(TKEY, 0);
1822                                 mainqenter(EXECUTE, 1);
1823                                 mainqenter(LEFTSHIFTKEY, 0);
1824                                 mainqenter(LEFTCTRLKEY, 0);
1825                                 mainqenter(LEFTALTKEY, 0);
1826                         }
1827                         break;
1828                 }
1829         }
1830
1831         allqueue(REDRAWVIEW3D, 0);
1832 }
1833
1834
1835 static uiBlock *info_help_systemmenu(void *arg_unused)
1836 {
1837         uiBlock *block;
1838         BPyMenu *pym;
1839         short yco = 20, menuwidth = 120;
1840         int i = 0;
1841
1842         block= uiNewBlock(&curarea->uiblocks, "info_help_systemmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
1843         uiBlockSetButmFunc(block, do_info_help_systemmenu, NULL);
1844         
1845         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Benchmark",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
1846         
1847         for (pym = BPyMenuTable[PYMENU_HELPSYSTEM]; pym; pym = pym->next, i++) {
1848                 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);
1849         }
1850         
1851         uiBlockSetDirection(block, UI_RIGHT);
1852         uiTextBoundsBlock(block, 60);
1853                 
1854         return block;
1855 }
1856
1857 static void do_info_helpmenu(void *arg, int event)
1858 {
1859         ScrArea *sa;
1860
1861         if(curarea->spacetype==SPACE_INFO) {
1862                 sa= find_biggest_area_of_type(SPACE_SCRIPT);
1863                 if (!sa) sa= closest_bigger_area();
1864                 areawinset(sa->win);
1865         }
1866
1867         /* events >=10 are registered bpython scripts */
1868         if (event >= 10) BPY_menu_do_python(PYMENU_HELP, event - 10);
1869         else {
1870                 switch(event) {
1871                                                                         
1872                 case 0: /* About Blender */
1873                         break;
1874                 }
1875         }
1876
1877         allqueue(REDRAWINFO, 0);
1878 }
1879
1880 static uiBlock *info_helpmenu(void *arg_unused)
1881 {
1882 /*              static short tog=0; */
1883         uiBlock *block;
1884         short yco= 0;
1885         short menuwidth=120;
1886         BPyMenu *pym;
1887         int i = 0;
1888         
1889         block= uiNewBlock(&curarea->uiblocks, "info_helpmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
1890         uiBlockSetButmFunc(block, do_info_helpmenu, NULL);
1891         
1892         uiDefIconTextBut(block, BUTM, B_SHOWSPLASH, ICON_BLANK1, "About Blender...",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
1893         
1894         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1895         
1896         for (pym = BPyMenuTable[PYMENU_HELP]; pym; pym = pym->next, i++) {
1897                 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);
1898         }
1899         
1900         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1901         
1902         uiDefIconTextBlockBut(block, info_help_websitesmenu, NULL, ICON_RIGHTARROW_THIN, "Websites", 0, yco-=20, 120, 19, "");
1903         
1904         uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1905         
1906         uiDefIconTextBlockBut(block, info_help_systemmenu, NULL, ICON_RIGHTARROW_THIN, "System", 0, yco-=20, 120, 19, "");
1907
1908         uiBlockSetDirection(block, UI_DOWN);
1909         uiTextBoundsBlock(block, 80);
1910
1911         return block;
1912 }
1913
1914 /************************** END MAIN MENU *****************************/
1915 /* ugly global yes, for renderwin.c to write to */
1916 char info_time_str[32]="";
1917
1918 static void info_text(int x, int y)
1919 {
1920         Object *ob= OBACT;
1921         extern float hashvectf[];
1922         extern unsigned long mem_in_use, mmap_in_use;
1923         unsigned int swatch_color;
1924         float fac1, fac2, fac3;
1925         char infostr[300], memstr[64];
1926         char *headerstr, *s;
1927         int hsize;
1928
1929         s= memstr + sprintf(memstr," | Mem:%.2fM ", ((mem_in_use-mmap_in_use)>>10)/1024.0);
1930         if(mmap_in_use)
1931                 sprintf(s,"(%.2fM) ", ((mmap_in_use)>>10)/1024.0);
1932
1933         
1934         if(G.obedit) {
1935                 s = infostr;
1936
1937                 s+= sprintf(s, "%s", G.editModeTitleExtra);
1938                 if(G.obedit->type==OB_MESH) {
1939                         if(G.scene->selectmode & SCE_SELECT_VERTEX)
1940                                 s+= sprintf(s,"Ve:%d-%d | Ed:%d-%d | Fa:%d-%d",
1941                                                 G.totvertsel, G.totvert, G.totedgesel, G.totedge, G.totfacesel, G.totface);
1942                         else if(G.scene->selectmode & SCE_SELECT_EDGE)
1943                                 s+= sprintf(s,"Ed:%d-%d | Fa:%d-%d",
1944                                                 G.totedgesel, G.totedge, G.totfacesel, G.totface);
1945                         else 
1946                                 s+= sprintf(s,"Fa:%d-%d", G.totfacesel, G.totface);
1947                 }
1948                 else if(G.obedit->type==OB_ARMATURE) {
1949                         s+= sprintf(s,"Ve:%d-%d | Bo:%d-%d", G.totvertsel, G.totvert, G.totbonesel, G.totbone);
1950                 }
1951                 else {
1952                         s+= sprintf(s,"Ve:%d-%d", G.totvertsel, G.totvert);
1953                 }
1954
1955                 strcat(s, memstr);
1956         }
1957         else if(ob && (ob->flag & OB_POSEMODE)) {
1958                 sprintf(infostr,"Bo:%d-%d %s",
1959                                         G.totbonesel, G.totbone, memstr);
1960         }
1961         else {
1962                 sprintf(infostr,"Ve:%d | Fa:%d | Ob:%d-%d | La:%d %s | Time:%s | ",
1963                         G.totvert, G.totface, G.totobj, G.totobjsel, G.totlamp, memstr, info_time_str);
1964         }
1965         if(ob) {
1966                 strcat(infostr, ob->id.name+2);
1967         }
1968
1969         if (g_progress_bar && g_progress_info) {
1970                 headerstr= g_progress_info;
1971         } else {
1972                 headerstr= versionstr; 
1973         }
1974
1975         if      (g_progress_bar) {
1976                 hsize = 4 + (138.0 * g_done);
1977                 fac1 = 0.5 * g_done; /* do some rainbow colors on progress */
1978                 fac2 = 1.0;
1979                 fac3 = 0.9;
1980         } else {
1981                 hsize= 30+BIF_GetStringWidth(G.font, headerstr, (U.transopts & USER_TR_BUTTONS));
1982
1983                 /* promise! Never change these lines again! (zr & ton did!) */
1984                 fac1= fabs(hashvectf[ 2*G.version+4]);
1985                 fac2= 0.5+0.1*hashvectf[ G.version+3];
1986                 fac3= 0.7;
1987         }
1988         
1989         swatch_color= hsv_to_cpack(fac1, fac2, fac3);
1990
1991         cpack( swatch_color );
1992         glRecti(x-24,  y-6,  x-30+hsize,        y+14);
1993
1994         glColor3ub(0, 0, 0); /* makes text black colored rect */
1995         
1996         glRasterPos2i(x, y);
1997         BIF_RasterPos(x, y);
1998
1999         BIF_DrawString(G.font, headerstr, (U.transopts & USER_TR_MENUS));
2000         hsize= BIF_GetStringWidth(G.font, headerstr, (U.transopts & USER_TR_BUTTONS));
2001         
2002         BIF_ThemeColor(TH_MENU_TEXT); /* makes text readable on dark theme */
2003         
2004         glRasterPos2i(x+hsize+10,       y);
2005         BIF_RasterPos(x+hsize+10,       y);
2006         
2007         BIF_DrawString(G.font, infostr, (U.transopts & USER_TR_MENUS));
2008 }
2009
2010 void info_buttons(void)
2011 {
2012         uiBlock *block;
2013         short xco= 42;
2014         int xmax;
2015
2016         block= uiNewBlock(&curarea->uiblocks, "header info", UI_EMBOSSN, UI_HELV, curarea->headwin);
2017
2018         if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
2019         else uiBlockSetCol(block, TH_HEADERDESEL);
2020         
2021         if(curarea->flag & HEADER_NO_PULLDOWN) {
2022                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_RIGHT,
2023                                 xco,2,XIC,YIC-2,
2024                                 &(curarea->flag), 0, 0, 0, 0, "Enables display of pulldown menus");
2025         } else {
2026                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_DOWN,
2027                                 xco,2,XIC,YIC-2,
2028                                 &(curarea->flag), 0, 0, 0, 0, "Hides pulldown menus");
2029         }
2030         xco+=XIC;
2031
2032         if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
2033         
2034                 uiBlockSetEmboss(block, UI_EMBOSSP);
2035
2036                 /* the 'xmax - 3' rather than xmax is to prevent some weird flickering where the highlighted
2037                  * menu is drawn wider than it should be. The ypos of -1 is to make it properly fill the
2038                  * height of the header */
2039                 xmax= GetButStringLength("File");
2040                 uiDefPulldownBut(block, info_filemenu, NULL, "File",    xco, -1, xmax-3, 22, "");
2041                 xco+= xmax;
2042
2043                 xmax= GetButStringLength("Add");
2044                 uiDefPulldownBut(block, info_addmenu, NULL, "Add",      xco, -1, xmax-3, 22, "");
2045                 xco+= xmax;
2046
2047                 xmax= GetButStringLength("Timeline");
2048                 uiDefPulldownBut(block, info_timelinemenu, NULL, "Timeline",    xco, -1, xmax-3, 22, "");
2049                 xco+= xmax;
2050
2051                 xmax= GetButStringLength("Game");
2052                 uiDefPulldownBut(block, info_gamemenu, NULL, "Game",    xco, -1, xmax-3, 22, "");
2053                 xco+= xmax;
2054
2055                 xmax= GetButStringLength("Render");
2056                 uiDefPulldownBut(block, info_rendermenu, NULL, "Render",        xco, -1, xmax-3, 22, "");
2057                 xco+= xmax;
2058
2059                 xmax= GetButStringLength("Help");
2060                 uiDefPulldownBut(block, info_helpmenu, NULL, "Help",    xco, -1, xmax-3, 22, "");
2061                 xco+= xmax;
2062
2063         }
2064
2065         /* pack icon indicates a packed file */
2066         
2067         if (G.fileflags & G_AUTOPACK) {
2068                 uiBlockSetEmboss(block, UI_EMBOSSN);
2069                 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.");
2070                 xco += XIC;
2071         }
2072
2073         if (curarea->full == 0) {
2074                 curarea->butspacetype= SPACE_INFO;
2075                 uiBlockSetEmboss(block, UI_EMBOSS);
2076                 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.");
2077                 
2078                 /* STD SCREEN BUTTONS */
2079                 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);
2080                 
2081                 xco +=8;
2082         
2083                 /* STD SCENE BUTTONS */
2084                 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);
2085         }
2086         else xco= 430;
2087         
2088 BIF_SetScale(block->aspect);
2089         info_text(xco+24, 6);
2090         
2091         uiBlockSetEmboss(block, UI_EMBOSSN);
2092         uiDefIconBut(block, BUT, B_SHOWSPLASH, ICON_BLENDER, xco+2, 0,XIC,YIC, 0, 0, 0, 0, 0, "Click to display Splash Screen");
2093
2094         /* always do as last */
2095         curarea->headbutlen= xco+2*XIC;
2096
2097 #if 0
2098 // #ifdef _WIN32        // FULLSCREEN
2099         if(U.uiflag & USER_FLIPFULLSCREEN) {
2100                 uiDefIconBut(block, BUT, B_FLIPFULLSCREEN, ICON_WINDOW_WINDOW,
2101                                 (short)(curarea->winx-XIC-5), 0,XIC,YIC,
2102                                 0, 0, 0, 0, 0, "Toggles Blender to fullscreen mode");/* dir             */
2103         } else {
2104                 uiDefIconBut(block, BUT, B_FLIPFULLSCREEN, ICON_WINDOW_FULLSCREEN,
2105                                 (short)(curarea->winx-XIC-5), 0,XIC,YIC,
2106                                 0, 0, 0, 0, 0, "Toggles Blender to fullscreen mode");/* dir             */
2107         }
2108 #endif
2109         
2110         uiDrawBlock(block);
2111 }