f82ecc8f085fc200bb6160e1a5f62731b2c5315e
[blender.git] / source / blender / src / headerbuttons.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <string.h>
34 #include <math.h>
35
36 #include <sys/types.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #ifdef WIN32
43 #include "BLI_winstuff.h"
44 #endif
45
46 #include "MEM_guardedalloc.h"
47
48 #include "BMF_Api.h"
49
50 #include "BLI_blenlib.h"
51 #include "BLI_arithb.h"
52 #include "BLI_editVert.h"
53 #include "BLI_storage_types.h"
54
55 #include "IMB_imbuf_types.h"
56 #include "IMB_imbuf.h"
57
58 #include "DNA_ID.h"
59 #include "DNA_action_types.h"
60 #include "DNA_armature_types.h"
61 #include "DNA_camera_types.h"
62 #include "DNA_curve_types.h"
63 #include "DNA_group_types.h"
64 #include "DNA_image_types.h"
65 #include "DNA_ipo_types.h"
66 #include "DNA_key_types.h"
67 #include "DNA_lamp_types.h"
68 #include "DNA_lattice_types.h"
69 #include "DNA_material_types.h"
70 #include "DNA_mesh_types.h"
71 #include "DNA_meta_types.h"
72 #include "DNA_object_types.h"
73 #include "DNA_oops_types.h"
74 #include "DNA_packedFile_types.h"
75 #include "DNA_scene_types.h"
76 #include "DNA_screen_types.h"
77 #include "DNA_sequence_types.h"
78 #include "DNA_sound_types.h"
79 #include "DNA_space_types.h"
80 #include "DNA_texture_types.h"
81 #include "DNA_text_types.h"
82 #include "DNA_userdef_types.h"
83 #include "DNA_view2d_types.h"
84 #include "DNA_view3d_types.h"
85 #include "DNA_world_types.h"
86 #include "DNA_constraint_types.h"
87
88 #include "BKE_utildefines.h"
89
90 #include "BKE_constraint.h"
91 #include "BKE_action.h"
92 #include "BKE_armature.h"
93 #include "BKE_blender.h"
94 #include "BKE_curve.h"
95 #include "BKE_displist.h"
96 #include "BKE_exotic.h"
97 #include "BKE_global.h"
98 #include "BKE_image.h"
99 #include "BKE_ika.h"
100 #include "BKE_ipo.h"
101 #include "BKE_key.h"
102 #include "BKE_lattice.h"
103 #include "BKE_library.h"
104 #include "BKE_main.h"
105 #include "BKE_material.h"
106 #include "BKE_mball.h"
107 #include "BKE_mesh.h"
108 #include "BKE_object.h"
109 #include "BKE_packedFile.h"
110 #include "BKE_sca.h"
111 #include "BKE_scene.h"
112 #include "BKE_texture.h"
113 #include "BKE_text.h"
114 #include "BKE_world.h"
115
116 #include "BLO_readfile.h"
117 #include "BLO_writefile.h"
118
119 #include "BIF_drawimage.h"
120 #include "BIF_drawoops.h"
121 #include "BIF_drawscene.h"
122 #include "BIF_drawtext.h"
123 #include "BIF_editarmature.h"
124 #include "BIF_editfont.h"
125 #include "BIF_editlattice.h"
126 #include "BIF_editconstraint.h"
127 #include "BIF_editmesh.h"
128 #include "BIF_editmesh.h"
129 #include "BIF_editsima.h"
130 #include "BIF_editsound.h"
131 #include "BIF_editsound.h"
132 #include "BIF_gl.h"
133 #include "BIF_imasel.h"
134 #include "BIF_interface.h"
135 #include "BIF_mainqueue.h"
136 #include "BIF_mywindow.h"
137 #include "BIF_poseobject.h"
138 #include "BIF_renderwin.h"
139 #include "BIF_resources.h"
140 #include "BIF_screen.h"
141 #include "BIF_space.h"
142 #include "BIF_toets.h"
143 #include "BIF_toets.h"
144 #include "BIF_toolbox.h"
145 #include "BIF_usiblender.h"
146 #include "BIF_previewrender.h"
147 #include "BIF_writeimage.h"
148
149 #include "BSE_edit.h"
150 #include "BSE_filesel.h"
151 #include "BSE_headerbuttons.h"
152 #include "BSE_view.h"
153 #include "BSE_sequence.h"
154 #include "BSE_editaction.h"
155 #include "BSE_editaction_types.h"
156 #include "BSE_editipo.h"
157 #include "BSE_drawipo.h"
158
159 #include "BDR_drawmesh.h"
160 #include "BDR_vpaint.h"
161 #include "BDR_editface.h"
162 #include "BDR_editobject.h"
163 #include "BDR_editcurve.h"
164 #include "BDR_editmball.h"
165
166 #include "BPY_extern.h" // Blender Python library
167
168 #include "interface.h"
169 #include "mydevice.h"
170 #include "blendef.h"
171 #include "render.h"
172 #include "ipo.h"
173 #include "nla.h"        /* __NLA : To be removed later */
174
175 #include "TPT_DependKludge.h"
176
177 /* local (?) functions */
178 void do_file_buttons(short event);
179 void do_text_buttons(unsigned short event);
180 void load_space_sound(char *str);
181 void load_sound_buttons(char *str);
182 void load_space_image(char *str);
183 void image_replace(Image *old, Image *new);
184 void replace_space_image(char *str);
185 void do_image_buttons(unsigned short event);
186 void do_imasel_buttons(short event);
187 static void check_packAll(void);
188 static void unique_bone_name(Bone *bone, bArmature *arm);
189 static void validate_bonebutton(void *data1, void *data2);
190 static int bonename_exists(Bone *orig, char *name, ListBase *list);
191
192 static  void test_idbutton_cb(void *namev, void *arg2_unused)
193 {
194         char *name= namev;
195         test_idbutton(name+2);
196 }
197
198 #define SPACEICONMAX    13 /* See release/datafiles/blenderbuttons */
199
200 #include "BIF_poseobject.h"
201
202 #include "SYS_System.h"
203
204 static int std_libbuttons(uiBlock *block, 
205                                                   int xco, int pin, short *pinpoin, 
206                                                   int browse, ID *id, ID *parid, 
207                                                   short *menupoin, int users, 
208                                                   int lib, int del, int autobut);
209
210
211 extern char versionstr[]; /* from blender.c */
212 /*  extern                void add_text_fs(char *file);  *//* from text.c, BIF_text.h*/
213
214  /* LET OP:  alle headerbuttons voor zelfde window steeds zelfde naam
215   *                     event B_REDR is standaard redraw
216   *
217   */
218
219
220 /*
221  * The next define turns the newest menu structure on.
222  * There are some loose ends here at the moment so leave this undefined for now.
223  */
224 /* #define EXPERIMENTAL_MENUS */
225
226
227 #define XIC 20
228 #define YIC 20
229
230 static int viewmovetemp=0;
231
232 /*  extern void info_buttons(); in BSE_headerbuttons.c */
233
234 extern char videosc_dir[];      /* exotic.c */
235
236 /* *********************************************************************** */
237
238 void write_videoscape_fs()
239 {
240         if(G.obedit) {
241                 error("Can't save Videoscape. Press TAB to leave EditMode");
242         }
243         else {
244                 if(videosc_dir[0]==0) strcpy(videosc_dir, G.sce);
245                 activate_fileselect(FILE_SPECIAL, "SAVE VIDEOSCAPE", videosc_dir, write_videoscape);
246         }
247 }
248
249 void write_vrml_fs()
250 {
251         if(G.obedit) {
252                 error("Can't save VRML. Press TAB to leave EditMode");
253         }
254         else {
255                 if(videosc_dir[0]==0) strcpy(videosc_dir, G.sce);
256         
257                 activate_fileselect(FILE_SPECIAL, "SAVE VRML1", videosc_dir, write_vrml);
258         }
259         
260 }
261
262 void write_dxf_fs()
263 {
264         if(G.obedit) {
265                 error("Can't save DXF. Press TAB to leave EditMode");
266         }
267         else {
268
269                 if(videosc_dir[0]==0) strcpy(videosc_dir, G.sce);
270
271                 activate_fileselect(FILE_SPECIAL, "SAVE DXF", videosc_dir, write_dxf);  
272         }
273 }
274
275 /* ********************** GLOBAL ****************************** */
276
277 static int std_libbuttons(uiBlock *block, int xco, int pin, short *pinpoin, int browse, ID *id, ID *parid, short *menupoin, int users, int lib, int del, int autobut)
278 {
279         ListBase *lb;
280         Object *ob;
281         Ipo *ipo;
282         uiBut *but;
283         int len, idwasnul=0, idtype, oldcol;
284         char *str=NULL, str1[10];
285         
286         oldcol= uiBlockGetCol(block);
287
288         if(id && pin) {
289                 uiDefIconButS(block, ICONTOG, pin, ICON_PIN_DEHLT,      (short)xco,0,XIC,YIC, pinpoin, 0, 0, 0, 0, "Pin this data block; no update according Object selection");
290                 xco+= XIC;
291         }
292         if(browse) {
293                 if(id==0) {
294                         idwasnul= 1;
295                         /* alleen de browse button */
296                         ob= OBACT;
297                         if(curarea->spacetype==SPACE_IMAGE) {
298                                 id= G.main->image.first;
299                         }
300                         else if(curarea->spacetype==SPACE_SOUND) {
301                                 id= G.main->sound.first;
302                         }
303                         else if(curarea->spacetype==SPACE_ACTION) {
304                                 id= G.main->action.first;
305                         }
306                         else if(curarea->spacetype==SPACE_NLA) {
307                                 id=NULL;
308                         }
309                         else if(curarea->spacetype==SPACE_IPO) {
310                                 id= G.main->ipo.first;
311                                 /* testen op ipotype */
312                                 while(id) {
313                                         ipo= (Ipo *)id;
314                                         if(G.sipo->blocktype==ipo->blocktype) break;
315                                         id= id->next;
316                                 }
317                         }
318                         else if(curarea->spacetype==SPACE_BUTS) {
319                                 if(browse==B_WORLDBROWSE) {
320                                         id= G.main->world.first;
321                                 }
322                                 else if(ob && ob->type && (ob->type<OB_LAMP)) {
323                                         if(G.buts->mainb==BUTS_MAT) id= G.main->mat.first;
324                                         else if(G.buts->mainb==BUTS_TEX) id= G.main->tex.first;
325                                 }
326                         }
327                         else if(curarea->spacetype==SPACE_TEXT) {
328                                 id= G.main->text.first;
329                         }
330                 }
331                 if(id) {
332                         char *extrastr= NULL;
333                         
334                         idtype= GS(id->name);
335                         lb= wich_libbase(G.main, GS(id->name));
336                         
337                         if(idwasnul) id= NULL;
338                         else if(id->us>1) uiBlockSetCol(block, BUTDBLUE);
339
340                         if (pin && *pinpoin) {
341                                 uiBlockSetCol(block, BUTDPINK);
342                         }
343                         
344                         if ELEM7( idtype, ID_SCE, ID_SCR, ID_MA, ID_TE, ID_WO, ID_IP, ID_AC) extrastr= "ADD NEW %x 32767";
345                         else if (idtype==ID_TXT) extrastr= "OPEN NEW %x 32766 |ADD NEW %x 32767";
346                         else if (idtype==ID_SO) extrastr= "OPEN NEW %x 32766";
347                         
348                         uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
349                         if( idtype==ID_SCE || idtype==ID_SCR ) uiClearButLock();
350                         
351                         if(curarea->spacetype==SPACE_BUTS)
352                                 uiSetButLock(idtype!=ID_SCR && G.obedit!=0 && G.buts->mainb==BUTS_EDIT, NULL);
353                         
354                         if(parid) uiSetButLock(parid->lib!=0, "Can't edit library data");
355
356                         if (lb) {
357                                 if( idtype==ID_IP)
358                                         IPOnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin, G.sipo->blocktype);
359                                 else
360                                         IDnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin);
361                         }
362                         
363                         uiDefButS(block, MENU, browse, str, (short)xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock or Add NEW");
364                         
365                         uiClearButLock();
366                 
367                         MEM_freeN(str);
368                         xco+= XIC;
369                 }
370                 else if(curarea->spacetype==SPACE_BUTS) {
371                         if ELEM3(G.buts->mainb, BUTS_MAT, BUTS_TEX, BUTS_WORLD) {
372                                 uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
373                                 if(parid) uiSetButLock(parid->lib!=0, "Can't edit library data");
374                                 uiDefButS(block, MENU, browse, "ADD NEW %x 32767",(short) xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock");
375                                 uiClearButLock();
376                         } else if (G.buts->mainb == BUTS_SOUND) {
377                                 uiDefButS(block, MENU, browse, "OPEN NEW %x 32766",(short) xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock");
378                         }
379                 }
380                 else if(curarea->spacetype==SPACE_TEXT) {
381                         uiDefButS(block, MENU, browse, "OPEN NEW %x 32766 | ADD NEW %x 32767", (short)xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock");
382                 }
383                 else if(curarea->spacetype==SPACE_SOUND) {
384                         uiDefButS(block, MENU, browse, "OPEN NEW %x 32766",(short)xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock");
385                 }
386                 else if(curarea->spacetype==SPACE_NLA) {
387                 }
388                 else if(curarea->spacetype==SPACE_ACTION) {
389                         uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
390                         if(parid) uiSetButLock(parid->lib!=0, "Can't edit library data");
391
392                         uiDefButS(block, MENU, browse, "ADD NEW %x 32767", xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock");
393                         uiClearButLock();
394                 }
395                 else if(curarea->spacetype==SPACE_IPO) {
396                         uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
397                         if(parid) uiSetButLock(parid->lib!=0, "Can't edit library data");
398
399                         uiDefButS(block, MENU, browse, "ADD NEW %x 32767", (short)xco,0,XIC,YIC, menupoin, 0, 0, 0, 0, "Browse Datablock");
400                         uiClearButLock();
401                 }
402         }
403
404
405         uiBlockSetCol(block, oldcol);
406
407         if(id) {
408         
409                 /* name */
410                 if(id->us>1) uiBlockSetCol(block, BUTDBLUE);
411                 /* Pinned data ? */
412                 if (pin && *pinpoin) {
413                         uiBlockSetCol(block, BUTDPINK);
414                 }
415                 /* Redalert overrides pin color */
416                 if(id->us<=0) uiBlockSetCol(block, REDALERT);
417
418                 uiSetButLock(id->lib!=0, "Can't edit library data");
419                 
420                 str1[0]= id->name[0];
421                 str1[1]= id->name[1];
422                 str1[2]= ':';
423                 str1[3]= 0;
424                 if(strcmp(str1, "SC:")==0) strcpy(str1, "SCE:");
425                 else if(strcmp(str1, "SR:")==0) strcpy(str1, "SCR:");
426                 
427                 if( GS(id->name)==ID_IP) len= 110;
428                 else len= 120;
429                 
430                 but= uiDefBut(block, TEX, B_IDNAME, str1,(short)xco, 0, (short)len, YIC, id->name+2, 0.0, 19.0, 0, 0, "Datablock name");
431                 uiButSetFunc(but, test_idbutton_cb, id->name, NULL);
432
433                 uiClearButLock();
434
435                 xco+= len;
436                 
437                 if(id->lib) {
438                         
439                         if(parid && parid->lib) uiDefIconBut(block, BUT, 0, ICON_DATALIB,(short)xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Indirect Library Datablock");
440                         else uiDefIconBut(block, BUT, lib, ICON_PARLIB, (short)xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Library DataBlock, press to make local");
441                         
442                         xco+= XIC;
443                 }
444                 
445                 
446                 if(users && id->us>1) {
447                         uiSetButLock (pin && *pinpoin, "Can't make pinned data single-user");
448                         
449                         sprintf(str1, "%d", id->us);
450                         if(id->us<100) {
451                                 
452                                 uiDefBut(block, BUT, users, str1,       (short)xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Number of users,  press to make single-user");
453                                 xco+= XIC;
454                         }
455                         else {
456                                 uiDefBut(block, BUT, users, str1,       (short)xco, 0, XIC+10, YIC, 0, 0, 0, 0, 0, "Number of users,  press to make single-user");
457                                 xco+= XIC+10;
458                         }
459                         
460                         uiClearButLock();
461                         
462                 }
463                 
464                 if(del) {
465
466                         uiSetButLock (pin && *pinpoin, "Can't unlink pinned data");
467                         if(parid && parid->lib);
468                         else {
469                                 uiDefIconBut(block, BUT, del, ICON_X,   (short)xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Delete link to this Datablock");
470                                 xco+= XIC;
471                         }
472
473                         uiClearButLock();
474                 }
475
476                 if(autobut) {
477                         if(parid && parid->lib);
478                         else {
479                                 uiDefIconBut(block, BUT, autobut, ICON_AUTO,(short)xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Automatic name");
480                                 xco+= XIC;
481                         }
482                         
483                         
484                 }
485         }
486         else xco+=XIC;
487         
488         uiBlockSetCol(block, oldcol);
489
490         return xco;
491 }
492
493 void update_for_newframe(void)
494 {
495         allqueue(REDRAWVIEW3D, 0);
496         allqueue(REDRAWACTION,0);
497         allqueue(REDRAWNLA,0);
498         allqueue(REDRAWIPO, 0);
499         allqueue(REDRAWINFO, 1);
500         allqueue(REDRAWSEQ, 1);
501         allqueue(REDRAWSOUND, 1);
502         allqueue(REDRAWBUTSHEAD, 1);
503         allqueue(REDRAWBUTSMAT, 1);
504         allqueue(REDRAWBUTSLAMP, 1);
505
506         /* layers/materials, object ipos are calculted in where_is_object (too) */
507         do_all_ipos();
508         BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
509         do_all_keys();
510         do_all_actions();
511         do_all_ikas();
512
513         test_all_displists();
514 }
515
516 static void show_splash(void)
517 {
518         extern char datatoc_splash_jpg[];
519         extern int datatoc_splash_jpg_size;
520         char *string = NULL;
521
522 #ifdef NAN_BUILDINFO
523         char buffer[1024];
524         extern char * build_date;
525         extern char * build_time;
526         extern char * build_platform;
527         extern char * build_type;
528
529         string = &buffer[0];
530         sprintf(string,"Built on %s %s     Version %s %s", build_date, build_time, build_platform, build_type);
531 #endif
532
533         splash((void *)datatoc_splash_jpg, datatoc_splash_jpg_size, string);
534 }
535
536 void do_global_buttons(unsigned short event)
537 {
538         ListBase *lb;
539         Object *ob;
540         Material *ma;
541         MTex *mtex;
542         Ipo *ipo;
543         Lamp *la;
544         World *wrld;
545         Sequence *seq;
546         bAction *act;
547         ID *id, *idtest, *from;
548         int nr= 1;
549         
550         ob= OBACT;
551         
552         id= 0;  /* id op nul voor texbrowse */
553         
554         switch(event) {
555         
556         case B_NEWFRAME:
557                 scrarea_queue_winredraw(curarea);
558                 scrarea_queue_headredraw(curarea);
559
560                 update_for_newframe();
561                 break;          
562         case B_REDR:
563                 scrarea_queue_winredraw(curarea);
564                 scrarea_queue_headredraw(curarea);
565                 break;
566         case B_EDITBROWSE:
567                 if(ob==0) return;
568                 if(ob->id.lib) return;
569                 id= ob->data;
570                 if(id==0) return;
571
572                 if(G.buts->menunr== -2) {
573                         activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_EDITBROWSE, &G.buts->menunr, do_global_buttons);
574                         return;
575                 }
576                 if(G.buts->menunr < 0) return;
577                 
578                 lb= wich_libbase(G.main, GS(id->name));
579                 idtest= lb->first;
580                 while(idtest) {
581                         if(nr==G.buts->menunr) {
582                                 if(idtest!=id) {
583                                         id->us--;
584                                         id_us_plus(idtest);
585                                         
586                                         ob->data= idtest;
587                                         
588                                         test_object_materials(idtest);
589                                         
590                                         if( GS(idtest->name)==ID_CU ) {
591                                                 test_curve_type(ob);
592                                                 allqueue(REDRAWBUTSEDIT, 0);
593                                                 makeDispList(ob);
594                                         }
595                                         else if( ob->type==OB_MESH ) {
596                                                 makeDispList(ob);
597                                         }
598                                         
599                                         allqueue(REDRAWBUTSEDIT, 0);
600                                         allqueue(REDRAWVIEW3D, 0);
601                                         allqueue(REDRAWACTION,0);
602                                         allqueue(REDRAWIPO, 0);
603                                         allqueue(REDRAWNLA,0);
604                                 }
605                                 break;
606                         }
607                         nr++;
608                         idtest= idtest->next;
609                 }
610
611                 break;
612         case B_MESHBROWSE:
613                 if(ob==0) return;
614                 if(ob->id.lib) return;
615                 
616                 id= ob->data;
617                 if(id==0) id= G.main->mesh.first;
618                 if(id==0) return;
619                 
620                 if(G.buts->menunr== -2) {
621                         activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_MESHBROWSE, &G.buts->menunr, do_global_buttons);
622                         return;
623                 }
624                 if(G.buts->menunr < 0) return;
625                 
626
627                 idtest= G.main->mesh.first;
628                 while(idtest) {
629                         if(nr==G.buts->menunr) {
630                                         
631                                 set_mesh(ob, (Mesh *)idtest);
632                                 
633                                 allqueue(REDRAWBUTSEDIT, 0);
634                                 allqueue(REDRAWVIEW3D, 0);
635                                 allqueue(REDRAWACTION,0);
636                                 allqueue(REDRAWIPO, 0);
637
638                                 break;
639                         }
640                         nr++;
641                         idtest= idtest->next;
642                 }
643
644                 break;
645         case B_MATBROWSE:
646                 if(G.buts->menunr== -2) {
647                         activate_databrowse((ID *)G.buts->lockpoin, ID_MA, 0, B_MATBROWSE, &G.buts->menunr, do_global_buttons);
648                         return;
649                 }
650                 
651                 if(G.buts->menunr < 0) return;
652                 
653                 if(G.buts->pin) {
654                         
655                 }
656                 else {
657                         
658                         ma= give_current_material(ob, ob->actcol);
659                         nr= 1;
660                         
661                         id= (ID *)ma;
662                         
663                         idtest= G.main->mat.first;
664                         while(idtest) {
665                                 if(nr==G.buts->menunr) {
666                                         break;
667                                 }
668                                 nr++;
669                                 idtest= idtest->next;
670                         }
671                         if(idtest==0) { /* new mat */
672                                 if(id)  idtest= (ID *)copy_material((Material *)id);
673                                 else {
674                                         idtest= (ID *)add_material("Material");
675                                 }
676                                 idtest->us--;
677                         }
678                         if(idtest!=id) {
679                                 assign_material(ob, (Material *)idtest, ob->actcol);
680                                 
681                                 allqueue(REDRAWBUTSHEAD, 0);
682                                 allqueue(REDRAWBUTSMAT, 0);
683                                 allqueue(REDRAWIPO, 0);
684                                 BIF_preview_changed(G.buts);
685                         }
686                         
687                 }
688                 break;
689         case B_MATDELETE:
690                 if(G.buts->pin) {
691                         
692                 }
693                 else {
694                         ma= give_current_material(ob, ob->actcol);
695                         if(ma) {
696                                 assign_material(ob, 0, ob->actcol);
697                                 allqueue(REDRAWBUTSHEAD, 0);
698                                 allqueue(REDRAWBUTSMAT, 0);
699                                 allqueue(REDRAWIPO, 0);
700                                 BIF_preview_changed(G.buts);
701                         }
702                 }
703                 break;
704         case B_TEXDELETE:
705                 if(G.buts->pin) {
706                         
707                 }
708                 else {
709                         if(G.buts->texfrom==0) {        /* from mat */
710                                 ma= give_current_material(ob, ob->actcol);
711                                 if(ma) {
712                                         mtex= ma->mtex[ ma->texact ];
713                                         if(mtex) {
714                                                 if(mtex->tex) mtex->tex->id.us--;
715                                                 MEM_freeN(mtex);
716                                                 ma->mtex[ ma->texact ]= 0;
717                                                 allqueue(REDRAWBUTSTEX, 0);
718                                                 allqueue(REDRAWIPO, 0);
719                                                 BIF_preview_changed(G.buts);
720                                         }
721                                 }
722                         }
723                         else if(G.buts->texfrom==1) {   /* from world */
724                                 wrld= G.scene->world;
725                                 if(wrld) {
726                                         mtex= wrld->mtex[ wrld->texact ];
727                                         if(mtex) {
728                                                 if(mtex->tex) mtex->tex->id.us--;
729                                                 MEM_freeN(mtex);
730                                                 wrld->mtex[ wrld->texact ]= 0;
731                                                 allqueue(REDRAWBUTSTEX, 0);
732                                                 allqueue(REDRAWIPO, 0);
733                                                 BIF_preview_changed(G.buts);
734                                         }
735                                 }
736                         }
737                         else {  /* from lamp */
738                                 la= ob->data;
739                                 if(la && ob->type==OB_LAMP) {   /* voor zekerheid */
740                                         mtex= la->mtex[ la->texact ];
741                                         if(mtex) {
742                                                 if(mtex->tex) mtex->tex->id.us--;
743                                                 MEM_freeN(mtex);
744                                                 la->mtex[ la->texact ]= 0;
745                                                 allqueue(REDRAWBUTSTEX, 0);
746                                                 allqueue(REDRAWIPO, 0);
747                                                 BIF_preview_changed(G.buts);
748                                         }
749                                 }
750                         }
751                 }
752                 break;
753         case B_EXTEXBROWSE:     
754         case B_TEXBROWSE:
755
756                 if(G.buts->texnr== -2) {
757                         
758                         id= G.buts->lockpoin;
759                         if(event==B_EXTEXBROWSE) {
760                                 id= 0;
761                                 ma= give_current_material(ob, ob->actcol);
762                                 if(ma) {
763                                         mtex= ma->mtex[ ma->texact ];
764                                         if(mtex) id= (ID *)mtex->tex;
765                                 }
766                         }
767                         
768                         activate_databrowse(id, ID_TE, 0, B_TEXBROWSE, &G.buts->texnr, do_global_buttons);
769                         return;
770                 }
771                 if(G.buts->texnr < 0) break;
772                 
773                 if(G.buts->pin) {
774                         
775                 }
776                 else {
777                         id= 0;
778                         
779                         ma= give_current_material(ob, ob->actcol);
780                         if(ma) {
781                                 mtex= ma->mtex[ ma->texact ];
782                                 if(mtex) id= (ID *)mtex->tex;
783                         }
784
785                         idtest= G.main->tex.first;
786                         while(idtest) {
787                                 if(nr==G.buts->texnr) {
788                                         break;
789                                 }
790                                 nr++;
791                                 idtest= idtest->next;
792                         }
793                         if(idtest==0) { /* new tex */
794                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
795                                 else idtest= (ID *)add_texture("Tex");
796                                 idtest->us--;
797                         }
798                         if(idtest!=id && ma) {
799                                 
800                                 if( ma->mtex[ma->texact]==0) ma->mtex[ma->texact]= add_mtex();
801                                 
802                                 ma->mtex[ ma->texact ]->tex= (Tex *)idtest;
803                                 id_us_plus(idtest);
804                                 if(id) id->us--;
805                                 
806                                 allqueue(REDRAWBUTSHEAD, 0);
807                                 allqueue(REDRAWBUTSTEX, 0);
808                                 allqueue(REDRAWBUTSMAT, 0);
809                                 allqueue(REDRAWIPO, 0);
810                                 BIF_preview_changed(G.buts);
811                         }
812                 }
813                 break;
814         case B_ACTIONDELETE:
815                 act=ob->action;
816                 
817                 if (act)
818                         act->id.us--;
819                 ob->action=NULL;
820                 allqueue(REDRAWACTION, 0);
821                 allqueue(REDRAWNLA, 0);
822                 allqueue(REDRAWIPO, 0);
823                 break;
824         case B_ACTIONBROWSE:
825                 if (!ob)
826                         break;
827                 act=ob->action;
828                 id= (ID *)act;
829
830                 if (G.saction->actnr== -2){
831                                 activate_databrowse((ID *)G.saction->action, ID_AC,  0, B_ACTIONBROWSE, &G.saction->actnr, do_global_buttons);
832                         return;
833                 }
834
835                 if(G.saction->actnr < 0) break;
836
837                 /*      See if we have selected a valid action */
838                 for (idtest= G.main->action.first; idtest; idtest= idtest->next) {
839                                 if(nr==G.saction->actnr) {
840                                         break;
841                                 }
842                                 nr++;
843                         
844                 }
845
846                 if(G.saction->pin) {
847                         G.saction->action= (bAction *)idtest;
848                         allqueue(REDRAWACTION, 0);
849                 }
850                 else {
851
852                         /* Store current action */
853                         if (!idtest){
854                                 if (act)
855                                         idtest= (ID *)copy_action(act);
856                                 else 
857                                         idtest=(ID *)add_empty_action();
858                                 idtest->us--;
859                         }
860                         
861                         
862                         if(idtest!=id && ob) {
863                                 act= (bAction *)idtest;
864                                 
865                                 ob->action= act;
866                                 ob->activecon=NULL;
867                                 id_us_plus(idtest);
868                                 
869                                 if(id) id->us--;
870                                 
871                                 // Update everything
872                                 do_global_buttons (B_NEWFRAME);
873                                 allqueue(REDRAWVIEW3D, 0);
874                                 allqueue(REDRAWNLA, 0);
875                                 allqueue(REDRAWACTION, 0);
876                                 allqueue(REDRAWHEADERS, 0);     
877                         }
878                 }
879                 
880                 break;
881         case B_IPOBROWSE:
882
883                 ipo= get_ipo_to_edit(&from);
884                 id= (ID *)ipo;
885                 if(from==0) return;
886
887                 if(G.sipo->menunr== -2) {
888                         activate_databrowse((ID *)G.sipo->ipo, ID_IP, GS(from->name), B_IPOBROWSE, &G.sipo->menunr, do_global_buttons);
889                         return;
890                 }
891
892                 if(G.sipo->menunr < 0) break;
893
894                 idtest= G.main->ipo.first;
895                 while(idtest) {
896                         if( ((Ipo *)idtest)->blocktype == G.sipo->blocktype) {
897                                 if(nr==G.sipo->menunr) {
898                                         break;
899                                 }
900                                 nr++;
901                         }
902                         idtest= idtest->next;
903                 }
904
905                 if(G.sipo->pin) {
906                         if(idtest) {
907                                 G.sipo->ipo= (Ipo *)idtest;
908                                 allspace(REMAKEIPO, 0);         // in fact it should only do this one, but there is no function for it
909                         }
910                 }
911                 else {
912                         // assign the ipo to ...
913
914                         if(idtest==0) {
915                                 if(ipo) idtest= (ID *)copy_ipo(ipo);
916                                 else {
917                                         nr= GS(from->name);
918                                         if(nr==ID_OB){
919                                                 if (G.sipo->blocktype==IPO_CO)
920                                                         idtest= (ID *)add_ipo("CoIpo", IPO_CO); /* BLEARGH! */
921                                                 else
922                                                         idtest= (ID *)add_ipo("ObIpo", nr);
923                                         }
924                                         else if(nr==ID_MA) idtest= (ID *)add_ipo("MatIpo", nr);
925                                         else if(nr==ID_SEQ) idtest= (ID *)add_ipo("MatSeq", nr);
926                                         else if(nr==ID_CU) idtest= (ID *)add_ipo("CuIpo", nr);
927                                         else if(nr==ID_KE) idtest= (ID *)add_ipo("KeyIpo", nr);
928                                         else if(nr==ID_WO) idtest= (ID *)add_ipo("WoIpo", nr);
929                                         else if(nr==ID_LA) idtest= (ID *)add_ipo("LaIpo", nr);
930                                         else if(nr==ID_CA) idtest= (ID *)add_ipo("CaIpo", nr);
931                                         else if(nr==ID_SO) idtest= (ID *)add_ipo("SndIpo", nr);
932                                         else if(nr==ID_AC) idtest= (ID *)add_ipo("ActIpo", nr);
933                                         else error("Warn bugs@blender.nl!");
934                                 }
935                                 idtest->us--;
936                         }
937                         if(idtest!=id && from) {
938                                 ipo= (Ipo *)idtest;
939                 
940                                 if (ipo->blocktype==IPO_CO){
941                                         ((Object*)from)->activecon->ipo = ipo;
942                                         id_us_plus(idtest);
943                                         allqueue(REDRAWVIEW3D, 0);
944                                         allqueue(REDRAWACTION, 0);
945                                         allqueue(REDRAWNLA, 0);
946                                 }
947                                 else if(ipo->blocktype==ID_OB) {
948                                         ( (Object *)from)->ipo= ipo;
949                                         id_us_plus(idtest);
950                                         allqueue(REDRAWVIEW3D, 0);
951                                 }
952                                 else if(ipo->blocktype==ID_AC) {
953                                         bActionChannel *chan;
954                                         chan = get_hilighted_action_channel ((bAction*)from);
955                                         if (!chan){
956                                                 error ("Create an action channel first");
957                                                 return;
958                                         }
959                                         chan->ipo=ipo;
960                                         id_us_plus(idtest);
961                                         allqueue(REDRAWNLA, 0);
962                                         allqueue(REDRAWACTION, 0);
963                                 }
964                                 else if(ipo->blocktype==ID_MA) {
965                                         ( (Material *)from)->ipo= ipo;
966                                         id_us_plus(idtest);
967                                         allqueue(REDRAWBUTSMAT, 0);
968                                 }
969                                 else if(ipo->blocktype==ID_SEQ) {
970                                         seq= (Sequence *)from;
971                                         if(seq->type & SEQ_EFFECT) {
972                                                 id_us_plus(idtest);
973                                                 seq->ipo= ipo;
974                                         }
975                                 }
976                                 else if(ipo->blocktype==ID_CU) {
977                                         ( (Curve *)from)->ipo= ipo;
978                                         id_us_plus(idtest);
979                                         allqueue(REDRAWVIEW3D, 0);
980                                 }
981                                 else if(ipo->blocktype==ID_KE) {
982                                         ( (Key *)from)->ipo= ipo;
983                                         
984                                         id_us_plus(idtest);
985                                         allqueue(REDRAWVIEW3D, 0);
986                                         
987                                 }
988                                 else if(ipo->blocktype==ID_WO) {
989                                         ( (World *)from)->ipo= ipo;
990                                         id_us_plus(idtest);
991                                         allqueue(REDRAWBUTSWORLD, 0);
992                                 }
993                                 else if(ipo->blocktype==ID_LA) {
994                                         ( (Lamp *)from)->ipo= ipo;
995                                         id_us_plus(idtest);
996                                         allqueue(REDRAWBUTSLAMP, 0);
997                                 }
998                                 else if(ipo->blocktype==ID_CA) {
999                                         ( (Camera *)from)->ipo= ipo;
1000                                         id_us_plus(idtest);
1001                                         allqueue(REDRAWBUTSEDIT, 0);
1002                                 }
1003                                 else if(ipo->blocktype==ID_SO) {
1004                                         ( (bSound *)from)->ipo= ipo;
1005                                         id_us_plus(idtest);
1006                                         allqueue(REDRAWBUTSEDIT, 0);
1007                                 }
1008                                 else
1009                                         printf("error in browse ipo \n");
1010                                 
1011                                 if(id) id->us--;
1012                                 
1013                                 scrarea_queue_winredraw(curarea);
1014                                 scrarea_queue_headredraw(curarea);
1015                                 allqueue(REDRAWIPO, 0);
1016                         }
1017                 }
1018                 break;
1019         case B_IPODELETE:
1020                 ipo= get_ipo_to_edit(&from);
1021                 if(from==0) return;
1022                 
1023                 ipo->id.us--;
1024                 
1025                 if(ipo->blocktype==ID_OB) ( (Object *)from)->ipo= 0;
1026                 else if(ipo->blocktype==ID_MA) ( (Material *)from)->ipo= 0;
1027                 else if(ipo->blocktype==ID_SEQ) ( (Sequence *)from)->ipo= 0;
1028                 else if(ipo->blocktype==ID_CU) ( (Curve *)from)->ipo= 0;
1029                 else if(ipo->blocktype==ID_KE) ( (Key *)from)->ipo= 0;
1030                 else if(ipo->blocktype==ID_WO) ( (World *)from)->ipo= 0;
1031                 else if(ipo->blocktype==ID_LA) ( (Lamp *)from)->ipo= 0;
1032                 else if(ipo->blocktype==ID_WO) ( (World *)from)->ipo= 0;
1033                 else if(ipo->blocktype==ID_CA) ( (Camera *)from)->ipo= 0;
1034                 else if(ipo->blocktype==ID_SO) ( (bSound *)from)->ipo= 0;
1035                 else if(ipo->blocktype==ID_AC) get_hilighted_action_channel((bAction*)from)->ipo= 0;
1036                 else if(ipo->blocktype==IPO_CO) ((Object *)from)->activecon->ipo= 0;
1037
1038                 else error("Warn bugs@blender.nl!");
1039                 
1040                 editipo_changed(G.sipo, 1);     /* doredraw */
1041                 allqueue(REDRAWIPO, 0);
1042                 allqueue(REDRAWNLA, 0);
1043                 allqueue (REDRAWACTION, 0);
1044                 
1045                 break;
1046         case B_WORLDBROWSE:
1047
1048                 if(G.buts->menunr==-2) {
1049                         activate_databrowse((ID *)G.scene->world, ID_WO, 0, B_WORLDBROWSE, &G.buts->menunr, do_global_buttons);
1050                         break;
1051                 }
1052
1053                 if(G.buts->menunr < 0) break;
1054                 /* geen lock */
1055                         
1056                 wrld= G.scene->world;
1057                 nr= 1;
1058                 
1059                 id= (ID *)wrld;
1060                 
1061                 idtest= G.main->world.first;
1062                 while(idtest) {
1063                         if(nr==G.buts->menunr) {
1064                                 break;
1065                         }
1066                         nr++;
1067                         idtest= idtest->next;
1068                 }
1069                 if(idtest==0) { /* new world */
1070                         if(id) idtest= (ID *)copy_world((World *)id);
1071                         else idtest= (ID *)add_world("World");
1072                         idtest->us--;
1073                 }
1074                 if(idtest!=id) {
1075                         G.scene->world= (World *)idtest;
1076                         id_us_plus(idtest);
1077                         if(id) id->us--;
1078                         
1079                         allqueue(REDRAWBUTSHEAD, 0);
1080                         allqueue(REDRAWBUTSWORLD, 0);
1081                         allqueue(REDRAWIPO, 0);
1082                         BIF_preview_changed(G.buts);
1083                 }
1084                 break;
1085         case B_WORLDDELETE:
1086                 if(G.scene->world) {
1087                         G.scene->world->id.us--;
1088                         G.scene->world= 0;
1089                         allqueue(REDRAWBUTSWORLD, 0);
1090                         allqueue(REDRAWIPO, 0);
1091                 }
1092                 
1093                 break;
1094         case B_WTEXBROWSE:
1095
1096                 if(G.buts->texnr== -2) {
1097                         id= 0;
1098                         wrld= G.scene->world;
1099                         if(wrld) {
1100                                 mtex= wrld->mtex[ wrld->texact ];
1101                                 if(mtex) id= (ID *)mtex->tex;
1102                         }
1103
1104                         activate_databrowse((ID *)id, ID_TE, 0, B_WTEXBROWSE, &G.buts->texnr, do_global_buttons);
1105                         return;
1106                 }
1107                 if(G.buts->texnr < 0) break;
1108
1109                 if(G.buts->pin) {
1110                         
1111                 }
1112                 else {
1113                         id= 0;
1114                         
1115                         wrld= G.scene->world;
1116                         if(wrld) {
1117                                 mtex= wrld->mtex[ wrld->texact ];
1118                                 if(mtex) id= (ID *)mtex->tex;
1119                         }
1120
1121                         idtest= G.main->tex.first;
1122                         while(idtest) {
1123                                 if(nr==G.buts->texnr) {
1124                                         break;
1125                                 }
1126                                 nr++;
1127                                 idtest= idtest->next;
1128                         }
1129                         if(idtest==0) { /* new tex */
1130                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
1131                                 else idtest= (ID *)add_texture("Tex");
1132                                 idtest->us--;
1133                         }
1134                         if(idtest!=id && wrld) {
1135                                 
1136                                 if( wrld->mtex[wrld->texact]==0) {
1137                                         wrld->mtex[wrld->texact]= add_mtex();
1138                                         wrld->mtex[wrld->texact]->texco= TEXCO_VIEW;
1139                                 }
1140                                 wrld->mtex[ wrld->texact ]->tex= (Tex *)idtest;
1141                                 id_us_plus(idtest);
1142                                 if(id) id->us--;
1143                                 
1144                                 allqueue(REDRAWBUTSHEAD, 0);
1145                                 allqueue(REDRAWBUTSTEX, 0);
1146                                 allqueue(REDRAWBUTSWORLD, 0);
1147                                 allqueue(REDRAWIPO, 0);
1148                                 BIF_preview_changed(G.buts);
1149                         }
1150                 }
1151                 break;
1152         case B_LAMPBROWSE:
1153                 /* geen lock */
1154                 if(ob==0) return;
1155                 if(ob->type!=OB_LAMP) return;
1156
1157                 if(G.buts->menunr== -2) {
1158                         activate_databrowse((ID *)G.buts->lockpoin, ID_LA, 0, B_LAMPBROWSE, &G.buts->menunr, do_global_buttons);
1159                         return;
1160                 }
1161                 if(G.buts->menunr < 0) break;
1162                 
1163                 la= ob->data;
1164                 nr= 1;
1165                 id= (ID *)la;
1166                 
1167                 idtest= G.main->lamp.first;
1168                 while(idtest) {
1169                         if(nr==G.buts->menunr) {
1170                                 break;
1171                         }
1172                         nr++;
1173                         idtest= idtest->next;
1174                 }
1175                 if(idtest==0) { /* geen new lamp */
1176                         return;
1177                 }
1178                 if(idtest!=id) {
1179                         ob->data= (Lamp *)idtest;
1180                         id_us_plus(idtest);
1181                         if(id) id->us--;
1182                         
1183                         allqueue(REDRAWBUTSHEAD, 0);
1184                         allqueue(REDRAWBUTSLAMP, 0);
1185                         allqueue(REDRAWVIEW3D, 0);
1186                         allqueue(REDRAWIPO, 0);
1187                         BIF_preview_changed(G.buts);
1188                 }
1189                 break;
1190         
1191         case B_LTEXBROWSE:
1192
1193                 if(ob==0) return;
1194                 if(ob->type!=OB_LAMP) return;
1195
1196                 if(G.buts->texnr== -2) {
1197                         id= 0;
1198                         la= ob->data;
1199                         mtex= la->mtex[ la->texact ];
1200                         if(mtex) id= (ID *)mtex->tex;
1201
1202                         activate_databrowse(id, ID_TE, 0, B_LTEXBROWSE, &G.buts->texnr, do_global_buttons);
1203                         return;
1204                 }
1205                 if(G.buts->texnr < 0) break;
1206
1207                 if(G.buts->pin) {
1208                         
1209                 }
1210                 else {
1211                         id= 0;
1212                         
1213                         la= ob->data;
1214                         mtex= la->mtex[ la->texact ];
1215                         if(mtex) id= (ID *)mtex->tex;
1216
1217                         idtest= G.main->tex.first;
1218                         while(idtest) {
1219                                 if(nr==G.buts->texnr) {
1220                                         break;
1221                                 }
1222                                 nr++;
1223                                 idtest= idtest->next;
1224                         }
1225                         if(idtest==0) { /* new tex */
1226                                 if(id)  idtest= (ID *)copy_texture((Tex *)id);
1227                                 else idtest= (ID *)add_texture("Tex");
1228                                 idtest->us--;
1229                         }
1230                         if(idtest!=id && la) {
1231                                 
1232                                 if( la->mtex[la->texact]==0) {
1233                                         la->mtex[la->texact]= add_mtex();
1234                                         la->mtex[la->texact]->texco= TEXCO_GLOB;
1235                                 }
1236                                 la->mtex[ la->texact ]->tex= (Tex *)idtest;
1237                                 id_us_plus(idtest);
1238                                 if(id) id->us--;
1239                                 
1240                                 allqueue(REDRAWBUTSHEAD, 0);
1241                                 allqueue(REDRAWBUTSTEX, 0);
1242                                 allqueue(REDRAWBUTSLAMP, 0);
1243                                 allqueue(REDRAWIPO, 0);
1244                                 BIF_preview_changed(G.buts);
1245                         }
1246                 }
1247                 break;
1248         
1249         case B_IMAGEDELETE:
1250                 G.sima->image= 0;
1251                 image_changed(G.sima, 0);
1252                 allqueue(REDRAWIMAGE, 0);
1253                 break;
1254         
1255         case B_AUTOMATNAME:
1256                 automatname(G.buts->lockpoin);
1257                 allqueue(REDRAWBUTSHEAD, 0);
1258                 break;          
1259         case B_AUTOTEXNAME:
1260                 if(G.buts->mainb==BUTS_TEX) {
1261                         autotexname(G.buts->lockpoin);
1262                         allqueue(REDRAWBUTSHEAD, 0);
1263                         allqueue(REDRAWBUTSTEX, 0);
1264                 }
1265                 else if(G.buts->mainb==BUTS_MAT) {
1266                         ma= G.buts->lockpoin;
1267                         if(ma->mtex[ ma->texact]) autotexname(ma->mtex[ma->texact]->tex);
1268                         allqueue(REDRAWBUTSMAT, 0);
1269                 }
1270                 else if(G.buts->mainb==BUTS_WORLD) {
1271                         wrld= G.buts->lockpoin;
1272                         if(wrld->mtex[ wrld->texact]) autotexname(wrld->mtex[wrld->texact]->tex);
1273                         allqueue(REDRAWBUTSWORLD, 0);
1274                 }
1275                 else if(G.buts->mainb==BUTS_LAMP) {
1276                         la= G.buts->lockpoin;
1277                         if(la->mtex[ la->texact]) autotexname(la->mtex[la->texact]->tex);
1278                         allqueue(REDRAWBUTSLAMP, 0);
1279                 }
1280                 break;
1281
1282         case B_RESETAUTOSAVE:
1283                 reset_autosave();
1284                 break;
1285         case B_SOUNDTOGGLE:
1286                 SYS_WriteCommandLineInt(SYS_GetSystem(), "noaudio", (U.gameflags & USERDEF_DISABLE_SOUND));
1287                 break;
1288         case B_SHOWSPLASH:
1289                 show_splash();
1290                 break;
1291         case B_MIPMAPCHANGED:
1292                 set_mipmap(!(U.gameflags & USERDEF_DISABLE_SOUND));
1293                 allqueue(REDRAWVIEW3D, 0);
1294                 break;
1295         case B_NEWSPACE:
1296                 newspace(curarea, curarea->butspacetype);
1297                 break;
1298         case B_LOADTEMP:        /* is button uit space.c */
1299                 BIF_read_autosavefile();
1300                 break;
1301         case B_FULL:
1302                 if(curarea->spacetype!=SPACE_INFO) {
1303                         area_fullscreen();
1304                 }
1305                 break;  
1306
1307         case B_IDNAME:
1308                         /* changing a metaballs name, sadly enough,
1309                          * can require it to be updated because its
1310                          * basis might have changed... -zr
1311                          */
1312                 if (OBACT && OBACT->type==OB_MBALL)
1313                         makeDispList(OBACT);
1314                         
1315                 /* redraw omdat naam veranderd is: nieuwe pup */
1316                 scrarea_queue_headredraw(curarea);
1317                 allqueue(REDRAWBUTSHEAD, 0);
1318                 allqueue(REDRAWINFO, 1);
1319                 allqueue(REDRAWOOPS, 1);
1320                 /* naam scene ook in set PUPmenu */
1321                 if ELEM(curarea->spacetype, SPACE_BUTS, SPACE_INFO) allqueue(REDRAWBUTSALL, 0);
1322
1323                 allqueue(REDRAWHEADERS, 0);
1324
1325                 break;
1326         }
1327 }
1328
1329
1330 void do_global_buttons2(short event)
1331 {
1332         Base *base;
1333         Object *ob;
1334         Material *ma;
1335         MTex *mtex;
1336         Mesh *me;
1337         Curve *cu;
1338         MetaBall *mb;
1339         Ipo *ipo;
1340         Lamp *la;
1341         Lattice *lt;
1342         World *wrld;
1343         ID *idfrom;     
1344         bAction *act;
1345
1346         /* algemeen: Single User mag als from==LOCAL 
1347          *                       Make Local mag als (from==LOCAL && id==LIB)
1348          */
1349         
1350         ob= OBACT;
1351         
1352         switch(event) {
1353                 
1354         case B_LAMPALONE:
1355                 if(ob && ob->id.lib==0) {
1356                         la= ob->data;
1357                         if(la->id.us>1) {
1358                                 if(okee("Single user")) {
1359                                         ob->data= copy_lamp(la);
1360                                         la->id.us--;
1361                                 }
1362                         }
1363                 }
1364                 break;
1365         case B_LAMPLOCAL:
1366                 if(ob && ob->id.lib==0) {
1367                         la= ob->data;
1368                         if(la->id.lib) {
1369                                 if(okee("Make local")) {
1370                                         make_local_lamp(la);
1371                                 }
1372                         }
1373                 }
1374                 break;
1375         
1376         case B_ARMLOCAL:
1377                 if (ob&&ob->id.lib==0){
1378                         bArmature *arm=ob->data;
1379                         if (arm->id.lib){
1380                                 if(okee("Make local")) {
1381                                         make_local_armature(arm);
1382                                 }
1383                         }
1384                 }
1385                 break;
1386         case B_ARMALONE:
1387                 if(ob && ob->id.lib==0) {
1388                         bArmature *arm=ob->data;
1389                         if(arm->id.us>1) {
1390                                 if(okee("Single user")) {
1391                                         ob->data= copy_armature(arm);
1392                                         arm->id.us--;
1393                                 }
1394                         }
1395                 }
1396                 break;
1397         case B_ACTLOCAL:
1398                 if(ob && ob->id.lib==0) {
1399                         act= ob->action;
1400                         if(act->id.lib) {
1401                                 if(okee("Make local")) {
1402                                         make_local_action(act);
1403                                         allqueue(REDRAWACTION,0);
1404                                 }
1405                         }
1406                 }
1407                 break;
1408         case B_ACTALONE:
1409                 if (ob)
1410                         act= ob->action;
1411                 
1412                 if(ob && ob->id.lib==0) {
1413                         if(act->id.us>1) {
1414                                 if(okee("Single user")) {
1415                                         ob->action=copy_action(act);
1416                                         ob->activecon=NULL;
1417                                         act->id.us--;
1418                                         allqueue(REDRAWACTION, 0);
1419                                 }
1420                         }
1421                 }
1422                 break;
1423
1424         case B_CAMERAALONE:
1425                 if(ob && ob->id.lib==0) {
1426                         Camera *ca= ob->data;
1427                         if(ca->id.us>1) {
1428                                 if(okee("Single user")) {
1429                                         ob->data= copy_camera(ca);
1430                                         ca->id.us--;
1431                                 }
1432                         }
1433                 }
1434                 break;
1435         case B_CAMERALOCAL:
1436                 if(ob && ob->id.lib==0) {
1437                         Camera *ca= ob->data;
1438                         if(ca->id.lib) {
1439                                 if(okee("Make local")) {
1440                                         make_local_camera(ca);
1441                                 }
1442                         }
1443                 }
1444                 break;
1445         case B_WORLDALONE:
1446                 wrld= G.scene->world;
1447                 if(wrld->id.us>1) {
1448                         if(okee("Single user")) {
1449                                 G.scene->world= copy_world(wrld);
1450                                 wrld->id.us--;
1451                         }
1452                 }
1453                 break;
1454         case B_WORLDLOCAL:
1455                 wrld= G.scene->world;
1456                 if(wrld && wrld->id.lib) {
1457                         if(okee("Make local")) {
1458                                 make_local_world(wrld);
1459                         }
1460                 }
1461                 break;
1462
1463         case B_LATTALONE:
1464                 if(ob && ob->id.lib==0) {
1465                         lt= ob->data;
1466                         if(lt->id.us>1) {
1467                                 if(okee("Single user")) {
1468                                         ob->data= copy_lattice(lt);
1469                                         lt->id.us--;
1470                                 }
1471                         }
1472                 }
1473                 break;
1474         case B_LATTLOCAL:
1475                 if(ob && ob->id.lib==0) {
1476                         lt= ob->data;
1477                         if(lt->id.lib) {
1478                                 if(okee("Make local")) {
1479                                         make_local_lattice(lt);
1480                                 }
1481                         }
1482                 }
1483                 break;
1484         
1485         case B_MATALONE:
1486                 if(ob==0) return;
1487                 ma= give_current_material(ob, ob->actcol);
1488                 idfrom= material_from(ob, ob->actcol);
1489                 if(idfrom && idfrom->lib==0) {
1490                         if(ma->id.us>1) {
1491                                 if(okee("Single user")) {
1492                                         ma= copy_material(ma);
1493                                         ma->id.us= 0;
1494                                         assign_material(ob, ma, ob->actcol);
1495                                 }
1496                         }
1497                 }
1498                 break;
1499         case B_MATLOCAL:
1500                 if(ob==0) return;
1501                 idfrom= material_from(ob, ob->actcol);
1502                 if(idfrom->lib==0) {
1503                         ma= give_current_material(ob, ob->actcol);
1504                         if(ma && ma->id.lib) {
1505                                 if(okee("Make local")) {
1506                                         make_local_material(ma);
1507                                 }
1508                         }
1509                 }
1510                 break;
1511
1512         case B_MESHLOCAL:
1513                 if(ob && ob->id.lib==0) {
1514                         me= ob->data;
1515                         if(me && me->id.lib) {
1516                                 if(okee("Make local")) {
1517                                         make_local_mesh(me);
1518                                         make_local_key( me->key );
1519                                 }
1520                         }
1521                 }
1522                 break;
1523
1524         case B_MBALLALONE:
1525                 if(ob && ob->id.lib==0) {
1526                         mb= ob->data;
1527                         if(mb->id.us>1) {
1528                                 if(okee("Single user")) {
1529                                         ob->data= copy_mball(mb);
1530                                         mb->id.us--;
1531                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1532                                 }
1533                         }
1534                 }
1535                 break;
1536         case B_MBALLLOCAL:
1537                 if(ob && ob->id.lib==0) {
1538                         mb= ob->data;
1539                         if(mb->id.lib) {
1540                                 if(okee("Make local")) {
1541                                         make_local_mball(mb);
1542                                 }
1543                         }
1544                 }
1545                 break;
1546
1547         case B_CURVEALONE:
1548                 if(ob && ob->id.lib==0) {
1549                         cu= ob->data;
1550                         if(cu->id.us>1) {
1551                                 if(okee("Single user")) {
1552                                         ob->data= copy_curve(cu);
1553                                         cu->id.us--;
1554                                         makeDispList(ob);
1555                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1556                                 }
1557                         }
1558                 }
1559                 break;
1560         case B_CURVELOCAL:
1561                 if(ob && ob->id.lib==0) {
1562                         cu= ob->data;
1563                         if(cu->id.lib) {
1564                                 if(okee("Make local")) {
1565                                         make_local_curve(cu);
1566                                         make_local_key( cu->key );
1567                                         makeDispList(ob);
1568                                 }
1569                         }
1570                 }
1571                 break;
1572                 
1573         case B_TEXALONE:
1574                 if(G.buts->texfrom==0) {        /* from mat */
1575                         if(ob==0) return;
1576                         ma= give_current_material(ob, ob->actcol);
1577                         if(ma && ma->id.lib==0) {
1578                                 mtex= ma->mtex[ ma->texact ];
1579                                 if(mtex->tex && mtex->tex->id.us>1) {
1580                                         if(okee("Single user")) {
1581                                                 mtex->tex->id.us--;
1582                                                 mtex->tex= copy_texture(mtex->tex);
1583                                         }
1584                                 }
1585                         }
1586                 }
1587                 else if(G.buts->texfrom==1) {   /* from world */
1588                         wrld= G.scene->world;
1589                         if(wrld->id.lib==0) {
1590                                 mtex= wrld->mtex[ wrld->texact ];
1591                                 if(mtex->tex && mtex->tex->id.us>1) {
1592                                         if(okee("Single user")) {
1593                                                 mtex->tex->id.us--;
1594                                                 mtex->tex= copy_texture(mtex->tex);
1595                                         }
1596                                 }
1597                         }
1598                 }
1599                 else if(G.buts->texfrom==2) {   /* from lamp */
1600                         if(ob==0 || ob->type!=OB_LAMP) return;
1601                         la= ob->data;
1602                         if(la->id.lib==0) {
1603                                 mtex= la->mtex[ la->texact ];
1604                                 if(mtex->tex && mtex->tex->id.us>1) {
1605                                         if(okee("Single user")) {
1606                                                 mtex->tex->id.us--;
1607                                                 mtex->tex= copy_texture(mtex->tex);
1608                                         }
1609                                 }
1610                         }
1611                 }
1612                 break;
1613         case B_TEXLOCAL:
1614                 if(G.buts->texfrom==0) {        /* from mat */
1615                         if(ob==0) return;
1616                         ma= give_current_material(ob, ob->actcol);
1617                         if(ma && ma->id.lib==0) {
1618                                 mtex= ma->mtex[ ma->texact ];
1619                                 if(mtex->tex && mtex->tex->id.lib) {
1620                                         if(okee("Make local")) {
1621                                                 make_local_texture(mtex->tex);
1622                                         }
1623                                 }
1624                         }
1625                 }
1626                 else if(G.buts->texfrom==1) {   /* from world */
1627                         wrld= G.scene->world;
1628                         if(wrld->id.lib==0) {
1629                                 mtex= wrld->mtex[ wrld->texact ];
1630                                 if(mtex->tex && mtex->tex->id.lib) {
1631                                         if(okee("Make local")) {
1632                                                 make_local_texture(mtex->tex);
1633                                         }
1634                                 }
1635                         }
1636                 }
1637                 else if(G.buts->texfrom==2) {   /* from lamp */
1638                         if(ob==0 || ob->type!=OB_LAMP) return;
1639                         la= ob->data;
1640                         if(la->id.lib==0) {
1641                                 mtex= la->mtex[ la->texact ];
1642                                 if(mtex->tex && mtex->tex->id.lib) {
1643                                         if(okee("Make local")) {
1644                                                 make_local_texture(mtex->tex);
1645                                         }
1646                                 }
1647                         }
1648                 }
1649                 break;
1650         
1651         case B_IPOALONE:
1652                 ipo= get_ipo_to_edit(&idfrom);
1653                 
1654                 if(idfrom && idfrom->lib==0) {
1655                         if(ipo->id.us>1) {
1656                                 if(okee("Single user")) {
1657                                         if(ipo->blocktype==ID_OB) ((Object *)idfrom)->ipo= copy_ipo(ipo);
1658                                         else if(ipo->blocktype==ID_MA) ((Material *)idfrom)->ipo= copy_ipo(ipo);
1659                                         else if(ipo->blocktype==ID_SEQ) ((Sequence *)idfrom)->ipo= copy_ipo(ipo);
1660                                         else if(ipo->blocktype==ID_CU) ((Curve *)idfrom)->ipo= copy_ipo(ipo);
1661                                         else if(ipo->blocktype==ID_KE) ((Key *)idfrom)->ipo= copy_ipo(ipo);
1662                                         else if(ipo->blocktype==ID_LA) ((Lamp *)idfrom)->ipo= copy_ipo(ipo);
1663                                         else if(ipo->blocktype==ID_WO) ((World *)idfrom)->ipo= copy_ipo(ipo);
1664                                         else if(ipo->blocktype==ID_CA) ((Camera *)idfrom)->ipo= copy_ipo(ipo);
1665                                         else if(ipo->blocktype==ID_SO) ((bSound *)idfrom)->ipo= copy_ipo(ipo);
1666                                         else if(ipo->blocktype==ID_AC) get_hilighted_action_channel((bAction *)idfrom)->ipo= copy_ipo(ipo);
1667                                         else if(ipo->blocktype==IPO_CO) ((Object *)idfrom)->activecon->ipo= copy_ipo(ipo);
1668                                         else error("Warn ton!");
1669                                         
1670                                         ipo->id.us--;
1671                                         allqueue(REDRAWIPO, 0);
1672                                 }
1673                         }
1674                 }
1675                 break;
1676         case B_IPOLOCAL:
1677                 ipo= get_ipo_to_edit(&idfrom);
1678                 
1679                 if(idfrom && idfrom->lib==0) {
1680                         if(ipo->id.lib) {
1681                                 if(okee("Make local")) {
1682                                         make_local_ipo(ipo);
1683                                         allqueue(REDRAWIPO, 0);
1684                                 }
1685                         }
1686                 }
1687                 break;
1688
1689         case B_OBALONE:
1690                 if(G.scene->id.lib==0) {
1691                         if(ob->id.us>1) {
1692                                 if(okee("Single user")) {
1693                                         base= FIRSTBASE;
1694                                         while(base) {
1695                                                 if(base->object==ob) {
1696                                                         base->object= copy_object(ob);
1697                                                         ob->id.us--;
1698                                                         allqueue(REDRAWVIEW3D, 0);
1699                                                         break;
1700                                                 }
1701                                                 base= base->next;
1702                                         }
1703                                 }
1704                         }
1705                 }
1706                 break;
1707         case B_OBLOCAL:
1708                 if(G.scene->id.lib==0) {
1709                         if(ob->id.lib) {
1710                                 if(okee("Make local")) {
1711                                         make_local_object(ob);
1712                                         allqueue(REDRAWVIEW3D, 0);
1713                                 }
1714                         }
1715                 }
1716                 break;
1717         case B_MESHALONE:
1718                 if(ob && ob->id.lib==0) {
1719                         
1720                         me= ob->data;
1721                         
1722                         if(me && me->id.us>1) {
1723                                 if(okee("Single user")) {
1724                                         Mesh *men= copy_mesh(me);
1725                                         men->id.us= 0;
1726                                         
1727                                         set_mesh(ob, men);
1728                                         
1729                                         if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
1730                                 }
1731                         }
1732                 }
1733                 break;
1734         }
1735         
1736         allqueue(REDRAWBUTSALL, 0);
1737         allqueue(REDRAWOOPS, 0);
1738 }
1739
1740 /* ********************** EMPTY ****************************** */
1741 /* ********************** INFO ****************************** */
1742
1743 int buttons_do_unpack()
1744 {
1745         int how;
1746         char menu[2048];
1747         char line[128];
1748         int ret_value = RET_OK, count = 0;
1749
1750         count = countPackedFiles();
1751
1752         if (count) {
1753                 if (count == 1) {
1754                         sprintf(menu, "Unpack 1 file%%t");
1755                 } else {
1756                         sprintf(menu, "Unpack %d files%%t", count);
1757                 }
1758                 
1759                 sprintf(line, "|Use files in current directory (create when necessary)%%x%d", PF_USE_LOCAL);
1760                 strcat(menu, line);
1761         
1762                 sprintf(line, "|Write files to current directory (overwrite existing files)%%x%d", PF_WRITE_LOCAL);
1763                 strcat(menu, line);
1764         
1765                 sprintf(line, "|%%l|Use files in original location (create when necessary)%%x%d", PF_USE_ORIGINAL);
1766                 strcat(menu, line);
1767         
1768                 sprintf(line, "|Write files to original location (overwrite existing files)%%x%d", PF_WRITE_ORIGINAL);
1769                 strcat(menu, line);
1770         
1771                 sprintf(line, "|%%l|Disable AutoPack, keep all packed files %%x%d", PF_KEEP);
1772                 strcat(menu, line);
1773         
1774                 sprintf(line, "|Ask for each file %%x%d", PF_ASK);
1775                 strcat(menu, line);
1776                 
1777                 how = pupmenu(menu);
1778                 
1779                 if(how != -1) {
1780                         if (how != PF_KEEP) {
1781                                 unpackAll(how);
1782                         }
1783                         G.fileflags &= ~G_AUTOPACK;
1784                 } else {
1785                         ret_value = RET_CANCEL;
1786                 }
1787         } else {
1788                 pupmenu("No packed files. Autopack disabled");
1789         }
1790         
1791         return (ret_value);
1792 }
1793
1794 /* here, because of all creator stuff */
1795
1796 Scene *copy_scene(Scene *sce, int level)
1797 {
1798         /* level 0: alle objects shared
1799          * level 1: alle objectdata shared
1800          * level 2: volledige kopie
1801          */
1802         Scene *scen;
1803         Base *base, *obase;
1804
1805
1806         /* level 0 */
1807         scen= copy_libblock(sce);
1808         duplicatelist(&(scen->base), &(sce->base));
1809         
1810         clear_id_newpoins();
1811         
1812         id_us_plus((ID *)scen->world);
1813         id_us_plus((ID *)scen->set);
1814         
1815         scen->ed= 0;
1816         scen->radio= 0;
1817         
1818         obase= sce->base.first;
1819         base= scen->base.first;
1820         while(base) {
1821                 base->object->id.us++;
1822                 if(obase==sce->basact) scen->basact= base;
1823                 
1824                 obase= obase->next;
1825                 base= base->next;
1826         }
1827         
1828         if(level==0) return scen;
1829         
1830         /* level 1 */
1831         G.scene= scen;
1832         single_object_users(0);
1833
1834         /*  camera */
1835         ID_NEW(G.scene->camera);
1836                 
1837         /* level 2 */
1838         if(level>=2) {
1839                 if(scen->world) {
1840                         scen->world->id.us--;
1841                         scen->world= copy_world(scen->world);
1842                 }
1843                 single_obdata_users(0);
1844                 single_mat_users_expand();
1845                 single_tex_users_expand();
1846         }
1847
1848         clear_id_newpoins();
1849
1850         BPY_copy_scriptlink(&sce->scriptlink);
1851
1852
1853
1854         // make a private copy of the avicodecdata
1855
1856         if (sce->r.avicodecdata) {
1857
1858                 scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata);
1859
1860                 scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecdata->lpFormat);
1861
1862                 scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecdata->lpParms);
1863
1864         }
1865
1866         return scen;
1867 }
1868
1869 void do_info_buttons(unsigned short event)
1870 {
1871         bScreen *sc, *oldscreen;
1872         Scene *sce, *sce1;
1873         ScrArea *sa;
1874         int nr;
1875         
1876         switch(event) {
1877         
1878         case B_INFOSCR:         /* menu select screen */
1879
1880                 if( G.curscreen->screennr== -2) {
1881                         if(curarea->winy <50) {
1882                                 sa= closest_bigger_area();
1883                                 areawinset(sa->win);
1884                         }
1885                         activate_databrowse((ID *)G.curscreen, ID_SCR, 0, B_INFOSCR, &G.curscreen->screennr, do_info_buttons);
1886                         return;
1887                 }
1888                 if( G.curscreen->screennr < 0) return;
1889                 
1890                 sc= G.main->screen.first;
1891                 nr= 1;
1892                 while(sc) {
1893                         if(nr==G.curscreen->screennr) {
1894                                 if(is_allowed_to_change_screen(sc)) setscreen(sc);
1895                                 else error("Unable to perform function in EditMode");
1896                                 break;
1897                         }
1898                         nr++;
1899                         sc= sc->id.next;
1900                 }
1901                 /* laatste item: NEW SCREEN */
1902                 if(sc==0) {
1903                         duplicate_screen();
1904                 }
1905                 break;
1906         case B_INFODELSCR:
1907                 /* dit event alleen met buttons doen, zodoende nooit vanuit full aanroepbaar */
1908
1909                 if(G.curscreen->id.prev) sc= G.curscreen->id.prev;
1910                 else if(G.curscreen->id.next) sc= G.curscreen->id.next;
1911                 else return;
1912                 if(okee("Delete current screen")) {
1913                         /* vind nieuwe G.curscreen */
1914                         
1915                         oldscreen= G.curscreen;
1916                         setscreen(sc);          /* deze test of sc een full heeft */
1917                         unlink_screen(oldscreen);
1918                         free_libblock(&G.main->screen, oldscreen);
1919                 }
1920                 scrarea_queue_headredraw(curarea);
1921
1922                 break;
1923         case B_INFOSCE:         /* menu select scene */
1924                 
1925                 if( G.obedit) {
1926                         error("Unable to perform function in EditMode");
1927                         return;
1928                 }
1929                 if( G.curscreen->scenenr== -2) {
1930                         if(curarea->winy <50) {
1931                                 sa= closest_bigger_area();
1932                                 areawinset(sa->win);
1933                         }
1934                         activate_databrowse((ID *)G.scene, ID_SCE, 0, B_INFOSCE, &G.curscreen->scenenr, do_info_buttons);
1935                         return;
1936                 }
1937                 if( G.curscreen->scenenr < 0) return;
1938
1939                 sce= G.main->scene.first;
1940                 nr= 1;
1941                 while(sce) {
1942                         if(nr==G.curscreen->scenenr) {
1943                                 if(sce!=G.scene) set_scene(sce);
1944                                 break;
1945                         }
1946                         nr++;
1947                         sce= sce->id.next;
1948                 }
1949                 /* laatste item: NEW SCENE */
1950                 if(sce==0) {
1951                         nr= pupmenu("Add scene%t|Empty|Link Objects|Link ObData|Full Copy");
1952                         if(nr<= 0) return;
1953                         if(nr==1) {
1954                                 sce= add_scene(G.scene->id.name+2);
1955                                 sce->r= G.scene->r;
1956                         }
1957                         else sce= copy_scene(G.scene, nr-2);
1958                         
1959                         set_scene(sce);
1960                 }
1961
1962                 break;
1963         case B_INFODELSCE:
1964                 
1965                 if(G.scene->id.prev) sce= G.scene->id.prev;
1966                 else if(G.scene->id.next) sce= G.scene->id.next;
1967                 else return;
1968                 if(okee("Delete current scene")) {
1969                         
1970                         /* alle sets aflopen */
1971                         sce1= G.main->scene.first;
1972                         while(sce1) {
1973                                 if(sce1->set == G.scene) sce1->set= 0;
1974                                 sce1= sce1->id.next;
1975                         }
1976                         
1977                         /* alle sequences aflopen */
1978                         clear_scene_in_allseqs(G.scene);
1979                         
1980                         /* alle schermen */
1981                         sc= G.main->screen.first;
1982                         while(sc) {
1983                                 if(sc->scene == G.scene) sc->scene= sce;
1984                                 sc= sc->id.next;
1985                         }
1986                         free_libblock(&G.main->scene, G.scene);
1987                         set_scene(sce);
1988                 }
1989         
1990                 break;
1991         case B_FILEMENU:
1992                 tbox_setmain(9);
1993                 toolbox();
1994                 break;
1995         }
1996 }
1997
1998 /* strubi shamelessly abused the status line as a progress bar... 
1999    feel free to kill him after release */
2000
2001 static int      g_progress_bar = 0;
2002 static char *g_progress_info = 0;
2003 static float g_done;
2004
2005 int start_progress_bar(void)
2006 {
2007         g_progress_bar = 1;
2008         return 1;               // we never fail (yet)
2009 }
2010
2011 void end_progress_bar(void)
2012 {
2013         g_progress_bar = 0;
2014 }
2015
2016 static void update_progress_bar(float done, char *info)
2017 {
2018         g_done = done;
2019         g_progress_info = info;
2020 }
2021
2022 /** Progress bar
2023         'done': a value between 0.0 and 1.0, showing progress
2024         'info': a info text what is currently being done
2025
2026         Make sure that the progress bar is always called with:
2027         done = 0.0 first
2028                 and
2029         done = 1.0 last -- or alternatively use:
2030
2031         start_progressbar();
2032         do_stuff_and_callback_progress_bar();
2033         end_progressbar();
2034 */
2035 int progress_bar(float done, char *busy_info)
2036 {
2037         ScrArea *sa;
2038         short val; 
2039
2040         /* User break (ESC) */
2041         while (qtest()) {
2042                 if (extern_qread(&val) == ESCKEY) 
2043                         return 0;
2044         }
2045         if (done == 0.0) {
2046                 start_progress_bar();
2047         } else if (done > 0.99) {
2048                 end_progress_bar();
2049         }
2050
2051         sa= G.curscreen->areabase.first;
2052         while(sa) {
2053                 if (sa->spacetype == SPACE_INFO) {
2054                         update_progress_bar(done, busy_info);
2055
2056                         curarea = sa;
2057
2058                         scrarea_do_headdraw(curarea);
2059                         areawinset(curarea->win);
2060                         sa->head_swap= WIN_BACK_OK;
2061                         screen_swapbuffers();
2062                 }
2063                 sa = sa->next;
2064         }
2065         return 1;
2066 }
2067
2068
2069 static void check_packAll()
2070 {
2071         // first check for dirty images
2072         Image *ima;
2073
2074         ima = G.main->image.first;
2075         while (ima) {
2076                 if (ima->ibuf && (ima->ibuf->userflags &= IB_BITMAPDIRTY)) {
2077                         break;
2078                 }
2079                 ima= ima->id.next;
2080         }
2081         
2082         if (ima == 0 || okee("Some images are painted on. These changes will be lost. Continue ?")) {
2083                 packAll();
2084                 G.fileflags |= G_AUTOPACK;
2085         }
2086 }
2087
2088
2089 /* KEYED FUNCTIONS 
2090    --------------- */
2091
2092 /* this function name is meaningless and only called that way for some
2093    obscurity 
2094    It is called by a function table from the license_key;
2095    see include/keyed_functions.h
2096 */
2097
2098 struct twostrings
2099 {
2100         char *outname;
2101         char *exename;
2102 };
2103
2104 /** This function is called for writing runtimes.
2105   * It's locked behind the key and called through a function table
2106   * which is initialized properly by the Python key code (if valid)
2107   */
2108 int make_beautiful_animation(void *vp) 
2109 {
2110         char *freestr= NULL;
2111         struct twostrings *twostrings = (struct twostrings *) vp;
2112         char *str = twostrings->outname;
2113         char *ext = 0;
2114
2115 #ifdef _WIN32
2116         ext = ".exe";
2117 #endif
2118
2119 #ifdef __APPLE__
2120         ext = ".app";
2121 #endif
2122         if (ext && (!BLI_testextensie(str, ext))) {
2123                 freestr= MEM_mallocN(strlen(str) + strlen(ext) + 1, "write_runtime_check");
2124                 strcpy(freestr, str);
2125                 strcat(freestr, ext);
2126                 str= freestr;
2127         }
2128
2129         if (!BLI_exists(str) || saveover(str))
2130                 BLO_write_runtime(str, twostrings->exename);
2131
2132         if (freestr)
2133                 MEM_freeN(freestr);
2134         
2135         return 0;
2136 }
2137
2138 /*
2139 int make_nice_software(void)
2140 {
2141         Fptr f = KEY_RETURN_TRUE;
2142         if (f) return f(0);
2143         else return 0;
2144 }
2145 */
2146         
2147 static void write_runtime_check_dynamic(char *str) 
2148 {
2149         struct twostrings twostrings;
2150
2151         twostrings.outname = str;
2152         twostrings.exename = "blenderdynplayer.exe";
2153
2154         make_beautiful_animation((void *) &twostrings);
2155 }
2156
2157 static void write_runtime_check(char *str) 
2158 {
2159         struct twostrings twostrings;
2160         char player[128];
2161
2162         twostrings.outname = str;
2163         twostrings.exename = player;
2164
2165         strcpy(player, "blenderplayer");
2166
2167 #ifdef _WIN32
2168         strcat(player, ".exe");
2169 #endif
2170
2171 #ifdef __APPLE__
2172         strcat(player, ".app");
2173 #endif
2174
2175         make_beautiful_animation((void *) &twostrings);
2176 }
2177 /* end keyed functions */
2178
2179
2180 static void do_info_filemenu(void *arg, int event)
2181 {
2182         ScrArea *sa;
2183         char dir[FILE_MAXDIR];
2184         
2185         if(curarea->spacetype==SPACE_INFO) {
2186                 sa= closest_bigger_area();
2187                 areawinset(sa->win);
2188         }
2189
2190         /* these are no defines, easier this way, the codes are in the function below */
2191         switch(event) {
2192         case 0:
2193                 if (okee("ERASE ALL")) {
2194                         if (!BIF_read_homefile())
2195                                 error("No file ~/.B.blend");
2196                 }
2197                 break;
2198         case 1:
2199                 activate_fileselect(FILE_BLENDER, "LOAD FILE", G.sce, BIF_read_file);
2200                 break;
2201         case 2:
2202                 {
2203                         char *s= MEM_mallocN(strlen(G.sce) + 11 + 1, "okee_reload");
2204                         strcpy(s, "Open file: ");
2205                         strcat(s, G.sce);
2206                         if (okee(s))
2207                                 BIF_read_file(G.sce);
2208                         MEM_freeN(s);
2209                 }
2210                 break;
2211         case 3:
2212                 activate_fileselect(FILE_LOADLIB, "LOAD LIBRARY", G.lib, 0);
2213                 break;
2214         case 4:
2215                 strcpy(dir, G.sce);
2216                 untitled(dir);
2217                 activate_fileselect(FILE_BLENDER, "SAVE FILE", dir, BIF_write_file);
2218                 break;
2219         case 5:
2220                 strcpy(dir, G.sce);
2221                 if (untitled(dir)) {
2222                         activate_fileselect(FILE_BLENDER, "SAVE FILE", dir, BIF_write_file);
2223                 } else {
2224                         BIF_write_file(dir);
2225                         free_filesel_spec(dir);
2226                 }
2227                 break;
2228         case 6:
2229                 mainqenter(F3KEY, 1);
2230                 break;
2231         case 7:
2232                 write_vrml_fs();
2233                 break;
2234         case 8:
2235                 write_dxf_fs();
2236                 break;
2237         case 9:
2238                 write_videoscape_fs();
2239                 break;
2240 /*
2241         case 20:
2242                 strcpy(dir, G.sce);
2243                 activate_fileselect(FILE_SPECIAL, "INSTALL LICENSE KEY", dir, loadKeyboard);
2244                 break;
2245         case 21:
2246                 SHOW_LICENSE_KEY();
2247                 break;
2248 */
2249         case 22:
2250                 activate_fileselect(FILE_SPECIAL, "WRITE RUNTIME", "", write_runtime_check);
2251                 break;
2252         case 23:
2253                 activate_fileselect(FILE_SPECIAL, "WRITE DYNAMIC RUNTIME", "", write_runtime_check_dynamic);
2254                 break;
2255         case 30:
2256                 // import menu, no handling
2257                 break;
2258
2259 #ifdef EXPERIMENTAL_MENUS
2260         case 10:
2261                 check_packAll();
2262                 break;
2263         case 11:
2264                 unpackAll(PF_WRITE_LOCAL);
2265                 G.fileflags &= ~G_AUTOPACK;
2266                 break;
2267         case 12:
2268                 if (buttons_do_unpack() != RET_CANCEL) {
2269                         /* Clear autopack bit only if user selected one of the unpack options */
2270                         G.fileflags &= ~G_AUTOPACK;
2271                 }
2272                 break;
2273         case 13:
2274 #else /* EXPERIMENTAL_MENUS */
2275         case 10:
2276 #endif /* EXPERIMENTAL_MENUS */
2277                 exit_usiblender();
2278                 break;          
2279         }
2280         allqueue(REDRAWINFO, 0);
2281 }
2282
2283 void do_info_file_optionsmenu(void *arg, int event)
2284 {
2285         G.fileflags ^= (1 << event);
2286
2287         // allqueue(REDRAWINFO, 0);
2288 }
2289
2290
2291 static uiBlock *info_file_optionsmenu(void *arg_unused)
2292 {
2293         uiBlock *block;
2294         short yco= 0, xco = 20;
2295
2296         block= uiNewBlock(&curarea->uiblocks, "runtime_options", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2297         uiBlockSetButmFunc(block, do_info_file_optionsmenu, NULL);
2298         uiBlockSetXOfs(block,-40);  // offset to parent button
2299
2300         /* flags are case-values */
2301         uiDefBut(block, BUTM, 1, "Compress File",       xco, yco-=20, 100, 19, NULL, 0.0, 0.0, 0, G_FILE_COMPRESS_BIT, "Use file compression");
2302 /*
2303         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");
2304         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");
2305 */
2306         /* Toggle buttons */
2307         
2308         yco= 0;
2309         xco -= 20;
2310         uiBlockSetEmboss(block, UI_EMBOSSW);
2311         uiBlockSetButmFunc(block, NULL, NULL);
2312         /* flags are defines */
2313         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, "");
2314 /*
2315         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, "");
2316         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, "");
2317 */
2318         uiBlockSetDirection(block, UI_RIGHT);
2319                 
2320         return block;
2321 }
2322
2323 static uiBlock *info_runtime_optionsmenu(void *arg_unused)
2324 {
2325         uiBlock *block;
2326         short yco= 0, xco = 20;
2327
2328         block= uiNewBlock(&curarea->uiblocks, "add_surfacemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2329         uiBlockSetXOfs(block, -40);  // offset to parent button
2330
2331         uiBlockSetEmboss(block, UI_EMBOSSW);
2332
2333         uiDefBut(block, LABEL, 0, "Size options:",              xco, yco-=20, 114, 19, 0, 0.0, 0.0, 0, 0, "");
2334         uiDefButS(block, NUM, 0, "X:",          xco+19, yco-=20, 95, 19,    &G.scene->r.xplay, 10.0, 2000.0, 0, 0, "X screen/window resolution");
2335         uiDefButS(block, NUM, 0, "Y:",          xco+19, yco-=20, 95, 19, &G.scene->r.yplay, 10.0, 2000.0, 0, 0, "Y screen/window resolution");
2336
2337         uiDefBut(block, SEPR, 0, "",            xco, yco-=4, 114, 4, NULL, 0.0, 0.0, 0, 0, "");
2338
2339         uiDefBut(block, LABEL, 0, "Fullscreen options:",                xco, yco-=20, 114, 19, 0, 0.0, 0.0, 0, 0, "");
2340         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");
2341         uiDefButS(block, NUM, 0, "Freq:",       xco+19, yco-=20, 95, 19, &G.scene->r.freqplay, 10.0, 120.0, 0, 0, "Clock frequency of fullscreen display");
2342         uiDefButS(block, NUM, 0, "Bits:",       xco+19, yco-=20, 95, 19, &G.scene->r.depth, 1.0, 32.0, 0, 0, "Bit depth of full screen disply");
2343
2344         uiDefBut(block, SEPR, 0, "",            xco, yco-=4, 114, 4, NULL, 0.0, 0.0, 0, 0, "");
2345
2346         /* stereo settings */
2347         /* can't use any definition from the game engine here so hardcode it. Change it here when it changes there!
2348          * RAS_IRasterizer has definitions:
2349          * RAS_STEREO_NOSTEREO     1
2350          * RAS_STEREO_QUADBUFFERED 2
2351          * RAS_STEREO_ABOVEBELOW   3
2352          * RAS_STEREO_INTERLACED   4   future
2353          */
2354         uiDefBut(block, LABEL, 0, "Stereo options", xco, yco-=20, 114, 19, 0, 0.0, 0.0, 0, 0, "");
2355         uiDefButS(block, ROW, 0, "no stereo", xco+19, yco-=20, 95, 19, &(G.scene->r.stereomode), 6.0, 1.0, 0, 0, "Disables stereo");
2356         uiDefButS(block, ROW, 0, "h/w pageflip", xco+19, yco-=20, 95, 19, &(G.scene->r.stereomode), 6.0, 2.0, 0, 0, "Enables h/w pageflip stereo method");
2357         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");
2358 #if 0
2359         // future
2360         uiDefButS(block, ROW, 0, "syncdoubling", xco+19, yco, 95, 19, &(G.scene->r.stereomode), 5.0, 4.0, 0, 0, "Enables interlaced stereo method");
2361 #endif
2362
2363         uiBlockSetDirection(block, UI_RIGHT);
2364                 
2365         return block;
2366 }
2367
2368 static uiBlock *info_file_importmenu(void *arg_unused)
2369 {
2370         uiBlock *block;
2371         short yco= 0, xco = 20;
2372
2373         block= uiNewBlock(&curarea->uiblocks, "importmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2374         uiBlockSetXOfs(block, -40);  // offset to parent button
2375
2376         uiBlockSetEmboss(block, UI_EMBOSSW);
2377
2378         /* flags are defines */
2379         uiDefBut(block, LABEL, 0, "VRML 2.0 options", xco, yco, 125, 19,   NULL, 0.0, 0.0, 0, 0, "");
2380         uiDefButS(block, TOG|BIT|0, 0, "SepLayers", xco, yco-=20, 75, 19,                 &U.vrmlflag, 0.0, 0.0, 0, 0, "Separate Empties, Lamps, etc. into Layers");
2381         uiDefButS(block, TOG|BIT|1, 0, "Scale 1/100", xco, yco-=20, 75, 19,   &U.vrmlflag, 0.0, 0.0, 0, 0, "Scale scene by 1/100 (3DS VRML)");
2382         uiDefButS(block, TOG|BIT|2, 0, "Two Sided", xco, yco-=20, 75, 19,   &U.vrmlflag, 0.0, 0.0, 0, 0, "Import two sided faces");
2383
2384         uiBlockSetDirection(block, UI_RIGHT);
2385                 
2386         return block;
2387 }
2388
2389 static uiBlock *info_filemenu(void *arg_unused)
2390 {
2391         uiBlock *block;
2392         short xco=0;
2393
2394         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
2395         uiBlockSetButmFunc(block, do_info_filemenu, NULL);
2396         
2397         uiDefBut(block, BUTM, 1, "New|Ctrl X",                          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "Start a new project (and delete the current)");
2398         uiDefBut(block, BUTM, 1, "Open|F1",                                     0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "Open a new file");
2399         uiDefBut(block, BUTM, 1, "Reopen Last|Ctrl O",          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Revert to the last version saved to file");
2400         uiDefBut(block, BUTM, 1, "Append|Shift F1",                     0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "Append contents of a file to the current project");
2401         uiDefBlockBut(block, info_file_importmenu, NULL, "Import Settings|>>", 0, xco-=20, 160, 19, "");
2402
2403         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2404         uiDefBut(block, BUTM, 1, "Save As|F2",                          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "Save to a new file");
2405         uiDefBut(block, BUTM, 1, "Save|Ctrl W",                         0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "Save to the current file");
2406
2407         uiDefBlockBut(block, info_file_optionsmenu, NULL, "File options|>>", 0, xco-=20, 160, 19, "Click to open the File Options menu");
2408
2409         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2410
2411         uiDefBut(block, BUTM, 1, "Save Runtime",                        0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 22, "Create a runtime executable with the current project");
2412 #ifdef _WIN32
2413         uiDefBut(block, BUTM, 1, "Save dynamic Runtime",                        0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 23, "Create a dynamic runtime executable with the current project (requieres extenal python20.dll)");
2414 #endif
2415         uiDefBlockBut(block, info_runtime_optionsmenu, NULL, "Runtime options|>>", 0, xco-=20, 160, 19, "Click to open the File Options menu");
2416
2417         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2418         uiDefBut(block, BUTM, 1, "Save Image|F3",                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 6, "Save the image in the render buffer to a file");
2419         uiDefBut(block, BUTM, 1, "Save VRML 1.0|Ctrl F2",               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "Save the current scene to a file in VRML 1.0 format");
2420         uiDefBut(block, BUTM, 1, "Save DXF|Shift F2",           0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "Save the current scene to a file in DXF format");
2421         uiDefBut(block, BUTM, 1, "Save VideoScape|Alt W",       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 9, "Save the current scene to a file in VideoScape format");
2422
2423
2424         /*
2425         if (LICENSE_KEY_VALID) {
2426                 uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
2427                 uiDefBut(block, BUTM, 1, "Show License Key", 0, xco-=20,        140, 19, NULL, 0.0, 0.0, 1, 21, "Show the personal information stored in your Blender License Key");
2428                 uiDefIconBut(block, BUTM, 1, ICON_PUBLISHER,                     141,xco,       19,  19, NULL, 0.0, 0.0, 1, 21, "Show the personal information stored in your Blender License Key");
2429         } else if (I_AM_PUBLISHER) {
2430                 uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
2431                 uiDefBut(block, BUTM, 1, "Install License Key", 0, xco-=20,     140, 19, NULL, 0.0, 0.0, 1, 20, "Install your Blender License Key");
2432                 uiDefIconBut(block, BUTM, 1, ICON_PUBLISHER,                     141,xco,       19,  19, NULL, 0.0, 0.0, 1, 20, "Install your Blender License Key");
2433         }
2434         */
2435
2436
2437         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
2438
2439 #ifdef EXPERIMENTAL_MENUS
2440         uiDefBut(block, BUTM, 1, "Pack Data",                                           0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "");
2441         uiDefBut(block, BUTM, 1, "Unpack Data to current dir",          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 11, "");
2442         uiDefBut(block, BUTM, 1, "Advanced Unpack",                                     0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 12, "");
2443         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6, 160, 6, NULL, 0.0, 0.0, 1, 0, "");
2444         uiDefBut(block, BUTM, 1, "Quit | Q",                            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 13, "Quit Blender immediately");
2445 #else /* EXPERIMENTAL_MENUS */
2446         uiDefBut(block, BUTM, 1, "Quit | Q",                            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, "Quit Blender immediately");
2447 #endif /* EXPERIMENTAL_MENUS */
2448         uiBlockSetDirection(block, UI_DOWN);
2449
2450         
2451         return block;
2452 }
2453
2454 static void do_info_editmenu(void *arg, int event)
2455 {
2456         int oldqual;
2457
2458         switch(event) {
2459                 
2460         case 0:
2461                 /* (De)Select All */
2462                 if(select_area(SPACE_VIEW3D)) mainqenter(AKEY, 1);
2463                 break;
2464                 /* Border Select */
2465         case 1:
2466                 if(select_area(SPACE_VIEW3D)) mainqenter(BKEY, 1);
2467                 break;
2468         case 2:
2469                 /* Circle Select */
2470                 /*if(select_area(SPACE_VIEW3D)) {
2471                         winqread3d(BKEY, 1, 0);
2472                         winqread3d(BKEY, 1, 0);
2473                 }*/
2474                 break;
2475         case 3:
2476                 /* Duplicate */
2477                 if(select_area(SPACE_VIEW3D)) {
2478                         oldqual = G.qual;
2479                         G.qual = LR_SHIFTKEY;
2480                         winqread3d(DKEY, 1, 0);
2481                         G.qual = oldqual;
2482                 }
2483                 break;
2484         case 4:
2485                 /* Delete */
2486                 if(select_area(SPACE_VIEW3D)) {
2487                         winqread3d(XKEY, 1, 0);
2488                 }
2489                 break;
2490         case 5:
2491                 /* Edit Mode */
2492                 if(select_area(SPACE_VIEW3D)) {
2493                         blenderqread(TABKEY, 1);
2494                 }
2495                 break;
2496         case 6:
2497                 /* Grabber */
2498                 if(select_area(SPACE_VIEW3D)) {
2499                         transform('g');
2500                 }
2501                 break;
2502         case 7:
2503                 /* Rotate */
2504                 if(select_area(SPACE_VIEW3D)) {
2505                         transform('r');
2506                 }
2507                 break;
2508         case 8:
2509                 /* Scale */
2510                 if(select_area(SPACE_VIEW3D)) {
2511                         transform('s');
2512                 }
2513                 break;
2514         case 9:
2515                 /* Shear */
2516                 if (!G.obedit) {
2517                         enter_editmode();
2518                         /* ### put these into a deselectall_gen() */
2519                         if(G.obedit->type==OB_MESH) deselectall_mesh();
2520                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) deselectall_nurb();
2521                         else if(G.obedit->type==OB_MBALL) deselectall_mball();
2522                         else if(G.obedit->type==OB_LATTICE) deselectall_Latt();
2523                         /* ### */
2524                 }       
2525                 if(select_area(SPACE_VIEW3D)) {
2526                         transform('S');
2527                 }
2528                 break;
2529         case 10:
2530                 /* Warp/Bend */
2531                 if (!G.obedit) {
2532                         enter_editmode();
2533                         /* ### put these into a deselectall_gen() */
2534                         if(G.obedit->type==OB_MESH) deselectall_mesh();
2535                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) deselectall_nurb();
2536                         else if(G.obedit->type==OB_MBALL) deselectall_mball();
2537                         else if(G.obedit->type==OB_LATTICE) deselectall_Latt();
2538                         /* ### */
2539                 }       
2540                 if(select_area(SPACE_VIEW3D)) {
2541                         oldqual = G.qual;
2542                         G.qual = LR_SHIFTKEY;
2543                         winqread3d(WKEY, 1, 0);
2544                         G.qual = oldqual;
2545                 }
2546                 break;
2547         case 11:
2548                 /* Snap */
2549                 if(select_area(SPACE_VIEW3D)) {
2550                         oldqual = G.qual;
2551                         G.qual = LR_SHIFTKEY;
2552                         winqread3d(SKEY, 1, 0);
2553                         G.qual = oldqual;
2554                 }
2555                 break;
2556         }
2557         allqueue(REDRAWINFO, 0);
2558 }
2559
2560
2561 static uiBlock *info_editmenu(void *arg_unused)
2562 {
2563 /*      static short tog=0; */
2564         uiBlock *block;
2565         short xco= 0;
2566         
2567         block= uiNewBlock(&curarea->uiblocks, "editmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
2568         uiBlockSetButmFunc(block, do_info_editmenu, NULL);
2569
2570         uiDefBut(block, BUTM, 1, "(De)Select All|A",    0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "Select all objects in the scene or empty the selection");
2571         uiDefBut(block, BUTM, 1, "Border Select|B",             0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "Select objects in a rectangular area (press B again to activate circle select in edit mode)");
2572
2573         /* uiDefBut(block, BUTM, 1, "Circle Select",            0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "Select objects in a circular area"); */
2574         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
2575         uiDefBut(block, BUTM, 1, "Duplicate|Shift D",   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 3, "Duplicate the selected object(s)");
2576         uiDefBut(block, BUTM, 1, "Delete|X",                    0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 4, "Delete the selected object(s)");
2577         uiDefBut(block, BUTM, 1, "Edit Mode|Tab",               0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 5, "Toggle between object and edit mode");
2578         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
2579         uiDefBut(block, BUTM, 1, "Grabber|G",                   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 6, "Move the selected object(s)");
2580         uiDefBut(block, BUTM, 1, "Rotate|R",                    0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 7, "Rotate the selected object(s)");
2581         uiDefBut(block, BUTM, 1, "Scale|S",                             0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 8, "Scale the selected object(s)");
2582         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
2583         uiDefBut(block, BUTM, 1, "Shear|Ctrl S",                0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 9, "Shear the selected object(s)");
2584         uiDefBut(block, BUTM, 1, "Warp/Bend|Shift W",   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 10, "Warp or bend the selected objects");
2585         uiDefBut(block, BUTM, 1, "Snap Menu|Shift S",   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 11, "Activate the snap menu");
2586         
2587         uiBlockSetDirection(block, UI_DOWN);
2588                 
2589         return block;
2590 }
2591
2592 static void do_info_add_meshmenu(void *arg, int event)
2593 {
2594
2595         switch(event) {         
2596 #ifdef EXPERIMENTAL_MENUS
2597         /* Maarten's proposal for a new Add Mesh menu */
2598                 case 0:
2599                         /* Line */
2600                         //add_primitiveMesh(4);
2601                         break;
2602                 case 1:
2603                         /* Circle */
2604                         if(select_area(SPACE_VIEW3D)) {
2605                                 add_primitiveMesh(4);
2606                         }
2607                         break;
2608                 case 2:
2609                         /* Plane */
2610                         add_primitiveMesh(0);
2611                         break;
2612                 case 3:
2613                         /* Cube */
2614                         add_primitiveMesh(1);
2615                         break;
2616                 case 4:
2617                         /* UVsphere */
2618                         add_primitiveMesh(11);
2619                         break;
2620                 case 5:
2621                         /* IcoSphere */
2622                         add_primitiveMesh(12);
2623                         break;
2624                 case 6:
2625                         /* Cylinder */
2626                         add_primitiveMesh(5);
2627                         break;
2628                 case 7:
2629                         /* Tube */
2630                         add_primitiveMesh(6);
2631                         break;
2632                 case 8:
2633                         /* Cone */
2634                         add_primitiveMesh(7);
2635                         break;
2636                 case 9:
2637                         /* Grid */
2638                         add_primitiveMesh(10);
2639                         break;
2640 #else /* EXPERIMENTAL_MENUS*/ 
2641                 case 0:
2642                         /* Plane */
2643                         add_primitiveMesh(0);
2644                         break;
2645                 case 1:
2646                         /* Cube */
2647                         add_primitiveMesh(1);
2648                         break;
2649                 case 2:
2650                         /* Circle */
2651                         add_primitiveMesh(4);
2652                         break;
2653                 case 3:
2654                         /* UVsphere */
2655                         add_primitiveMesh(11);
2656                         break;
2657                 case 4:
2658                         /* IcoSphere */
2659                         add_primitiveMesh(12);
2660                         break;
2661                 case 5:
2662                         /* Cylinder */
2663                         add_primitiveMesh(5);
2664                         break;
2665                 case 6:
2666                         /* Tube */
2667                         add_primitiveMesh(6);
2668                         break;
2669                 case 7:
2670                         /* Cone */
2671                         add_primitiveMesh(7);
2672                         break;
2673                 case 8:
2674                         /* Grid */
2675                         add_primitiveMesh(10);
2676                         break;
2677 #endif /* EXPERIMENTAL_MENUS */
2678                 default:
2679                         break;
2680         }
2681         allqueue(REDRAWINFO, 0);
2682 }
2683
2684 static uiBlock *info_add_meshmenu(void *arg_unused)
2685 {
2686 /*      static short tog=0; */
2687         uiBlock *block;
2688         short xco= 0;
2689         
2690         block= uiNewBlock(&curarea->uiblocks, "add_meshmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2691         uiBlockSetButmFunc(block, do_info_add_meshmenu, NULL);
2692
2693 #ifdef EXPERIMENTAL_MENUS
2694         /* Maarten's proposal for a new Add Mesh menu */
2695         uiDefBut(block, BUTM, 1, "Line|",                                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "Add a Mesh Line");
2696         uiDefBut(block, BUTM, 1, "Circle|",                                     0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "Add a Mesh Circle");
2697         uiDefBut(block, SEPR, 0, "",                                            0, xco-=6,  160, 6,  NULL, 0.0, 0.0, 0, 0, "");
2698         uiDefBut(block, BUTM, 1, "Plane|",                                      0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Add a Mesh Plane");
2699         uiDefBut(block, BUTM, 1, "Cube|",                                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "Add a Mesh Cube");
2700         uiDefBut(block, BUTM, 1, "UVsphere",                            0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "Add a Mesh Sphere");
2701         uiDefBut(block, BUTM, 1, "IcoSphere|",                          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "Add a Mesh Isocohedron Sphere");
2702         uiDefBut(block, BUTM, 1, "Cylinder With Caps|",         0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 6, "Add a Mesh Cylinder with caps");
2703         uiDefBut(block, BUTM, 1, "Cylinder Without Caps|",      0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "Add a Mesh Cylinder without caps");
2704         uiDefBut(block, BUTM, 1, "Cone|",                                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "Add a Mesh Cone");
2705         uiDefBut(block, BUTM, 1, "Grid|",                                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 9, "Add a Mesh Grid");
2706 #else /* EXPERIMENTAL_MENUS */
2707         uiDefBut(block, BUTM, 1, "Plane|",                              0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "Add a Mesh Plane");
2708         uiDefBut(block, BUTM, 1, "Cube|",                               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "Add a Mesh Cube");
2709         uiDefBut(block, BUTM, 1, "Circle|",                             0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Add a Mesh Circle");
2710         uiDefBut(block, BUTM, 1, "UVsphere",                    0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "Add a Mesh Sphere");
2711         uiDefBut(block, BUTM, 1, "IcoSphere|",                  0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "Add a Mesh Isocohedron Sphere");
2712         uiDefBut(block, BUTM, 1, "Cylinder|",                   0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "Add a Mesh Cylinder");
2713         uiDefBut(block, BUTM, 1, "Tube|",                               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 6, "Add a Mesh Tube");
2714         uiDefBut(block, BUTM, 1, "Cone|",                               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 7, "Add a Mesh Cone");
2715         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6,  160, 6,  NULL, 0.0, 0.0, 0, 0, "");
2716         uiDefBut(block, BUTM, 1, "Grid|",                               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 8, "Add a Mesh Grid");
2717 #endif /* EXPERIMENTAL_MENUS */
2718
2719         uiBlockSetDirection(block, UI_RIGHT);
2720                 
2721         return block;
2722 }
2723
2724 static void do_info_add_curvemenu(void *arg, int event)
2725 {
2726
2727         switch(event) {         
2728                 case 0:
2729                         /* Bezier Curve */
2730                         add_primitiveCurve(10);
2731                         break;
2732                 case 1:
2733                         /* Bezier Circle */
2734                         add_primitiveCurve(11);
2735                         break;
2736                 case 2:
2737                         /* NURB Curve */
2738                         add_primitiveCurve(40);
2739                         break;
2740                 case 3:
2741                         /* NURB Circle */
2742                         add_primitiveCurve(41);
2743                         break;
2744                 case 4:
2745                         /* Path */
2746                         add_primitiveCurve(46);
2747                         break;
2748                 default:
2749                         break;
2750         }
2751         allqueue(REDRAWINFO, 0);
2752 }
2753
2754 static uiBlock *info_add_curvemenu(void *arg_unused)
2755 {
2756 /*      static short tog=0; */
2757         uiBlock *block;
2758         short xco= 0;
2759         
2760         block= uiNewBlock(&curarea->uiblocks, "add_curvemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2761         uiBlockSetButmFunc(block, do_info_add_curvemenu, NULL);
2762
2763         uiDefBut(block, BUTM, 1, "Bezier Curve|",       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "Add a Bezier curve");
2764         uiDefBut(block, BUTM, 1, "Bezier Circle|",      0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "Add a Bezier circle");
2765         uiDefBut(block, BUTM, 1, "NURBS Curve|",                0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Add a NURB curve");
2766         uiDefBut(block, BUTM, 1, "NURBS Circle",                0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "Add a NURB circle");
2767         uiDefBut(block, BUTM, 1, "Path|",                       0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "Add a path");
2768         
2769         uiBlockSetDirection(block, UI_RIGHT);
2770                 
2771         return block;
2772 }
2773
2774
2775 static void do_info_add_surfacemenu(void *arg, int event)
2776 {
2777
2778         switch(event) {         
2779                 case 0:
2780                         /* Curve */
2781                         add_primitiveNurb(0);
2782                         break;
2783                 case 1:
2784                         /* Circle */
2785                         add_primitiveNurb(1);
2786                         break;
2787                 case 2:
2788                         /* Surface */
2789                         add_primitiveNurb(2);
2790                         break;
2791                 case 3:
2792                         /* Tube */
2793                         add_primitiveNurb(3);
2794                         break;
2795                 case 4:
2796                         /* Sphere */
2797                         add_primitiveNurb(4);
2798                         break;
2799                 case 5:
2800                         /* Donut */
2801                         add_primitiveNurb(5);
2802                         break;
2803                 default:
2804                         break;
2805         }
2806         allqueue(REDRAWINFO, 0);
2807 }
2808
2809 static uiBlock *info_add_surfacemenu(void *arg_unused)
2810 {
2811 /*      static short tog=0; */
2812         uiBlock *block;
2813         short xco= 0;
2814         
2815         block= uiNewBlock(&curarea->uiblocks, "add_surfacemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2816         uiBlockSetButmFunc(block, do_info_add_surfacemenu, NULL);
2817
2818         uiDefBut(block, BUTM, 1, "NURBS Curve|",                0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "Add a curve");
2819         uiDefBut(block, BUTM, 1, "NURBS Circle|",               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, "Add a circle");
2820         uiDefBut(block, BUTM, 1, "NURBS Surface|",      0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Add a surface");
2821         uiDefBut(block, BUTM, 1, "NURBS Tube",          0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 3, "Add a tube");
2822         uiDefBut(block, BUTM, 1, "NURBS Sphere|",               0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 4, "Add a sphere");
2823         uiDefBut(block, BUTM, 1, "NURBS Donut|",                0, xco-=20, 160, 19, NULL, 0.0, 0.0, 1, 5, "Add a donut");
2824
2825         uiBlockSetDirection(block, UI_RIGHT);
2826                 
2827         return block;
2828 }
2829
2830 static void do_info_addmenu(void *arg, int event)
2831 {
2832
2833         switch(event) {         
2834                 case 0:
2835                         /* Mesh */
2836                         break;
2837                 case 1:
2838                         /* Curve */
2839                         break;
2840                 case 2:
2841                         /* Surface */
2842                         break;
2843                 case 3:
2844                         /* Text (argument is discarded) */
2845                         add_primitiveFont(event);
2846                         break;
2847                 case 4:
2848                         /* Metaball  (argument is discarded) */
2849                         add_primitiveMball(event);
2850                         break;
2851                 case 5:
2852                         /* Empty */
2853                         add_object_draw(OB_EMPTY);
2854                         break;
2855                 case 6:
2856                         /* Camera */
2857                         add_object_draw(OB_CAMERA);
2858                         break;
2859                 case 7:
2860                         /* Lamp */
2861                         add_object_draw(OB_LAMP);
2862                         break;
2863                 case 8:
2864                         /* Armature */
2865                         add_primitiveArmature(OB_ARMATURE);
2866                         break;
2867                 case 9:
2868                         /* Lattice */
2869                         add_object_draw(OB_LATTICE);
2870                         break;
2871                 default:
2872                         break;
2873         }
2874         allqueue(REDRAWINFO, 0);
2875 }
2876
2877
2878 static uiBlock *info_addmenu(void *arg_unused)
2879 {
2880 /*      static short tog=0; */
2881         uiBlock *block;
2882         short xco= 0;
2883         
2884         block= uiNewBlock(&curarea->uiblocks, "addmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
2885         uiBlockSetButmFunc(block, do_info_addmenu, NULL);
2886
2887         uiDefBlockBut(block, info_add_meshmenu, NULL, "Mesh|>>", 0, xco-=20, 120, 19, "Click to open the Add Mesh menu");
2888         uiDefBlockBut(block, info_add_curvemenu, NULL, "Curve|>>", 0, xco-=20, 120, 19, "Click to open the Add Curve menu");
2889         uiDefBlockBut(block, info_add_surfacemenu, NULL, "Surface|>>", 0, xco-=20, 120, 19, "Click to open the Add Surface menu");
2890
2891         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
2892         uiDefBut(block, BUTM, 1, "Text|",                               0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 3, "");
2893         uiDefBut(block, BUTM, 1, "Metaball|",                   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 4, "");
2894         uiDefBut(block, BUTM, 1, "Empty|",                              0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 5, "");
2895         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
2896         uiDefBut(block, BUTM, 1, "Camera|",                             0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 6, "");
2897         uiDefBut(block, BUTM, 1, "Lamp|",                               0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 7, "");
2898 //      uiDefBut(block, BUTM, 1, "Armature|",                   0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 8, "");
2899         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
2900         uiDefBut(block, BUTM, 1, "Lattice|",                    0, xco-=20, 120, 19, NULL, 0.0, 0.0, 1, 9, "");
2901         
2902         uiBlockSetDirection(block, UI_DOWN);
2903                 
2904         return block;
2905 }
2906
2907 static void do_info_viewmenu(void *arg, int event)
2908 {
2909         switch(event) {
2910         case 0:
2911                 if(select_area(SPACE_VIEW3D)) mainqenter(PAD1, 1);
2912                 break;
2913         case 1:
2914                 if(select_area(SPACE_VIEW3D)) mainqenter(PAD3, 1);
2915                 break;
2916         case 2:
2917                 if(select_area(SPACE_VIEW3D)) mainqenter(PAD7, 1);
2918                 break;
2919         case 3:
2920                 if(select_area(SPACE_VIEW3D)) mainqenter(PAD0, 1);
2921                 break;
2922         case 4:
2923                 if(select_area(SPACE_VIEW3D)) mainqenter(PADPLUSKEY, 1);
2924                 break;
2925         case 5:
2926                 if(select_area(SPACE_VIEW3D)) mainqenter(PADMINUS, 1);
2927                 break;
2928         case 6:
2929                 if(select_area(SPACE_VIEW3D)) mainqenter(CKEY, 1);
2930                 break;
2931         case 7:
2932                 if(select_area(SPACE_VIEW3D)) mainqenter(HOMEKEY, 1);
2933                 break;
2934         }
2935         allqueue(REDRAWINFO, 0);
2936 }
2937
2938 static uiBlock *info_viewmenu(void *arg_unused)
2939 {
2940 /*      static short tog=0; */
2941         uiBlock *block;
2942         short xco= 0;
2943         
2944         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
2945         uiBlockSetButmFunc(block, do_info_viewmenu, NULL);
2946
2947         // uiBlockSetCol(block, BUTBLUE);
2948         
2949         uiDefBut(block, BUTM, 1, "Front|NumPad 1",              0, xco-=20, 140, 19, NULL, 0.0, 0.0, 0, 0, "");
2950         uiDefBut(block, BUTM, 1, "Right|NumPad 3",              0, xco-=20, 140, 19, NULL, 0.0, 0.0, 0, 1, "");
2951         uiDefBut(block, BUTM, 1, "Top|NumPad 7",                0, xco-=20, 140, 19, NULL, 0.0, 0.0, 0, 2, "");
2952         uiDefBut(block, BUTM, 1, "Camera|NumPad 0",             0, xco-=20, 140, 19, NULL, 0.0, 0.0, 0, 3, "");
2953
2954         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 140, 6, NULL, 0.0, 0.0, 0, 0, "");
2955         uiDefBut(block, BUTM, 1, "Zoom In|NumPad +",    0, xco-=20, 140, 19, NULL, 0.0, 0.0, 0, 4, "");
2956         uiDefBut(block, BUTM, 1, "Zoom Out|NumPad -",   0, xco-=20, 140, 19, NULL, 0.0, 0.0, 0, 5, "");
2957         
2958         uiDefBut(block, SEPR, 0, "",                                    0, xco-=6, 140, 6, NULL, 0.0, 0.0, 0, 0, "");
2959         uiDefBut(block, BUTM, 1, "Center|C",                    0, xco-=20, 140, 19, NULL, 0.0, 0.0, 0, 6, "");
2960         uiDefBut(block, BUTM, 1, "View All|Home",               0, xco-=20, 140, 19, NULL, 0.0, 0.0, 0, 7, "");
2961         
2962         uiBlockSetDirection(block, UI_DOWN);
2963         
2964         return block;
2965 }
2966
2967 static void do_game_menu(void *arg, int event)
2968 {
2969         switch (event) {
2970         case G_FILE_ENABLE_ALL_FRAMES_BIT:
2971         case G_FILE_SHOW_FRAMERATE_BIT:
2972         case G_FILE_SHOW_DEBUG_PROPS_BIT:
2973         case G_FILE_AUTOPLAY_BIT:
2974                 G.fileflags ^= (1 << event);
2975                 break;
2976         default:
2977                 ; /* ignore the rest */
2978         }
2979 }
2980
2981
2982 static uiBlock *info_gamemenu(void *arg_unused)
2983 {
2984         uiBlock *block;
2985         short yco= 0;
2986         
2987         block= uiNewBlock(&curarea->uiblocks, "gamemenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
2988         uiBlockSetCol(block, BUTBLUE);
2989         uiBlockSetDirection(block, UI_DOWN);
2990         
2991         uiDefBut(block, BUTM, B_STARTGAME, "Start Game|P", 
2992                          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 0, 0, 
2993                          "Start the game (press the Escape key to stop)");
2994         uiDefBut(block, SEPR, 0, "",
2995                         -20, yco-=6, 180, 6, NULL, 0.0, 0.0, 1, 0, "");
2996
2997         /* flags are case-values */
2998         uiBlockSetButmFunc(block, do_game_menu, NULL);
2999