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