Evil commit! Nothing really changed except;
[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                                                         addedgeface_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                                                 single_user();
1542                                         }
1543                                 }
1544                                 else if(G.qual==LR_SHIFTKEY)
1545                                         if(U.uiflag & USER_GLOBALUNDO) BIF_redo();
1546                                         
1547                                 break;
1548                         case VKEY:
1549                                 ob= OBACT;
1550                                 if((G.qual==LR_SHIFTKEY)) {
1551                                         if ((G.obedit) && G.obedit->type==OB_MESH) {
1552                                                 align_view_to_selected(v3d);
1553                                         }
1554                                         else if (G.f & G_FACESELECT) {
1555                                                 align_view_to_selected(v3d);
1556                                         }
1557                                 }
1558                                 else if(G.qual==LR_ALTKEY)
1559                                         image_aspect();
1560                                 else if (G.qual==0){
1561                                         if(G.obedit) {
1562                                                 if(G.obedit->type==OB_CURVE) {
1563                                                         undo_push_curve("Handle change");
1564                                                         sethandlesNurb(2);
1565                                                         makeDispList(G.obedit);
1566                                                         allqueue(REDRAWVIEW3D, 0);
1567                                                 }
1568                                         }
1569                                         else if(ob && ob->type == OB_MESH) 
1570                                                 set_vpaint();
1571                                 }
1572                                 break;
1573                         case WKEY:
1574                                 if((G.qual==LR_SHIFTKEY)) {
1575                                         transform('w');
1576                                 }
1577                                 else if(G.qual==LR_ALTKEY) {
1578                                         /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
1579                                 }
1580                                 else if(G.qual==LR_CTRLKEY) {
1581                                         if(G.obedit) {
1582                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF) {
1583                                                         switchdirectionNurb2();
1584                                                 }
1585                                         }
1586                                 }
1587                                 else if((G.qual==0))
1588                                         special_editmenu();
1589                                 
1590                                 break;
1591                         case XKEY:
1592                         case DELKEY:
1593                                 if(G.qual==0)
1594                                         delete_context_selected();
1595                                 break;
1596                         case YKEY:
1597                                 if((G.qual==0) && (G.obedit)) {
1598                                         if(G.obedit->type==OB_MESH) split_mesh();
1599                                 }
1600                                 break;
1601                         case ZKEY:
1602                                 toggle_shading();
1603                                 
1604                                 scrarea_queue_headredraw(curarea);
1605                                 scrarea_queue_winredraw(curarea);
1606                                 break;
1607                         
1608                         case HOMEKEY:
1609                                 if(G.qual==0)
1610                                         view3d_home(0);
1611                                 break;
1612                         case COMMAKEY:
1613                                 if(G.qual==LR_CTRLKEY) {
1614                                         G.vd->around= V3D_CENTROID;
1615                                 } else if(G.qual==LR_SHIFTKEY) {
1616                                         G.vd->around= V3D_CENTROID;
1617                                 } else if(G.qual==0) {
1618                                         G.vd->around= V3D_CENTRE;
1619                                 }
1620                                 scrarea_queue_headredraw(curarea);
1621                                 break;
1622                                 
1623                         case PERIODKEY:
1624                                 if(G.qual==LR_CTRLKEY) {
1625                                         G.vd->around= V3D_LOCAL;
1626                                 }       else if(G.qual==0) {
1627                                         G.vd->around= V3D_CURSOR;
1628                                 }
1629                                 scrarea_queue_headredraw(curarea);
1630                                 break;
1631                         
1632                         case PADSLASHKEY:
1633                                 if(G.qual==0) {
1634                                         if(G.vd->localview) {
1635                                                 G.vd->localview= 0;
1636                                                 endlocalview(curarea);
1637                                         }
1638                                         else {
1639                                                 G.vd->localview= 1;
1640                                                 initlocalview();
1641                                         }
1642                                         scrarea_queue_headredraw(curarea);
1643                                 }
1644                                 break;
1645                         case PADASTERKEY:       /* '*' */
1646                                 if(G.qual==0) {
1647                                         ob= OBACT;
1648                                         if(ob) {
1649                                                 obmat_to_viewmat(ob);
1650                                                 if(G.vd->persp==2) G.vd->persp= 1;
1651                                                 scrarea_queue_winredraw(curarea);
1652                                         }
1653                                 }
1654                                 break;
1655                         case PADPERIOD: /* '.' */
1656                                 if(G.qual==0)
1657                                         centreview();
1658                                 break;
1659                         
1660                         case PAGEUPKEY:
1661                                 if(G.qual==LR_CTRLKEY)
1662                                         movekey_obipo(1);
1663                                 else if((G.qual==0))
1664                                         nextkey_obipo(1);       /* in editipo.c */
1665                                 break;
1666
1667                         case PAGEDOWNKEY:
1668                                 if(G.qual==LR_CTRLKEY)
1669                                         movekey_obipo(-1);
1670                                 else if((G.qual==0))
1671                                         nextkey_obipo(-1);
1672                                 break;
1673                                 
1674                         case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
1675                         case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
1676                         case PADENTER:
1677                                 persptoetsen(event);
1678                                 doredraw= 1;
1679                                 break;
1680                         case PADMINUS:
1681                                 if ( (G.qual==LR_CTRLKEY)
1682                                          && (G.obedit) && (G.obedit->type==OB_MESH) )
1683                                         select_less();
1684                                 else {
1685                                         persptoetsen(event);
1686                                         doredraw= 1;
1687                                 }
1688                                 break;
1689
1690                         case PADPLUSKEY:
1691                                 if ( (G.qual==LR_CTRLKEY)
1692                                          && (G.obedit) && (G.obedit->type==OB_MESH) )
1693                                         select_more();
1694                                 else {
1695                                         persptoetsen(event);
1696                                         doredraw= 1;
1697                                 }
1698                                 break;
1699
1700                         case ESCKEY:
1701                                 if(G.qual==0) {
1702                                         if (G.vd->flag & V3D_DISPIMAGE) {
1703                                                 G.vd->flag &= ~V3D_DISPIMAGE;
1704                                                 doredraw= 1;
1705                                         }
1706                                 }
1707                                 break;
1708                         }
1709                 }
1710         }
1711         
1712         if(doredraw) {
1713                 scrarea_queue_winredraw(curarea);
1714                 scrarea_queue_headredraw(curarea);
1715         }
1716 }
1717
1718 void initview3d(ScrArea *sa)
1719 {
1720         View3D *vd;
1721         
1722         vd= MEM_callocN(sizeof(View3D), "initview3d");
1723         BLI_addhead(&sa->spacedata, vd);        /* addhead! not addtail */
1724
1725         vd->spacetype= SPACE_VIEW3D;
1726         vd->blockscale= 0.7;
1727         vd->viewquat[0]= 1.0;
1728         vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0;
1729         vd->persp= 1;
1730         vd->drawtype= OB_WIRE;
1731         vd->view= 7;
1732         vd->dist= 10.0;
1733         vd->lens= 35.0f;
1734         vd->near= 0.01f;
1735         vd->far= 500.0f;
1736         vd->grid= 1.0f;
1737         vd->gridlines= 16;
1738         vd->lay= vd->layact= 1;
1739         if(G.scene) {
1740                 vd->lay= vd->layact= G.scene->lay;
1741                 vd->camera= G.scene->camera;
1742         }
1743         vd->scenelock= 1;
1744         vd->gridflag |= V3D_SHOW_X;
1745         vd->gridflag |= V3D_SHOW_Y;
1746         vd->gridflag |= V3D_SHOW_FLOOR;
1747         vd->gridflag &= ~V3D_SHOW_Z;
1748 }
1749
1750
1751 /* ******************** SPACE: IPO ********************** */
1752
1753 static void changeview2dspace(ScrArea *sa, void *spacedata)
1754 {
1755         if(G.v2d==0) return;
1756
1757         test_view2d(G.v2d, curarea->winx, curarea->winy);
1758         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
1759 }
1760
1761 void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
1762 {
1763         extern void do_ipobuts(unsigned short event);   // drawipo.c
1764         unsigned short event= evt->event;
1765         short val= evt->val;
1766         SpaceIpo *sipo= curarea->spacedata.first;
1767         View2D *v2d= &sipo->v2d;
1768         float dx, dy;
1769         int cfra, doredraw= 0;
1770         short mval[2];
1771         short mousebut = L_MOUSE;
1772         
1773         if(sa->win==0) return;
1774
1775         if(val) {
1776                 if( uiDoBlocks(&sa->uiblocks, event)!=UI_NOTHING ) event= 0;
1777
1778                 /* swap mouse buttons based on user preference */
1779                 if (U.flag & USER_LMOUSESELECT) {
1780                         if (evt->event == LEFTMOUSE) {
1781                                 event = RIGHTMOUSE;
1782                                 mousebut = L_MOUSE;
1783                         } else if (evt->event == RIGHTMOUSE) {
1784                                 event = LEFTMOUSE;
1785                                 mousebut = R_MOUSE;
1786                         }
1787                 }
1788
1789                 switch(event) {
1790                 case UI_BUT_EVENT:
1791                         /* note: bad bad code, will be cleaned! is because event queues are all shattered */
1792                         if(val>0 && val < 65) do_ipowin_buts(val-1);
1793                         else do_ipobuts(val);
1794                         break;
1795                         
1796                 case LEFTMOUSE:
1797                         if( in_ipo_buttons() ) {
1798                                 do_ipo_selectbuttons();
1799                                 doredraw= 1;
1800                         }                       
1801                         else if(G.qual & LR_CTRLKEY) add_vert_ipo();
1802                         else {
1803                                 do {
1804                                         getmouseco_areawin(mval);
1805                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
1806                                         
1807                                         cfra= (int)dx;
1808                                         if(cfra< 1) cfra= 1;
1809                                         
1810                                         if( cfra!=CFRA ) {
1811                                                 CFRA= cfra;
1812                                                 update_for_newframe();
1813                                                 force_draw_plus(SPACE_VIEW3D);
1814                                                 force_draw_plus(SPACE_ACTION);
1815                                                 force_draw_plus(SPACE_BUTS);    /* To make constraint sliders redraw */
1816                                         }
1817                                 
1818                                 } while(get_mbut() & mousebut);
1819                         }
1820                         break;
1821                 case RIGHTMOUSE:
1822                         mouse_select_ipo();
1823                         allqueue (REDRAWACTION, 0);
1824                         allqueue(REDRAWNLA, 0);
1825                         break;
1826                 case MIDDLEMOUSE:
1827                         if(in_ipo_buttons()) {
1828                                 scroll_ipobuts();
1829                         }
1830                         else view2dmove(event); /* in drawipo.c */
1831                         break;
1832                 case WHEELUPMOUSE:
1833                 case WHEELDOWNMOUSE:
1834                         view2dmove(event);      /* in drawipo.c */
1835                         break;
1836                 case PADPLUSKEY:
1837                         view2d_zoom(v2d, 0.1154, sa->winx, sa->winy);
1838                         doredraw= 1;
1839                         break;
1840                 case PADMINUS:
1841                         view2d_zoom(v2d, -0.15, sa->winx, sa->winy);
1842                         doredraw= 1;
1843                         break;
1844                 case PAGEUPKEY:
1845                         if(G.qual==LR_CTRLKEY)
1846                                 movekey_ipo(1);
1847                         else if((G.qual==0))
1848                                 nextkey_ipo(1);
1849                         break;
1850                 case PAGEDOWNKEY:
1851                         if(G.qual==LR_CTRLKEY)
1852                                 movekey_ipo(-1);
1853                         else if((G.qual==0))
1854                                 nextkey_ipo(-1);
1855                         break;
1856                 case HOMEKEY:
1857                         if((G.qual==0))
1858                                 do_ipo_buttons(B_IPOHOME);
1859                         break;
1860                         
1861                 case AKEY:
1862                         if((G.qual==0)) {
1863                                 if(in_ipo_buttons()) {
1864                                         swap_visible_editipo();
1865                                 }
1866                                 else swap_selectall_editipo();
1867                                 allspace (REMAKEIPO, 0);
1868                                 allqueue (REDRAWNLA, 0);
1869                                 allqueue (REDRAWACTION, 0);
1870                         }
1871                         break;
1872                 case BKEY:
1873                         if((G.qual==0))
1874                                 borderselect_ipo();
1875                         break;
1876                 case CKEY:
1877                         if((G.qual==0))
1878                                 move_to_frame();
1879                         break;
1880                 case DKEY:
1881                         if((G.qual==LR_SHIFTKEY))
1882                                 add_duplicate_editipo();
1883                         break;
1884                 case GKEY:
1885                         if((G.qual==0))
1886                                 transform_ipo('g');
1887                         break;
1888                 case HKEY:
1889                         if((G.qual==LR_SHIFTKEY))
1890                                 sethandles_ipo(HD_AUTO);
1891                         else if((G.qual==0))
1892                                 sethandles_ipo(HD_ALIGN);
1893                         break;
1894                 case JKEY:
1895                         if((G.qual==0))
1896                                 join_ipo_menu();
1897                         break;
1898                 case KKEY:
1899                         if((G.qual==0)) {
1900                                 ipo_toggle_showkey();
1901                                 scrarea_queue_headredraw(curarea);
1902                                 allqueue(REDRAWVIEW3D, 0);
1903                                 doredraw= 1;
1904                         }
1905                         break;
1906                 case NKEY:
1907                         toggle_blockhandler(sa, IPO_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
1908                         doredraw= 1;
1909                         break;
1910                 case RKEY:
1911                         if((G.qual==0))
1912                                 ipo_record();
1913                         break;
1914                 case SKEY:
1915                         if((G.qual==LR_SHIFTKEY)) {             
1916                                 ipo_snap_menu();
1917                         } else if((G.qual==0))
1918                                 transform_ipo('s');
1919                         break;
1920                 case TKEY:
1921                         if((G.qual==0))
1922                                 set_ipotype();
1923                         break;
1924                 case VKEY:
1925                         if((G.qual==0))
1926                                 sethandles_ipo(HD_VECT);
1927                         break;
1928                 case XKEY:
1929                 case DELKEY:
1930                         if((G.qual==LR_SHIFTKEY))
1931                                 delete_key();
1932                         else if((G.qual==0))
1933                                 del_ipo();
1934                         break;
1935                 }
1936         }
1937
1938         if(doredraw) scrarea_queue_winredraw(sa);
1939 }
1940
1941 void initipo(ScrArea *sa)
1942 {
1943         SpaceIpo *sipo;
1944         
1945         sipo= MEM_callocN(sizeof(SpaceIpo), "initipo");
1946         BLI_addhead(&sa->spacedata, sipo);
1947
1948         sipo->spacetype= SPACE_IPO;
1949         sipo->blockscale= 0.7;
1950         
1951         /* sipo space loopt van (0,-?) tot (??,?) */
1952         sipo->v2d.tot.xmin= 0.0;
1953         sipo->v2d.tot.ymin= -10.0;
1954         sipo->v2d.tot.xmax= G.scene->r.efra;
1955         sipo->v2d.tot.ymax= 10.0;
1956
1957         sipo->v2d.cur= sipo->v2d.tot;
1958
1959         sipo->v2d.min[0]= 0.01f;
1960         sipo->v2d.min[1]= 0.01f;
1961
1962         sipo->v2d.max[0]= 15000.0f;
1963         sipo->v2d.max[1]= 10000.0f;
1964         
1965         sipo->v2d.scroll= L_SCROLL+B_SCROLL;
1966         sipo->v2d.keeptot= 0;
1967
1968         sipo->blocktype= ID_OB;
1969 }
1970
1971 /* ******************** SPACE: INFO ********************** */
1972
1973 void space_mipmap_button_function(int event) {
1974         set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
1975
1976         allqueue(REDRAWVIEW3D, 0);
1977 }
1978
1979 void space_sound_button_function(int event)
1980 {
1981         int a;
1982         SYS_SystemHandle syshandle;
1983
1984         if ((syshandle = SYS_GetSystem()))
1985         {
1986                 a = (U.gameflags & USER_DISABLE_SOUND);
1987                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
1988         }
1989 }
1990
1991 #define B_ADD_THEME     3301
1992 #define B_DEL_THEME     3302
1993 #define B_NAME_THEME    3303
1994 #define B_THEMECOL              3304
1995 #define B_UPDATE_THEME  3305
1996 #define B_CHANGE_THEME  3306
1997 #define B_THEME_COPY    3307
1998 #define B_THEME_PASTE   3308
1999
2000 #define B_RECALCLIGHT   3310
2001
2002 // needed for event; choose new 'curmain' resets it...
2003 static short th_curcol= TH_BACK;
2004 static char *th_curcol_ptr= NULL;
2005 static char th_curcol_arr[4]={0, 0, 0, 255};
2006
2007 void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
2008 {
2009         bTheme *btheme, *bt;
2010         int spacetype= 0;
2011         static short cur=1, curmain=2;
2012         short a, tot=0, isbuiltin= 0;
2013         char string[21*32], *strp, *col;
2014         
2015         y3= y2+23;      // exception!
2016         
2017         /* count total, max 16! */
2018         for(bt= U.themes.first; bt; bt= bt->next) tot++;
2019         
2020         /* if cur not is 1; move that to front of list */
2021         if(cur!=1) {
2022                 a= 1;
2023                 for(bt= U.themes.first; bt; bt= bt->next, a++) {
2024                         if(a==cur) {
2025                                 BLI_remlink(&U.themes, bt);
2026                                 BLI_addhead(&U.themes, bt);
2027                                 allqueue(REDRAWALL, 0);
2028                                 cur= 1;
2029                                 break;
2030                         }
2031                 }
2032         }
2033         
2034         /* the current theme */
2035         btheme= U.themes.first;
2036         if(strcmp(btheme->name, "Default")==0) isbuiltin= 1;
2037
2038         /* construct popup script */
2039         string[0]= 0;
2040         for(bt= U.themes.first; bt; bt= bt->next) {
2041                 strcat(string, bt->name);
2042                 if(btheme->next) strcat(string, "   |");
2043         }
2044         uiDefButS(block, MENU, B_UPDATE_THEME, string,                  45,y3,200,20, &cur, 0, 0, 0, 0, "Current theme");
2045         
2046         /* add / delete / name */
2047
2048         if(tot<16)
2049                 uiDefBut(block, BUT, B_ADD_THEME, "Add",        45,y2,200,20, NULL, 0, 0, 0, 0, "Makes new copy of this theme");
2050         if(tot>1 && isbuiltin==0)
2051                 uiDefBut(block, BUT, B_DEL_THEME, "Delete", 45,y1,200,20, NULL, 0, 0, 0, 0, "Delete theme");
2052
2053         if(isbuiltin) return;
2054         
2055         /* name */
2056         uiDefBut(block, TEX, B_NAME_THEME, "",                  255,y3,200,20, btheme->name, 1.0, 30.0, 0, 0, "Rename theme");
2057
2058         /* main choices pup */
2059         uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|%l|3D View %x2|%l|Ipo Curve Editor %x3|Action Editor %x4|"
2060                 "NLA Editor %x5|%l|UV/Image Editor %x6|Video Sequence Editor %x7|Audio Timeline %x8|Text Editor %x9|%l|User Preferences %x10|"
2061                 "OOPS Schematic %x11|Buttons Window %x12|%l|File Browser %x13|Image Browser %x14",
2062                                                                                                         255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
2063         if(curmain==1) spacetype= 0;
2064         else if(curmain==2) spacetype= SPACE_VIEW3D;
2065         else if(curmain==3) spacetype= SPACE_IPO;
2066         else if(curmain==4) spacetype= SPACE_ACTION;
2067         else if(curmain==5) spacetype= SPACE_NLA;
2068         else if(curmain==6) spacetype= SPACE_IMAGE;
2069         else if(curmain==7) spacetype= SPACE_SEQ;
2070         else if(curmain==8) spacetype= SPACE_SOUND;
2071         else if(curmain==9) spacetype= SPACE_TEXT;
2072         else if(curmain==10) spacetype= SPACE_INFO;
2073         else if(curmain==11) spacetype= SPACE_OOPS;
2074         else if(curmain==12) spacetype= SPACE_BUTS;
2075         else if(curmain==13) spacetype= SPACE_FILE;
2076         else if(curmain==14) spacetype= SPACE_IMASEL;
2077         else return; // only needed while coding... when adding themes for more windows
2078         
2079         /* color choices pup */
2080         if(curmain==1) {
2081                 strp= BIF_ThemeColorsPup(0);
2082                 if(th_curcol==TH_BACK) th_curcol= TH_BUT_OUTLINE;  // switching main choices...
2083         }
2084         else strp= BIF_ThemeColorsPup(spacetype);
2085         
2086         uiDefButS(block, MENU, B_REDR, strp,                    255,y1,200,20, &th_curcol, 0, 0, 0, 0, "Current color");
2087         MEM_freeN(strp);
2088         
2089         th_curcol_ptr= col= BIF_ThemeGetColorPtr(btheme, spacetype, th_curcol);
2090         if(col==NULL) return;
2091         
2092         /* first handle exceptions, special single values, row selection, etc */
2093         if(th_curcol==TH_VERTEX_SIZE) {
2094                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Vertex size ", 465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
2095         }
2096         else if(th_curcol==TH_BUT_DRAWTYPE) {
2097                 uiBlockBeginAlign(block);
2098                 uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal",        465,y3,100,20,  col, 2.0, 0.0, 0, 0, "");
2099                 uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 565,y3,100,20,  col, 2.0, 1.0, 0, 0, "");
2100                 uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded",        465,y2,100,20,  col, 2.0, 2.0, 0, 0, "");
2101                 uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool",       565,y2,100,20,  col, 2.0, 3.0, 0, 0, "");
2102                 uiBlockEndAlign(block);
2103         }
2104         else {
2105                 uiBlockBeginAlign(block);
2106                 if ELEM3(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT) {
2107                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
2108                 }
2109                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
2110                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"G ",   465,y2,200,20,  col+1, 0.0, 255.0, B_THEMECOL, 0, "");
2111                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"B ",   465,y1,200,20,  col+2, 0.0, 255.0, B_THEMECOL, 0, "");
2112                 uiBlockEndAlign(block);
2113
2114                 uiDefButC(block, COL, B_UPDATE_THEME, "",               675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
2115                                 
2116                 /* copy paste */
2117                 uiBlockBeginAlign(block);
2118                 uiDefBut(block, BUT, B_THEME_COPY, "Copy Color",        755,y2,120,20, NULL, 0, 0, 0, 0, "Stores current color in buffer");
2119                 uiDefBut(block, BUT, B_THEME_PASTE, "Paste Color",      755,y1,120,20, NULL, 0, 0, 0, 0, "Pastes buffer color");
2120                 uiBlockEndAlign(block);
2121                 
2122                 uiDefButC(block, COL, 0, "",                            885,y1,50,y2-y1+20, th_curcol_arr, 0, 0, 0, 0, "");
2123                 
2124         }
2125 }
2126
2127
2128 void drawinfospace(ScrArea *sa, void *spacedata)
2129 {
2130         uiBlock *block;
2131         static short cur_light=0, cur_light_var=0;
2132         float fac, col[3];
2133         short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y5, y6;
2134         short y2label, y3label, y4label, y5label, y6label;
2135         short spref, mpref, lpref, smfileselbut;
2136         short edgsp, midsp;
2137         char naam[32];
2138
2139         if(curarea->win==0) return;
2140
2141         BIF_GetThemeColor3fv(TH_BACK, col);
2142         glClearColor(col[0], col[1], col[2], 0.0);
2143         glClear(GL_COLOR_BUFFER_BIT);
2144
2145         fac= ((float)curarea->winx)/1280.0f;
2146         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2147         
2148         sprintf(naam, "infowin %d", curarea->win);
2149         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->win);
2150
2151
2152         /* Vars for nice grid alignment */ 
2153         dx= (1280-90)/7;        /* spacing for use in equally dividing 'tab' row */
2154
2155         xpos = 45;              /* left padding */
2156         ypos = 50;              /* bottom padding for buttons */
2157         ypostab = 10;           /* bottom padding for 'tab' row */
2158
2159         buth = 20;              /* standard button height */
2160
2161         spref = 90;     /* standard size for small preferences button */
2162         mpref = 189;    /* standard size for medium preferences button */
2163         lpref = 288;    /* standard size for large preferences button */
2164         smfileselbut = buth;    /* standard size for fileselect button (square) */
2165
2166         edgsp = 3;              /* space from edge of end 'tab' to edge of end button */
2167         midsp = 9;              /* horizontal space between buttons */
2168
2169         rspace = 3;             /* default space between rows */
2170
2171         y1 = ypos;              /* grid alignment for each row of buttons */
2172         y2 = ypos+buth+rspace;
2173         y3 = ypos+2*(buth+rspace);
2174         y4 = ypos+3*(buth+rspace);
2175         y5 = ypos+4*(buth+rspace);
2176         y6 = ypos+5*(buth+rspace);
2177
2178
2179         y2label = y2-2;         /* adjustments to offset the labels down to align better */
2180         y3label = y3-2;
2181         y4label = y4-2;
2182         y5label = y5-2;
2183         y6label = y6-2;
2184
2185
2186         /* set the colour to blue and draw the main 'tab' controls */
2187
2188         uiBlockSetCol(block, TH_BUT_SETTING1);
2189         uiBlockBeginAlign(block);
2190         
2191         uiDefButS(block, ROW,B_USERPREF,"View & Controls",
2192                 xpos,ypostab,(short)dx,buth,
2193                 &U.userpref,1.0,0.0, 0, 0,"");
2194                 
2195         uiDefButS(block, ROW,B_USERPREF,"Edit Methods",
2196                 (short)(xpos+dx),ypostab,(short)dx,buth,
2197                 &U.userpref,1.0,1.0, 0, 0,"");
2198
2199         uiDefButS(block, ROW,B_USERPREF,"Language & Font",
2200                 (short)(xpos+2*dx),ypostab,(short)dx,buth,
2201                 &U.userpref,1.0,2.0, 0, 0,"");
2202
2203         uiDefButS(block, ROW,B_USERPREF,"Themes",
2204                 (short)(xpos+3*dx),ypostab,(short)dx,buth,
2205                 &U.userpref,1.0,6.0, 0, 0,"");
2206
2207         uiDefButS(block, ROW,B_USERPREF,"Auto Save",
2208                 (short)(xpos+4*dx),ypostab,(short)dx,buth,
2209                 &U.userpref,1.0,3.0, 0, 0,"");
2210
2211         uiDefButS(block, ROW,B_USERPREF,"System & OpenGL",
2212                 (short)(xpos+5*dx),ypostab,(short)dx,buth,
2213                 &U.userpref,1.0,4.0, 0, 0,"");
2214                 
2215         uiDefButS(block, ROW,B_USERPREF,"File Paths",
2216                 (short)(xpos+6*dx),ypostab,(short)dx,buth,
2217                 &U.userpref,1.0,5.0, 0, 0,"");
2218
2219         uiBlockSetCol(block, TH_AUTO);
2220         uiBlockEndAlign(block);
2221         /* end 'tab' controls */
2222
2223         /* line 2: left x co-ord, top y co-ord, width, height */
2224
2225         if(U.userpref == 6) {
2226                 info_user_themebuts(block, y1, y2, y3);
2227         }
2228         else if (U.userpref == 0) { /* view & controls */
2229
2230                 uiDefBut(block, LABEL,0,"Display:",
2231                         xpos,y6label,spref,buth,
2232                         0, 0, 0, 0, 0, "");     
2233                 uiDefButBitS(block, TOG, USER_TOOLTIPS, 0, "ToolTips",
2234                         (xpos+edgsp),y5,spref,buth,
2235                         &(U.flag), 0, 0, 0, 0,
2236                         "Display tooltips (help tags) over buttons");
2237                 uiDefButBitS(block, TOG, USER_DRAWVIEWINFO, B_DRAWINFO, "Object Info",
2238                         (xpos+edgsp),y4,spref,buth,
2239                         &(U.uiflag), 0, 0, 0, 0,
2240                         "Display active object name and frame number in the 3D View");
2241                 uiDefButBitS(block, TOG, USER_SCENEGLOBAL, 0, "Global Scene",
2242                         (xpos+edgsp),y3,spref,buth,
2243                         &(U.flag), 0, 0, 0, 0,
2244                         "Forces the current Scene to be displayed in all Screens");
2245 #ifndef __APPLE__       
2246                 uiDefButS(block, TOG|BIT|0, 0, "Large Cursors",
2247                         (xpos+edgsp),y2,spref,buth,
2248                         &(U.curssize), 0, 0, 0, 0,
2249                         "Use large mouse cursors when available");
2250 #else 
2251                 U.curssize=0; /*Small Cursor always for OS X for now */
2252 #endif
2253
2254                 uiDefBut(block, LABEL,0,"Menus:",
2255                         (xpos+(2*edgsp)+spref),y6label,spref,buth,
2256                         0, 0, 0, 0, 0, "");
2257                 uiDefButBitS(block, TOG, USER_MENUOPENAUTO, 0, "Open on Mouse Over",
2258                         (xpos+edgsp+spref+midsp),y5,mpref,buth,
2259                         &(U.uiflag), 0, 0, 0, 0,
2260                         "Open menu buttons and pulldowns automatically when the mouse is hovering");
2261                 uiDefButS(block, NUM, 0, "Top Level:",
2262                         (xpos+edgsp+spref+midsp),y4,spref+edgsp,buth,
2263                         &(U.menuthreshold1), 1, 40, 0, 0,
2264                         "Time delay in 1/10 seconds before automatically opening top level menus");
2265                 uiDefButS(block, NUM, 0, "Sublevels:",
2266                         (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y4,spref+edgsp,buth,
2267                         &(U.menuthreshold2), 1, 40, 0, 0,
2268                         "Time delay in 1/10 seconds before automatically opening menu sublevels");
2269
2270                 uiDefBut(block, LABEL,0,"Toolbox click-hold delay:",
2271                         (xpos+(2*edgsp)+spref),y3label,mpref,buth,
2272                         0, 0, 0, 0, 0, "");
2273                 uiDefButS(block, NUM, 0, "LMB:",
2274                         (xpos+edgsp+spref+midsp),y2,spref+edgsp,buth,
2275                         &(U.tb_leftmouse), 2, 40, 0, 0,
2276                         "Time in 1/10 seconds to hold the Left Mouse Button before opening the toolbox");
2277                 uiDefButS(block, NUM, 0, "RMB:",
2278                         (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y2,spref+edgsp,buth,
2279                         &(U.tb_rightmouse), 2, 40, 0, 0,
2280                         "Time in 1/10 seconds to hold the Right Mouse Button before opening the toolbox");      
2281                 uiDefButBitS(block, TOG, USER_PANELPINNED, 0, "Pin Floating Panels",
2282                         (xpos+edgsp+spref+midsp),y1,mpref,buth,
2283                         &(U.uiflag), 0, 0, 0, 0,
2284                         "Make floating panels invoked by a hotkey (eg. N Key) open at the previous location");
2285                 
2286                 
2287                 uiDefBut(block, LABEL,0,"Snap to grid:",
2288                         (xpos+(2*edgsp)+spref+midsp+mpref),y6label,mpref,buth,
2289                         0, 0, 0, 0, 0, "");
2290                 uiDefButBitS(block, TOG, USER_AUTOGRABGRID, 0, "Grab/Move",
2291                         (xpos+edgsp+mpref+spref+(2*midsp)),y5,spref,buth,
2292                         &(U.flag), 0, 0, 0, 0,
2293                         "Snap objects and sub-objects to grid units when moving");
2294                 uiDefButBitS(block, TOG, USER_AUTOROTGRID, 0, "Rotate",
2295                         (xpos+edgsp+mpref+spref+(2*midsp)),y4,spref,buth,
2296                         &(U.flag), 0, 0, 0, 0,
2297                         "Snap objects and sub-objects to grid units when rotating");
2298                 uiDefButBitS(block, TOG, USER_AUTOSIZEGRID, 0, "Scale",
2299                         (xpos+edgsp+mpref+spref+(2*midsp)),y3,spref,buth,
2300                         &(U.flag), 0, 0, 0, 0,
2301                         "Snap objects and sub-objects to grid units when scaling");
2302                 
2303                 uiDefButBitS(block, TOG, USER_LOCKAROUND, B_DRAWINFO, "Global Pivot",
2304                         (xpos+edgsp+mpref+spref+(2*midsp)),y1,spref,buth,
2305                         &(U.uiflag), 0, 0, 0, 0,
2306                         "Lock the same rotation/scaling pivot in all 3D Views");        
2307                 
2308                 uiDefBut(block, LABEL,0,"View zoom:",
2309                         (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y6label,mpref,buth,
2310                         0, 0, 0, 0, 0, "");
2311                 uiBlockBeginAlign(block);
2312                 uiDefButS(block, ROW, 0, "Continue",
2313                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y5,(mpref/3),buth,
2314                         &(U.viewzoom), 40, USER_ZOOM_CONT, 0, 0,
2315                         "Old style zoom, continues while moving mouse up or down");
2316                 uiDefButS(block, ROW, 0, "Dolly",
2317                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/3)),y5,(mpref/3),buth,
2318                         &(U.viewzoom), 40, USER_ZOOM_DOLLY, 0, 0,
2319                         "Zooms in and out based on vertical mouse movement.");
2320                 uiDefButS(block, ROW, 0, "Scale",
2321                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(2*mpref/3)),y5,(mpref/3),buth,
2322                         &(U.viewzoom), 40, USER_ZOOM_SCALE, 0, 0,
2323                         "Zooms in and out like scaling the view, mouse movements relative to center.");
2324                 uiBlockEndAlign(block);
2325                 
2326                 uiDefBut(block, LABEL,0,"View rotation:",
2327                         (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y4label,mpref,buth,
2328                         0, 0, 0, 0, 0, "");
2329                 uiBlockBeginAlign(block);
2330                 uiDefButBitS(block, TOG, USER_TRACKBALL, B_DRAWINFO, "Trackball",
2331                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y3,(mpref/2),buth,
2332                         &(U.flag), 0, 0, 0, 0,
2333                         "Allow the view to tumble freely when orbiting with the Middle Mouse Button");
2334                 uiDefButBitS(block, TOGN, USER_TRACKBALL, B_DRAWINFO, "Turntable",
2335                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/2)),y3,(mpref/2),buth,
2336                         &(U.flag), 0, 0, 0, 0,
2337                         "Keep the Global Z axis pointing upwards when orbiting the view with the Middle Mouse Button");
2338                 uiBlockEndAlign(block);
2339                 
2340                 uiDefButBitS(block, TOG, USER_AUTOPERSP, B_DRAWINFO, "Auto Perspective",
2341                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y1,spref,buth,
2342                         &(U.uiflag), 0, 0, 0, 0,
2343                         "Automatically switch between orthographic and perspective when changing from top/front/side views");
2344
2345                 uiDefBut(block, LABEL,0,"Select with:",
2346                         (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y6label,mpref,buth,
2347                         0, 0, 0, 0, 0, "");
2348                 uiBlockBeginAlign(block);
2349                 uiDefButBitS(block, TOG, USER_LMOUSESELECT, B_DRAWINFO, "Left Mouse",
2350                         (xpos+edgsp+(3*mpref)+(4*midsp)),y5,(mpref/2),buth,
2351                         &(U.flag), 0, 0, 0, 0, "Use the Left Mouse Button for selection");
2352                 uiDefButBitS(block, TOGN, USER_LMOUSESELECT, B_DRAWINFO, "Right Mouse",
2353                         (xpos+edgsp+(3*mpref)+(4*midsp)+(mpref/2)),y5,(mpref/2),buth,
2354                         &(U.flag), 0, 0, 0, 0, "Use the Right Mouse Button for selection");
2355                 uiBlockEndAlign(block);
2356                 
2357                 
2358                 if(U.flag & USER_LMOUSESELECT) {
2359                         uiDefBut(block, LABEL,0,"Cursor with: Right Mouse",
2360                                 (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
2361                                 0, 0, 0, 0, 0, "");
2362                 } else {
2363                         uiDefBut(block, LABEL,0,"Cursor with: Left Mouse",
2364                                 (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
2365                                 0, 0, 0, 0, 0, "");
2366                 }
2367
2368                 uiDefButBitS(block, TOG, USER_TWOBUTTONMOUSE, 0, "Emulate 3 Button Mouse",
2369                         (xpos+edgsp+(3*mpref)+(4*midsp)),y3,mpref,buth,
2370                         &(U.flag), 0, 0, 0, 0,
2371                         "Emulates a middle mouse button with Alt LeftMouse");
2372                 
2373                         
2374                 uiDefBut(block, LABEL,0,"Middle Mouse Button:",
2375                         (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y6label,mpref,buth,
2376                         0, 0, 0, 0, 0, "");
2377                 uiBlockBeginAlign(block);
2378                 uiDefButBitS(block, TOGN, USER_VIEWMOVE, B_DRAWINFO, "Rotate View",
2379                         (xpos+edgsp+(4*mpref)+(5*midsp)),y5,(mpref/2),buth,
2380                         &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
2381                 uiDefButBitS(block, TOG, USER_VIEWMOVE, B_DRAWINFO, "Pan View",
2382                         (xpos+edgsp+(4*mpref)+(5*midsp)+(mpref/2)),y5,(mpref/2),buth,
2383                         &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
2384                 uiBlockEndAlign(block);
2385                         
2386                 uiDefBut(block, LABEL,0,"Mouse Wheel:",
2387                         (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y4label,mpref,buth,
2388                         0, 0, 0, 0, 0, "");
2389                 uiDefButBitS(block, TOG, USER_WHEELZOOMDIR, 0, "Invert Zoom",
2390                         (xpos+edgsp+(4*mpref)+(5*midsp)),y3,spref,buth,
2391                         &(U.uiflag), 0, 0, 0, 0,
2392                         "Swap the Mouse Wheel zoom direction");
2393                 uiDefButI(block, NUM, 0, "Scroll Lines:",
2394                         (xpos+edgsp+(4*mpref)+(6*midsp)+spref-edgsp),y3,spref+edgsp,buth,
2395                         &U.wheellinescroll, 0.0, 32.0, 0, 0,
2396                         "The number of lines scrolled at a time with the mouse wheel"); 
2397
2398
2399         } else if (U.userpref == 1) { /* edit methods */
2400
2401
2402                 uiDefBut(block, LABEL,0,"Material linked to:",
2403                         xpos,y3label,mpref,buth,
2404                         0, 0, 0, 0, 0, "");
2405                 uiBlockBeginAlign(block);
2406                 uiDefButBitS(block, TOGN, USER_MAT_ON_OB, B_DRAWINFO, "ObData",
2407                         (xpos+edgsp),y2,(mpref/2),buth,
2408                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
2409                 uiDefButBitS(block, TOG, USER_MAT_ON_OB, B_DRAWINFO, "Object",
2410                         (xpos+edgsp+(mpref/2)),y2,(mpref/2),buth,
2411                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
2412                 uiBlockEndAlign(block);
2413
2414
2415                 uiDefBut(block, LABEL,0,"Editmode undo:",
2416                         (xpos+(2*edgsp)+mpref),y3label, mpref,buth,
2417                         0, 0, 0, 0, 0, "");
2418                 uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps:",
2419                         (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2420                         &(U.undosteps), 2, 64, 0, 0, "Number of undo steps available in Edit Mode (smaller values conserve memory)");
2421
2422                 uiDefButBitS(block, TOG, USER_GLOBALUNDO, B_DRAWINFO, "Global undo",
2423                         (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2424                         &(U.uiflag), 2, 64, 0, 0, "");
2425
2426
2427                 uiDefBut(block, LABEL,0,"Auto keyframe on:",
2428                         (xpos+(2*edgsp)+(2*mpref)+midsp),y3label,mpref,buth,
2429                         0, 0, 0, 0, 0, "");
2430                 uiDefButBitS(block, TOG, USER_KEYINSERTACT, 0, "Action",
2431                         (xpos+edgsp+(2*mpref)+(2*midsp)),y2,(spref+edgsp),buth,
2432                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Action Ipo curve");
2433                 uiDefButBitS(block, TOG, USER_KEYINSERTOBJ, 0, "Object",
2434                         (xpos+edgsp+(2*mpref)+(3*midsp)+spref-edgsp),y2,(spref+edgsp),buth,
2435                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Object Ipo curve");
2436
2437
2438                 uiDefBut(block, LABEL,0,"Duplicate with object:",
2439                         (xpos+(2*edgsp)+(3*midsp)+(3*mpref)+spref),y3label,mpref,buth,
2440                         0, 0, 0, 0, 0, "");
2441
2442                 uiDefButBitS(block, TOG, USER_DUP_MESH, 0, "Mesh",
2443                         (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y2,(spref+edgsp),buth,
2444                         &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
2445                 uiDefButBitS(block, TOG, USER_DUP_ARM, 0, "Armature",
2446                         (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y1,(spref+edgsp),buth,
2447                         &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
2448
2449                 uiDefButBitS(block, TOG, USER_DUP_SURF, 0, "Surface",
2450                         (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y2,(spref+edgsp),buth,
2451                         &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
2452                 uiDefButBitS(block, TOG, USER_DUP_LAMP, 0, "Lamp",
2453                         (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y1,(spref+edgsp),buth,
2454                         &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
2455
2456                 uiDefButBitS(block, TOG, USER_DUP_CURVE, 0, "Curve",
2457                         (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y2,(spref+edgsp),buth,
2458                         &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
2459                 uiDefButBitS(block, TOG, USER_DUP_MAT, 0, "Material",
2460                         (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y1,(spref+edgsp),buth,
2461                         &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
2462
2463                 uiDefButBitS(block, TOG, USER_DUP_FONT, 0, "Text",
2464                         (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y2,(spref+edgsp),buth,
2465                         &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
2466                 uiDefButBitS(block, TOG, USER_DUP_TEX, 0, "Texture",
2467                         (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y1,(spref+edgsp),buth,
2468                         &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
2469
2470                 uiDefButBitS(block, TOG, USER_DUP_MBALL, 0, "Metaball",
2471                         (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y2,(spref+edgsp),buth,
2472                         &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
2473                 uiDefButBitS(block, TOG, USER_DUP_IPO, 0, "Ipo",
2474                         (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y1,(spref+edgsp),buth,
2475                         &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
2476         
2477         } else if(U.userpref == 2) { /* language & colors */
2478
2479 #ifdef INTERNATIONAL
2480                 char curfont[320];
2481
2482                 sprintf(curfont, "Interface Font: ");
2483                 strcat(curfont,U.fontname);
2484
2485                 uiDefButBitS(block, TOG, USER_DOTRANSLATE, B_DOLANGUIFONT, "International Fonts",
2486                         xpos,y2,mpref,buth,
2487                         &(U.transopts), 0, 0, 0, 0, "Activate international interface");
2488
2489                 if(U.transopts & USER_DOTRANSLATE) {
2490                         uiDefBut(block, LABEL,0,curfont,
2491                                 (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2492                                 0, 0, 0, 0, 0, "");
2493
2494                         uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
2495                                 xpos,y1,mpref,buth,
2496                                 0, 0, 0, 0, 0, "Select a new font for the interface");
2497
2498
2499                         uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
2500                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2501                                 &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
2502
2503 /*
2504                         uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
2505                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2506                                 &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
2507
2508
2509                         uiDefBut(block, LABEL,0,"Translate:",
2510                                 (xpos+edgsp+(2.1*mpref)+(2*midsp)),y3label,mpref,buth,
2511                                 0, 0, 0, 0, 0, "");
2512 */
2513
2514                         uiDefButBitS(block, TOG, USER_TR_TOOLTIPS, B_SETTRANSBUTS, "Tooltips",
2515                                 (xpos+edgsp+(2.2*mpref)+(3*midsp)),y1,spref,buth,
2516                                 &(U.transopts), 0, 0, 0, 0, "Translate tooltips");
2517
2518                         uiDefButBitS(block, TOG, USER_TR_BUTTONS, B_SETTRANSBUTS, "Buttons",
2519                                 (xpos+edgsp+(2.2*mpref)+(4*midsp)+spref),y1,spref,buth,
2520                                 &(U.transopts), 0, 0, 0, 0, "Translate button labels");
2521
2522                         uiDefButBitS(block, TOG, USER_TR_MENUS, B_SETTRANSBUTS, "Toolbox",
2523                                 (xpos+edgsp+(2.2*mpref)+(5*midsp)+(2*spref)),y1,spref,buth,
2524                                 &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
2525
2526                         uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
2527                                 (xpos+edgsp+(2.2*mpref)+(3*midsp)),y2,mpref+(0.5*mpref)+3,buth,
2528                                 &U.language, 0, 0, 0, 0, "Select interface language");
2529                                 
2530                         /* uiDefButBitS(block, TOG, USER_TR_TEXTEDIT, B_SETTRANSBUTS, "FTF All windows",
2531                                 (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
2532                                 &(U.transopts), 0, 0, 0, 0,
2533                                 "Use FTF drawing for fileselect and textwindow "
2534                                 "(under construction)");
2535                         */
2536                 }
2537
2538 /* end of INTERNATIONAL */
2539 #endif
2540
2541         } else if(U.userpref == 3) { /* auto save */
2542
2543
2544                 uiDefButS(block, NUM, 0, "Save Versions:",
2545                         (xpos+edgsp),y3,mpref,buth,
2546                         &U.versions, 0.0, 32.0, 0, 0,
2547                         "The number of old versions to maintain in the current directory, when manually saving");
2548
2549                 uiDefButBitS(block, TOG, USER_AUTOSAVE, B_RESETAUTOSAVE, "Auto Save Temp Files",
2550                         (xpos+edgsp+mpref+midsp),y3,mpref,buth,
2551                         &(U.flag), 0, 0, 0, 0,
2552                         "Enables automatic saving of temporary files");
2553
2554                 if(U.flag & USER_AUTOSAVE) {
2555
2556                         uiDefButI(block, NUM, B_RESETAUTOSAVE, "Minutes:",
2557                                 (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2558                                 &(U.savetime), 1.0, 60.0, 0, 0,
2559                                 "The time (in minutes) to wait between automatic temporary saves");
2560
2561                         uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
2562                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2563                                 0, 0, 0, 0, 0,"Open the most recently saved temporary file");
2564                 }
2565
2566         } else if (U.userpref == 4) { /* system & opengl */
2567                 uiDefBut(block, LABEL,0,"Solid OpenGL light:",
2568                         xpos+edgsp, y3label, mpref, buth,
2569                         0, 0, 0, 0, 0, "");
2570                 
2571                 uiDefButS(block, MENU, B_REDR, "Light1 %x0|Light2 %x1|Light3 %x2",
2572                         xpos+edgsp, y2, 2*mpref/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
2573                 uiBlockSetCol(block, TH_BUT_SETTING1);
2574                 uiDefButI(block, TOG|BIT|0, B_RECALCLIGHT, "On",
2575                         xpos+edgsp+2*mpref/6, y2, mpref/6, buth, 
2576                         &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "");
2577                         
2578                 uiBlockSetCol(block, TH_AUTO);
2579                 uiDefButS(block, ROW, B_REDR, "Vec",
2580                         xpos+edgsp+3*mpref/6, y2, mpref/6, buth, 
2581                         &cur_light_var, 123.0, 0.0, 0, 0, "");
2582                 uiDefButS(block, ROW, B_REDR, "Col",
2583                         xpos+edgsp+4*mpref/6, y2, mpref/6, buth, 
2584                         &cur_light_var, 123.0, 1.0, 0, 0, "");
2585                 uiDefButS(block, ROW, B_REDR, "Spec",
2586                         xpos+edgsp+5*mpref/6, y2, mpref/6, buth, 
2587                         &cur_light_var, 123.0, 2.0, 0, 0, "");
2588
2589                 if(cur_light_var==1) {
2590                         uiDefButF(block, NUM, B_RECALCLIGHT, "R ",
2591                                 xpos+edgsp, y1, mpref/3, buth, 
2592                                 U.light[cur_light].col, 0.0, 1.0, 100, 2, "");
2593                         uiDefButF(block, NUM, B_RECALCLIGHT, "G ",
2594                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2595                                 U.light[cur_light].col+1, 0.0, 1.0, 100, 2, "");
2596                         uiDefButF(block, NUM, B_RECALCLIGHT, "B ",
2597                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2598                                 U.light[cur_light].col+2, 0.0, 1.0, 100, 2, "");
2599                 }
2600                 else if(cur_light_var==2) {
2601                         uiDefButF(block, NUM, B_RECALCLIGHT, "sR ",
2602                                 xpos+edgsp, y1, mpref/3, buth, 
2603                                 U.light[cur_light].spec, 0.0, 1.0, 100, 2, "");
2604                         uiDefButF(block, NUM, B_RECALCLIGHT, "sG ",
2605                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2606                                 U.light[cur_light].spec+1, 0.0, 1.0, 100, 2, "");
2607                         uiDefButF(block, NUM, B_RECALCLIGHT, "sB ",
2608                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2609                                 U.light[cur_light].spec+2, 0.0, 1.0, 100, 2, "");
2610                 }
2611                 else if(cur_light_var==0) {
2612                         uiDefButF(block, NUM, B_RECALCLIGHT, "X ",
2613                                 xpos+edgsp, y1, mpref/3, buth, 
2614                                 U.light[cur_light].vec, -1.0, 1.0, 100, 2, "");
2615                         uiDefButF(block, NUM, B_RECALCLIGHT, "Y ",
2616                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2617                                 U.light[cur_light].vec+1, -1.0, 1.0, 100, 2, "");
2618                         uiDefButF(block, NUM, B_RECALCLIGHT, "Z ",
2619                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2620                                 U.light[cur_light].vec+2, -1.0, 1.0, 100, 2, "");
2621                 }
2622
2623 /*
2624                 uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
2625                         (xpos+edgsp),y2,lpref,buth,
2626                         &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
2627
2628                 uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
2629                         (xpos+edgsp), y1, lpref,buth,
2630                         &U.console_out, 0, 0, 0, 0, "Select console output method");
2631
2632                 uiDefButS(block, NUM, B_CONSOLENUMLINES, "Lines:",
2633                         (xpos+edgsp+lpref+midsp),y1,spref,buth,
2634                         &U.console_buffer, 1.0, 4000.0, 0, 0, "Maximum number of internal console lines");
2635 */
2636
2637 #ifdef _WIN32
2638                 uiDefBut(block, LABEL,0,"Win Codecs:",
2639                         (xpos+edgsp+(1*midsp)+(1*mpref)),y3label,mpref,buth,
2640                         0, 0, 0, 0, 0, "");
2641
2642                 uiDefButBitS(block, TOG, USER_ALLWINCODECS, 0, "Enable all codecs",
2643                         (xpos+edgsp+(1*mpref)+(1*midsp)),y2,mpref,buth,
2644                         &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
2645 #endif
2646
2647                 uiDefBut(block, LABEL,0,"Keyboard:",
2648                         (xpos+edgsp+(3*midsp)+(3*mpref)),y3label,mpref,buth,
2649                         0, 0, 0, 0, 0, "");
2650
2651                 uiDefButBitS(block, TOG, USER_NO_CAPSLOCK, B_U_CAPSLOCK, "Disable Caps Lock",
2652                         (xpos+edgsp+(3*midsp)+(3*mpref)),y1,mpref,buth,
2653                         &(U.flag), 0, 0, 0, 0,
2654                         "Disables the Caps Lock key when entering text");
2655
2656                 uiDefButBitS(block, TOG, USER_NONUMPAD, 0, "Emulate Numpad",
2657                         (xpos+edgsp+(3*midsp)+(3*mpref)),y2,mpref,buth,
2658                         &(U.flag), 0, 0, 0, 0,
2659                         "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
2660
2661
2662                 uiDefBut(block, LABEL,0,"System:",
2663                         (xpos+edgsp+(4*midsp)+(4*mpref)),y3label,mpref,buth,
2664                         0, 0, 0, 0, 0, "");
2665
2666                 uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Sound",
2667                         (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
2668                         &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
2669
2670                 uiDefButBitS(block, TOG, USER_FILTERFILEEXTS, 0, "Filter File Extensions",
2671                         (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
2672                         &(U.uiflag), 0, 0, 0, 0, "Display only files with extensions in the image select window");
2673
2674
2675                 uiDefBut(block, LABEL,0,"OpenGL:",
2676                         (xpos+edgsp+(5*midsp)+(5*mpref)),y3label,mpref,buth,
2677                         0, 0, 0, 0, 0, "");
2678
2679                 uiDefButBitI(block, TOGN, USER_DISABLE_MIPMAP, B_MIPMAPCHANGED, "Mipmaps",
2680                         (xpos+edgsp+(5*mpref)+(5*midsp)),y2,mpref,buth,
2681                         &(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
2682
2683                 uiDefButBitI(block, TOG, USER_VERTEX_ARRAYS, 0, "Vertex Arrays",
2684                         (xpos+edgsp+(5*mpref)+(5*midsp)),y1,mpref,buth,
2685                         &(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
2686
2687                 uiDefBut(block, LABEL,0,"Audio mixing buffer:",
2688                         (xpos+edgsp+(2*midsp)+(2*mpref)),y3label,mpref,buth,
2689                         0, 0, 0, 0, 0, "");
2690                 uiBlockBeginAlign(block);
2691                 uiDefButI(block, ROW, 0, "256",
2692                         (xpos+edgsp+(2*midsp)+(2*mpref)),y2,(mpref/4),buth,
2693                         &U.mixbufsize, 2.0, 256.0, 0, 0, "Set audio mixing buffer size to 256 samples");
2694                 uiDefButI(block, ROW, 0, "512",
2695                         (xpos+edgsp+(2*midsp)+(2*mpref)+(mpref/4)),y2,(mpref/4),buth,
2696                         &U.mixbufsize, 2.0, 512.0, 0, 0, "Set audio mixing buffer size to 512 samples");        
2697                 uiDefButI(block, ROW, 0, "1024",
2698                         (xpos+edgsp+(2*midsp)+(2*mpref)+(2*mpref/4)),y2,(mpref/4),buth,
2699                         &U.mixbufsize, 2.0, 1024.0, 0, 0, "Set audio mixing buffer size to 1024 samples");              
2700                 uiDefButI(block, ROW, 0, "2048",
2701                         (xpos+edgsp+(2*midsp)+(2*mpref)+(3*mpref/4)),y2,(mpref/4),buth,
2702                         &U.mixbufsize, 2.0, 2048.0, 0, 0, "Set audio mixing buffer size to 2048 samples");                      
2703                 uiBlockEndAlign(block);
2704
2705         } else if(U.userpref == 5) { /* file paths */
2706
2707                 /* yafray: (temporary) path button for yafray xml export, now with fileselect */
2708                 uiDefBut(block, TEX, 0, "YFexport: ",
2709                         (xpos+edgsp), y2+buth+rspace, lpref-smfileselbut, buth,
2710                         U.yfexportdir, 1.0, 63.0, 0, 0,
2711                         "The default directory for yafray xml export (must exist!)");
2712                 uiDefIconBut(block, BUT, B_YAFRAYDIRFILESEL, ICON_FILESEL,
2713                         (xpos+edgsp+lpref-smfileselbut), y2+buth+rspace, smfileselbut, buth,
2714                         0, 0, 0, 0, 0, "Select the default yafray export directory");
2715
2716                 uiDefBut(block, TEX, 0, "Fonts: ",
2717                         (xpos+edgsp),y2,(lpref-smfileselbut),buth,
2718                         U.fontdir, 1.0, 63.0, 0, 0,
2719                         "The default directory to search for loading fonts");
2720                 uiDefIconBut(block, BUT, B_FONTDIRFILESEL, ICON_FILESEL,
2721                         (xpos+edgsp+lpref-smfileselbut),y2,smfileselbut,buth,
2722                         0, 0, 0, 0, 0, "Select the default font directory");
2723
2724                 uiDefBut(block, TEX, 0, "Textures: ",
2725                         (xpos+edgsp+lpref+midsp),y2,(lpref-smfileselbut),buth,
2726                         U.textudir, 1.0, 63.0, 0, 0, "The default directory to search for textures");
2727                 uiDefIconBut(block, BUT, B_TEXTUDIRFILESEL, ICON_FILESEL,
2728                         (xpos+edgsp+(2*lpref)+midsp-smfileselbut),y2,smfileselbut,buth,
2729                         0, 0, 0, 0, 0, "Select the default texture location");
2730
2731
2732                 uiDefBut(block, TEX, 0, "Tex Plugins: ",
2733                         (xpos+edgsp+(2*lpref)+(2*midsp)),y2,(lpref-smfileselbut),buth,
2734                         U.plugtexdir, 1.0, 63.0, 0, 0, "The default directory to search for texture plugins");
2735                 uiDefIconBut(block, BUT, B_PLUGTEXDIRFILESEL, ICON_FILESEL,
2736                         (xpos+edgsp+(3*lpref)+(2*midsp)-smfileselbut),y2,smfileselbut,buth,
2737                         0, 0, 0, 0, 0, "Select the default texture plugin location");
2738
2739                 uiDefBut(block, TEX, 0, "Seq Plugins: ",
2740                         (xpos+edgsp+(3*lpref)+(3*midsp)),y2,(lpref-smfileselbut),buth,
2741                         U.plugseqdir, 1.0, 63.0, 0, 0, "The default directory to search for sequence plugins");
2742                 uiDefIconBut(block, BUT, B_PLUGSEQDIRFILESEL, ICON_FILESEL,
2743                         (xpos+edgsp+(4*lpref)+(3*midsp)-smfileselbut),y2,smfileselbut,buth,
2744                         0, 0, 0, 0, 0, "Select the default sequence plugin location");
2745
2746
2747                 uiDefBut(block, TEX, 0, "Render: ",
2748                         (xpos+edgsp),y1,(lpref-smfileselbut),buth,
2749                         U.renderdir, 1.0, 63.0, 0, 0, "The default directory for rendering output");
2750                 uiDefIconBut(block, BUT, B_RENDERDIRFILESEL, ICON_FILESEL,
2751                         (xpos+edgsp+lpref-smfileselbut),y1,smfileselbut,buth,
2752                         0, 0, 0, 0, 0, "Select the default render output location");
2753
2754                 uiDefBut(block, TEX, 0, "Python: ",
2755                         (xpos+edgsp+lpref+midsp),y1,(lpref-2*smfileselbut),buth,
2756                         U.pythondir, 1.0, 63.0, 0, 0, "The default directory to search for Python scripts");
2757                 uiDefIconBut(block, BUT, B_PYMENUEVAL, ICON_SCRIPT,
2758                         (xpos+edgsp+(2*lpref)+midsp-2*smfileselbut),y1,smfileselbut,buth,
2759                         0, 0, 0, 0, 0, "Re-evaluate scripts registration in menus");
2760                 uiDefIconBut(block, BUT, B_PYTHONDIRFILESEL, ICON_FILESEL,
2761                         (xpos+edgsp+(2*lpref)+midsp-smfileselbut),y1,smfileselbut,buth,
2762                         0, 0, 0, 0, 0, "Select the default Python script location");
2763
2764
2765                 uiDefBut(block, TEX, 0, "Sounds: ",
2766                         (xpos+edgsp+(2*lpref)+(2*midsp)),y1,(lpref-smfileselbut),buth,
2767                         U.sounddir, 1.0, 63.0, 0, 0, "The default directory to search for sounds");
2768                 uiDefIconBut(block, BUT, B_SOUNDDIRFILESEL, ICON_FILESEL,
2769                         (xpos+edgsp+(3*lpref)+(2*midsp)-smfileselbut),y1,smfileselbut,buth,
2770                         0, 0, 0, 0, 0, "Select the default sound location");
2771
2772                 uiDefBut(block, TEX, 0, "Temp: ",
2773                          (xpos+edgsp+(3*lpref)+(3*midsp)),y1,(lpref-smfileselbut),buth,
2774                          U.tempdir, 1.0, 63.0, 0, 0, "The directory for storing temporary save files");
2775                 uiDefIconBut(block, BUT, B_TEMPDIRFILESEL, ICON_FILESEL,
2776                         (xpos+edgsp+(4*lpref)+(3*midsp)-smfileselbut),y1,smfileselbut,buth,
2777                         0, 0, 0, 0, 0, "Select the default temporary save file location");
2778
2779         }
2780
2781         uiDrawBlock(block);
2782         
2783         myortho2(-0.375, (float)(sa->winx)-0.375, -0.375, (float)(sa->winy)-0.375);
2784         draw_area_emboss(sa);
2785         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2786         sa->win_swap= WIN_BACK_OK;
2787         
2788 }
2789
2790
2791 void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2792 {
2793         unsigned short event= evt->event;
2794         short val= evt->val;
2795         
2796         if(val) {
2797                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2798
2799                 switch(event) {
2800                 case UI_BUT_EVENT:
2801    &n