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