Bug fix #1939
[blender.git] / source / blender / src / space.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  * - here initialize and free and handling SPACE data
34  */
35
36 #include <string.h>
37 #include <stdio.h>
38
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
42
43 #ifdef WIN32
44 #include "BLI_winstuff.h"
45 #endif
46
47 #include "MEM_guardedalloc.h"
48
49 #ifdef INTERNATIONAL
50 #include "BIF_language.h"
51 #endif
52
53 #include "IMB_imbuf_types.h"
54 #include "IMB_imbuf.h"
55
56 #include "BLI_blenlib.h"
57 #include "BLI_arithb.h"
58 #include "BLI_linklist.h"
59
60 #include "DNA_action_types.h"
61 #include "DNA_curve_types.h"
62 #include "DNA_image_types.h"
63 #include "DNA_ipo_types.h"
64 #include "DNA_mesh_types.h"
65 #include "DNA_object_types.h"
66 #include "DNA_scene_types.h"
67 #include "DNA_screen_types.h"
68 #include "DNA_sequence_types.h"
69 #include "DNA_sound_types.h"
70 #include "DNA_space_types.h"
71 #include "DNA_userdef_types.h"
72 #include "DNA_view2d_types.h"
73 #include "DNA_view3d_types.h"
74
75 #include "BKE_blender.h"
76 #include "BKE_curve.h"
77 #include "BKE_displist.h"
78 #include "BKE_global.h"
79 #include "BKE_ipo.h"
80 #include "BKE_main.h"
81 #include "BKE_scene.h"
82 #include "BKE_utildefines.h"
83
84 #include "BIF_spacetypes.h"  // first, nasty dependency with typedef
85
86 #include "BIF_butspace.h"
87 #include "BIF_drawimage.h"
88 #include "BIF_drawseq.h"
89 #include "BIF_drawtext.h"
90 #include "BIF_drawscript.h"
91 #include "BIF_editarmature.h"
92 #include "BIF_editfont.h"
93 #include "BIF_editika.h"
94 #include "BIF_editkey.h"
95 #include "BIF_editlattice.h"
96 #include "BIF_editmesh.h"
97 #include "BIF_editmode_undo.h"
98 #include "BIF_editnla.h"
99 #include "BIF_editoops.h"
100 #include "BIF_editseq.h"
101 #include "BIF_editsima.h"
102 #include "BIF_editsound.h"
103 #include "BIF_editview.h"
104 #include "BIF_gl.h"
105 #include "BIF_imasel.h"
106 #include "BIF_interface.h"
107 #include "BIF_meshtools.h"
108 #include "BIF_mywindow.h"
109 #include "BIF_oops.h"
110 #include "BIF_outliner.h"
111 #include "BIF_resources.h"
112 #include "BIF_screen.h"
113 #include "BIF_space.h"
114 #include "BIF_toets.h"
115 #include "BIF_toolbox.h"
116 #include "BIF_usiblender.h"
117 #include "BIF_previewrender.h"
118
119 #include "BSE_edit.h"
120 #include "BSE_view.h"
121 #include "BSE_editipo.h"
122 #include "BSE_drawipo.h"
123 #include "BSE_drawview.h"
124 #include "BSE_drawnla.h"
125 #include "BSE_filesel.h"
126 #include "BSE_headerbuttons.h"
127 #include "BSE_editnla_types.h"
128
129 #include "BDR_vpaint.h"
130 #include "BDR_editmball.h"
131 #include "BDR_editobject.h"
132 #include "BDR_editcurve.h"
133 #include "BDR_editface.h"
134 #include "BDR_drawmesh.h"
135 #include "BDR_drawobject.h"
136 #include "BDR_unwrapper.h"
137
138 #include "BLO_readfile.h" /* for BLO_blendhandle_close */
139
140 #include "BPY_extern.h"
141
142 #include "mydevice.h"
143 #include "blendef.h"
144 #include "datatoc.h"
145
146 #include "TPT_DependKludge.h"
147 #ifdef NAN_TPT
148 #include "BSE_trans_types.h"
149 #include "IMG_Api.h"
150 #endif /* NAN_TPT */
151
152 #include "SYS_System.h" /* for the user def menu ... should move elsewhere. */
153
154 extern void StartKetsjiShell(ScrArea *area, char* startscenename, struct Main* maggie, int always_use_expand_framing);
155
156 /**
157  * When the mipmap setting changes, we want to redraw the view right
158  * away to reflect this setting.
159  */
160 void space_mipmap_button_function(int event);
161
162 void free_soundspace(SpaceSound *ssound);
163
164 /* *************************************** */
165
166 /* don't know yet how the handlers will evolve, for simplicity
167    i choose for an array with eventcodes, this saves in a file!
168    */
169 void add_blockhandler(ScrArea *sa, short eventcode, short val)
170 {
171         SpaceLink *sl= sa->spacedata.first;
172         short a;
173         
174         // find empty spot
175         for(a=0; a<SPACE_MAXHANDLER; a+=2) {
176                 if( sl->blockhandler[a]==eventcode ) {
177                         sl->blockhandler[a+1]= val;
178                         break;
179                 }
180                 else if( sl->blockhandler[a]==0) {
181                         sl->blockhandler[a]= eventcode;
182                         sl->blockhandler[a+1]= val;
183                         break;
184                 }
185         }
186         if(a==SPACE_MAXHANDLER) printf("error; max (4) blockhandlers reached!\n");
187 }
188
189 void rem_blockhandler(ScrArea *sa, short eventcode)
190 {
191         SpaceLink *sl= sa->spacedata.first;
192         short a;
193         
194         for(a=0; a<SPACE_MAXHANDLER; a+=2) {
195                 if( sl->blockhandler[a]==eventcode) {
196                         sl->blockhandler[a]= 0;
197                         break;
198                 }
199         }
200 }
201
202 void toggle_blockhandler(ScrArea *sa, short eventcode, short val)
203 {
204         SpaceLink *sl= sa->spacedata.first;
205         short a, addnew=1;
206         
207         // find if it exists
208         for(a=0; a<SPACE_MAXHANDLER; a+=2) {
209                 if( sl->blockhandler[a]==eventcode ) {
210                         sl->blockhandler[a]= 0;
211                         addnew= 0;
212                 }
213         }
214         if(addnew) add_blockhandler(sa, eventcode, val);
215 }
216
217
218
219 /* ************* SPACE: VIEW3D  ************* */
220
221 /*  extern void drawview3dspace(ScrArea *sa, void *spacedata); BSE_drawview.h */
222
223
224 void copy_view3d_lock(short val)
225 {
226         bScreen *sc;
227         int bit;
228         
229         /* from G.scene copy to the other views */
230         sc= G.main->screen.first;
231         
232         while(sc) {
233                 if(sc->scene==G.scene) {
234                         ScrArea *sa= sc->areabase.first;
235                         while(sa) {
236                                 SpaceLink *sl= sa->spacedata.first;
237                                 while(sl) {
238                                         if(sl->spacetype==SPACE_OOPS && val==REDRAW) {
239                                                 if(sa->win) scrarea_queue_winredraw(sa);
240                                         }
241                                         else if(sl->spacetype==SPACE_VIEW3D) {
242                                                 View3D *vd= (View3D*) sl;
243                                                 if(vd->scenelock && vd->localview==0) {
244                                                         vd->lay= G.scene->lay;
245                                                         vd->camera= G.scene->camera;
246                                                         
247                                                         if(vd->camera==0 && vd->persp>1) vd->persp= 1;
248                                                         
249                                                         if( (vd->lay & vd->layact) == 0) {
250                                                                 bit= 0;
251                                                                 while(bit<32) {
252                                                                         if(vd->lay & (1<<bit)) {
253                                                                                 vd->layact= 1<<bit;
254                                                                                 break;
255                                                                         }
256                                                                         bit++;
257                                                                 }
258                                                         }
259                                                         
260                                                         if(val==REDRAW && vd==sa->spacedata.first) {
261                                                                 if(sa->win) scrarea_queue_redraw(sa);
262                                                         }
263                                                 }
264                                         }
265                                         sl= sl->next;
266                                 }
267                                 sa= sa->next;
268                         }
269                 }
270                 sc= sc->id.next;
271         }
272 }
273
274 void handle_view3d_around()
275 {
276         bScreen *sc;
277         
278         if ((U.uiflag & USER_LOCKAROUND)==0) return;
279         
280         /* copies from G.vd->around to other view3ds */
281         
282         sc= G.main->screen.first;
283         
284         while(sc) {
285                 if(sc->scene==G.scene) {
286                         ScrArea *sa= sc->areabase.first;
287                         while(sa) {
288                                 SpaceLink *sl= sa->spacedata.first;
289                                 while(sl) {
290                                         if(sl->spacetype==SPACE_VIEW3D) {
291                                                 View3D *vd= (View3D*) sl;
292                                                 if (vd != G.vd) {
293                                                         vd->around= G.vd->around;
294                                                         if (G.vd->flag & V3D_ALIGN)
295                                                                 vd->flag |= V3D_ALIGN;
296                                                         else
297                                                                 vd->flag &= ~V3D_ALIGN;
298                                                         scrarea_queue_headredraw(sa);
299                                                 }
300                                         }
301                                         sl= sl->next;
302                                 }
303                                 sa= sa->next;
304                         }
305                 }
306                 sc= sc->id.next;
307         }
308 }
309
310 void handle_view3d_lock()
311 {
312         if (G.vd != NULL) {
313                 if(G.vd->localview==0 && G.vd->scenelock && curarea->spacetype==SPACE_VIEW3D) {
314
315                         /* copy to scene */
316                         G.scene->lay= G.vd->lay;
317                         G.scene->camera= G.vd->camera;
318         
319                         copy_view3d_lock(REDRAW);
320                 }
321         }
322 }
323
324 void space_set_commmandline_options(void) {
325         SYS_SystemHandle syshandle;
326         int a;
327                 
328         if ( (syshandle = SYS_GetSystem()) ) {
329                 /* User defined settings */
330                 a= (U.gameflags & USER_VERTEX_ARRAYS);
331                 SYS_WriteCommandLineInt(syshandle, "vertexarrays", a);
332
333                 a= (U.gameflags & USER_DISABLE_SOUND);
334                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
335
336                 a= (U.gameflags & USER_DISABLE_MIPMAP);
337                 set_mipmap(!a);
338                 SYS_WriteCommandLineInt(syshandle, "nomipmap", a);
339
340                 /* File specific settings: */
341                 /* Only test the first one. These two are switched
342                  * simultaneously. */
343                 a= (G.fileflags & G_FILE_SHOW_FRAMERATE);
344                 SYS_WriteCommandLineInt(syshandle, "show_framerate", a);
345                 SYS_WriteCommandLineInt(syshandle, "show_profile", a);
346
347                 /* When in wireframe mode, always draw debug props. */
348                 if (G.vd) {
349                         a = ( (G.fileflags & G_FILE_SHOW_DEBUG_PROPS) 
350                                   || (G.vd->drawtype == OB_WIRE)          
351                                   || (G.vd->drawtype == OB_SOLID)         );
352                         SYS_WriteCommandLineInt(syshandle, "show_properties", a);
353                 }
354
355                 a= (G.fileflags & G_FILE_ENABLE_ALL_FRAMES);
356                 SYS_WriteCommandLineInt(syshandle, "fixedtime", a);
357         }
358 }
359
360 #if GAMEBLENDER == 1
361         /**
362          * These two routines imported from the gameengine, 
363          * I suspect a lot of the resetting stuff is cruft
364          * and can be removed, but it should be checked.
365          */
366 static void SaveState(void)
367 {
368         glPushAttrib(GL_ALL_ATTRIB_BITS);
369
370         init_realtime_GL();
371         init_gl_stuff();
372
373         if(G.scene->camera==0 || G.scene->camera->type!=OB_CAMERA)
374                 error("no (correct) camera");
375
376         waitcursor(1);
377 }
378
379 static void RestoreState(void)
380 {
381         curarea->win_swap = 0;
382         curarea->head_swap=0;
383         allqueue(REDRAWVIEW3D, 1);
384         allqueue(REDRAWBUTSALL, 0);
385         reset_slowparents();
386         waitcursor(0);
387         G.qual= 0;
388         glPopAttrib();
389 }
390
391 static LinkNode *save_and_reset_all_scene_cfra(void)
392 {
393         LinkNode *storelist= NULL;
394         Scene *sc;
395         
396         for (sc= G.main->scene.first; sc; sc= sc->id.next) {
397                 BLI_linklist_prepend(&storelist, (void*) (long) sc->r.cfra);
398                 sc->r.cfra= 1;
399
400                 set_scene_bg(sc);
401         }
402         
403         BLI_linklist_reverse(&storelist);
404         
405         return storelist;
406 }
407
408 static void restore_all_scene_cfra(LinkNode *storelist) {
409         LinkNode *sc_store= storelist;
410         Scene *sc;
411         
412         for (sc= G.main->scene.first; sc; sc= sc->id.next) {
413                 int stored_cfra= (int) sc_store->link;
414                 
415                 sc->r.cfra= stored_cfra;
416                 set_scene_bg(sc);
417                 
418                 sc_store= sc_store->next;
419         }
420         
421         BLI_linklist_free(storelist, NULL);
422 }
423 #endif
424
425 void start_game(void)
426 {
427 #if GAMEBLENDER == 1
428 #ifndef NO_KETSJI
429         Scene *sc, *startscene = G.scene;
430         LinkNode *scene_cfra_store;
431
432                 /* XXX, silly code -  the game engine can
433                  * access any scene through logic, so we try 
434                  * to make sure each scene has a valid camera, 
435                  * just in case the game engine tries to use it.
436                  * 
437                  * Better would be to make a better routine
438                  * in the game engine for finding the camera.
439                  *  - zr
440                  */
441         for (sc= G.main->scene.first; sc; sc= sc->id.next) {
442                 if (!sc->camera) {
443                         Base *base;
444         
445                         for (base= sc->base.first; base; base= base->next)
446                                 if (base->object->type==OB_CAMERA)
447                                         break;
448                         
449                         sc->camera= base?base->object:NULL;
450                 }
451         }
452
453         /* these two lines make sure front and backbuffer are equal. for swapbuffers */
454         markdirty_all();
455         screen_swapbuffers();
456
457         /* can start from header */
458         mywinset(curarea->win);
459     
460         scene_cfra_store= save_and_reset_all_scene_cfra();
461         
462
463         /* game engine will do its own sounds. */
464         sound_stop_all_sounds();
465         sound_exit_audio();
466         
467         /* Before jumping into Ketsji, we configure some settings. */
468         space_set_commmandline_options();
469
470         SaveState();
471         StartKetsjiShell(curarea, startscene->id.name+2, G.main, 1);
472         RestoreState();
473
474         /* Restart BPY - unload the game engine modules. */
475         BPY_end_python();
476         BPY_start_python(0, NULL); /* argc, argv stored there already */
477         BPY_post_start_python(); /* userpref path and menus init */
478
479         restore_all_scene_cfra(scene_cfra_store);
480         set_scene_bg(startscene);
481         
482         if (G.flags & G_FLAGS_AUTOPLAY)
483                 exit_usiblender();
484
485                 /* groups could have changed ipo */
486         allqueue(REDRAWNLA, 0);
487         allqueue(REDRAWACTION, 0);
488         allspace(REMAKEIPO, 0);
489         allqueue(REDRAWIPO, 0);
490 #endif
491 #else
492         notice("Game engine is disabled in this release!");
493 #endif
494 }
495
496 static void changeview3dspace(ScrArea *sa, void *spacedata)
497 {
498         setwinmatrixview3d(0);  /* 0= no pick rect */
499 }
500
501         /* Callable from editmode and faceselect mode from the
502          * moment, would be nice (and is easy) to generalize
503          * to any mode.
504          */
505 static void align_view_to_selected(View3D *v3d)
506 {
507         int nr= pupmenu("Align View%t|To Selected (top)%x2|To Selected (front)%x1|To Selected (side)%x0");
508
509         if (nr!=-1) {
510                 int axis= nr;
511
512                 if ((G.obedit) && (G.obedit->type == OB_MESH)) {
513                         editmesh_align_view_to_selected(v3d, axis);
514                         addqueue(v3d->area->win, REDRAW, 1);
515                 } else if (G.f & G_FACESELECT) {
516                         Object *obact= OBACT;
517                         if (obact && obact->type==OB_MESH) {
518                                 Mesh *me= obact->data;
519
520                                 if (me->tface) {
521                                         faceselect_align_view_to_selected(v3d, me, axis);
522                                         addqueue(v3d->area->win, REDRAW, 1);
523                                 }
524                         }
525                 }
526         }
527 }
528
529 void select_children(Object *ob, int recursive)
530 {
531         Base *base;
532
533         for (base= FIRSTBASE; base; base= base->next)
534                 if (ob == base->object->parent) {
535                         base->flag |= SELECT;
536                         base->object->flag |= SELECT;
537                         if (recursive) select_children(base->object, 1);
538                 }
539 }
540
541 void select_parent(void)        /* Makes parent active and de-selected OBACT */
542 {
543         Base *base, *startbase, *basact=NULL, *oldbasact;
544         
545         if (!(OBACT) || !(OBACT->parent)) return;
546         BASACT->flag &= (~SELECT);
547         BASACT->object->flag &= (~SELECT);
548         startbase=  FIRSTBASE;
549         if(BASACT && BASACT->next) startbase= BASACT->next;
550         base = startbase;
551         while(base) {
552                 if(base->object==BASACT->object->parent) { basact=base; break; }
553                 base=base->next;
554                 if(base==0) base= FIRSTBASE;
555                 if(base==startbase) break;
556         }
557         oldbasact = BASACT;
558         BASACT = basact;
559         basact->flag |= SELECT;         
560         
561         basact->object->flag= basact->flag;
562         
563         set_active_base(basact);
564 }
565
566
567 void select_group_menu(void)
568 {
569         char *str;
570         short nr;
571
572         /* make menu string */
573         
574         str= MEM_mallocN(160, "groupmenu");
575         strcpy(str, "Select Grouped%t|Children%x1|"
576                     "Immediate Children%x2|Parent%x3|"
577                     "Objects on Shared Layers%x4");
578
579         /* here we go */
580         
581         nr= pupmenu(str);
582         MEM_freeN(str);
583         
584         select_group(nr);
585 }
586
587 void select_group(short nr)
588 {
589         Base *base;
590
591         if(nr==4) {
592                 base= FIRSTBASE;
593                 while(base) {
594                         if (base->lay & OBACT->lay) {
595                                 base->flag |= SELECT;
596                                 base->object->flag |= SELECT;
597                         }
598                         base= base->next;
599                 }               
600         }
601         else if(nr==2) select_children(OBACT, 0);
602         else if(nr==1) select_children(OBACT, 1);
603         else if(nr==3) select_parent();
604         
605         allqueue(REDRAWVIEW3D, 0);
606         allqueue(REDRAWBUTSOBJECT, 0);
607         allspace(REMAKEIPO, 0);
608         allqueue(REDRAWIPO, 0);
609 }
610
611 static unsigned short convert_for_nonumpad(unsigned short event)
612 {
613         if (event>=ZEROKEY && event<=NINEKEY) {
614                 return event - ZEROKEY + PAD0;
615         } else if (event==MINUSKEY) {
616                 return PADMINUS;
617         } else if (event==EQUALKEY) {
618                 return PADPLUSKEY;
619         } else if (event==BACKSLASHKEY) {
620                 return PADSLASHKEY;
621         } else {
622                 return event;
623         }
624 }
625
626 /* *************** */
627
628 void BIF_undo_push(char *str)
629 {
630         if(G.obedit) {
631                 if(G.obedit->type==OB_MESH)
632                         undo_push_mesh(str);
633                 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
634                         undo_push_curve(str);
635                 else if (G.obedit->type==OB_FONT)
636                         undo_push_font(str);
637                 else if (G.obedit->type==OB_MBALL)
638                         undo_push_mball(str);
639                 else if (G.obedit->type==OB_LATTICE)
640                         undo_push_lattice(str);
641         }
642         else {
643                 if(U.uiflag & USER_GLOBALUNDO) 
644                         BKE_write_undo(str);
645         }
646 }
647
648 void BIF_undo(void)
649 {       
650         if(G.obedit) {
651                 if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
652                         undo_editmode_step(1);
653         }
654         else {
655                 if(G.f & G_WEIGHTPAINT)
656                         wpaint_undo();
657                 else if(G.f & G_VERTEXPAINT)
658                         vpaint_undo();
659                 else {
660                         /* now also in faceselect mode */
661                         if(U.uiflag & USER_GLOBALUNDO) BKE_undo_step(1);
662                 }
663         }
664 }
665
666 void BIF_redo(void)
667 {
668         if(G.obedit) {
669                 if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
670                         undo_editmode_step(-1);
671         }
672         else {
673                 if(G.f & G_WEIGHTPAINT)
674                         wpaint_undo();
675                 else if(G.f & G_VERTEXPAINT)
676                         vpaint_undo();
677                 else {
678                         /* includes faceselect now */
679                         if(U.uiflag & USER_GLOBALUNDO) BKE_undo_step(-1);
680                 }
681         }
682 }
683
684 void BIF_undo_menu(void)
685 {
686         if(G.obedit) {
687                 if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
688                         undo_editmode_menu();
689                 allqueue(REDRAWALL, 0);
690         }
691         else {
692                 if(G.f & G_WEIGHTPAINT)
693                         ;
694                 else if(G.f & G_VERTEXPAINT)
695                         ;
696                 else {
697                         if(U.uiflag & USER_GLOBALUNDO) {
698                                 char *menu= BKE_undo_menu_string();
699                                 if(menu) {
700                                         short event= pupmenu_col(menu, 20);
701                                         MEM_freeN(menu);
702                                         if(event>0) BKE_undo_number(event);
703                                 }
704                         }
705                 }
706         }
707 }
708
709 /* *************** */
710
711 static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
712 {
713         unsigned short event= evt->event;
714         short val= evt->val;
715         char ascii= evt->ascii;
716         View3D *v3d= curarea->spacedata.first;
717         Object *ob;
718         float *curs;
719         int doredraw= 0, pupval;
720         
721         if(curarea->win==0) return;     /* when it comes from sa->headqread() */
722         
723         if(val) {
724
725                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
726                 if(event==MOUSEY || event==MOUSEX) return;
727                 
728                 if(event==UI_BUT_EVENT) do_butspace(val); // temporal, view3d deserves own queue?
729                 
730                 /* swap mouse buttons based on user preference */
731                 if (U.flag & USER_LMOUSESELECT) {
732                         if (event==LEFTMOUSE) event = RIGHTMOUSE;
733                         else if (event==RIGHTMOUSE) event = LEFTMOUSE;
734                 }
735                 
736                 /* TEXTEDITING?? */
737                 if((G.obedit) && G.obedit->type==OB_FONT) {
738                         switch(event) {
739                         
740                         case LEFTMOUSE:
741                                 mouse_cursor();
742                                 break;
743                         case MIDDLEMOUSE:
744                                 /* use '&' here, because of alt+leftmouse which emulates middlemouse */
745                                 if(U.flag & USER_VIEWMOVE) {
746                                         if((G.qual==LR_SHIFTKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
747                                                 viewmove(0);
748                                         else if((G.qual==LR_CTRLKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
749                                                 viewmove(2);
750                                         else if((G.qual==0) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==LR_ALTKEY)))
751                                                 viewmove(1);
752                                 }
753                                 else {
754                                         if((G.qual==LR_SHIFTKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
755                                                 viewmove(1);
756                                         else if((G.qual==LR_CTRLKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
757                                                 viewmove(2);
758                                         else
759                                                 viewmove(0);
760                                 }
761                                 break;
762                                 
763                         case WHEELUPMOUSE:
764                                 /* Regular:   Zoom in */
765                                 /* Shift:     Scroll up */
766                                 /* Ctrl:      Scroll right */
767                                 /* Alt-Shift: Rotate up */
768                                 /* Alt-Ctrl:  Rotate right */
769
770                                 if( G.qual & LR_SHIFTKEY ) {
771                                         if( G.qual & LR_ALTKEY ) { 
772                                                 G.qual &= ~LR_SHIFTKEY;
773                                                 persptoetsen(PAD2);
774                                                 G.qual |= LR_SHIFTKEY;
775                                         } else {
776                                                 persptoetsen(PAD2);
777                                         }
778                                 } else if( G.qual & LR_CTRLKEY ) {
779                                         if( G.qual & LR_ALTKEY ) { 
780                                                 G.qual &= ~LR_CTRLKEY;
781                                                 persptoetsen(PAD4);
782                                                 G.qual |= LR_CTRLKEY;
783                                         } else {
784                                                 persptoetsen(PAD4);
785                                         }
786                                 } else if(U.uiflag & USER_WHEELZOOMDIR) 
787                                         persptoetsen(PADMINUS);
788                                 else
789                                         persptoetsen(PADPLUSKEY);
790
791                                 doredraw= 1;
792                                 break;
793
794                         case WHEELDOWNMOUSE:
795                                 /* Regular:   Zoom out */
796                                 /* Shift:     Scroll down */
797                                 /* Ctrl:      Scroll left */
798                                 /* Alt-Shift: Rotate down */
799                                 /* Alt-Ctrl:  Rotate left */
800
801                                 if( G.qual & LR_SHIFTKEY ) {
802                                         if( G.qual & LR_ALTKEY ) { 
803                                                 G.qual &= ~LR_SHIFTKEY;
804                                                 persptoetsen(PAD8);
805                                                 G.qual |= LR_SHIFTKEY;
806                                         } else {
807                                                 persptoetsen(PAD8);
808                                         }
809                                 } else if( G.qual & LR_CTRLKEY ) {
810                                         if( G.qual & LR_ALTKEY ) { 
811                                                 G.qual &= ~LR_CTRLKEY;
812                                                 persptoetsen(PAD6);
813                                                 G.qual |= LR_CTRLKEY;
814                                         } else {
815                                                 persptoetsen(PAD6);
816                                         }
817                                 } else if(U.uiflag & USER_WHEELZOOMDIR) 
818                                         persptoetsen(PADPLUSKEY);
819                                 else
820                                         persptoetsen(PADMINUS);
821                                 
822                                 doredraw= 1;
823                                 break;
824
825                         case UKEY:
826                                 if(G.qual==LR_ALTKEY) {
827                                         remake_editText();
828                                         doredraw= 1;
829                                 } 
830                                 else {
831                                         do_textedit(event, val, ascii);
832                                 }
833                                 break;
834                         case VKEY:
835                                 if(G.qual==LR_ALTKEY) {
836                                         paste_editText();
837                                         doredraw= 1;
838                                 } 
839                                 else {
840                                         do_textedit(event, val, ascii);
841                                 }
842                                 break;
843                         case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
844                         case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
845                         case PADENTER:
846                                 persptoetsen(event);
847                                 doredraw= 1;
848                                 break;
849                                 
850                         default:
851                                 do_textedit(event, val, ascii);
852                                 break;
853                         }
854                 }
855                 else {
856
857                         if (U.flag & USER_NONUMPAD) {
858                                 event= convert_for_nonumpad(event);
859                         }
860
861                         switch(event) {
862                         
863                         case BACKBUFDRAW:
864                                 backdrawview3d(1);
865                                 break;
866                                                 
867                         /* LEFTMOUSE and RIGHTMOUSE event codes can be swapped above,
868                          * based on user preference USER_LMOUSESELECT
869                          */
870                         case LEFTMOUSE: 
871                                 if ((G.obedit) || !(G.f&(G_VERTEXPAINT|G_WEIGHTPAINT|G_TEXTUREPAINT))) {
872                                         mouse_cursor();
873                                 } else if (G.f & G_VERTEXPAINT) {
874                                         vertex_paint();
875                                 }
876                                 else if (G.f & G_WEIGHTPAINT){
877                                         weight_paint();
878                                 }
879                                 else if (G.f & G_TEXTUREPAINT) {
880                                         face_draw();
881                                 }
882                                 break;
883                         case MIDDLEMOUSE:
884                                 /* use '&' here, because of alt+leftmouse which emulates middlemouse */
885                                 if(U.flag & USER_VIEWMOVE) {
886                                         if((G.qual==LR_SHIFTKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
887                                                 viewmove(0);
888                                         else if((G.qual==LR_CTRLKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
889                                                 viewmove(2);
890                                         else if((G.qual==0) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==LR_ALTKEY)))
891                                                 viewmove(1);
892                                 }
893                                 else {
894                                         if((G.qual==LR_SHIFTKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
895                                                 viewmove(1);
896                                         else if((G.qual==LR_CTRLKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
897                                                 viewmove(2);
898                                         else if((G.qual==0) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==LR_ALTKEY)))
899                                                 viewmove(0);
900                                 }
901                                 break;
902                         case RIGHTMOUSE:
903                                 if((G.obedit) && (G.qual & LR_CTRLKEY)==0) {
904                                         if(G.obedit->type==OB_MESH)
905                                                 mouse_mesh();
906                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
907                                                 mouse_nurb();
908                                         else if(G.obedit->type==OB_MBALL)
909                                                 mouse_mball();
910                                         else if(G.obedit->type==OB_LATTICE)
911                                                 mouse_lattice();
912                                         else if(G.obedit->type==OB_ARMATURE)
913                                                 mouse_armature();
914                                 }
915                                 else if((G.obedit) && (G.qual == (LR_CTRLKEY|LR_ALTKEY)))
916                                         mouse_mesh();   // loop select for 1 mousebutton dudes
917                                 else if((G.obedit) && (G.qual == (LR_CTRLKEY|LR_ALTKEY|LR_SHIFTKEY)))
918                                         mouse_mesh();   // loop select for 1 mousebutton dudes
919                                 else if(G.obpose) { 
920                                         if (G.obpose->type==OB_ARMATURE)
921                                                 mousepose_armature();
922                                 }
923                                 else if(G.qual==LR_CTRLKEY)
924                                         mouse_select(); // also allow in editmode, for vertex parenting
925                                 else if(G.f & G_FACESELECT)
926                                         face_select();
927                                 else if( G.f & (G_VERTEXPAINT|G_TEXTUREPAINT))
928                                         sample_vpaint();
929                                 else
930                                         mouse_select();
931                                 break;
932                         case WHEELUPMOUSE:
933                                 /* Regular:   Zoom in */
934                                 /* Shift:     Scroll up */
935                                 /* Ctrl:      Scroll right */
936                                 /* Alt-Shift: Rotate up */
937                                 /* Alt-Ctrl:  Rotate right */
938
939                                 if( G.qual & LR_SHIFTKEY ) {
940                                         if( G.qual & LR_ALTKEY ) { 
941                                                 G.qual &= ~LR_SHIFTKEY;
942                                                 persptoetsen(PAD2);
943                                                 G.qual |= LR_SHIFTKEY;
944                                         } else {
945                                                 persptoetsen(PAD2);
946                                         }
947                                 } else if( G.qual & LR_CTRLKEY ) {
948                                         if( G.qual & LR_ALTKEY ) { 
949                                                 G.qual &= ~LR_CTRLKEY;
950                                                 persptoetsen(PAD4);
951                                                 G.qual |= LR_CTRLKEY;
952                                         } else {
953                                                 persptoetsen(PAD4);
954                                         }
955                                 } else if(U.uiflag & USER_WHEELZOOMDIR) 
956                                         persptoetsen(PADMINUS);
957                                 else
958                                         persptoetsen(PADPLUSKEY);
959
960                                 doredraw= 1;
961                                 break;
962                         case WHEELDOWNMOUSE:
963                                 /* Regular:   Zoom out */
964                                 /* Shift:     Scroll down */
965                                 /* Ctrl:      Scroll left */
966                                 /* Alt-Shift: Rotate down */
967                                 /* Alt-Ctrl:  Rotate left */
968
969                                 if( G.qual & LR_SHIFTKEY ) {
970                                         if( G.qual & LR_ALTKEY ) { 
971                                                 G.qual &= ~LR_SHIFTKEY;
972                                                 persptoetsen(PAD8);
973                                                 G.qual |= LR_SHIFTKEY;
974                                         } else {
975                                                 persptoetsen(PAD8);
976                                         }
977                                 } else if( G.qual & LR_CTRLKEY ) {
978                                         if( G.qual & LR_ALTKEY ) { 
979                                                 G.qual &= ~LR_CTRLKEY;
980                                                 persptoetsen(PAD6);
981                                                 G.qual |= LR_CTRLKEY;
982                                         } else {
983                                                 persptoetsen(PAD6);
984                                         }
985                                 } else if(U.uiflag & USER_WHEELZOOMDIR) 
986                                         persptoetsen(PADPLUSKEY);
987                                 else
988                                         persptoetsen(PADMINUS);
989                                 
990                                 doredraw= 1;
991                                 break;
992                         
993                         case ONEKEY:
994                                 ob= OBACT;
995                                 if(G.qual==LR_CTRLKEY) {
996                                         if(ob && ob->type == OB_MESH) {
997                                                 flip_subdivison(ob, 1);
998                                         }
999                                 }
1000                                 else do_layer_buttons(0); 
1001                                 break;
1002                                 
1003                         case TWOKEY:
1004                                 ob= OBACT;
1005                                 if(G.qual==LR_CTRLKEY) {
1006                                         if(ob && ob->type == OB_MESH) {
1007                                                 flip_subdivison(ob, 2);
1008                                         }
1009                                 }
1010                                 else do_layer_buttons(1); 
1011                                 break;
1012                                 
1013                         case THREEKEY:
1014                                 ob= OBACT;
1015                                 if(G.qual==LR_CTRLKEY) {
1016                                         if(ob && ob->type == OB_MESH) {
1017                                                 flip_subdivison(ob, 3);
1018                                         }
1019                                 }
1020                                 else do_layer_buttons(2); 
1021                                 break;
1022                                 
1023                         case FOURKEY:
1024                                 ob= OBACT;
1025                                 if(G.qual==LR_CTRLKEY) {
1026                                         if(ob && ob->type == OB_MESH) {
1027                                                 flip_subdivison(ob, 4);
1028                                         }
1029                                 }
1030                                 else do_layer_buttons(3); 
1031                                 break;
1032                                 
1033                         case FIVEKEY:
1034                                 do_layer_buttons(4); break;
1035                         case SIXKEY:
1036                                 do_layer_buttons(5); break;
1037                         case SEVENKEY:
1038                                 do_layer_buttons(6); break;
1039                         case EIGHTKEY:
1040                                 do_layer_buttons(7); break;
1041                         case NINEKEY:
1042                                 do_layer_buttons(8); break;
1043                         case ZEROKEY:
1044                                 do_layer_buttons(9); break;
1045                         case MINUSKEY:
1046                                 do_layer_buttons(10); break;
1047                         case EQUALKEY:
1048                                 do_layer_buttons(11); break;
1049                         case ACCENTGRAVEKEY:
1050                                 do_layer_buttons(-1); break;
1051                                 
1052                         case AKEY:
1053                                 if(G.qual & LR_CTRLKEY) apply_object(); // also with shift!
1054                                 else if((G.qual==LR_SHIFTKEY)) {
1055                                         toolbox_n_add();
1056                                 }
1057                                 else {
1058                                         if(G.obedit) {
1059                                                 if(G.obedit->type==OB_MESH)
1060                                                         deselectall_mesh();
1061                                                 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
1062                                                         deselectall_nurb();
1063                                                 else if(G.obedit->type==OB_MBALL)
1064                                                         deselectall_mball();
1065                                                 else if(G.obedit->type==OB_LATTICE)
1066                                                         deselectall_Latt();
1067                                                 else if(G.obedit->type==OB_ARMATURE)
1068                                                         deselectall_armature();
1069                                         }
1070                                         else if (G.obpose){
1071                                                 switch (G.obpose->type){
1072                                                 case OB_ARMATURE:
1073                                                         deselectall_posearmature(1);
1074                                                         break;
1075                                                 }
1076                                         }
1077                                         else {
1078                                                 if(G.f & G_FACESELECT) deselectall_tface();
1079                                                 else {
1080                                                         /* by design, the center of the active object 
1081                                                          * (which need not necessarily by selected) will
1082                                                          * still be drawn as if it were selected.
1083                                                          */
1084                                                         deselectall();
1085                                                 }
1086                                         }
1087                                 }
1088                                 break;
1089                         case BKEY:
1090                                 if((G.qual==LR_SHIFTKEY))
1091                                         set_render_border();
1092                                 else if((G.qual==LR_ALTKEY)){
1093                                         if(G.obedit && G.obedit->type==OB_MESH) {
1094                                                 /* Loop Select Operations */
1095                                                 /*   Vertexloop */
1096                                                 /*   Faceloop   */                                              
1097                                                 vertex_loop_select(); 
1098                                         }
1099                                 }
1100                                 else if((G.qual==0))
1101                                         borderselect();
1102                                 break;
1103                         case CKEY:
1104                                 if(G.qual==LR_CTRLKEY) {
1105                                         copy_attr_menu();
1106                                 }
1107                                 else if(G.qual==LR_ALTKEY) {
1108                                         convertmenu();  /* editobject.c */
1109                                 }
1110                                 else if((G.qual==LR_SHIFTKEY)) {
1111                                         view3d_home(1);
1112                                         curs= give_cursor();
1113                                         curs[0]=curs[1]=curs[2]= 0.0;
1114                                         allqueue(REDRAWVIEW3D, 0);
1115                                 }
1116                                 else if((G.obedit) && ELEM(G.obedit->type, OB_CURVE, OB_SURF) ) {
1117                                         makecyclicNurb();
1118                                         makeDispList(G.obedit);
1119                                         allqueue(REDRAWVIEW3D, 0);
1120                                 }
1121                                 else if((G.qual==0)){
1122                                         curs= give_cursor();
1123                                         G.vd->ofs[0]= -curs[0];
1124                                         G.vd->ofs[1]= -curs[1];
1125                                         G.vd->ofs[2]= -curs[2];
1126                                         scrarea_queue_winredraw(curarea);
1127                                 }
1128                         
1129                                 break;
1130                         case DKEY:
1131                                 if((G.qual==LR_SHIFTKEY)) {
1132                                         duplicate_context_selected();
1133                                 }
1134                                 else if(G.qual==LR_ALTKEY) {
1135                                         if(G.obpose)
1136                                                 error ("Duplicate not possible in posemode.");
1137                                         else if((G.obedit==0))
1138                                                 adduplicate(0);
1139                                 }
1140                                 else if(G.qual==LR_CTRLKEY) {
1141                                         imagestodisplist();
1142                                 }
1143                                 else if((G.qual==0)){
1144                                         pupval= pupmenu("Draw mode%t|BoundBox %x1|Wire %x2|OpenGL Solid %x3|Shaded Solid %x4|Textured Solid %x5");
1145                                         if(pupval>0) {
1146                                                 G.vd->drawtype= pupval;
1147                                                 doredraw= 1;
1148                                         
1149                                         }
1150                                 }
1151                                 
1152                                 break;
1153                         case EKEY:
1154                                 if (G.qual==0){
1155                                         if(G.obedit) {
1156                                                 if(G.obedit->type==OB_MESH)
1157                                                         extrude_mesh();
1158                                                 else if(G.obedit->type==OB_CURVE)
1159                                                         addvert_Nurb('e');
1160                                                 else if(G.obedit->type==OB_SURF)
1161                                                         extrude_nurb();
1162                                                 else if(G.obedit->type==OB_ARMATURE)
1163                                                         extrude_armature();
1164                                         }
1165                                         else {
1166                                                 ob= OBACT;
1167                                                 if(ob && ob->type==OB_IKA) if(okee("extrude IKA"))
1168                                                         extrude_ika(ob, 1);
1169                                         }
1170                                 }
1171                                 else if (G.qual==LR_CTRLKEY) {
1172                                         if(G.obedit && G.obedit->type==OB_MESH)
1173                                                 Edge_Menu();
1174                                 }
1175                                 else if (G.qual==LR_SHIFTKEY) {
1176                                         if (G.obedit && G.obedit->type==OB_MESH) {
1177                                                 transform('e');
1178                                         }
1179                                 }
1180                                 break;
1181                         case FKEY:
1182                                 if(G.obedit) {
1183                                         if(G.obedit->type==OB_MESH) {
1184                                                 if((G.qual==LR_SHIFTKEY))
1185                                                         fill_mesh();
1186                                                 else if(G.qual==LR_ALTKEY)
1187                                                         beauty_fill();
1188                                                 else if(G.qual==LR_CTRLKEY)
1189                                                         edge_flip();
1190                                                 else if (G.qual==0)
1191                                                         addedgeface_mesh();
1192                                         }
1193                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addsegment_nurb();
1194                                 }
1195                                 else if(G.qual==LR_CTRLKEY)
1196                                         sort_faces();
1197                                 else if((G.qual==LR_SHIFTKEY))
1198                                         fly();
1199                                 else {
1200                                                 set_faceselect();
1201                                         }
1202                                 
1203                                 break;
1204                         case GKEY:
1205                                 /* RMGRP if(G.qual & LR_CTRLKEY) add_selected_to_group();
1206                                 else if(G.qual & LR_ALTKEY) rem_selected_from_group(); */
1207                                 if((G.qual==LR_SHIFTKEY))
1208                                         select_group_menu();
1209                                 else if(G.qual==LR_ALTKEY)
1210                                         clear_object('g');
1211                                 else if((G.qual==0))
1212                                         transform('g');
1213                                 break;
1214                         case HKEY:
1215                                 if(G.obedit) {
1216                                         if(G.obedit->type==OB_MESH) {
1217                                                 if(G.qual==LR_CTRLKEY)
1218                                                         add_hook();
1219                                                 else if(G.qual==LR_ALTKEY)
1220                                                         reveal_mesh();
1221                                                 else if((G.qual==LR_SHIFTKEY))
1222                                                         hide_mesh(1);
1223                                                 else if((G.qual==0)) 
1224                                                         hide_mesh(0);
1225                                         }
1226                                         else if(G.obedit->type== OB_SURF) {
1227                                                 if(G.qual==LR_CTRLKEY)
1228                                                         add_hook();
1229                                                 else if(G.qual==LR_ALTKEY)
1230                                                         revealNurb();
1231                                                 else if((G.qual==LR_SHIFTKEY))
1232                                                         hideNurb(1);
1233                                                 else if((G.qual==0))
1234                                                         hideNurb(0);
1235                                         }
1236                                         else if(G.obedit->type==OB_CURVE) {
1237                                                 if(G.qual==LR_CTRLKEY)
1238                                                         add_hook();
1239                                                 else {
1240                                                         if(G.qual==LR_CTRLKEY)
1241                                                                 autocalchandlesNurb_all(1);     /* flag=1, selected */
1242                                                         else if((G.qual==LR_SHIFTKEY))
1243                                                                 sethandlesNurb(1);
1244                                                         else if((G.qual==0))
1245                                                                 sethandlesNurb(3);
1246                                                         
1247                                                         makeDispList(G.obedit);
1248                                                         BIF_undo_push("Handle change");
1249                                                         allqueue(REDRAWVIEW3D, 0);
1250                                                 }
1251                                         }
1252                                         else if(G.obedit->type==OB_LATTICE) {
1253                                                 if(G.qual==LR_CTRLKEY) add_hook();
1254                                         }
1255                                 }
1256                                 else if(G.f & G_FACESELECT)
1257                                         hide_tface();
1258                                 else if(G.obpose) {
1259                                         if (G.qual==0)
1260                                                 hide_selected_pose_bones();
1261                                         else if (G.qual==LR_SHIFTKEY)
1262                                                 hide_unselected_pose_bones();
1263                                         else if (G.qual==LR_ALTKEY)
1264                                                 show_all_pose_bones();
1265                                 }
1266                                 break;
1267                         case IKEY:
1268                                 break;
1269                                 
1270                         case JKEY:
1271                                 if(G.qual==LR_CTRLKEY) {
1272                                         if( (ob= OBACT) ) {
1273                                                 if(ob->type == OB_MESH)
1274                                                         join_mesh();
1275                                                 else if(ob->type == OB_CURVE)
1276                                                         join_curve(OB_CURVE);
1277                                                 else if(ob->type == OB_SURF)
1278                                                         join_curve(OB_SURF);
1279                                                 else if(ob->type == OB_ARMATURE)
1280                                                         join_armature ();
1281                                         }
1282                                         else if ((G.obedit) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
1283                                                 addsegment_nurb();
1284                                 }
1285                                 else if(G.obedit) {
1286                                         if(G.obedit->type==OB_MESH) {
1287                                                 join_triangles();
1288                                         }
1289                                 }
1290
1291                                 break;
1292                         case KKEY:
1293                                 if(G.obedit) {
1294                                         if (G.obedit->type==OB_MESH) {
1295                                                 if (G.qual==LR_SHIFTKEY)
1296                                                         KnifeSubdivide(KNIFE_PROMPT);
1297                                                 else if (G.qual==0)
1298                                                         LoopMenu();
1299                                         }
1300                                         else if(G.obedit->type==OB_SURF)
1301                                                 printknots();
1302                                 }
1303                                 else {
1304                                         if((G.qual==LR_SHIFTKEY)) {
1305                                                 if(G.f & G_FACESELECT)
1306                                                         clear_vpaint_selectedfaces();
1307                                                 else if(G.f & G_VERTEXPAINT)
1308                                                         clear_vpaint();
1309                                                 else
1310                                                         select_select_keys();
1311                                         }
1312                                         else if(G.qual==LR_CTRLKEY)
1313                                                 make_skeleton();
1314 /*                                      else if(G.qual & LR_ALTKEY) delete_skeleton(); */
1315                                         else if (G.qual==0)
1316                                                 set_ob_ipoflags();
1317                                 }
1318                                 
1319                                 break;
1320                         case LKEY:
1321                                 if(G.obedit) {
1322                                         if(G.obedit->type==OB_MESH)
1323                                                 selectconnected_mesh(G.qual);
1324                                         if(G.obedit->type==OB_ARMATURE)
1325                                                 selectconnected_armature();
1326                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
1327                                                 selectconnected_nurb();
1328                                 }
1329                                 else if(G.obpose) {
1330                                         if(G.obpose->type==OB_ARMATURE)
1331                                                 selectconnected_posearmature();
1332                                 }
1333                                 else {
1334                                         if((G.qual==LR_SHIFTKEY))
1335                                                 selectlinks_menu();
1336                                         else if(G.qual==LR_CTRLKEY)
1337                                                 make_links_menu();
1338                                         else if(G.f & G_FACESELECT)
1339                                                 select_linked_tfaces();
1340                                         else if((G.qual==0))
1341                                                 make_local();
1342                                 }
1343                                 break;
1344                         case MKEY:
1345                                 if(G.obedit){
1346                                         if(G.qual==LR_ALTKEY) {
1347                                                 if(G.obedit->type==OB_MESH) {
1348                                                         mergemenu();
1349                                                         makeDispList(G.obedit);
1350                                                 }
1351                                         }
1352                                         else if((G.qual==0) || (G.qual==LR_CTRLKEY)) {
1353                                                 mirrormenu();
1354                                         }
1355                                         if(G.qual & (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY)) {
1356                                                 if(G.obedit->type==OB_MESH) select_non_manifold();
1357                                         }
1358                                 }
1359                                 else if(G.qual & LR_CTRLKEY) {
1360                                         mirrormenu();
1361                                 }
1362                                 else if(G.qual==0) {
1363                                      movetolayer();
1364                                 }
1365                                 break;
1366                         case NKEY:
1367                                 if((G.qual==0)) {
1368                                         toggle_blockhandler(curarea, VIEW3D_HANDLER_OBJECT, UI_PNL_TO_MOUSE);
1369                                         allqueue(REDRAWVIEW3D, 0);
1370                                 }
1371                                 else if(G.obedit) {
1372                                         switch (G.obedit->type){
1373                                         case OB_ARMATURE:
1374                                                 if(G.qual==LR_CTRLKEY){
1375                                                         if (okee("Recalculate bone roll angles")) {
1376                                                                 auto_align_armature();
1377                                                                 allqueue(REDRAWVIEW3D, 0);
1378                                                         }
1379                                                 }
1380                                                 break;
1381                                         case OB_MESH: 
1382                                                 if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
1383                                                         if(okee("Recalculate normals inside")) {
1384                                                                 righthandfaces(2);
1385                                                                 allqueue(REDRAWVIEW3D, 0);
1386                                                                 BIF_undo_push("Recalculate normals inside");
1387                                                         }
1388                                                 }
1389                                                 else if(G.qual==LR_CTRLKEY){
1390                                                         if(okee("Recalculate normals outside")) {
1391                                                                 righthandfaces(1);
1392                                                                 allqueue(REDRAWVIEW3D, 0);
1393                                                                 BIF_undo_push("Recalculate normals outside");
1394                                                         }
1395                                                 }
1396                                                 break;
1397                                         }
1398                                 }
1399                                 
1400                                 break;
1401                         case OKEY:
1402                                 ob= OBACT;
1403                                 if(G.obedit) {
1404                                         extern int prop_mode;
1405
1406                                         if (G.qual==LR_SHIFTKEY) {
1407                                                 prop_mode= !prop_mode;
1408                                                 allqueue(REDRAWHEADERS, 0);
1409                                         }
1410                                         else if((G.qual==0)) {
1411                                                 G.f ^= G_PROPORTIONAL;
1412                                                 allqueue(REDRAWHEADERS, 0);
1413                                         }
1414                                 }
1415                                 else if((G.qual==LR_SHIFTKEY)) {
1416                                         if(ob && ob->type == OB_MESH) {
1417                                                 flip_subdivison(ob, -1);
1418                                         }
1419                                 }
1420                                 else if(G.qual==LR_ALTKEY) clear_object('o');
1421                                 break;
1422
1423                         case PKEY:
1424                                 
1425                                 if(G.obedit) {
1426                                         if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
1427                                                 make_parent();
1428                                         else if((G.qual==0) && G.obedit->type==OB_MESH)
1429                                                 separatemenu();
1430                                         else if ((G.qual==0) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
1431                                                 separate_nurb();
1432                                 }
1433                                 else if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
1434                                         make_parent();
1435                                 else if(G.qual==LR_ALTKEY)
1436                                         clear_parent();
1437                                 else if((G.qual==0)) {
1438                         start_game();
1439                                 }
1440                                 break;                          
1441                         case RKEY:
1442                                 if((G.obedit==0) && (G.f & G_FACESELECT) && (G.qual==0))
1443                                         rotate_uv_tface();
1444                                 else if(G.qual==LR_ALTKEY)
1445                                         clear_object('r');
1446                                 else if (G.obedit) {
1447                                         if((G.qual==LR_SHIFTKEY)) {
1448                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF)                                     
1449                                                         selectrow_nurb();
1450                                                 else if (G.obedit->type==OB_MESH)
1451                                                         loopoperations(LOOP_SELECT);
1452                                         }
1453                                         else if(G.qual==LR_CTRLKEY) {
1454                                                 if (G.obedit->type==OB_MESH)
1455                                                         loopoperations(LOOP_CUT);
1456                                         }
1457                                         else if((G.qual==0))
1458                                                 transform('r');
1459                                 }
1460                                 else if((G.qual==0))
1461                                         transform('r');
1462                                 break;
1463                         case SKEY:
1464                                 if(G.obedit) {
1465                                         if(G.qual==LR_ALTKEY)
1466                                                 transform('N'); /* scale along normal */
1467                                         else if(G.qual==LR_CTRLKEY)
1468                                                 transform('S');
1469                                         else if(G.qual==LR_SHIFTKEY)
1470                                                 snapmenu();
1471                                         else if((G.qual==0))
1472                                                 transform('s');
1473                                 }
1474                                 else if(G.qual==LR_ALTKEY) {
1475                                         clear_object('s');
1476                                 }
1477                                 else if((G.qual==LR_SHIFTKEY))
1478                                         snapmenu();
1479                                 else if((G.qual==0))
1480                                         transform('s');
1481                                 break;
1482                         case TKEY:
1483                                 if(G.obedit){
1484                                         if((G.qual==LR_CTRLKEY) && G.obedit->type==OB_MESH) {
1485                                                 convert_to_triface(0);
1486                                                 allqueue(REDRAWVIEW3D, 0);
1487                                                 countall();
1488                                                 makeDispList(G.obedit);
1489                                         }
1490                                         else if((G.qual==LR_ALTKEY) && G.obedit->type==OB_CURVE)
1491                                                 clear_tilt();
1492                                         else if((G.qual==0))
1493                                                 transform('t');
1494                                 }
1495                                 else if(G.qual==LR_CTRLKEY) {
1496                                         make_track();
1497                                 }
1498                                 else if(G.qual==LR_ALTKEY) {
1499                                         clear_track();
1500                                 }
1501                                 else if((G.qual==0)){
1502                                         texspace_edit();
1503                                 }
1504                                 
1505                                 break;
1506                         case UKEY:
1507                                 if(G.obedit) {
1508                                         if(G.obedit->type==OB_MESH) {
1509                                                 if(G.qual==0) BIF_undo(); else BIF_redo();
1510                                         }
1511                                         else if(G.obedit->type==OB_ARMATURE)
1512                                                 remake_editArmature();
1513                                         else if ELEM4(G.obedit->type, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE) {
1514                                                 if(G.qual==0) BIF_undo(); else BIF_redo();
1515                                         }
1516                                 }
1517                                 else if((G.qual==0)) {
1518                                         if (G.f & G_FACESELECT)
1519                                                 uv_autocalc_tface();
1520                                         else if(G.f & G_WEIGHTPAINT)
1521                                                 wpaint_undo();
1522                                         else if(G.f & G_VERTEXPAINT)
1523                                                 vpaint_undo();
1524                                         else {
1525                                                 single_user();
1526                                         }
1527                                 }
1528                                         
1529                                 break;
1530                         case VKEY:
1531                                 ob= OBACT;
1532                                 if((G.qual==LR_SHIFTKEY)) {
1533                                         if ((G.obedit) && G.obedit->type==OB_MESH) {
1534                                                 align_view_to_selected(v3d);
1535                                         }
1536                                         else if (G.f & G_FACESELECT) {
1537                                                 align_view_to_selected(v3d);
1538                                         }
1539                                 }
1540                                 else if(G.qual==LR_ALTKEY)
1541                                         image_aspect();
1542                                 else if (G.qual==0){
1543                                         if(G.obedit) {
1544                                                 if(G.obedit->type==OB_CURVE) {
1545                                                         sethandlesNurb(2);
1546                                                         makeDispList(G.obedit);
1547                                                         allqueue(REDRAWVIEW3D, 0);
1548                                                         BIF_undo_push("Handle change");
1549                                                 }
1550                                         }
1551                                         else if(ob && ob->type == OB_MESH) 
1552                                                 set_vpaint();
1553                                 }
1554                                 break;
1555                         case WKEY:
1556                                 if((G.qual==LR_SHIFTKEY)) {
1557                                         transform('w');
1558                                 }
1559                                 else if(G.qual==LR_ALTKEY) {
1560                                         /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
1561                                 }
1562                                 else if(G.qual==LR_CTRLKEY) {
1563                                         if(G.obedit) {
1564                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF) {
1565                                                         switchdirectionNurb2();
1566                                                 }
1567                                         }
1568                                 }
1569                                 else if((G.qual==0))
1570                                         special_editmenu();
1571                                 
1572                                 break;
1573                         case XKEY:
1574                         case DELKEY:
1575                                 if(G.qual==0)
1576                                         delete_context_selected();
1577                                 break;
1578                         case YKEY:
1579                                 if((G.qual==0) && (G.obedit)) {
1580                                         if(G.obedit->type==OB_MESH) split_mesh();
1581                                 }
1582                                 break;
1583                         case ZKEY:
1584                                 toggle_shading();
1585                                 
1586                                 scrarea_queue_headredraw(curarea);
1587                                 scrarea_queue_winredraw(curarea);
1588                                 break;
1589                         
1590                         case HOMEKEY:
1591                                 if(G.qual==0)
1592                                         view3d_home(0);
1593                                 break;
1594                         case COMMAKEY:
1595                                 if(G.qual==LR_CTRLKEY) {
1596                                         G.vd->around= V3D_CENTROID;
1597                                 } else if(G.qual==LR_SHIFTKEY) {
1598                                         G.vd->around= V3D_CENTROID;
1599                                 } else if(G.qual==0) {
1600                                         G.vd->around= V3D_CENTRE;
1601                                 }
1602                                 scrarea_queue_headredraw(curarea);
1603                                 break;
1604                                 
1605                         case PERIODKEY:
1606                                 if(G.qual==LR_CTRLKEY) {
1607                                         G.vd->around= V3D_LOCAL;
1608                                 }       else if(G.qual==0) {
1609                                         G.vd->around= V3D_CURSOR;
1610                                 }
1611                                 scrarea_queue_headredraw(curarea);
1612                                 break;
1613                         
1614                         case PADSLASHKEY:
1615                                 if(G.qual==0) {
1616                                         if(G.vd->localview) {
1617                                                 G.vd->localview= 0;
1618                                                 endlocalview(curarea);
1619                                         }
1620                                         else {
1621                                                 G.vd->localview= 1;
1622                                                 initlocalview();
1623                                         }
1624                                         scrarea_queue_headredraw(curarea);
1625                                 }
1626                                 break;
1627                         case PADASTERKEY:       /* '*' */
1628                                 if(G.qual==0) {
1629                                         ob= OBACT;
1630                                         if(ob) {
1631                                                 obmat_to_viewmat(ob);
1632                                                 if(G.vd->persp==2) G.vd->persp= 1;
1633                                                 scrarea_queue_winredraw(curarea);
1634                                         }
1635                                 }
1636                                 break;
1637                         case PADPERIOD: /* '.' */
1638                                 if(G.qual==0)
1639                                         centreview();
1640                                 break;
1641                         
1642                         case PAGEUPKEY:
1643                                 if(G.qual==LR_CTRLKEY)
1644                                         movekey_obipo(1);
1645                                 else if((G.qual==0))
1646                                         nextkey_obipo(1);       /* in editipo.c */
1647                                 break;
1648
1649                         case PAGEDOWNKEY:
1650                                 if(G.qual==LR_CTRLKEY)
1651                                         movekey_obipo(-1);
1652                                 else if((G.qual==0))
1653                                         nextkey_obipo(-1);
1654                                 break;
1655                                 
1656                         case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
1657                         case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
1658                         case PADENTER:
1659                                 persptoetsen(event);
1660                                 doredraw= 1;
1661                                 break;
1662                         case PADMINUS:
1663                                 if ( (G.qual==LR_CTRLKEY)
1664                                          && (G.obedit) && (G.obedit->type==OB_MESH) )
1665                                         select_less();
1666                                 else {
1667                                         persptoetsen(event);
1668                                         doredraw= 1;
1669                                 }
1670                                 break;
1671
1672                         case PADPLUSKEY:
1673                                 if ( (G.qual==LR_CTRLKEY)
1674                                          && (G.obedit) && (G.obedit->type==OB_MESH) )
1675                                         select_more();
1676                                 else {
1677                                         persptoetsen(event);
1678                                         doredraw= 1;
1679                                 }
1680                                 break;
1681
1682                         case ESCKEY:
1683                                 if(G.qual==0) {
1684                                         if (G.vd->flag & V3D_DISPIMAGE) {
1685                                                 G.vd->flag &= ~V3D_DISPIMAGE;
1686                                                 doredraw= 1;
1687                                         }
1688                                 }
1689                                 break;
1690                         }
1691                 }
1692         }
1693         
1694         if(doredraw) {
1695                 scrarea_queue_winredraw(curarea);
1696                 scrarea_queue_headredraw(curarea);
1697         }
1698 }
1699
1700 static void initview3d(ScrArea *sa)
1701 {
1702         View3D *vd;
1703         
1704         vd= MEM_callocN(sizeof(View3D), "initview3d");
1705         BLI_addhead(&sa->spacedata, vd);        /* addhead! not addtail */
1706
1707         vd->spacetype= SPACE_VIEW3D;
1708         vd->blockscale= 0.7;
1709         vd->viewquat[0]= 1.0;
1710         vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0;
1711         vd->persp= 1;
1712         vd->drawtype= OB_WIRE;
1713         vd->view= 7;
1714         vd->dist= 10.0;
1715         vd->lens= 35.0f;
1716         vd->near= 0.01f;
1717         vd->far= 500.0f;
1718         vd->grid= 1.0f;
1719         vd->gridlines= 16;
1720         vd->lay= vd->layact= 1;
1721         if(G.scene) {
1722                 vd->lay= vd->layact= G.scene->lay;
1723                 vd->camera= G.scene->camera;
1724         }
1725         vd->scenelock= 1;
1726         vd->gridflag |= V3D_SHOW_X;
1727         vd->gridflag |= V3D_SHOW_Y;
1728         vd->gridflag |= V3D_SHOW_FLOOR;
1729         vd->gridflag &= ~V3D_SHOW_Z;
1730 }
1731
1732
1733 /* ******************** SPACE: IPO ********************** */
1734
1735 static void changeview2dspace(ScrArea *sa, void *spacedata)
1736 {
1737         if(G.v2d==0) return;
1738
1739         test_view2d(G.v2d, curarea->winx, curarea->winy);
1740         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
1741 }
1742
1743 static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
1744 {
1745         extern void do_ipobuts(unsigned short event);   // drawipo.c
1746         unsigned short event= evt->event;
1747         short val= evt->val;
1748         SpaceIpo *sipo= curarea->spacedata.first;
1749         View2D *v2d= &sipo->v2d;
1750         float dx, dy;
1751         int cfra, doredraw= 0;
1752         short mval[2];
1753         short mousebut = L_MOUSE;
1754         
1755         if(sa->win==0) return;
1756
1757         if(val) {
1758                 if( uiDoBlocks(&sa->uiblocks, event)!=UI_NOTHING ) event= 0;
1759
1760                 /* swap mouse buttons based on user preference */
1761                 if (U.flag & USER_LMOUSESELECT) {
1762                         if (event == LEFTMOUSE) {
1763                                 event = RIGHTMOUSE;
1764                                 mousebut = L_MOUSE;
1765                         } else if (event == RIGHTMOUSE) {
1766                                 event = LEFTMOUSE;
1767                                 mousebut = R_MOUSE;
1768                         }
1769                 }
1770
1771                 switch(event) {
1772                 case UI_BUT_EVENT:
1773                         /* note: bad bad code, will be cleaned! is because event queues are all shattered */
1774                         if(val>0 && val < 65) do_ipowin_buts(val-1);
1775                         else do_ipobuts(val);
1776                         break;
1777                         
1778                 case LEFTMOUSE:
1779                         if( in_ipo_buttons() ) {
1780                                 do_ipo_selectbuttons();
1781                                 doredraw= 1;
1782                         }
1783                         else if(view2dmove(LEFTMOUSE)); // only checks for sliders
1784                         else if(G.qual & LR_CTRLKEY) add_vert_ipo();
1785                         else {
1786                                 do {
1787                                         getmouseco_areawin(mval);
1788                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
1789                                         
1790                                         cfra= (int)dx;
1791                                         if(cfra< 1) cfra= 1;
1792                                         
1793                                         if( cfra!=CFRA ) {
1794                                                 CFRA= cfra;
1795                                                 update_for_newframe();
1796                                                 force_draw_all(0); /* To make constraint sliders redraw */
1797                                         }
1798                                 
1799                                 } while(get_mbut() & mousebut);
1800                         }
1801                         break;
1802                 case RIGHTMOUSE:
1803                         mouse_select_ipo();
1804                         allqueue (REDRAWACTION, 0);
1805                         allqueue(REDRAWNLA, 0);
1806                         break;
1807                 case MIDDLEMOUSE:
1808                         if(in_ipo_buttons()) {
1809                                 scroll_ipobuts();
1810                         }
1811                         else view2dmove(event); /* in drawipo.c */
1812                         break;
1813                 case WHEELUPMOUSE:
1814                 case WHEELDOWNMOUSE:
1815                         view2dmove(event);      /* in drawipo.c */
1816                         break;
1817                 case PADPLUSKEY:
1818                         view2d_zoom(v2d, 0.1154, sa->winx, sa->winy);
1819                         doredraw= 1;
1820                         break;
1821                 case PADMINUS:
1822                         view2d_zoom(v2d, -0.15, sa->winx, sa->winy);
1823                         doredraw= 1;
1824                         break;
1825                 case PAGEUPKEY:
1826                         if(G.qual==LR_CTRLKEY)
1827                                 movekey_ipo(1);
1828                         else if((G.qual==0))
1829                                 nextkey_ipo(1);
1830                         break;
1831                 case PAGEDOWNKEY:
1832                         if(G.qual==LR_CTRLKEY)
1833                                 movekey_ipo(-1);
1834                         else if((G.qual==0))
1835                                 nextkey_ipo(-1);
1836                         break;
1837                 case HOMEKEY:
1838                         if((G.qual==0))
1839                                 do_ipo_buttons(B_IPOHOME);
1840                         break;
1841                         
1842                 case AKEY:
1843                         if((G.qual==0)) {
1844                                 if(in_ipo_buttons()) {
1845                                         swap_visible_editipo();
1846                                 }
1847                                 else swap_selectall_editipo();
1848                                 allspace (REMAKEIPO, 0);
1849                                 allqueue (REDRAWNLA, 0);
1850                                 allqueue (REDRAWACTION, 0);
1851                         }
1852                         break;
1853                 case BKEY:
1854                         if((G.qual==0))
1855                                 borderselect_ipo();
1856                         break;
1857                 case CKEY:
1858                         if((G.qual==0))
1859                                 move_to_frame();
1860                         break;
1861                 case DKEY:
1862                         if((G.qual==LR_SHIFTKEY))
1863                                 add_duplicate_editipo();
1864                         break;
1865                 case GKEY:
1866                         if((G.qual==0))
1867                                 transform_ipo('g');
1868                         break;
1869                 case HKEY:
1870                         if((G.qual==LR_SHIFTKEY))
1871                                 sethandles_ipo(HD_AUTO);
1872                         else if((G.qual==0))
1873                                 sethandles_ipo(HD_ALIGN);
1874                         break;
1875                 case JKEY:
1876                         if((G.qual==0))
1877                                 join_ipo_menu();
1878                         break;
1879                 case KKEY:
1880                         if((G.qual==0)) {
1881                                 ipo_toggle_showkey();
1882                                 scrarea_queue_headredraw(curarea);
1883                                 allqueue(REDRAWVIEW3D, 0);
1884                                 doredraw= 1;
1885                         }
1886                         break;
1887                 case NKEY:
1888                         toggle_blockhandler(sa, IPO_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
1889                         doredraw= 1;
1890                         break;
1891                 case RKEY:
1892                         if((G.qual==0))
1893                                 ipo_record();
1894                         break;
1895                 case SKEY:
1896                         if((G.qual==LR_SHIFTKEY)) {             
1897                                 ipo_snap_menu();
1898                         } else if((G.qual==0))
1899                                 transform_ipo('s');
1900                         break;
1901                 case TKEY:
1902                         if((G.qual==0))
1903                                 set_ipotype();
1904                         break;
1905                 case VKEY:
1906                         if((G.qual==0))
1907                                 sethandles_ipo(HD_VECT);
1908                         break;
1909                 case XKEY:
1910                 case DELKEY:
1911                         if((G.qual==LR_SHIFTKEY))
1912                                 delete_key();
1913                         else if((G.qual==0))
1914                                 del_ipo();
1915                         break;
1916                 }
1917         }
1918
1919         if(doredraw) scrarea_queue_winredraw(sa);
1920 }
1921
1922 void initipo(ScrArea *sa)
1923 {
1924         SpaceIpo *sipo;
1925         
1926         sipo= MEM_callocN(sizeof(SpaceIpo), "initipo");
1927         BLI_addhead(&sa->spacedata, sipo);
1928
1929         sipo->spacetype= SPACE_IPO;
1930         sipo->blockscale= 0.7;
1931         
1932         /* sipo space loopt van (0,-?) tot (??,?) */
1933         sipo->v2d.tot.xmin= 0.0;
1934         sipo->v2d.tot.ymin= -10.0;
1935         sipo->v2d.tot.xmax= G.scene->r.efra;
1936         sipo->v2d.tot.ymax= 10.0;
1937
1938         sipo->v2d.cur= sipo->v2d.tot;
1939
1940         sipo->v2d.min[0]= 0.01f;
1941         sipo->v2d.min[1]= 0.01f;
1942
1943         sipo->v2d.max[0]= 15000.0f;
1944         sipo->v2d.max[1]= 10000.0f;
1945         
1946         sipo->v2d.scroll= L_SCROLL+B_SCROLL;
1947         sipo->v2d.keeptot= 0;
1948
1949         sipo->blocktype= ID_OB;
1950 }
1951
1952 /* ******************** SPACE: INFO ********************** */
1953
1954 void space_mipmap_button_function(int event) {
1955         set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
1956
1957         allqueue(REDRAWVIEW3D, 0);
1958 }
1959
1960 void space_sound_button_function(int event)
1961 {
1962         int a;
1963         SYS_SystemHandle syshandle;
1964
1965         if ((syshandle = SYS_GetSystem()))
1966         {
1967                 a = (U.gameflags & USER_DISABLE_SOUND);
1968                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
1969         }
1970 }
1971
1972 #define B_ADD_THEME     3301
1973 #define B_DEL_THEME     3302
1974 #define B_NAME_THEME    3303
1975 #define B_THEMECOL              3304
1976 #define B_UPDATE_THEME  3305
1977 #define B_CHANGE_THEME  3306
1978 #define B_THEME_COPY    3307
1979 #define B_THEME_PASTE   3308
1980
1981 #define B_RECALCLIGHT   3310
1982
1983 // needed for event; choose new 'curmain' resets it...
1984 static short th_curcol= TH_BACK;
1985 static char *th_curcol_ptr= NULL;
1986 static char th_curcol_arr[4]={0, 0, 0, 255};
1987
1988 void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
1989 {
1990         bTheme *btheme, *bt;
1991         int spacetype= 0;
1992         static short cur=1, curmain=2;
1993         short a, tot=0, isbuiltin= 0;
1994         char string[21*32], *strp, *col;
1995         
1996         y3= y2+23;      // exception!
1997         
1998         /* count total, max 16! */
1999         for(bt= U.themes.first; bt; bt= bt->next) tot++;
2000         
2001         /* if cur not is 1; move that to front of list */
2002         if(cur!=1) {
2003                 a= 1;
2004                 for(bt= U.themes.first; bt; bt= bt->next, a++) {
2005                         if(a==cur) {
2006                                 BLI_remlink(&U.themes, bt);
2007                                 BLI_addhead(&U.themes, bt);
2008                                 allqueue(REDRAWALL, 0);
2009                                 cur= 1;
2010                                 break;
2011                         }
2012                 }
2013         }
2014         
2015         /* the current theme */
2016         btheme= U.themes.first;
2017         if(strcmp(btheme->name, "Default")==0) isbuiltin= 1;
2018
2019         /* construct popup script */
2020         string[0]= 0;
2021         for(bt= U.themes.first; bt; bt= bt->next) {
2022                 strcat(string, bt->name);
2023                 if(btheme->next) strcat(string, "   |");
2024         }
2025         uiDefButS(block, MENU, B_UPDATE_THEME, string,                  45,y3,200,20, &cur, 0, 0, 0, 0, "Current theme");
2026         
2027         /* add / delete / name */
2028
2029         if(tot<16)
2030                 uiDefBut(block, BUT, B_ADD_THEME, "Add",        45,y2,200,20, NULL, 0, 0, 0, 0, "Makes new copy of this theme");
2031         if(tot>1 && isbuiltin==0)
2032                 uiDefBut(block, BUT, B_DEL_THEME, "Delete", 45,y1,200,20, NULL, 0, 0, 0, 0, "Delete theme");
2033
2034         if(isbuiltin) return;
2035         
2036         /* name */
2037         uiDefBut(block, TEX, B_NAME_THEME, "",                  255,y3,200,20, btheme->name, 1.0, 30.0, 0, 0, "Rename theme");
2038
2039         /* main choices pup */
2040         uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|%l|3D View %x2|%l|Ipo Curve Editor %x3|Action Editor %x4|"
2041                 "NLA Editor %x5|%l|UV/Image Editor %x6|Video Sequence Editor %x7|Audio Timeline %x8|Text Editor %x9|%l|User Preferences %x10|"
2042                 "Outliner %x11|Buttons Window %x12|%l|File Browser %x13|Image Browser %x14",
2043                                                                                                         255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
2044         if(curmain==1) spacetype= 0;
2045         else if(curmain==2) spacetype= SPACE_VIEW3D;
2046         else if(curmain==3) spacetype= SPACE_IPO;
2047         else if(curmain==4) spacetype= SPACE_ACTION;
2048         else if(curmain==5) spacetype= SPACE_NLA;
2049         else if(curmain==6) spacetype= SPACE_IMAGE;
2050         else if(curmain==7) spacetype= SPACE_SEQ;
2051         else if(curmain==8) spacetype= SPACE_SOUND;
2052         else if(curmain==9) spacetype= SPACE_TEXT;
2053         else if(curmain==10) spacetype= SPACE_INFO;
2054         else if(curmain==11) spacetype= SPACE_OOPS;
2055         else if(curmain==12) spacetype= SPACE_BUTS;
2056         else if(curmain==13) spacetype= SPACE_FILE;
2057         else if(curmain==14) spacetype= SPACE_IMASEL;
2058         else return; // only needed while coding... when adding themes for more windows
2059         
2060         /* color choices pup */
2061         if(curmain==1) {
2062                 strp= BIF_ThemeColorsPup(0);
2063                 if(th_curcol==TH_BACK) th_curcol= TH_BUT_OUTLINE;  // switching main choices...
2064         }
2065         else strp= BIF_ThemeColorsPup(spacetype);
2066         
2067         uiDefButS(block, MENU, B_REDR, strp,                    255,y1,200,20, &th_curcol, 0, 0, 0, 0, "Current color");
2068         MEM_freeN(strp);
2069         
2070         th_curcol_ptr= col= BIF_ThemeGetColorPtr(btheme, spacetype, th_curcol);
2071         if(col==NULL) return;
2072         
2073         /* first handle exceptions, special single values, row selection, etc */
2074         if(th_curcol==TH_VERTEX_SIZE) {
2075                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Vertex size ", 465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
2076         }
2077         else if(th_curcol==TH_FACEDOT_SIZE) {
2078                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Face dot size ",       465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
2079         }
2080         else if(th_curcol==TH_BUT_DRAWTYPE) {
2081                 uiBlockBeginAlign(block);
2082                 uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal",        465,y3,100,20,  col, 2.0, 0.0, 0, 0, "");
2083                 uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 565,y3,100,20,  col, 2.0, 1.0, 0, 0, "");
2084                 uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded",        465,y2,100,20,  col, 2.0, 2.0, 0, 0, "");
2085                 uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool",       565,y2,100,20,  col, 2.0, 3.0, 0, 0, "");
2086                 uiBlockEndAlign(block);
2087         }
2088         else {
2089                 uiBlockBeginAlign(block);
2090                 if ELEM6(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT, TH_MENU_BACK, TH_MENU_HILITE, TH_MENU_ITEM) {
2091                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
2092                 }
2093                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
2094                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"G ",   465,y2,200,20,  col+1, 0.0, 255.0, B_THEMECOL, 0, "");
2095                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"B ",   465,y1,200,20,  col+2, 0.0, 255.0, B_THEMECOL, 0, "");
2096                 uiBlockEndAlign(block);
2097
2098                 uiDefButC(block, COL, B_UPDATE_THEME, "",               675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
2099                                 
2100                 /* copy paste */
2101                 uiBlockBeginAlign(block);
2102                 uiDefBut(block, BUT, B_THEME_COPY, "Copy Color",        755,y2,120,20, NULL, 0, 0, 0, 0, "Stores current color in buffer");
2103                 uiDefBut(block, BUT, B_THEME_PASTE, "Paste Color",      755,y1,120,20, NULL, 0, 0, 0, 0, "Pastes buffer color");
2104                 uiBlockEndAlign(block);
2105                 
2106                 uiDefButC(block, COL, 0, "",                            885,y1,50,y2-y1+20, th_curcol_arr, 0, 0, 0, 0, "");
2107                 
2108         }
2109 }
2110
2111
2112 void drawinfospace(ScrArea *sa, void *spacedata)
2113 {
2114         uiBlock *block;
2115         static short cur_light=0, cur_light_var=0;
2116         float fac, col[3];
2117         short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y5, y6;
2118         short y2label, y3label, y4label, y5label, y6label;
2119         short spref, mpref, lpref, smfileselbut;
2120         short edgsp, midsp;
2121         char naam[32];
2122
2123         if(curarea->win==0) return;
2124
2125         BIF_GetThemeColor3fv(TH_BACK, col);
2126         glClearColor(col[0], col[1], col[2], 0.0);
2127         glClear(GL_COLOR_BUFFER_BIT);
2128
2129         fac= ((float)curarea->winx)/1280.0f;
2130         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2131         
2132         sprintf(naam, "infowin %d", curarea->win);
2133         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->win);
2134
2135
2136         /* Vars for nice grid alignment */ 
2137         dx= (1280-90)/7;        /* spacing for use in equally dividing 'tab' row */
2138
2139         xpos = 45;              /* left padding */
2140         ypos = 50;              /* bottom padding for buttons */
2141         ypostab = 10;           /* bottom padding for 'tab' row */
2142
2143         buth = 20;              /* standard button height */
2144
2145         spref = 90;     /* standard size for small preferences button */
2146         mpref = 189;    /* standard size for medium preferences button */
2147         lpref = 288;    /* standard size for large preferences button */
2148         smfileselbut = buth;    /* standard size for fileselect button (square) */
2149
2150         edgsp = 3;              /* space from edge of end 'tab' to edge of end button */
2151         midsp = 9;              /* horizontal space between buttons */
2152
2153         rspace = 3;             /* default space between rows */
2154
2155         y1 = ypos;              /* grid alignment for each row of buttons */
2156         y2 = ypos+buth+rspace;
2157         y3 = ypos+2*(buth+rspace);
2158         y4 = ypos+3*(buth+rspace);
2159         y5 = ypos+4*(buth+rspace);
2160         y6 = ypos+5*(buth+rspace);
2161
2162
2163         y2label = y2-2;         /* adjustments to offset the labels down to align better */
2164         y3label = y3-2;
2165         y4label = y4-2;
2166         y5label = y5-2;
2167         y6label = y6-2;
2168
2169
2170         /* set the colour to blue and draw the main 'tab' controls */
2171
2172         uiBlockSetCol(block, TH_BUT_SETTING1);
2173         uiBlockBeginAlign(block);
2174         
2175         uiDefButS(block, ROW,B_USERPREF,"View & Controls",
2176                 xpos,ypostab,(short)dx,buth,
2177                 &U.userpref,1.0,0.0, 0, 0,"");
2178                 
2179         uiDefButS(block, ROW,B_USERPREF,"Edit Methods",
2180                 (short)(xpos+dx),ypostab,(short)dx,buth,
2181                 &U.userpref,1.0,1.0, 0, 0,"");
2182
2183         uiDefButS(block, ROW,B_USERPREF,"Language & Font",
2184                 (short)(xpos+2*dx),ypostab,(short)dx,buth,
2185                 &U.userpref,1.0,2.0, 0, 0,"");
2186
2187         uiDefButS(block, ROW,B_USERPREF,"Themes",
2188                 (short)(xpos+3*dx),ypostab,(short)dx,buth,
2189                 &U.userpref,1.0,6.0, 0, 0,"");
2190
2191         uiDefButS(block, ROW,B_USERPREF,"Auto Save",
2192                 (short)(xpos+4*dx),ypostab,(short)dx,buth,
2193                 &U.userpref,1.0,3.0, 0, 0,"");
2194
2195         uiDefButS(block, ROW,B_USERPREF,"System & OpenGL",
2196                 (short)(xpos+5*dx),ypostab,(short)dx,buth,
2197                 &U.userpref,1.0,4.0, 0, 0,"");
2198                 
2199         uiDefButS(block, ROW,B_USERPREF,"File Paths",
2200                 (short)(xpos+6*dx),ypostab,(short)dx,buth,
2201                 &U.userpref,1.0,5.0, 0, 0,"");
2202
2203         uiBlockSetCol(block, TH_AUTO);
2204         uiBlockEndAlign(block);
2205         /* end 'tab' controls */
2206
2207         /* line 2: left x co-ord, top y co-ord, width, height */
2208
2209         if(U.userpref == 6) {
2210                 info_user_themebuts(block, y1, y2, y3);
2211         }
2212         else if (U.userpref == 0) { /* view & controls */
2213
2214                 uiDefBut(block, LABEL,0,"Display:",
2215                         xpos,y6label,spref,buth,
2216                         0, 0, 0, 0, 0, "");     
2217                 uiDefButBitS(block, TOG, USER_TOOLTIPS, 0, "ToolTips",
2218                         (xpos+edgsp),y5,spref,buth,
2219                         &(U.flag), 0, 0, 0, 0,
2220                         "Display tooltips (help tags) over buttons");
2221                 uiDefButBitS(block, TOG, USER_DRAWVIEWINFO, B_DRAWINFO, "Object Info",
2222                         (xpos+edgsp),y4,spref,buth,
2223                         &(U.uiflag), 0, 0, 0, 0,
2224                         "Display active object name and frame number in the 3D View");
2225                 uiDefButBitS(block, TOG, USER_SCENEGLOBAL, 0, "Global Scene",
2226                         (xpos+edgsp),y3,spref,buth,
2227                         &(U.flag), 0, 0, 0, 0,
2228                         "Forces the current Scene to be displayed in all Screens");
2229 #ifndef __APPLE__       
2230                 uiDefButS(block, TOG|BIT|0, 0, "Large Cursors",
2231                         (xpos+edgsp),y2,spref,buth,
2232                         &(U.curssize), 0, 0, 0, 0,
2233                         "Use large mouse cursors when available");
2234 #else 
2235                 U.curssize=0; /*Small Cursor always for OS X for now */
2236 #endif
2237
2238                 uiDefBut(block, LABEL,0,"Menus:",
2239                         (xpos+(2*edgsp)+spref),y6label,spref,buth,
2240                         0, 0, 0, 0, 0, "");
2241                 uiDefButBitS(block, TOG, USER_MENUOPENAUTO, 0, "Open on Mouse Over",
2242                         (xpos+edgsp+spref+midsp),y5,mpref,buth,
2243                         &(U.uiflag), 0, 0, 0, 0,
2244                         "Open menu buttons and pulldowns automatically when the mouse is hovering");
2245                 uiDefButS(block, NUM, 0, "Top Level:",
2246                         (xpos+edgsp+spref+midsp),y4,spref+edgsp,buth,
2247                         &(U.menuthreshold1), 1, 40, 0, 0,
2248                         "Time delay in 1/10 seconds before automatically opening top level menus");
2249                 uiDefButS(block, NUM, 0, "Sublevels:",
2250                         (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y4,spref+edgsp,buth,
2251                         &(U.menuthreshold2), 1, 40, 0, 0,
2252                         "Time delay in 1/10 seconds before automatically opening menu sublevels");
2253
2254                 uiDefBut(block, LABEL,0,"Toolbox click-hold delay:",
2255                         (xpos+(2*edgsp)+spref),y3label,mpref,buth,
2256                         0, 0, 0, 0, 0, "");
2257                 uiDefButS(block, NUM, 0, "LMB:",
2258                         (xpos+edgsp+spref+midsp),y2,spref+edgsp,buth,
2259                         &(U.tb_leftmouse), 2, 40, 0, 0,
2260                         "Time in 1/10 seconds to hold the Left Mouse Button before opening the toolbox");
2261                 uiDefButS(block, NUM, 0, "RMB:",
2262                         (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y2,spref+edgsp,buth,
2263                         &(U.tb_rightmouse), 2, 40, 0, 0,
2264                         "Time in 1/10 seconds to hold the Right Mouse Button before opening the toolbox");      
2265                 uiDefButBitS(block, TOG, USER_PANELPINNED, 0, "Pin Floating Panels",
2266                         (xpos+edgsp+spref+midsp),y1,mpref,buth,
2267                         &(U.uiflag), 0, 0, 0, 0,
2268                         "Make floating panels invoked by a hotkey (eg. N Key) open at the previous location");
2269                 
2270                 
2271                 uiDefBut(block, LABEL,0,"Snap to grid:",
2272                         (xpos+(2*edgsp)+spref+midsp+mpref),y6label,mpref,buth,
2273                         0, 0, 0, 0, 0, "");
2274                 uiDefButBitS(block, TOG, USER_AUTOGRABGRID, 0, "Grab/Move",
2275                         (xpos+edgsp+mpref+spref+(2*midsp)),y5,spref,buth,
2276                         &(U.flag), 0, 0, 0, 0,
2277                         "Snap objects and sub-objects to grid units when moving");
2278                 uiDefButBitS(block, TOG, USER_AUTOROTGRID, 0, "Rotate",
2279                         (xpos+edgsp+mpref+spref+(2*midsp)),y4,spref,buth,
2280                         &(U.flag), 0, 0, 0, 0,
2281                         "Snap objects and sub-objects to grid units when rotating");
2282                 uiDefButBitS(block, TOG, USER_AUTOSIZEGRID, 0, "Scale",
2283                         (xpos+edgsp+mpref+spref+(2*midsp)),y3,spref,buth,
2284                         &(U.flag), 0, 0, 0, 0,
2285                         "Snap objects and sub-objects to grid units when scaling");
2286                 
2287                 uiDefButBitS(block, TOG, USER_LOCKAROUND, B_DRAWINFO, "Global Pivot",
2288                         (xpos+edgsp+mpref+spref+(2*midsp)),y1,spref,buth,
2289                         &(U.uiflag), 0, 0, 0, 0,
2290                         "Lock the same rotation/scaling pivot in all 3D Views");        
2291                 
2292                 uiDefBut(block, LABEL,0,"View zoom:",
2293                         (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y6label,mpref,buth,
2294                         0, 0, 0, 0, 0, "");
2295                 uiBlockBeginAlign(block);
2296                 uiDefButS(block, ROW, 0, "Continue",
2297                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y5,(mpref/3),buth,
2298                         &(U.viewzoom), 40, USER_ZOOM_CONT, 0, 0,
2299                         "Old style zoom, continues while moving mouse up or down");
2300                 uiDefButS(block, ROW, 0, "Dolly",
2301                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/3)),y5,(mpref/3),buth,
2302                         &(U.viewzoom), 40, USER_ZOOM_DOLLY, 0, 0,
2303                         "Zooms in and out based on vertical mouse movement.");
2304                 uiDefButS(block, ROW, 0, "Scale",
2305                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(2*mpref/3)),y5,(mpref/3),buth,
2306                         &(U.viewzoom), 40, USER_ZOOM_SCALE, 0, 0,
2307                         "Zooms in and out like scaling the view, mouse movements relative to center.");
2308                 uiBlockEndAlign(block);
2309                 
2310                 uiDefBut(block, LABEL,0,"View rotation:",
2311                         (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y4label,mpref,buth,
2312                         0, 0, 0, 0, 0, "");
2313                 uiBlockBeginAlign(block);
2314                 uiDefButBitS(block, TOG, USER_TRACKBALL, B_DRAWINFO, "Trackball",
2315                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y3,(mpref/2),buth,
2316                         &(U.flag), 0, 0, 0, 0,
2317                         "Allow the view to tumble freely when orbiting with the Middle Mouse Button");
2318                 uiDefButBitS(block, TOGN, USER_TRACKBALL, B_DRAWINFO, "Turntable",
2319                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/2)),y3,(mpref/2),buth,
2320                         &(U.flag), 0, 0, 0, 0,
2321                         "Keep the Global Z axis pointing upwards when orbiting the view with the Middle Mouse Button");
2322                 uiBlockEndAlign(block);
2323                 
2324                 uiDefButBitS(block, TOG, USER_AUTOPERSP, B_DRAWINFO, "Auto Perspective",
2325                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y1,spref,buth,
2326                         &(U.uiflag), 0, 0, 0, 0,
2327                         "Automatically switch between orthographic and perspective when changing from top/front/side views");
2328
2329                 uiDefBut(block, LABEL,0,"Select with:",
2330                         (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y6label,mpref,buth,
2331                         0, 0, 0, 0, 0, "");
2332                 uiBlockBeginAlign(block);
2333                 uiDefButBitS(block, TOG, USER_LMOUSESELECT, B_DRAWINFO, "Left Mouse",
2334                         (xpos+edgsp+(3*mpref)+(4*midsp)),y5,(mpref/2),buth,
2335                         &(U.flag), 0, 0, 0, 0, "Use the Left Mouse Button for selection");
2336                 uiDefButBitS(block, TOGN, USER_LMOUSESELECT, B_DRAWINFO, "Right Mouse",
2337                         (xpos+edgsp+(3*mpref)+(4*midsp)+(mpref/2)),y5,(mpref/2),buth,
2338                         &(U.flag), 0, 0, 0, 0, "Use the Right Mouse Button for selection");
2339                 uiBlockEndAlign(block);
2340                 
2341                 
2342                 if(U.flag & USER_LMOUSESELECT) {
2343                         uiDefBut(block, LABEL,0,"Cursor with: Right Mouse",
2344                                 (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
2345                                 0, 0, 0, 0, 0, "");
2346                 } else {
2347                         uiDefBut(block, LABEL,0,"Cursor with: Left Mouse",
2348                                 (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
2349                                 0, 0, 0, 0, 0, "");
2350                 }
2351                 
2352                 /* illegal combo... */
2353                 if (U.flag & USER_LMOUSESELECT) 
2354                         U.flag &= ~USER_TWOBUTTONMOUSE;
2355                 
2356                 uiDefButBitS(block, TOG, USER_TWOBUTTONMOUSE, B_DRAWINFO, "Emulate 3 Button Mouse",
2357                         (xpos+edgsp+(3*mpref)+(4*midsp)),y3,mpref,buth,
2358                         &(U.flag), 0, 0, 0, 0,
2359                         "Emulates Middle Mouse with Alt+LeftMouse (doesnt work with Left Mouse Select option)");
2360                 
2361                         
2362                 uiDefBut(block, LABEL,0,"Middle Mouse Button:",
2363                         (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y6label,mpref,buth,
2364                         0, 0, 0, 0, 0, "");
2365                 uiBlockBeginAlign(block);
2366                 uiDefButBitS(block, TOGN, USER_VIEWMOVE, B_DRAWINFO, "Rotate View",
2367                         (xpos+edgsp+(4*mpref)+(5*midsp)),y5,(mpref/2),buth,
2368                         &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
2369                 uiDefButBitS(block, TOG, USER_VIEWMOVE, B_DRAWINFO, "Pan View",
2370                         (xpos+edgsp+(4*mpref)+(5*midsp)+(mpref/2)),y5,(mpref/2),buth,
2371                         &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
2372                 uiBlockEndAlign(block);
2373                         
2374                 uiDefBut(block, LABEL,0,"Mouse Wheel:",
2375                         (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y4label,mpref,buth,
2376                         0, 0, 0, 0, 0, "");
2377                 uiDefButBitS(block, TOG, USER_WHEELZOOMDIR, 0, "Invert Zoom",
2378                         (xpos+edgsp+(4*mpref)+(5*midsp)),y3,spref,buth,
2379                         &(U.uiflag), 0, 0, 0, 0,
2380                         "Swap the Mouse Wheel zoom direction");
2381                 uiDefButI(block, NUM, 0, "Scroll Lines:",
2382                         (xpos+edgsp+(4*mpref)+(6*midsp)+spref-edgsp),y3,spref+edgsp,buth,
2383                         &U.wheellinescroll, 0.0, 32.0, 0, 0,
2384                         "The number of lines scrolled at a time with the mouse wheel"); 
2385
2386
2387         } else if (U.userpref == 1) { /* edit methods */
2388
2389
2390                 uiDefBut(block, LABEL,0,"Material linked to:",
2391                         xpos,y3label,mpref,buth,
2392                         0, 0, 0, 0, 0, "");
2393                 uiBlockBeginAlign(block);
2394                 uiDefButBitS(block, TOGN, USER_MAT_ON_OB, B_DRAWINFO, "ObData",
2395                         (xpos+edgsp),y2,(mpref/2),buth,
2396                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
2397                 uiDefButBitS(block, TOG, USER_MAT_ON_OB, B_DRAWINFO, "Object",
2398                         (xpos+edgsp+(mpref/2)),y2,(mpref/2),buth,
2399                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
2400                 uiBlockEndAlign(block);
2401
2402
2403                 uiDefBut(block, LABEL,0,"Editmode undo:",
2404                         (xpos+(2*edgsp)+mpref),y3label, mpref,buth,
2405                         0, 0, 0, 0, 0, "");
2406                 uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps:",
2407                         (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2408                         &(U.undosteps), 2, 64, 0, 0, "Number of undo steps available in Edit Mode (smaller values conserve memory)");
2409
2410                 uiDefButBitS(block, TOG, USER_GLOBALUNDO, B_DRAWINFO, "Global undo",
2411                         (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2412                         &(U.uiflag), 2, 64, 0, 0, "");
2413
2414
2415                 uiDefBut(block, LABEL,0,"Auto keyframe on:",
2416                         (xpos+(2*edgsp)+(2*mpref)+midsp),y3label,mpref,buth,
2417                         0, 0, 0, 0, 0, "");
2418                 uiDefButBitS(block, TOG, USER_KEYINSERTACT, 0, "Action",
2419                         (xpos+edgsp+(2*mpref)+(2*midsp)),y2,(spref+edgsp),buth,
2420                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Action Ipo curve");
2421                 uiDefButBitS(block, TOG, USER_KEYINSERTOBJ, 0, "Object",
2422                         (xpos+edgsp+(2*mpref)+(3*midsp)+spref-edgsp),y2,(spref+edgsp),buth,
2423                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Object Ipo curve");
2424
2425
2426                 uiDefBut(block, LABEL,0,"Duplicate with object:",
2427                         (xpos+(2*edgsp)+(3*midsp)+(3*mpref)+spref),y3label,mpref,buth,
2428                         0, 0, 0, 0, 0, "");
2429
2430                 uiDefButBitS(block, TOG, USER_DUP_MESH, 0, "Mesh",
2431                         (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y2,(spref+edgsp),buth,
2432                         &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
2433                 uiDefButBitS(block, TOG, USER_DUP_ARM, 0, "Armature",
2434                         (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y1,(spref+edgsp),buth,
2435                         &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
2436
2437                 uiDefButBitS(block, TOG, USER_DUP_SURF, 0, "Surface",
2438                         (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y2,(spref+edgsp),buth,
2439                         &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
2440                 uiDefButBitS(block, TOG, USER_DUP_LAMP, 0, "Lamp",
2441                         (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y1,(spref+edgsp),buth,
2442                         &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
2443
2444                 uiDefButBitS(block, TOG, USER_DUP_CURVE, 0, "Curve",
2445                         (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y2,(spref+edgsp),buth,
2446                         &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
2447                 uiDefButBitS(block, TOG, USER_DUP_MAT, 0, "Material",
2448                         (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y1,(spref+edgsp),buth,
2449                         &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
2450
2451                 uiDefButBitS(block, TOG, USER_DUP_FONT, 0, "Text",
2452                         (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y2,(spref+edgsp),buth,
2453                         &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
2454                 uiDefButBitS(block, TOG, USER_DUP_TEX, 0, "Texture",
2455                         (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y1,(spref+edgsp),buth,
2456                         &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
2457
2458                 uiDefButBitS(block, TOG, USER_DUP_MBALL, 0, "Metaball",
2459                         (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y2,(spref+edgsp),buth,
2460                         &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
2461                 uiDefButBitS(block, TOG, USER_DUP_IPO, 0, "Ipo",
2462                         (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y1,(spref+edgsp),buth,
2463                         &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
2464         
2465         } else if(U.userpref == 2) { /* language & colors */
2466
2467 #ifdef INTERNATIONAL
2468                 uiDefButBitS(block, TOG, USER_DOTRANSLATE, B_DOLANGUIFONT, "International Fonts",
2469                         xpos,y2,mpref,buth,
2470                         &(U.transopts), 0, 0, 0, 0, "Activate international interface");
2471
2472                 if(U.transopts & USER_DOTRANSLATE) {
2473                         char curfont[320];
2474                         
2475                         sprintf(curfont, "Interface Font: ");
2476                         if(U.fontname[0]) strcat(curfont, U.fontname);
2477                         else strcat(curfont, "Built-in");
2478                         
2479                         uiDefBut(block, LABEL,0,curfont,
2480                                 (xpos),y3,4*mpref,buth,
2481                                 0, 0, 0, 0, 0, "");
2482
2483                         uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
2484                                 xpos,y1,mpref,buth,
2485                                 0, 0, 0, 0, 0, "Select a new font for the interface");
2486
2487                         uiDefButI(block, BUT, B_RESTOREFONT, "Restore to default",
2488                                           (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2489                                           &U.fontsize, 0, 0, 0, 0, "Restores to using the default included antialised font");
2490                         
2491                         uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
2492                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2493                                 &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
2494
2495 /*
2496                         uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
2497                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2498                                 &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
2499
2500
2501                         uiDefBut(block, LABEL,0,"Translate:",
2502                                 (xpos+edgsp+(2.1*mpref)+(2*midsp)),y3label,mpref,buth,
2503                                 0, 0, 0, 0, 0, "");
2504 */
2505
2506                         uiDefButBitS(block, TOG, USER_TR_TOOLTIPS, B_SETTRANSBUTS, "Tooltips",
2507                                 (xpos+edgsp+(2.2*mpref)+(3*midsp)),y1,spref,buth,
2508                                 &(U.transopts), 0, 0, 0, 0, "Translate tooltips");
2509
2510                         uiDefButBitS(block, TOG, USER_TR_BUTTONS, B_SETTRANSBUTS, "Buttons",
2511                                 (xpos+edgsp+(2.2*mpref)+(4*midsp)+spref),y1,spref,buth,
2512                                 &(U.transopts), 0, 0, 0, 0, "Translate button labels");
2513
2514                         uiDefButBitS(block, TOG, USER_TR_MENUS, B_SETTRANSBUTS, "Toolbox",
2515                                 (xpos+edgsp+(2.2*mpref)+(5*midsp)+(2*spref)),y1,spref,buth,
2516                                 &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
2517
2518                         uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
2519                                 (xpos+edgsp+(2.2*mpref)+(3*midsp)),y2,mpref+(0.5*mpref)+3,buth,
2520                                 &U.language, 0, 0, 0, 0, "Select interface language");
2521                                 
2522                         /* uiDefButBitS(block, TOG, USER_TR_TEXTEDIT, B_SETTRANSBUTS, "FTF All windows",
2523                                 (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
2524                                 &(U.transopts), 0, 0, 0, 0,
2525                                 "Use FTF drawing for fileselect and textwindow "
2526                                 "(under construction)");
2527                         */
2528                 }
2529
2530 /* end of INTERNATIONAL */
2531 #endif
2532
2533         } else if(U.userpref == 3) { /* auto save */
2534
2535
2536                 uiDefButS(block, NUM, 0, "Save Versions:",
2537                         (xpos+edgsp),y3,mpref,buth,
2538                         &U.versions, 0.0, 32.0, 0, 0,
2539                         "The number of old versions to maintain in the current directory, when manually saving");
2540
2541                 uiDefButBitS(block, TOG, USER_AUTOSAVE, B_RESETAUTOSAVE, "Auto Save Temp Files",
2542                         (xpos+edgsp+mpref+midsp),y3,mpref,buth,
2543                         &(U.flag), 0, 0, 0, 0,
2544                         "Enables automatic saving of temporary files");
2545
2546                 if(U.flag & USER_AUTOSAVE) {
2547
2548                         uiDefButI(block, NUM, B_RESETAUTOSAVE, "Minutes:",
2549                                 (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2550                                 &(U.savetime), 1.0, 60.0, 0, 0,
2551                                 "The time (in minutes) to wait between automatic temporary saves");
2552
2553                         uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
2554                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2555                                 0, 0, 0, 0, 0,"Open the most recently saved temporary file");
2556                 }
2557
2558         } else if (U.userpref == 4) { /* system & opengl */
2559                 uiDefBut(block, LABEL,0,"Solid OpenGL light:",
2560                         xpos+edgsp, y3label, mpref, buth,
2561                         0, 0, 0, 0, 0, "");
2562                 
2563                 uiDefButS(block, MENU, B_REDR, "Light1 %x0|Light2 %x1|Light3 %x2",
2564                         xpos+edgsp, y2, 2*mpref/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
2565                 uiBlockSetCol(block, TH_BUT_SETTING1);
2566                 uiDefButI(block, TOG|BIT|0, B_RECALCLIGHT, "On",
2567                         xpos+edgsp+2*mpref/6, y2, mpref/6, buth, 
2568                         &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "Enable this OpenGL light in Solid draw mode");
2569                         
2570                 uiBlockSetCol(block, TH_AUTO);
2571                 uiDefButS(block, ROW, B_REDR, "Vec",
2572                         xpos+edgsp+3*mpref/6, y2, mpref/6, buth, 
2573                         &cur_light_var, 123.0, 0.0, 0, 0, "Lamp vector for OpenGL light");
2574                 uiDefButS(block, ROW, B_REDR, "Col",
2575                         xpos+edgsp+4*mpref/6, y2, mpref/6, buth, 
2576                         &cur_light_var, 123.0, 1.0, 0, 0, "Diffuse Color for OpenGL light");
2577                 uiDefButS(block, ROW, B_REDR, "Spec",
2578                         xpos+edgsp+5*mpref/6, y2, mpref/6, buth, 
2579                         &cur_light_var, 123.0, 2.0, 0, 0, "Specular color for OpenGL light");
2580
2581                 if(cur_light_var==1) {
2582                         uiDefButF(block, NUM, B_RECALCLIGHT, "R ",
2583                                 xpos+edgsp, y1, mpref/3, buth, 
2584                                 U.light[cur_light].col, 0.0, 1.0, 100, 2, "");
2585                         uiDefButF(block, NUM, B_RECALCLIGHT, "G ",
2586                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2587                                 U.light[cur_light].col+1, 0.0, 1.0, 100, 2, "");
2588                         uiDefButF(block, NUM, B_RECALCLIGHT, "B ",
2589                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2590                                 U.light[cur_light].col+2, 0.0, 1.0, 100, 2, "");
2591                 }
2592                 else if(cur_light_var==2) {
2593                         uiDefButF(block, NUM, B_RECALCLIGHT, "sR ",
2594                                 xpos+edgsp, y1, mpref/3, buth, 
2595                                 U.light[cur_light].spec, 0.0, 1.0, 100, 2, "");
2596                         uiDefButF(block, NUM, B_RECALCLIGHT, "sG ",
2597                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2598                                 U.light[cur_light].spec+1, 0.0, 1.0, 100, 2, "");
2599                         uiDefButF(block, NUM, B_RECALCLIGHT, "sB ",
2600                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2601                                 U.light[cur_light].spec+2, 0.0, 1.0, 100, 2, "");
2602                 }
2603                 else if(cur_light_var==0) {
2604                         uiDefButF(block, NUM, B_RECALCLIGHT, "X ",
2605                                 xpos+edgsp, y1, mpref/3, buth, 
2606                                 U.light[cur_light].vec, -1.0, 1.0, 100, 2, "");
2607                         uiDefButF(block, NUM, B_RECALCLIGHT, "Y ",
2608                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2609                                 U.light[cur_light].vec+1, -1.0, 1.0, 100, 2, "");
2610                         uiDefButF(block, NUM, B_RECALCLIGHT, "Z ",
2611                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2612                                 U.light[cur_light].vec+2, -1.0, 1.0, 100, 2, "");
2613                 }
2614
2615 /*
2616                 uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
2617                         (xpos+edgsp),y2,lpref,buth,
2618                         &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
2619
2620                 uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
2621                         (xpos+edgsp), y1, lpref,buth,
2622                         &U.console_out, 0, 0, 0, 0, "Select console output method");
2623
2624                 uiDefButS(block, NUM, B_CONSOLENUMLINES, "Lines:",
2625                         (xpos+edgsp+lpref+midsp),y1,spref,buth,
2626                         &U.console_buffer, 1.0, 4000.0, 0, 0, "Maximum number of internal console lines");
2627 */
2628
2629 #ifdef _WIN32
2630                 uiDefBut(block, LABEL,0,"Win Codecs:",
2631                         (xpos+edgsp+(1*midsp)+(1*mpref)),y3label,mpref,buth,
2632                         0, 0, 0, 0, 0, "");
2633
2634                 uiDefButBitS(block, TOG, USER_ALLWINCODECS, 0, "Enable all codecs",
2635                         (xpos+edgsp+(1*mpref)+(1*midsp)),y2,mpref,buth,
2636                         &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
2637 #endif
2638
2639                 uiDefBut(block, LABEL,0,"Keyboard:",
2640                         (xpos+edgsp+(3*midsp)+(3*mpref)),y3label,mpref,buth,
2641                         0, 0, 0, 0, 0, "");
2642
2643                 uiDefButBitS(block, TOG, USER_NO_CAPSLOCK, B_U_CAPSLOCK, "Disable Caps Lock",
2644                         (xpos+edgsp+(3*midsp)+(3*mpref)),y1,mpref,buth,
2645                         &(U.flag), 0, 0, 0, 0,
2646                         "Disables the Caps Lock key when entering text");
2647
2648                 uiDefButBitS(block, TOG, USER_NONUMPAD, 0, "Emulate Numpad",
2649                         (xpos+edgsp+(3*midsp)+(3*mpref)),y2,mpref,buth,
2650                         &(U.flag), 0, 0, 0, 0,
2651                         "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
2652
2653
2654                 uiDefBut(block, LABEL,0,"System:",
2655                         (xpos+edgsp+(4*midsp)+(4*mpref)),y3label,mpref,buth,
2656                         0, 0, 0, 0, 0, "");
2657
2658                 uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Sound",
2659                         (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
2660                         &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
2661
2662                 uiDefButBitS(block, TOG, USER_FILTERFILEEXTS, 0, "Filter File Extensions",
2663                         (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
2664                         &(U.uiflag), 0, 0, 0, 0, "Display only files with extensions in the image select window");
2665
2666
2667                 uiDefBut(block, LABEL,0,"OpenGL:",
2668                         (xpos+edgsp+(5*midsp)+(5*mpref)),y3label,mpref,buth,
2669                         0, 0, 0, 0, 0, "");
2670
2671                 uiDefButBitI(block, TOGN, USER_DISABLE_MIPMAP, B_MIPMAPCHANGED, "Mipmaps",
2672                         (xpos+edgsp+(5*mpref)+(5*midsp)),y2,mpref,buth,
2673                         &(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
2674
2675                 uiDefButBitI(block, TOG, USER_VERTEX_ARRAYS, 0, "Vertex Arrays",
2676                         (xpos+edgsp+(5*mpref)+(5*midsp)),y1,mpref,buth,
2677                         &(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
2678
2679                 uiDefBut(block, LABEL,0,"Audio mixing buffer:",
2680                         (xpos+edgsp+(2*midsp)+(2*mpref)),y3label,mpref,buth,
2681                         0, 0, 0, 0, 0, "");
2682                 uiBlockBeginAlign(block);
2683                 uiDefButI(block, ROW, 0, "256",
2684                         (xpos+edgsp+(2*midsp)+(2*mpref)),y2,(mpref/4),buth,
2685                         &U.mixbufsize, 2.0, 256.0, 0, 0, "Set audio mixing buffer size to 256 samples");
2686                 uiDefButI(block, ROW, 0, "512",
2687                         (xpos+edgsp+(2*midsp)+(2*mpref)+(mpref/4)),y2,(mpref/4),buth,
2688                         &U.mixbufsize, 2.0, 512.0, 0, 0, "Set audio mixing buffer size to 512 samples");        
2689                 uiDefButI(block, ROW, 0, "1024",
2690                         (xpos+edgsp+(2*midsp)+(2*mpref)+(2*mpref/4)),y2,(mpref/4),buth,
2691                         &U.mixbufsize, 2.0, 1024.0, 0, 0, "Set audio mixing buffer size to 1024 samples");              
2692                 uiDefButI(block, ROW, 0, "2048",
2693                         (xpos+edgsp+(2*midsp)+(2*mpref)+(3*mpref/4)),y2,(mpref/4),buth,
2694                         &U.mixbufsize, 2.0, 2048.0, 0, 0, "Set audio mixing buffer size to 2048 samples");                      
2695                 uiBlockEndAlign(block);
2696
2697         } else if(U.userpref == 5) { /* file paths */
2698
2699                 /* yafray: (temporary) path button for yafray xml export, now with fileselect */
2700                 uiDefBut(block, TEX, 0, "YFexport: ",
2701                         (xpos+edgsp), y2+buth+rspace, lpref-smfileselbut, buth,
2702                         U.yfexportdir, 1.0, 63.0, 0, 0,
2703                         "The default directory for yafray xml export (must exist!)");
2704                 uiDefIconBut(block, BUT, B_YAFRAYDIRFILESEL, ICON_FILESEL,
2705                         (xpos+edgsp+lpref-smfileselbut), y2+buth+rspace, smfileselbut, buth,
2706                         0, 0, 0, 0, 0, "Select the default yafray export directory");
2707
2708                 uiDefBut(block, TEX, 0, "Fonts: ",
2709                         (xpos+edgsp),y2,(lpref-smfileselbut),buth,
2710                         U.fontdir, 1.0, 63.0, 0, 0,
2711                         "The default directory to search for loading fonts");
2712                 uiDefIconBut(block, BUT, B_FONTDIRFILESEL, ICON_FILESEL,
2713                         (xpos+edgsp+lpref-smfileselbut),y2,smfileselbut,buth,
2714                         0, 0, 0, 0, 0, "Select the default font directory");
2715
2716                 uiDefBut(block, TEX, 0, "Textures: ",
2717                         (xpos+edgsp+lpref+midsp),y2,(lpref-smfileselbut),buth,
2718                         U.textudir, 1.0, 63.0, 0, 0, "The default directory to search for textures");
2719                 uiDefIconBut(block, BUT, B_TEXTUDIRFILESEL, ICON_FILESEL,
2720                         (xpos+edgsp+(2*lpref)+midsp-smfileselbut),y2,smfileselbut,buth,
2721                         0, 0, 0, 0, 0, "Select the default texture location");
2722
2723
2724                 uiDefBut(block, TEX, 0, "Tex Plugins: ",
2725                         (xpos+edgsp+(2*lpref)+(2*midsp)),y2,(lpref-smfileselbut),buth,
2726                         U.plugtexdir, 1.0, 63.0, 0, 0, "The default directory to search for texture plugins");
2727                 uiDefIconBut(block, BUT, B_PLUGTEXDIRFILESEL, ICON_FILESEL,
2728                         (xpos+edgsp+(3*lpref)+(2*midsp)-smfileselbut),y2,smfileselbut,buth,
2729                         0, 0, 0, 0, 0, "Select the default texture plugin location");
2730
2731                 uiDefBut(block, TEX, 0, "Seq Plugins: ",
2732                         (xpos+edgsp+(3*lpref)+(3*midsp)),y2,(lpref-smfileselbut),buth,
2733                         U.plugseqdir, 1.0, 63.0, 0, 0, "The default directory to search for sequence plugins");
2734                 uiDefIconBut(block, BUT, B_PLUGSEQDIRFILESEL, ICON_FILESEL,
2735                         (xpos+edgsp+(4*lpref)+(3*midsp)-smfileselbut),y2,smfileselbut,buth,
2736                         0, 0, 0, 0, 0, "Select the default sequence plugin location");
2737
2738
2739                 uiDefBut(block, TEX, 0, "Render: ",
2740                         (xpos+edgsp),y1,(lpref-smfileselbut),buth,
2741                         U.renderdir, 1.0, 63.0, 0, 0, "The default directory for rendering output");
2742                 uiDefIconBut(block, BUT, B_RENDERDIRFILESEL, ICON_FILESEL,
2743                         (xpos+edgsp+lpref-smfileselbut),y1,smfileselbut,buth,
2744                         0, 0, 0, 0, 0, "Select the default render output location");
2745
2746                 uiDefBut(block, TEX, 0, "Python: ",
2747                         (xpos+edgsp+lpref+midsp),y1,(lpref-2*smfileselbut),buth,
2748                         U.pythondir, 1.0, 63.0, 0, 0, "The default directory to search for Python scripts");
2749                 uiDefIconBut(block, BUT, B_PYMENUEVAL, ICON_SCRIPT,
2750                         (xpos+edgsp+(2*lpref)+midsp-2*smfileselbut),y1,smfileselbut,buth,
2751                         0, 0, 0, 0, 0, "Re-evaluate scripts registration in menus");
2752                 uiDefIconBut(block, BUT, B_PYTHONDIRFILESEL, ICON_FILESEL,
2753                         (xpos+edgsp+(2*lpref)+midsp-smfileselbut),y1,smfileselbut,buth,
2754                         0, 0, 0, 0, 0, "Select the default Python script location");
2755
2756
2757                 uiDefBut(block, TEX, 0, "Sounds: ",
2758                         (xpos+edgsp+(2*lpref)+(2*midsp)),y1,(lpref-smfileselbut),buth,
2759                         U.sounddir, 1.0, 63.0, 0, 0, "The default directory to search for sounds");
2760                 uiDefIconBut(block, BUT, B_SOUNDDIRFILESEL, ICON_FILESEL,
2761                         (xpos+edgsp+(3*lpref)+(2*midsp)-smfileselbut),y1,smfileselbut,buth,
2762                         0, 0, 0, 0, 0, "Select the default sound location");
2763
2764                 uiDefBut(block, TEX, 0, "Temp: ",
2765                          (xpos+edgsp+(3*lpref)+(3*midsp)),y1,(lpref-smfileselbut),buth,
2766                          U.tempdir, 1.0, 63.0, 0, 0, "The directory for storing temporary save files");
2767                 uiDefIconBut(block, BUT, B_TEMPDIRFILESEL, ICON_FILESEL,
2768                         (xpos+edgsp+(4*lpref)+(3*midsp)-smfileselbut),y1,smfileselbut,buth,
2769                         0, 0, 0, 0, 0, "Select the default temporary save file location");
2770
2771         }
2772
2773         uiDrawBlock(block);
2774         
2775         myortho2(-0.375, (float)(sa->winx)-0.375, -0.375, (float)(sa->winy)-0.375);
2776         draw_area_emboss(sa);
2777         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2778         sa->win_swap= WIN_BACK_OK;
2779         
2780 }
2781
2782
2783 static void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2784 {
2785         unsigned short event= evt->event;
2786         short val= evt->val;
2787         
2788         if(val) {
2789                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2790
2791                 switch(event) {
2792                 case UI_BUT_EVENT:
2793                         if(val==B_ADD_THEME) {
2794                                 bTheme *btheme, *new;
2795                                 
2796                                 btheme= U.themes.first;
2797                                 new= MEM_callocN(sizeof(bTheme), "theme");
2798                                 memcpy(new, btheme, sizeof(bTheme));
2799                                 BLI_addhead(&U.themes, new);
2800                                 strcpy(new->name, "New User Theme");
2801                                 addqueue(sa->win,&