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