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