- added "hide" flag for MetaElem. Hidden MetaElem doesn't influence polygonisation.
[blender.git] / source / blender / src / space.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  *
32  *
33  * - here initialize and free and handling SPACE data
34  */
35
36 #include <string.h>
37 #include <stdio.h>
38
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
42
43 #ifdef WIN32
44 #include "BLI_winstuff.h"
45 #endif
46
47 #include "MEM_guardedalloc.h"
48
49 #ifdef INTERNATIONAL
50 #include "BIF_language.h"
51 #endif
52
53 #include "IMB_imbuf_types.h"
54 #include "IMB_imbuf.h"
55
56 #include "BLI_blenlib.h"
57 #include "BLI_arithb.h"
58 #include "BLI_linklist.h"
59
60 #include "DNA_action_types.h"
61 #include "DNA_curve_types.h"
62 #include "DNA_image_types.h"
63 #include "DNA_ipo_types.h"
64 #include "DNA_mesh_types.h"
65 #include "DNA_object_types.h"
66 #include "DNA_scene_types.h"
67 #include "DNA_screen_types.h"
68 #include "DNA_sequence_types.h"
69 #include "DNA_sound_types.h"
70 #include "DNA_space_types.h"
71 #include "DNA_userdef_types.h"
72 #include "DNA_view2d_types.h"
73 #include "DNA_view3d_types.h"
74
75 #include "BKE_blender.h"
76 #include "BKE_curve.h"
77 #include "BKE_displist.h"
78 #include "BKE_global.h"
79 #include "BKE_ipo.h"
80 #include "BKE_main.h"
81 #include "BKE_scene.h"
82 #include "BKE_utildefines.h"
83
84 #include "BIF_spacetypes.h"  // first, nasty dependency with typedef
85
86 #include "BIF_butspace.h"
87 #include "BIF_drawimage.h"
88 #include "BIF_drawseq.h"
89 #include "BIF_drawtext.h"
90 #include "BIF_drawscript.h"
91 #include "BIF_editarmature.h"
92 #include "BIF_editfont.h"
93 #include "BIF_editika.h"
94 #include "BIF_editkey.h"
95 #include "BIF_editlattice.h"
96 #include "BIF_editmesh.h"
97 #include "BIF_editmode_undo.h"
98 #include "BIF_editnla.h"
99 #include "BIF_editoops.h"
100 #include "BIF_editseq.h"
101 #include "BIF_editsima.h"
102 #include "BIF_editsound.h"
103 #include "BIF_editview.h"
104 #include "BIF_gl.h"
105 #include "BIF_imasel.h"
106 #include "BIF_interface.h"
107 #include "BIF_meshtools.h"
108 #include "BIF_mywindow.h"
109 #include "BIF_oops.h"
110 #include "BIF_outliner.h"
111 #include "BIF_resources.h"
112 #include "BIF_screen.h"
113 #include "BIF_space.h"
114 #include "BIF_toets.h"
115 #include "BIF_toolbox.h"
116 #include "BIF_usiblender.h"
117 #include "BIF_previewrender.h"
118
119 #include "BSE_edit.h"
120 #include "BSE_view.h"
121 #include "BSE_editipo.h"
122 #include "BSE_drawipo.h"
123 #include "BSE_drawview.h"
124 #include "BSE_drawnla.h"
125 #include "BSE_filesel.h"
126 #include "BSE_headerbuttons.h"
127 #include "BSE_editnla_types.h"
128
129 #include "BDR_vpaint.h"
130 #include "BDR_editmball.h"
131 #include "BDR_editobject.h"
132 #include "BDR_editcurve.h"
133 #include "BDR_editface.h"
134 #include "BDR_drawmesh.h"
135 #include "BDR_drawobject.h"
136 #include "BDR_unwrapper.h"
137
138 #include "BLO_readfile.h" /* for BLO_blendhandle_close */
139
140 #include "PIL_time.h"
141
142 #include "BPY_extern.h"
143
144 #include "mydevice.h"
145 #include "blendef.h"
146 #include "datatoc.h"
147
148 #include "BIF_transform.h"
149
150 #include "TPT_DependKludge.h"
151 #ifdef NAN_TPT
152 #include "BSE_trans_types.h"
153 #include "IMG_Api.h"
154 #endif /* NAN_TPT */
155
156 #include "SYS_System.h" /* for the user def menu ... should move elsewhere. */
157
158 extern void StartKetsjiShell(ScrArea *area, char* startscenename, struct Main* maggie, int always_use_expand_framing);
159
160 /**
161  * When the mipmap setting changes, we want to redraw the view right
162  * away to reflect this setting.
163  */
164 void space_mipmap_button_function(int event);
165
166 void free_soundspace(SpaceSound *ssound);
167
168 /* *************************************** */
169
170 /* don't know yet how the handlers will evolve, for simplicity
171    i choose for an array with eventcodes, this saves in a file!
172    */
173 void add_blockhandler(ScrArea *sa, short eventcode, short val)
174 {
175         SpaceLink *sl= sa->spacedata.first;
176         short a;
177         
178         // find empty spot
179         for(a=0; a<SPACE_MAXHANDLER; a+=2) {
180                 if( sl->blockhandler[a]==eventcode ) {
181                         sl->blockhandler[a+1]= val;
182                         break;
183                 }
184                 else if( sl->blockhandler[a]==0) {
185                         sl->blockhandler[a]= eventcode;
186                         sl->blockhandler[a+1]= val;
187                         break;
188                 }
189         }
190         if(a==SPACE_MAXHANDLER) printf("error; max (4) blockhandlers reached!\n");
191 }
192
193 void rem_blockhandler(ScrArea *sa, short eventcode)
194 {
195         SpaceLink *sl= sa->spacedata.first;
196         short a;
197         
198         for(a=0; a<SPACE_MAXHANDLER; a+=2) {
199                 if( sl->blockhandler[a]==eventcode) {
200                         sl->blockhandler[a]= 0;
201                         break;
202                 }
203         }
204 }
205
206 void toggle_blockhandler(ScrArea *sa, short eventcode, short val)
207 {
208         SpaceLink *sl= sa->spacedata.first;
209         short a, addnew=1;
210         
211         // find if it exists
212         for(a=0; a<SPACE_MAXHANDLER; a+=2) {
213                 if( sl->blockhandler[a]==eventcode ) {
214                         sl->blockhandler[a]= 0;
215                         addnew= 0;
216                 }
217         }
218         if(addnew) add_blockhandler(sa, eventcode, val);
219 }
220
221
222
223 /* ************* SPACE: VIEW3D  ************* */
224
225 /*  extern void drawview3dspace(ScrArea *sa, void *spacedata); BSE_drawview.h */
226
227
228 void copy_view3d_lock(short val)
229 {
230         bScreen *sc;
231         int bit;
232         
233         /* from G.scene copy to the other views */
234         sc= G.main->screen.first;
235         
236         while(sc) {
237                 if(sc->scene==G.scene) {
238                         ScrArea *sa= sc->areabase.first;
239                         while(sa) {
240                                 SpaceLink *sl= sa->spacedata.first;
241                                 while(sl) {
242                                         if(sl->spacetype==SPACE_OOPS && val==REDRAW) {
243                                                 if(sa->win) scrarea_queue_winredraw(sa);
244                                         }
245                                         else if(sl->spacetype==SPACE_VIEW3D) {
246                                                 View3D *vd= (View3D*) sl;
247                                                 if(vd->scenelock && vd->localview==0) {
248                                                         vd->lay= G.scene->lay;
249                                                         vd->camera= G.scene->camera;
250                                                         
251                                                         if(vd->camera==0 && vd->persp>1) vd->persp= 1;
252                                                         
253                                                         if( (vd->lay & vd->layact) == 0) {
254                                                                 bit= 0;
255                                                                 while(bit<32) {
256                                                                         if(vd->lay & (1<<bit)) {
257                                                                                 vd->layact= 1<<bit;
258                                                                                 break;
259                                                                         }
260                                                                         bit++;
261                                                                 }
262                                                         }
263                                                         
264                                                         if(val==REDRAW && vd==sa->spacedata.first) {
265                                                                 if(sa->win) scrarea_queue_redraw(sa);
266                                                         }
267                                                 }
268                                         }
269                                         sl= sl->next;
270                                 }
271                                 sa= sa->next;
272                         }
273                 }
274                 sc= sc->id.next;
275         }
276 }
277
278 void handle_view3d_around()
279 {
280         bScreen *sc;
281         
282         if ((U.uiflag & USER_LOCKAROUND)==0) return;
283         
284         /* copies from G.vd->around to other view3ds */
285         
286         sc= G.main->screen.first;
287         
288         while(sc) {
289                 if(sc->scene==G.scene) {
290                         ScrArea *sa= sc->areabase.first;
291                         while(sa) {
292                                 SpaceLink *sl= sa->spacedata.first;
293                                 while(sl) {
294                                         if(sl->spacetype==SPACE_VIEW3D) {
295                                                 View3D *vd= (View3D*) sl;
296                                                 if (vd != G.vd) {
297                                                         vd->around= G.vd->around;
298                                                         if (G.vd->flag & V3D_ALIGN)
299                                                                 vd->flag |= V3D_ALIGN;
300                                                         else
301                                                                 vd->flag &= ~V3D_ALIGN;
302                                                         scrarea_queue_headredraw(sa);
303                                                 }
304                                         }
305                                         sl= sl->next;
306                                 }
307                                 sa= sa->next;
308                         }
309                 }
310                 sc= sc->id.next;
311         }
312 }
313
314 void handle_view3d_lock()
315 {
316         if (G.vd != NULL) {
317                 if(G.vd->localview==0 && G.vd->scenelock && curarea->spacetype==SPACE_VIEW3D) {
318
319                         /* copy to scene */
320                         G.scene->lay= G.vd->lay;
321                         G.scene->camera= G.vd->camera;
322         
323                         copy_view3d_lock(REDRAW);
324                 }
325         }
326 }
327
328 void space_set_commmandline_options(void) {
329         SYS_SystemHandle syshandle;
330         int a;
331                 
332         if ( (syshandle = SYS_GetSystem()) ) {
333                 /* User defined settings */
334                 a= (U.gameflags & USER_VERTEX_ARRAYS);
335                 SYS_WriteCommandLineInt(syshandle, "vertexarrays", a);
336
337                 a= (U.gameflags & USER_DISABLE_SOUND);
338                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
339
340                 a= (U.gameflags & USER_DISABLE_MIPMAP);
341                 set_mipmap(!a);
342                 SYS_WriteCommandLineInt(syshandle, "nomipmap", a);
343
344                 /* File specific settings: */
345                 /* Only test the first one. These two are switched
346                  * simultaneously. */
347                 a= (G.fileflags & G_FILE_SHOW_FRAMERATE);
348                 SYS_WriteCommandLineInt(syshandle, "show_framerate", a);
349                 SYS_WriteCommandLineInt(syshandle, "show_profile", a);
350
351                 /* When in wireframe mode, always draw debug props. */
352                 if (G.vd) {
353                         a = ( (G.fileflags & G_FILE_SHOW_DEBUG_PROPS) 
354                                   || (G.vd->drawtype == OB_WIRE)          
355                                   || (G.vd->drawtype == OB_SOLID)         );
356                         SYS_WriteCommandLineInt(syshandle, "show_properties", a);
357                 }
358
359                 a= (G.fileflags & G_FILE_ENABLE_ALL_FRAMES);
360                 SYS_WriteCommandLineInt(syshandle, "fixedtime", a);
361         }
362 }
363
364 #if GAMEBLENDER == 1
365         /**
366          * These two routines imported from the gameengine, 
367          * I suspect a lot of the resetting stuff is cruft
368          * and can be removed, but it should be checked.
369          */
370 static void SaveState(void)
371 {
372         glPushAttrib(GL_ALL_ATTRIB_BITS);
373
374         init_realtime_GL();
375         init_gl_stuff();
376
377         if(G.scene->camera==0 || G.scene->camera->type!=OB_CAMERA)
378                 error("no (correct) camera");
379
380         waitcursor(1);
381 }
382
383 static void RestoreState(void)
384 {
385         curarea->win_swap = 0;
386         curarea->head_swap=0;
387         allqueue(REDRAWVIEW3D, 1);
388         allqueue(REDRAWBUTSALL, 0);
389         reset_slowparents();
390         waitcursor(0);
391         G.qual= 0;
392         glPopAttrib();
393 }
394
395 static LinkNode *save_and_reset_all_scene_cfra(void)
396 {
397         LinkNode *storelist= NULL;
398         Scene *sc;
399         
400         for (sc= G.main->scene.first; sc; sc= sc->id.next) {
401                 BLI_linklist_prepend(&storelist, (void*) (long) sc->r.cfra);
402                 sc->r.cfra= 1;
403
404                 set_scene_bg(sc);
405         }
406         
407         BLI_linklist_reverse(&storelist);
408         
409         return storelist;
410 }
411
412 static void restore_all_scene_cfra(LinkNode *storelist) {
413         LinkNode *sc_store= storelist;
414         Scene *sc;
415         
416         for (sc= G.main->scene.first; sc; sc= sc->id.next) {
417                 int stored_cfra= (int) sc_store->link;
418                 
419                 sc->r.cfra= stored_cfra;
420                 set_scene_bg(sc);
421                 
422                 sc_store= sc_store->next;
423         }
424         
425         BLI_linklist_free(storelist, NULL);
426 }
427 #endif
428
429 void start_game(void)
430 {
431 #if GAMEBLENDER == 1
432 #ifndef NO_KETSJI
433         Scene *sc, *startscene = G.scene;
434         LinkNode *scene_cfra_store;
435
436                 /* XXX, silly code -  the game engine can
437                  * access any scene through logic, so we try 
438                  * to make sure each scene has a valid camera, 
439                  * just in case the game engine tries to use it.
440                  * 
441                  * Better would be to make a better routine
442                  * in the game engine for finding the camera.
443                  *  - zr
444                  */
445         for (sc= G.main->scene.first; sc; sc= sc->id.next) {
446                 if (!sc->camera) {
447                         Base *base;
448         
449                         for (base= sc->base.first; base; base= base->next)
450                                 if (base->object->type==OB_CAMERA)
451                                         break;
452                         
453                         sc->camera= base?base->object:NULL;
454                 }
455         }
456
457         /* these two lines make sure front and backbuffer are equal. for swapbuffers */
458         markdirty_all();
459         screen_swapbuffers();
460
461         /* can start from header */
462         mywinset(curarea->win);
463     
464         scene_cfra_store= save_and_reset_all_scene_cfra();
465         
466
467         /* game engine will do its own sounds. */
468         sound_stop_all_sounds();
469         sound_exit_audio();
470         
471         /* Before jumping into Ketsji, we configure some settings. */
472         space_set_commmandline_options();
473
474         SaveState();
475         StartKetsjiShell(curarea, startscene->id.name+2, G.main, 1);
476         RestoreState();
477
478         /* Restart BPY - unload the game engine modules. */
479         BPY_end_python();
480         BPY_start_python(0, NULL); /* argc, argv stored there already */
481         BPY_post_start_python(); /* userpref path and menus init */
482
483         restore_all_scene_cfra(scene_cfra_store);
484         set_scene_bg(startscene);
485         
486         if (G.flags & G_FLAGS_AUTOPLAY)
487                 exit_usiblender();
488
489                 /* groups could have changed ipo */
490         allqueue(REDRAWNLA, 0);
491         allqueue(REDRAWACTION, 0);
492         allspace(REMAKEIPO, 0);
493         allqueue(REDRAWIPO, 0);
494 #endif
495 #else
496         notice("Game engine is disabled in this release!");
497 #endif
498 }
499
500 static void changeview3dspace(ScrArea *sa, void *spacedata)
501 {
502         setwinmatrixview3d(0);  /* 0= no pick rect */
503 }
504
505         /* Callable from editmode and faceselect mode from the
506          * moment, would be nice (and is easy) to generalize
507          * to any mode.
508          */
509 static void align_view_to_selected(View3D *v3d)
510 {
511         int nr= pupmenu("Align View%t|To Selected (top)%x2|To Selected (front)%x1|To Selected (side)%x0");
512
513         if (nr!=-1) {
514                 int axis= nr;
515
516                 if ((G.obedit) && (G.obedit->type == OB_MESH)) {
517                         editmesh_align_view_to_selected(v3d, axis);
518                         addqueue(v3d->area->win, REDRAW, 1);
519                 } else if (G.f & G_FACESELECT) {
520                         Object *obact= OBACT;
521                         if (obact && obact->type==OB_MESH) {
522                                 Mesh *me= obact->data;
523
524                                 if (me->tface) {
525                                         faceselect_align_view_to_selected(v3d, me, axis);
526                                         addqueue(v3d->area->win, REDRAW, 1);
527                                 }
528                         }
529                 }
530         }
531 }
532
533 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(TFM_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                                         else if(G.obedit->type==OB_MBALL) {
1266                                                 if(G.qual==LR_ALTKEY)
1267                                                         reveal_mball();
1268                                                 else if((G.qual==LR_SHIFTKEY))
1269                                                         hide_mball(1);
1270                                                 else if((G.qual==0)) 
1271                                                         hide_mball(0);
1272                                         }
1273                                 }
1274                                 else if(G.f & G_FACESELECT)
1275                                         hide_tface();
1276                                 else if(G.obpose) {
1277                                         if (G.qual==0)
1278                                                 hide_selected_pose_bones();
1279                                         else if (G.qual==LR_SHIFTKEY)
1280                                                 hide_unselected_pose_bones();
1281                                         else if (G.qual==LR_ALTKEY)
1282                                                 show_all_pose_bones();
1283                                 }
1284                                 break;
1285                         case IKEY:
1286                                 break;
1287                                 
1288                         case JKEY:
1289                                 if(G.qual==LR_CTRLKEY) {
1290                                         if( (ob= OBACT) ) {
1291                                                 if(ob->type == OB_MESH)
1292                                                         join_mesh();
1293                                                 else if(ob->type == OB_CURVE)
1294                                                         join_curve(OB_CURVE);
1295                                                 else if(ob->type == OB_SURF)
1296                                                         join_curve(OB_SURF);
1297                                                 else if(ob->type == OB_ARMATURE)
1298                                                         join_armature ();
1299                                         }
1300                                         else if ((G.obedit) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
1301                                                 addsegment_nurb();
1302                                 }
1303                                 else if(G.obedit) {
1304                                         if(G.obedit->type==OB_MESH) {
1305                                                 join_triangles();
1306                                         }
1307                                 }
1308
1309                                 break;
1310                         case KKEY:
1311                                 if(G.obedit) {
1312                                         if (G.obedit->type==OB_MESH) {
1313                                                 if (G.qual==LR_SHIFTKEY)
1314                                                         KnifeSubdivide(KNIFE_PROMPT);
1315                                                 else if (G.qual==0)
1316                                                         LoopMenu();
1317                                         }
1318                                         else if(G.obedit->type==OB_SURF)
1319                                                 printknots();
1320                                 }
1321                                 else {
1322                                         if((G.qual==LR_SHIFTKEY)) {
1323                                                 if(G.f & G_FACESELECT)
1324                                                         clear_vpaint_selectedfaces();
1325                                                 else if(G.f & G_VERTEXPAINT)
1326                                                         clear_vpaint();
1327                                                 else
1328                                                         select_select_keys();
1329                                         }
1330                                         else if(G.qual==LR_CTRLKEY)
1331                                                 make_skeleton();
1332 /*                                      else if(G.qual & LR_ALTKEY) delete_skeleton(); */
1333                                         else if (G.qual==0)
1334                                                 set_ob_ipoflags();
1335                                 }
1336                                 
1337                                 break;
1338                         case LKEY:
1339                                 if(G.obedit) {
1340                                         if(G.obedit->type==OB_MESH)
1341                                                 selectconnected_mesh(G.qual);
1342                                         if(G.obedit->type==OB_ARMATURE)
1343                                                 selectconnected_armature();
1344                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
1345                                                 selectconnected_nurb();
1346                                 }
1347                                 else if(G.obpose) {
1348                                         if(G.obpose->type==OB_ARMATURE)
1349                                                 selectconnected_posearmature();
1350                                 }
1351                                 else {
1352                                         if((G.qual==LR_SHIFTKEY))
1353                                                 selectlinks_menu();
1354                                         else if(G.qual==LR_CTRLKEY)
1355                                                 make_links_menu();
1356                                         else if(G.f & G_FACESELECT)
1357                                                 select_linked_tfaces();
1358                                         else if((G.qual==0))
1359                                                 make_local();
1360                                 }
1361                                 break;
1362                         case MKEY:
1363                                 if(G.obedit){
1364                                         if(G.qual==LR_ALTKEY) {
1365                                                 if(G.obedit->type==OB_MESH) {
1366                                                         mergemenu();
1367                                                         makeDispList(G.obedit);
1368                                                 }
1369                                         }
1370                                         else if((G.qual==0) || (G.qual==LR_CTRLKEY)) {
1371                                                 mirrormenu();
1372                                         }
1373                                         if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
1374                                                 if(G.obedit->type==OB_MESH) select_non_manifold();
1375                                         }
1376                                 }
1377                                 else if(G.qual & LR_CTRLKEY) {
1378                                         mirrormenu();
1379                                 }
1380                                 else if(G.qual==0) {
1381                                      movetolayer();
1382                                 }
1383                                 break;
1384                         case NKEY:
1385                                 if((G.qual==0)) {
1386                                         toggle_blockhandler(curarea, VIEW3D_HANDLER_OBJECT, UI_PNL_TO_MOUSE);
1387                                         allqueue(REDRAWVIEW3D, 0);
1388                                 }
1389                                 else if(G.obedit) {
1390                                         switch (G.obedit->type){
1391                                         case OB_ARMATURE:
1392                                                 if(G.qual==LR_CTRLKEY){
1393                                                         if (okee("Recalculate bone roll angles")) {
1394                                                                 auto_align_armature();
1395                                                                 allqueue(REDRAWVIEW3D, 0);
1396                                                         }
1397                                                 }
1398                                                 break;
1399                                         case OB_MESH: 
1400                                                 if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
1401                                                         if(okee("Recalculate normals inside")) {
1402                                                                 righthandfaces(2);
1403                                                                 allqueue(REDRAWVIEW3D, 0);
1404                                                                 BIF_undo_push("Recalculate normals inside");
1405                                                         }
1406                                                 }
1407                                                 else if(G.qual==LR_CTRLKEY){
1408                                                         if(okee("Recalculate normals outside")) {
1409                                                                 righthandfaces(1);
1410                                                                 allqueue(REDRAWVIEW3D, 0);
1411                                                                 BIF_undo_push("Recalculate normals outside");
1412                                                         }
1413                                                 }
1414                                                 break;
1415                                         }
1416                                 }
1417                                 
1418                                 break;
1419                         case OKEY:
1420                                 ob= OBACT;
1421                                 if (G.qual==LR_SHIFTKEY) {
1422                                         extern int prop_mode;
1423 #ifdef NEWTRANSFORM
1424                                         prop_mode = (prop_mode+1)%5;
1425 #else
1426                                         prop_mode= !prop_mode;
1427 #endif
1428                                         allqueue(REDRAWHEADERS, 0);
1429                                 }
1430                                 else if((G.qual==0)) {
1431                                         G.f ^= G_PROPORTIONAL;
1432                                         allqueue(REDRAWHEADERS, 0);
1433                                 }
1434                                 else if((G.qual==LR_CTRLKEY)) {
1435                                         if(ob && ob->type == OB_MESH) {
1436                                                 flip_subdivison(ob, -1);
1437                                         }
1438                                 }
1439                                 else if(G.qual==LR_ALTKEY) {
1440                                         if(okee("Clear origin")) {
1441                                                 clear_object('o');
1442                                         }
1443                                 }
1444                                 break;
1445
1446                         case PKEY:
1447                                 
1448                                 if(G.obedit) {
1449                                         if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
1450                                                 make_parent();
1451                                         else if((G.qual==0) && G.obedit->type==OB_MESH)
1452                                                 separatemenu();
1453                                         else if ((G.qual==0) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
1454                                                 separate_nurb();
1455                                 }
1456                                 else if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
1457                                         make_parent();
1458                                 else if(G.qual==LR_ALTKEY)
1459                                         clear_parent();
1460                                 else if((G.qual==0)) {
1461                         start_game();
1462                                 }
1463                                 break;                          
1464                         case RKEY:
1465                                 if((G.obedit==0) && (G.f & G_FACESELECT) && (G.qual==0))
1466                                         rotate_uv_tface();
1467                                 else if(G.qual==LR_ALTKEY) {
1468                                         if(okee("Clear rotation")) {
1469                                                 clear_object('r');
1470                                         }
1471                                 } else if (G.obedit) {
1472                                         if((G.qual==LR_SHIFTKEY)) {
1473                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF)                                     
1474                                                         selectrow_nurb();
1475                                                 else if (G.obedit->type==OB_MESH)
1476                                                         loopoperations(LOOP_SELECT);
1477                                         }
1478                                         else if(G.qual==LR_CTRLKEY) {
1479                                                 if (G.obedit->type==OB_MESH)
1480                                                         loopoperations(LOOP_CUT);
1481                                         }
1482                                         else if((G.qual==0))
1483 #ifdef NEWTRANSFORM
1484                                                 Transform(TFM_ROTATION);
1485 #else
1486                                                 transform('r');
1487 #endif
1488                                 }
1489                                 else if((G.qual==0))
1490 #ifdef NEWTRANSFORM
1491                                         Transform(TFM_ROTATION);
1492 #else
1493                                         transform('r');
1494 #endif
1495                                 break;
1496                         case SKEY:
1497                                 if(G.obedit) {
1498                                         if(G.qual==LR_ALTKEY)
1499                                                 transform('N'); /* scale along normal */
1500                                         else if(G.qual==LR_CTRLKEY)
1501 #ifdef NEWTRANSFORM
1502                                                 Transform(TFM_SHEAR);
1503                                         else if(G.qual==(LR_CTRLKEY|LR_ALTKEY))
1504                                                 Transform(TFM_SHEAR);
1505 #else
1506                                                 transform('S');
1507 #endif
1508                                         else if(G.qual==LR_SHIFTKEY)
1509                                                 snapmenu();
1510                                         else if(G.qual==0)
1511 #ifdef NEWTRANSFORM
1512                                                 Transform(TFM_RESIZE);
1513                                         else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
1514                                                 Transform(TFM_TOSPHERE);
1515 #else
1516                                                 transform('s');
1517 #endif
1518                                 }
1519                                 else if(G.qual==LR_ALTKEY) {
1520                                         if(okee("Clear size")) {
1521                                                 clear_object('s');
1522                                         }
1523                                 }
1524                                 else if(G.qual==LR_SHIFTKEY) {
1525                                         snapmenu();
1526                                 }
1527                                 else if((G.qual==0))
1528 #ifdef NEWTRANSFORM
1529                                         Transform(TFM_RESIZE);
1530                                 else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
1531                                         Transform(TFM_TOSPHERE);
1532                                 else if(G.qual==(LR_CTRLKEY|LR_ALTKEY))
1533                                         Transform(TFM_SHEAR);
1534 #else
1535                                         transform('s');
1536 #endif
1537                                 break;
1538                         case TKEY:
1539                                 if(G.obedit){
1540                                         if((G.qual==LR_CTRLKEY) && G.obedit->type==OB_MESH) {
1541                                                 convert_to_triface(0);
1542                                                 allqueue(REDRAWVIEW3D, 0);
1543                                                 countall();
1544                                                 makeDispList(G.obedit);
1545                                         }
1546                                         else if((G.qual==LR_ALTKEY) && G.obedit->type==OB_CURVE)
1547                                                 clear_tilt();
1548                                         else if((G.qual==0))
1549                                                 transform('t');
1550                                 }
1551                                 else if(G.qual==LR_CTRLKEY) {
1552                                         make_track();
1553                                 }
1554                                 else if(G.qual==LR_ALTKEY) {
1555                                         clear_track();
1556                                 }
1557                                 else if((G.qual==0)){
1558                                         texspace_edit();
1559                                 }
1560                                 
1561                                 break;
1562                         case UKEY:
1563                                 if(G.obedit) {
1564                                         if(G.obedit->type==OB_MESH) {
1565                                                 if(G.qual==0) BIF_undo(); else BIF_redo();
1566                                         }
1567                                         else if(G.obedit->type==OB_ARMATURE)
1568                                                 remake_editArmature();
1569                                         else if ELEM4(G.obedit->type, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE) {
1570                                                 if(G.qual==0) BIF_undo(); else BIF_redo();
1571                                         }
1572                                 }
1573                                 else if((G.qual==0)) {
1574                                         if (G.f & G_FACESELECT)
1575                                                 uv_autocalc_tface();
1576                                         else if(G.f & G_WEIGHTPAINT)
1577                                                 wpaint_undo();
1578                                         else if(G.f & G_VERTEXPAINT)
1579                                                 vpaint_undo();
1580                                         else {
1581                                                 single_user();
1582                                         }
1583                                 }
1584                                         
1585                                 break;
1586                         case VKEY:
1587                                 ob= OBACT;
1588                                 if((G.qual==LR_SHIFTKEY)) {
1589                                         if ((G.obedit) && G.obedit->type==OB_MESH) {
1590                                                 align_view_to_selected(v3d);
1591                                         }
1592                                         else if (G.f & G_FACESELECT) {
1593                                                 align_view_to_selected(v3d);
1594                                         }
1595                                 }
1596                                 else if(G.qual==LR_ALTKEY)
1597                                         image_aspect();
1598                                 else if (G.qual==0){
1599                                         if(G.obedit) {
1600                                                 if(G.obedit->type==OB_CURVE) {
1601                                                         sethandlesNurb(2);
1602                                                         makeDispList(G.obedit);
1603                                                         allqueue(REDRAWVIEW3D, 0);
1604                                                         BIF_undo_push("Handle change");
1605                                                 }
1606                                         }
1607                                         else if(ob && ob->type == OB_MESH) 
1608                                                 set_vpaint();
1609                                 }
1610                                 break;
1611                         case WKEY:
1612                                 if((G.qual==LR_SHIFTKEY)) {
1613                                         transform('w');
1614                                 }
1615                                 else if(G.qual==LR_ALTKEY) {
1616                                         /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
1617                                 }
1618                                 else if(G.qual==LR_CTRLKEY) {
1619                                         if(G.obedit) {
1620                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF) {
1621                                                         switchdirectionNurb2();
1622                                                 }
1623                                         }
1624                                 }
1625                                 else if((G.qual==0))
1626                                         special_editmenu();
1627                                 
1628                                 break;
1629                         case XKEY:
1630                         case DELKEY:
1631                                 if(G.qual==0)
1632                                         delete_context_selected();
1633                                 break;
1634                         case YKEY:
1635                                 if((G.qual==0) && (G.obedit)) {
1636                                         if(G.obedit->type==OB_MESH) split_mesh();
1637                                 }
1638                                 break;
1639                         case ZKEY:
1640                                 toggle_shading();
1641                                 
1642                                 scrarea_queue_headredraw(curarea);
1643                                 scrarea_queue_winredraw(curarea);
1644                                 break;
1645                         
1646                         case HOMEKEY:
1647                                 if(G.qual==0)
1648                                         view3d_home(0);
1649                                 break;
1650                         case COMMAKEY:
1651                                 if(G.qual==LR_CTRLKEY) {
1652                                         G.vd->around= V3D_CENTROID;
1653                                 } else if(G.qual==LR_SHIFTKEY) {
1654                                         G.vd->around= V3D_CENTROID;
1655                                 } else if(G.qual==0) {
1656                                         G.vd->around= V3D_CENTRE;
1657                                 }
1658                                 handle_view3d_around();
1659                                 
1660                                 scrarea_queue_headredraw(curarea);
1661                                 break;
1662                                 
1663                         case PERIODKEY:
1664                                 if(G.qual==LR_CTRLKEY) {
1665                                         G.vd->around= V3D_LOCAL;
1666                                 }       else if(G.qual==0) {
1667                                         G.vd->around= V3D_CURSOR;
1668                                 }
1669                                 handle_view3d_around();
1670                                 
1671                                 scrarea_queue_headredraw(curarea);
1672                                 break;
1673                         
1674                         case PADSLASHKEY:
1675                                 if(G.qual==0) {
1676                                         if(G.vd->localview) {
1677                                                 G.vd->localview= 0;
1678                                                 endlocalview(curarea);
1679                                         }
1680                                         else {
1681                                                 G.vd->localview= 1;
1682                                                 initlocalview();
1683                                         }
1684                                         scrarea_queue_headredraw(curarea);
1685                                 }
1686                                 break;
1687                         case PADASTERKEY:       /* '*' */
1688                                 if(G.qual==0) {
1689                                         ob= OBACT;
1690                                         if(ob) {
1691                                                 if ((G.obedit) && (G.obedit->type == OB_MESH)) {
1692                                                         editmesh_align_view_to_selected(G.vd, 2);
1693                                                 } 
1694                                                 else if (G.f & G_FACESELECT) {
1695                                                         if(ob->type==OB_MESH) {
1696                                                                 Mesh *me= ob->data;
1697                                                                 faceselect_align_view_to_selected(G.vd, me, 2);
1698                                                         }
1699                                                 }
1700                                                 else
1701                                                         obmat_to_viewmat(ob);
1702                                                 
1703                                                 if(G.vd->persp==2) G.vd->persp= 1;
1704                                                 scrarea_queue_winredraw(curarea);
1705                                         }
1706                                 }
1707                                 break;
1708                         case PADPERIOD: /* '.' */
1709                                 if(G.qual==0)
1710                                         centreview();
1711                                 break;
1712                         
1713                         case PAGEUPKEY:
1714                                 if(G.qual==LR_CTRLKEY)
1715                                         movekey_obipo(1);
1716                                 else if((G.qual==0))
1717                                         nextkey_obipo(1);       /* in editipo.c */
1718                                 break;
1719
1720                         case PAGEDOWNKEY:
1721                                 if(G.qual==LR_CTRLKEY)
1722                                         movekey_obipo(-1);
1723                                 else if((G.qual==0))
1724                                         nextkey_obipo(-1);
1725                                 break;
1726                                 
1727                         case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
1728                         case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
1729                         case PADENTER:
1730                                 persptoetsen(event);
1731                                 doredraw= 1;
1732                                 break;
1733                         case PADMINUS:
1734                                 if ( (G.qual==LR_CTRLKEY)
1735                                          && (G.obedit) && (G.obedit->type==OB_MESH) )
1736                                         select_less();
1737                                 else {
1738                                         persptoetsen(event);
1739                                         doredraw= 1;
1740                                 }
1741                                 break;
1742
1743                         case PADPLUSKEY:
1744                                 if ( (G.qual==LR_CTRLKEY)
1745                                          && (G.obedit) && (G.obedit->type==OB_MESH) )
1746                                         select_more();
1747                                 else {
1748                                         persptoetsen(event);
1749                                         doredraw= 1;
1750                                 }
1751                                 break;
1752
1753                         case ESCKEY:
1754                                 if(G.qual==0) {
1755                                         if (G.vd->flag & V3D_DISPIMAGE) {
1756                                                 G.vd->flag &= ~V3D_DISPIMAGE;
1757                                                 doredraw= 1;
1758                                         }
1759                                 }
1760                                 break;
1761                         }
1762                 }
1763         }
1764         
1765         if(doredraw) {
1766                 scrarea_queue_winredraw(curarea);
1767                 scrarea_queue_headredraw(curarea);
1768         }
1769 }
1770
1771 static void initview3d(ScrArea *sa)
1772 {
1773         View3D *vd;
1774         
1775         vd= MEM_callocN(sizeof(View3D), "initview3d");
1776         BLI_addhead(&sa->spacedata, vd);        /* addhead! not addtail */
1777
1778         vd->spacetype= SPACE_VIEW3D;
1779         vd->blockscale= 0.7;
1780         vd->viewquat[0]= 1.0;
1781         vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0;
1782         vd->persp= 1;
1783         vd->drawtype= OB_WIRE;
1784         vd->view= 7;
1785         vd->dist= 10.0;
1786         vd->lens= 35.0f;
1787         vd->near= 0.01f;
1788         vd->far= 500.0f;
1789         vd->grid= 1.0f;
1790         vd->gridlines= 16;
1791         vd->lay= vd->layact= 1;
1792         if(G.scene) {
1793                 vd->lay= vd->layact= G.scene->lay;
1794                 vd->camera= G.scene->camera;
1795         }
1796         vd->scenelock= 1;
1797         vd->gridflag |= V3D_SHOW_X;
1798         vd->gridflag |= V3D_SHOW_Y;
1799         vd->gridflag |= V3D_SHOW_FLOOR;
1800         vd->gridflag &= ~V3D_SHOW_Z;
1801 }
1802
1803
1804 /* ******************** SPACE: IPO ********************** */
1805
1806 static void changeview2dspace(ScrArea *sa, void *spacedata)
1807 {
1808         if(G.v2d==0) return;
1809
1810         test_view2d(G.v2d, curarea->winx, curarea->winy);
1811         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
1812 }
1813
1814 static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
1815 {
1816         extern void do_ipobuts(unsigned short event);   // drawipo.c
1817         unsigned short event= evt->event;
1818         short val= evt->val;
1819         SpaceIpo *sipo= curarea->spacedata.first;
1820         View2D *v2d= &sipo->v2d;
1821         float dx, dy;
1822         int cfra, doredraw= 0;
1823         short mval[2];
1824         short mousebut = L_MOUSE;
1825         
1826         if(sa->win==0) return;
1827
1828         if(val) {
1829                 if( uiDoBlocks(&sa->uiblocks, event)!=UI_NOTHING ) event= 0;
1830
1831                 /* swap mouse buttons based on user preference */
1832                 if (U.flag & USER_LMOUSESELECT) {
1833                         if (event == LEFTMOUSE) {
1834                                 event = RIGHTMOUSE;
1835                                 mousebut = L_MOUSE;
1836                         } else if (event == RIGHTMOUSE) {
1837                                 event = LEFTMOUSE;
1838                                 mousebut = R_MOUSE;
1839                         }
1840                 }
1841
1842                 switch(event) {
1843                 case UI_BUT_EVENT:
1844                         /* note: bad bad code, will be cleaned! is because event queues are all shattered */
1845                         if(val>0 && val < 65) do_ipowin_buts(val-1);
1846                         else do_ipobuts(val);
1847                         break;
1848                         
1849                 case LEFTMOUSE:
1850                         if( in_ipo_buttons() ) {
1851                                 do_ipo_selectbuttons();
1852                                 doredraw= 1;
1853                         }
1854                         else if(view2dmove(LEFTMOUSE)); // only checks for sliders
1855                         else if(G.qual & LR_CTRLKEY) add_vert_ipo();
1856                         else {
1857                                 do {
1858                                         getmouseco_areawin(mval);
1859                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
1860                                         
1861                                         cfra= (int)dx;
1862                                         if(cfra< 1) cfra= 1;
1863                                         
1864                                         if( cfra!=CFRA ) {
1865                                                 CFRA= cfra;
1866                                                 update_for_newframe();
1867                                                 force_draw_all(0); /* To make constraint sliders redraw */
1868                                         }
1869                                         else PIL_sleep_ms(30);
1870                                 
1871                                 } while(get_mbut() & mousebut);
1872                         }
1873                         break;
1874                 case RIGHTMOUSE:
1875                         mouse_select_ipo();
1876                         allqueue (REDRAWACTION, 0);
1877                         allqueue(REDRAWNLA, 0);
1878                         break;
1879                 case MIDDLEMOUSE:
1880                         if(in_ipo_buttons()) {
1881                                 scroll_ipobuts();
1882                         }
1883                         else view2dmove(event); /* in drawipo.c */
1884                         break;
1885                 case WHEELUPMOUSE:
1886                 case WHEELDOWNMOUSE:
1887                         view2dmove(event);      /* in drawipo.c */
1888                         break;
1889                 case PADPLUSKEY:
1890                         view2d_zoom(v2d, 0.1154, sa->winx, sa->winy);
1891                         doredraw= 1;
1892                         break;
1893                 case PADMINUS:
1894                         view2d_zoom(v2d, -0.15, sa->winx, sa->winy);
1895                         doredraw= 1;
1896                         break;
1897                 case PAGEUPKEY:
1898                         if(G.qual==LR_CTRLKEY)
1899                                 movekey_ipo(1);
1900                         else if((G.qual==0))
1901                                 nextkey_ipo(1);
1902                         break;
1903                 case PAGEDOWNKEY:
1904                         if(G.qual==LR_CTRLKEY)
1905                                 movekey_ipo(-1);
1906                         else if((G.qual==0))
1907                                 nextkey_ipo(-1);
1908                         break;
1909                 case HOMEKEY:
1910                         if((G.qual==0))
1911                                 do_ipo_buttons(B_IPOHOME);
1912                         break;
1913                         
1914                 case AKEY:
1915                         if((G.qual==0)) {
1916                                 if(in_ipo_buttons()) {
1917                                         swap_visible_editipo();
1918                                 }
1919                                 else swap_selectall_editipo();
1920                                 allspace (REMAKEIPO, 0);
1921                                 allqueue (REDRAWNLA, 0);
1922                                 allqueue (REDRAWACTION, 0);
1923                         }
1924                         break;
1925                 case BKEY:
1926                         if((G.qual==0))
1927                                 borderselect_ipo();
1928                         break;
1929                 case CKEY:
1930                         if((G.qual==0))
1931                                 move_to_frame();
1932                         break;
1933                 case DKEY:
1934                         if((G.qual==LR_SHIFTKEY))
1935                                 add_duplicate_editipo();
1936                         break;
1937                 case GKEY:
1938                         if((G.qual==0))
1939                                 transform_ipo('g');
1940                         break;
1941                 case HKEY:
1942                         if((G.qual==LR_SHIFTKEY))
1943                                 sethandles_ipo(HD_AUTO);
1944                         else if((G.qual==0))
1945                                 sethandles_ipo(HD_ALIGN);
1946                         break;
1947                 case JKEY:
1948                         if((G.qual==0))
1949                                 join_ipo_menu();
1950                         break;
1951                 case KKEY:
1952                         if((G.qual==0)) {
1953                                 ipo_toggle_showkey();
1954                                 scrarea_queue_headredraw(curarea);
1955                                 allqueue(REDRAWVIEW3D, 0);
1956                                 doredraw= 1;
1957                         }
1958                         break;
1959                 case NKEY:
1960                         toggle_blockhandler(sa, IPO_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
1961                         doredraw= 1;
1962                         break;
1963                 case RKEY:
1964                         if((G.qual==0))
1965                                 ipo_record();
1966                         break;
1967                 case SKEY:
1968                         if((G.qual==LR_SHIFTKEY)) {             
1969                                 ipo_snap_menu();
1970                         } else if((G.qual==0))
1971                                 transform_ipo('s');
1972                         break;
1973                 case TKEY:
1974                         if((G.qual==0))
1975                                 set_ipotype();
1976                         break;
1977                 case VKEY:
1978                         if((G.qual==0))
1979                                 sethandles_ipo(HD_VECT);
1980                         break;
1981                 case XKEY:
1982                 case DELKEY:
1983                         if((G.qual==LR_SHIFTKEY))
1984                                 delete_key();
1985                         else if((G.qual==0))
1986                                 del_ipo();
1987                         break;
1988                 }
1989         }
1990
1991         if(doredraw) scrarea_queue_winredraw(sa);
1992 }
1993
1994 void initipo(ScrArea *sa)
1995 {
1996         SpaceIpo *sipo;
1997         
1998         sipo= MEM_callocN(sizeof(SpaceIpo), "initipo");
1999         BLI_addhead(&sa->spacedata, sipo);
2000
2001         sipo->spacetype= SPACE_IPO;
2002         sipo->blockscale= 0.7;
2003         
2004         /* sipo space loopt van (0,-?) tot (??,?) */
2005         sipo->v2d.tot.xmin= 0.0;
2006         sipo->v2d.tot.ymin= -10.0;
2007         sipo->v2d.tot.xmax= G.scene->r.efra;
2008         sipo->v2d.tot.ymax= 10.0;
2009
2010         sipo->v2d.cur= sipo->v2d.tot;
2011
2012         sipo->v2d.min[0]= 0.01f;
2013         sipo->v2d.min[1]= 0.01f;
2014
2015         sipo->v2d.max[0]= 15000.0f;
2016         sipo->v2d.max[1]= 10000.0f;
2017         
2018         sipo->v2d.scroll= L_SCROLL+B_SCROLL;
2019         sipo->v2d.keeptot= 0;
2020
2021         sipo->blocktype= ID_OB;
2022 }
2023
2024 /* ******************** SPACE: INFO ********************** */
2025
2026 void space_mipmap_button_function(int event) {
2027         set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
2028
2029         allqueue(REDRAWVIEW3D, 0);
2030 }
2031
2032 void space_sound_button_function(int event)
2033 {
2034         int a;
2035         SYS_SystemHandle syshandle;
2036
2037         if ((syshandle = SYS_GetSystem()))
2038         {
2039                 a = (U.gameflags & USER_DISABLE_SOUND);
2040                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
2041         }
2042 }
2043
2044 #define B_ADD_THEME     3301
2045 #define B_DEL_THEME     3302
2046 #define B_NAME_THEME    3303
2047 #define B_THEMECOL              3304
2048 #define B_UPDATE_THEME  3305
2049 #define B_CHANGE_THEME  3306
2050 #define B_THEME_COPY    3307
2051 #define B_THEME_PASTE   3308
2052
2053 #define B_RECALCLIGHT   3310
2054
2055 // needed for event; choose new 'curmain' resets it...
2056 static short th_curcol= TH_BACK;
2057 static char *th_curcol_ptr= NULL;
2058 static char th_curcol_arr[4]={0, 0, 0, 255};
2059
2060 void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
2061 {
2062         bTheme *btheme, *bt;
2063         int spacetype= 0;
2064         static short cur=1, curmain=2;
2065         short a, tot=0, isbuiltin= 0;
2066         char string[21*32], *strp, *col;
2067         
2068         y3= y2+23;      // exception!
2069         
2070         /* count total, max 16! */
2071         for(bt= U.themes.first; bt; bt= bt->next) tot++;
2072         
2073         /* if cur not is 1; move that to front of list */
2074         if(cur!=1) {
2075                 a= 1;
2076                 for(bt= U.themes.first; bt; bt= bt->next, a++) {
2077                         if(a==cur) {
2078                                 BLI_remlink(&U.themes, bt);
2079                                 BLI_addhead(&U.themes, bt);
2080                                 allqueue(REDRAWALL, 0);
2081                                 cur= 1;
2082                                 break;
2083                         }
2084                 }
2085         }
2086         
2087         /* the current theme */
2088         btheme= U.themes.first;
2089         if(strcmp(btheme->name, "Default")==0) isbuiltin= 1;
2090
2091         /* construct popup script */
2092         string[0]= 0;
2093         for(bt= U.themes.first; bt; bt= bt->next) {
2094                 strcat(string, bt->name);
2095                 if(btheme->next) strcat(string, "   |");
2096         }
2097         uiDefButS(block, MENU, B_UPDATE_THEME, string,                  45,y3,200,20, &cur, 0, 0, 0, 0, "Current theme");
2098         
2099         /* add / delete / name */
2100
2101         if(tot<16)
2102                 uiDefBut(block, BUT, B_ADD_THEME, "Add",        45,y2,200,20, NULL, 0, 0, 0, 0, "Makes new copy of this theme");
2103         if(tot>1 && isbuiltin==0)
2104                 uiDefBut(block, BUT, B_DEL_THEME, "Delete", 45,y1,200,20, NULL, 0, 0, 0, 0, "Delete theme");
2105
2106         if(isbuiltin) return;
2107         
2108         /* name */
2109         uiDefBut(block, TEX, B_NAME_THEME, "",                  255,y3,200,20, btheme->name, 1.0, 30.0, 0, 0, "Rename theme");
2110
2111         /* main choices pup */
2112         uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|%l|3D View %x2|%l|Ipo Curve Editor %x3|Action Editor %x4|"
2113                 "NLA Editor %x5|%l|UV/Image Editor %x6|Video Sequence Editor %x7|Audio Timeline %x8|Text Editor %x9|%l|User Preferences %x10|"
2114                 "Outliner %x11|Buttons Window %x12|%l|File Browser %x13|Image Browser %x14",
2115                                                                                                         255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
2116         if(curmain==1) spacetype= 0;
2117         else if(curmain==2) spacetype= SPACE_VIEW3D;
2118         else if(curmain==3) spacetype= SPACE_IPO;
2119         else if(curmain==4) spacetype= SPACE_ACTION;
2120         else if(curmain==5) spacetype= SPACE_NLA;
2121         else if(curmain==6) spacetype= SPACE_IMAGE;
2122         else if(curmain==7) spacetype= SPACE_SEQ;
2123         else if(curmain==8) spacetype= SPACE_SOUND;
2124         else if(curmain==9) spacetype= SPACE_TEXT;
2125         else if(curmain==10) spacetype= SPACE_INFO;
2126         else if(curmain==11) spacetype= SPACE_OOPS;
2127         else if(curmain==12) spacetype= SPACE_BUTS;
2128         else if(curmain==13) spacetype= SPACE_FILE;
2129         else if(curmain==14) spacetype= SPACE_IMASEL;
2130         else return; // only needed while coding... when adding themes for more windows
2131         
2132         /* color choices pup */
2133         if(curmain==1) {
2134                 strp= BIF_ThemeColorsPup(0);
2135                 if(th_curcol==TH_BACK) th_curcol= TH_BUT_OUTLINE;  // switching main choices...
2136         }
2137         else strp= BIF_ThemeColorsPup(spacetype);
2138         
2139         uiDefButS(block, MENU, B_REDR, strp,                    255,y1,200,20, &th_curcol, 0, 0, 0, 0, "Current color");
2140         MEM_freeN(strp);
2141         
2142         th_curcol_ptr= col= BIF_ThemeGetColorPtr(btheme, spacetype, th_curcol);
2143         if(col==NULL) return;
2144         
2145         /* first handle exceptions, special single values, row selection, etc */
2146         if(th_curcol==TH_VERTEX_SIZE) {
2147                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Vertex size ", 465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
2148         }
2149         else if(th_curcol==TH_FACEDOT_SIZE) {
2150                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Face dot size ",       465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
2151         }
2152         else if(th_curcol==TH_BUT_DRAWTYPE) {
2153                 uiBlockBeginAlign(block);
2154                 uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal",        465,y3,100,20,  col, 2.0, 0.0, 0, 0, "");
2155                 uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 565,y3,100,20,  col, 2.0, 1.0, 0, 0, "");
2156                 uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded",        465,y2,100,20,  col, 2.0, 2.0, 0, 0, "");
2157                 uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool",       565,y2,100,20,  col, 2.0, 3.0, 0, 0, "");
2158                 uiBlockEndAlign(block);
2159         }
2160         else {
2161                 uiBlockBeginAlign(block);
2162                 if ELEM6(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT, TH_MENU_BACK, TH_MENU_HILITE, TH_MENU_ITEM) {
2163                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
2164                 }
2165                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
2166                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"G ",   465,y2,200,20,  col+1, 0.0, 255.0, B_THEMECOL, 0, "");
2167                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"B ",   465,y1,200,20,  col+2, 0.0, 255.0, B_THEMECOL, 0, "");
2168                 uiBlockEndAlign(block);
2169
2170                 uiDefButC(block, COL, B_UPDATE_THEME, "",               675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
2171                                 
2172                 /* copy paste */
2173                 uiBlockBeginAlign(block);
2174                 uiDefBut(block, BUT, B_THEME_COPY, "Copy Color",        755,y2,120,20, NULL, 0, 0, 0, 0, "Stores current color in buffer");
2175                 uiDefBut(block, BUT, B_THEME_PASTE, "Paste Color",      755,y1,120,20, NULL, 0, 0, 0, 0, "Pastes buffer color");
2176                 uiBlockEndAlign(block);
2177                 
2178                 uiDefButC(block, COL, 0, "",                            885,y1,50,y2-y1+20, th_curcol_arr, 0, 0, 0, 0, "");
2179                 
2180         }
2181 }
2182
2183
2184 void drawinfospace(ScrArea *sa, void *spacedata)
2185 {
2186         uiBlock *block;
2187         static short cur_light=0, cur_light_var=0;
2188         float fac, col[3];
2189         short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y5, y6;
2190         short y2label, y3label, y4label, y5label, y6label;
2191         short spref, mpref, lpref, smfileselbut;
2192         short edgsp, midsp;
2193         char naam[32];
2194
2195         if(curarea->win==0) return;
2196
2197         BIF_GetThemeColor3fv(TH_BACK, col);
2198         glClearColor(col[0], col[1], col[2], 0.0);
2199         glClear(GL_COLOR_BUFFER_BIT);
2200
2201         if(curarea->winx<=1280.0) {
2202                 fac= ((float)curarea->winx)/1280.0f;
2203                 myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2204         }
2205         else {
2206                 myortho2(0.0, (float)curarea->winx, 0.0, (float)curarea->winy);
2207         }
2208         
2209         sprintf(naam, "infowin %d", curarea->win);
2210         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->win);
2211
2212
2213         /* Vars for nice grid alignment */ 
2214         dx= (1280-90)/7;        /* spacing for use in equally dividing 'tab' row */
2215
2216         xpos = 45;              /* left padding */
2217         ypos = 50;              /* bottom padding for buttons */
2218         ypostab = 10;           /* bottom padding for 'tab' row */
2219
2220         buth = 20;              /* standard button height */
2221
2222         spref = 90;     /* standard size for small preferences button */
2223         mpref = 189;    /* standard size for medium preferences button */
2224         lpref = 288;    /* standard size for large preferences button */
2225         smfileselbut = buth;    /* standard size for fileselect button (square) */
2226
2227         edgsp = 3;              /* space from edge of end 'tab' to edge of end button */
2228         midsp = 9;              /* horizontal space between buttons */
2229
2230         rspace = 3;             /* default space between rows */
2231
2232         y1 = ypos;              /* grid alignment for each row of buttons */
2233         y2 = ypos+buth+rspace;
2234         y3 = ypos+2*(buth+rspace);
2235         y4 = ypos+3*(buth+rspace);
2236         y5 = ypos+4*(buth+rspace);
2237         y6 = ypos+5*(buth+rspace);
2238
2239
2240         y2label = y2-2;         /* adjustments to offset the labels down to align better */
2241         y3label = y3-2;
2242         y4label = y4-2;
2243         y5label = y5-2;
2244         y6label = y6-2;
2245
2246
2247         /* set the colour to blue and draw the main 'tab' controls */
2248
2249         uiBlockSetCol(block, TH_BUT_SETTING1);
2250         uiBlockBeginAlign(block);
2251         
2252         uiDefButS(block, ROW,B_USERPREF,"View & Controls",
2253                 xpos,ypostab,(short)dx,buth,
2254                 &U.userpref,1.0,0.0, 0, 0,"");
2255                 
2256         uiDefButS(block, ROW,B_USERPREF,"Edit Methods",
2257                 (short)(xpos+dx),ypostab,(short)dx,buth,
2258                 &U.userpref,1.0,1.0, 0, 0,"");
2259
2260         uiDefButS(block, ROW,B_USERPREF,"Language & Font",
2261                 (short)(xpos+2*dx),ypostab,(short)dx,buth,
2262                 &U.userpref,1.0,2.0, 0, 0,"");
2263
2264         uiDefButS(block, ROW,B_USERPREF,"Themes",
2265                 (short)(xpos+3*dx),ypostab,(short)dx,buth,
2266                 &U.userpref,1.0,6.0, 0, 0,"");
2267
2268         uiDefButS(block, ROW,B_USERPREF,"Auto Save",
2269                 (short)(xpos+4*dx),ypostab,(short)dx,buth,
2270                 &U.userpref,1.0,3.0, 0, 0,"");
2271
2272         uiDefButS(block, ROW,B_USERPREF,"System & OpenGL",
2273                 (short)(xpos+5*dx),ypostab,(short)dx,buth,
2274                 &U.userpref,1.0,4.0, 0, 0,"");
2275                 
2276         uiDefButS(block, ROW,B_USERPREF,"File Paths",
2277                 (short)(xpos+6*dx),ypostab,(short)dx,buth,
2278                 &U.userpref,1.0,5.0, 0, 0,"");
2279
2280         uiBlockSetCol(block, TH_AUTO);
2281         uiBlockEndAlign(block);
2282         /* end 'tab' controls */
2283
2284         /* line 2: left x co-ord, top y co-ord, width, height */
2285
2286         if(U.userpref == 6) {
2287                 info_user_themebuts(block, y1, y2, y3);
2288         }
2289         else if (U.userpref == 0) { /* view & controls */
2290
2291                 uiDefBut(block, LABEL,0,"Display:",
2292                         xpos,y6label,spref,buth,
2293                         0, 0, 0, 0, 0, "");     
2294                 uiDefButBitS(block, TOG, USER_TOOLTIPS, 0, "ToolTips",
2295                         (xpos+edgsp),y5,spref,buth,
2296                         &(U.flag), 0, 0, 0, 0,
2297                         "Display tooltips (help tags) over buttons");
2298                 uiDefButBitS(block, TOG, USER_DRAWVIEWINFO, B_DRAWINFO, "Object Info",
2299                         (xpos+edgsp),y4,spref,buth,
2300                         &(U.uiflag), 0, 0, 0, 0,
2301                         "Display active object name and frame number in the 3D View");
2302                 uiDefButBitS(block, TOG, USER_SCENEGLOBAL, 0, "Global Scene",
2303                         (xpos+edgsp),y3,spref,buth,
2304                         &(U.flag), 0, 0, 0, 0,
2305                         "Forces the current Scene to be displayed in all Screens");
2306 #ifndef __APPLE__       
2307                 uiDefButS(block, TOG|BIT|0, 0, "Large Cursors",
2308                         (xpos+edgsp),y2,spref,buth,
2309                         &(U.curssize), 0, 0, 0, 0,
2310                         "Use large mouse cursors when available");
2311 #else 
2312                 U.curssize=0; /*Small Cursor always for OS X for now */
2313 #endif
2314
2315                 uiDefBut(block, LABEL,0,"Menus:",
2316                         (xpos+(2*edgsp)+spref),y6label,spref,buth,
2317                         0, 0, 0, 0, 0, "");
2318                 uiDefButBitS(block, TOG, USER_MENUOPENAUTO, 0, "Open on Mouse Over",
2319                         (xpos+edgsp+spref+midsp),y5,mpref,buth,
2320                         &(U.uiflag), 0, 0, 0, 0,
2321                         "Open menu buttons and pulldowns automatically when the mouse is hovering");
2322                 uiDefButS(block, NUM, 0, "Top Level:",
2323                         (xpos+edgsp+spref+midsp),y4,spref+edgsp,buth,
2324                         &(U.menuthreshold1), 1, 40, 0, 0,
2325                         "Time delay in 1/10 seconds before automatically opening top level menus");
2326                 uiDefButS(block, NUM, 0, "Sublevels:",
2327                         (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y4,spref+edgsp,buth,
2328                         &(U.menuthreshold2), 1, 40, 0, 0,
2329                         "Time delay in 1/10 seconds before automatically opening menu sublevels");
2330
2331                 uiDefBut(block, LABEL,0,"Toolbox click-hold delay:",
2332                         (xpos+(2*edgsp)+spref),y3label,mpref,buth,
2333                         0, 0, 0, 0, 0, "");
2334                 uiDefButS(block, NUM, 0, "LMB:",
2335                         (xpos+edgsp+spref+midsp),y2,spref+edgsp,buth,
2336                         &(U.tb_leftmouse), 2, 40, 0, 0,
2337                         "Time in 1/10 seconds to hold the Left Mouse Button before opening the toolbox");
2338                 uiDefButS(block, NUM, 0, "RMB:",
2339                         (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y2,spref+edgsp,buth,
2340                         &(U.tb_rightmouse), 2, 40, 0, 0,
2341                         "Time in 1/10 seconds to hold the Right Mouse Button before opening the toolbox");      
2342                 uiDefButBitS(block, TOG, USER_PANELPINNED, 0, "Pin Floating Panels",
2343                         (xpos+edgsp+spref+midsp),y1,mpref,buth,
2344                         &(U.uiflag), 0, 0, 0, 0,
2345                         "Make floating panels invoked by a hotkey (eg. N Key) open at the previous location");
2346                 
2347                 
2348                 uiDefBut(block, LABEL,0,"Snap to grid:",
2349                         (xpos+(2*edgsp)+spref+midsp+mpref),y6label,mpref,buth,
2350                         0, 0, 0, 0, 0, "");
2351                 uiDefButBitS(block, TOG, USER_AUTOGRABGRID, 0, "Grab/Move",
2352                         (xpos+edgsp+mpref+spref+(2*midsp)),y5,spref,buth,
2353                         &(U.flag), 0, 0, 0, 0,
2354                         "Snap objects and sub-objects to grid units when moving");
2355                 uiDefButBitS(block, TOG, USER_AUTOROTGRID, 0, "Rotate",
2356                         (xpos+edgsp+mpref+spref+(2*midsp)),y4,spref,buth,
2357                         &(U.flag), 0, 0, 0, 0,
2358                         "Snap objects and sub-objects to grid units when rotating");
2359                 uiDefButBitS(block, TOG, USER_AUTOSIZEGRID, 0, "Scale",
2360                         (xpos+edgsp+mpref+spref+(2*midsp)),y3,spref,buth,
2361                         &(U.flag), 0, 0, 0, 0,
2362                         "Snap objects and sub-objects to grid units when scaling");
2363                 
2364                 uiDefButBitS(block, TOG, USER_LOCKAROUND, B_DRAWINFO, "Global Pivot",
2365                         (xpos+edgsp+mpref+spref+(2*midsp)),y1,spref,buth,
2366                         &(U.uiflag), 0, 0, 0, 0,
2367                         "Lock the same rotation/scaling pivot in all 3D Views");        
2368                 
2369                 uiDefBut(block, LABEL,0,"View zoom:",
2370                         (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y6label,mpref,buth,
2371                         0, 0, 0, 0, 0, "");
2372                 uiBlockBeginAlign(block);
2373                 uiDefButS(block, ROW, 0, "Continue",
2374                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y5,(mpref/3),buth,
2375                         &(U.viewzoom), 40, USER_ZOOM_CONT, 0, 0,
2376                         "Old style zoom, continues while moving mouse up or down");
2377                 uiDefButS(block, ROW, 0, "Dolly",
2378                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/3)),y5,(mpref/3),buth,
2379                         &(U.viewzoom), 40, USER_ZOOM_DOLLY, 0, 0,
2380                         "Zooms in and out based on vertical mouse movement.");
2381                 uiDefButS(block, ROW, 0, "Scale",
2382                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(2*mpref/3)),y5,(mpref/3),buth,
2383                         &(U.viewzoom), 40, USER_ZOOM_SCALE, 0, 0,
2384                         "Zooms in and out like scaling the view, mouse movements relative to center.");
2385                 uiBlockEndAlign(block);
2386                 
2387                 uiDefBut(block, LABEL,0,"View rotation:",
2388                         (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y4label,mpref,buth,
2389                         0, 0, 0, 0, 0, "");
2390                 uiBlockBeginAlign(block);
2391                 uiDefButBitS(block, TOG, USER_TRACKBALL, B_DRAWINFO, "Trackball",
2392                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y3,(mpref/2),buth,
2393                         &(U.flag), 0, 0, 0, 0,
2394                         "Allow the view to tumble freely when orbiting with the Middle Mouse Button");
2395                 uiDefButBitS(block, TOGN, USER_TRACKBALL, B_DRAWINFO, "Turntable",
2396                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/2)),y3,(mpref/2),buth,
2397                         &(U.flag), 0, 0, 0, 0,
2398                         "Keep the Global Z axis pointing upwards when orbiting the view with the Middle Mouse Button");
2399                 uiBlockEndAlign(block);
2400                 
2401                 uiDefButBitS(block, TOG, USER_AUTOPERSP, B_DRAWINFO, "Auto Perspective",
2402                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y1,spref,buth,
2403                         &(U.uiflag), 0, 0, 0, 0,
2404                         "Automatically switch between orthographic and perspective when changing from top/front/side views");
2405
2406                 uiDefBut(block, LABEL,0,"Select with:",
2407                         (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y6label,mpref,buth,
2408                         0, 0, 0, 0, 0, "");
2409                 uiBlockBeginAlign(block);
2410                 uiDefButBitS(block, TOG, USER_LMOUSESELECT, B_DRAWINFO, "Left Mouse",
2411                         (xpos+edgsp+(3*mpref)+(4*midsp)),y5,(mpref/2),buth,
2412                         &(U.flag), 0, 0, 0, 0, "Use the Left Mouse Button for selection");
2413                 uiDefButBitS(block, TOGN, USER_LMOUSESELECT, B_DRAWINFO, "Right Mouse",
2414                         (xpos+edgsp+(3*mpref)+(4*midsp)+(mpref/2)),y5,(mpref/2),buth,
2415                         &(U.flag), 0, 0, 0, 0, "Use the Right Mouse Button for selection");
2416                 uiBlockEndAlign(block);
2417                 
2418                 
2419                 if(U.flag & USER_LMOUSESELECT) {
2420                         uiDefBut(block, LABEL,0,"Cursor with: Right Mouse",
2421                                 (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
2422                                 0, 0, 0, 0, 0, "");
2423                 } else {
2424                         uiDefBut(block, LABEL,0,"Cursor with: Left Mouse",
2425                                 (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
2426                                 0, 0, 0, 0, 0, "");
2427                 }
2428                 
2429                 /* illegal combo... */
2430                 if (U.flag & USER_LMOUSESELECT) 
2431                         U.flag &= ~USER_TWOBUTTONMOUSE;
2432                 
2433                 uiDefButBitS(block, TOG, USER_TWOBUTTONMOUSE, B_DRAWINFO, "Emulate 3 Button Mouse",
2434                         (xpos+edgsp+(3*mpref)+(4*midsp)),y3,mpref,buth,
2435                         &(U.flag), 0, 0, 0, 0,
2436                         "Emulates Middle Mouse with Alt+LeftMouse (doesnt work with Left Mouse Select option)");
2437                 
2438                         
2439                 uiDefBut(block, LABEL,0,"Middle Mouse Button:",
2440                         (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y6label,mpref,buth,
2441                         0, 0, 0, 0, 0, "");
2442                 uiBlockBeginAlign(block);
2443                 uiDefButBitS(block, TOGN, USER_VIEWMOVE, B_DRAWINFO, "Rotate View",
2444                         (xpos+edgsp+(4*mpref)+(5*midsp)),y5,(mpref/2),buth,
2445                         &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
2446                 uiDefButBitS(block, TOG, USER_VIEWMOVE, B_DRAWINFO, "Pan View",
2447                         (xpos+edgsp+(4*mpref)+(5*midsp)+(mpref/2)),y5,(mpref/2),buth,
2448                         &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
2449                 uiBlockEndAlign(block);
2450                         
2451                 uiDefBut(block, LABEL,0,"Mouse Wheel:",
2452                         (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y4label,mpref,buth,
2453                         0, 0, 0, 0, 0, "");
2454                 uiDefButBitS(block, TOG, USER_WHEELZOOMDIR, 0, "Invert Zoom",
2455                         (xpos+edgsp+(4*mpref)+(5*midsp)),y3,spref,buth,
2456                         &(U.uiflag), 0, 0, 0, 0,
2457                         "Swap the Mouse Wheel zoom direction");
2458                 uiDefButI(block, NUM, 0, "Scroll Lines:",
2459                         (xpos+edgsp+(4*mpref)+(6*midsp)+spref-edgsp),y3,spref+edgsp,buth,
2460                         &U.wheellinescroll, 0.0, 32.0, 0, 0,
2461                         "The number of lines scrolled at a time with the mouse wheel"); 
2462
2463
2464         } else if (U.userpref == 1) { /* edit methods */
2465
2466
2467                 uiDefBut(block, LABEL,0,"Material linked to:",
2468                         xpos,y3label,mpref,buth,
2469                         0, 0, 0, 0, 0, "");
2470                 uiBlockBeginAlign(block);
2471                 uiDefButBitS(block, TOGN, USER_MAT_ON_OB, B_DRAWINFO, "ObData",
2472                         (xpos+edgsp),y2,(mpref/2),buth,
2473                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
2474                 uiDefButBitS(block, TOG, USER_MAT_ON_OB, B_DRAWINFO, "Object",
2475                         (xpos+edgsp+(mpref/2)),y2,(mpref/2),buth,
2476                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
2477                 uiBlockEndAlign(block);
2478
2479
2480                 uiDefBut(block, LABEL,0,"Editmode undo:",
2481                         (xpos+(2*edgsp)+mpref),y3label, mpref,buth,
2482                         0, 0, 0, 0, 0, "");
2483                 uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps:",
2484                         (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2485                         &(U.undosteps), 2, 64, 0, 0, "Number of undo steps available in Edit Mode (smaller values conserve memory)");
2486
2487                 uiDefButBitS(block, TOG, USER_GLOBALUNDO, B_DRAWINFO, "Global undo",
2488                         (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2489                         &(U.uiflag), 2, 64, 0, 0, "");
2490
2491
2492                 uiDefBut(block, LABEL,0,"Auto keyframe on:",
2493                         (xpos+(2*edgsp)+(2*mpref)+midsp),y3label,mpref,buth,
2494                         0, 0, 0, 0, 0, "");
2495                 uiDefButBitS(block, TOG, USER_KEYINSERTACT, 0, "Action",
2496                         (xpos+edgsp+(2*mpref)+(2*midsp)),y2,(spref+edgsp),buth,
2497                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Action Ipo curve");
2498                 uiDefButBitS(block, TOG, USER_KEYINSERTOBJ, 0, "Object",
2499                         (xpos+edgsp+(2*mpref)+(3*midsp)+spref-edgsp),y2,(spref+edgsp),buth,
2500                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Object Ipo curve");
2501
2502
2503                 uiDefBut(block, LABEL,0,"Duplicate with object:",
2504                         (xpos+(2*edgsp)+(3*midsp)+(3*mpref)+spref),y3label,mpref,buth,
2505                         0, 0, 0, 0, 0, "");
2506
2507                 uiDefButBitS(block, TOG, USER_DUP_MESH, 0, "Mesh",
2508                         (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y2,(spref+edgsp),buth,
2509                         &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
2510                 uiDefButBitS(block, TOG, USER_DUP_ARM, 0, "Armature",
2511                         (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y1,(spref+edgsp),buth,
2512                         &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
2513
2514                 uiDefButBitS(block, TOG, USER_DUP_SURF, 0, "Surface",
2515                         (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y2,(spref+edgsp),buth,
2516                         &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
2517                 uiDefButBitS(block, TOG, USER_DUP_LAMP, 0, "Lamp",
2518                         (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y1,(spref+edgsp),buth,
2519                         &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
2520
2521                 uiDefButBitS(block, TOG, USER_DUP_CURVE, 0, "Curve",
2522                         (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y2,(spref+edgsp),buth,
2523                         &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
2524                 uiDefButBitS(block, TOG, USER_DUP_MAT, 0, "Material",
2525                         (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y1,(spref+edgsp),buth,
2526                         &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
2527
2528                 uiDefButBitS(block, TOG, USER_DUP_FONT, 0, "Text",
2529                         (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y2,(spref+edgsp),buth,
2530                         &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
2531                 uiDefButBitS(block, TOG, USER_DUP_TEX, 0, "Texture",
2532                         (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y1,(spref+edgsp),buth,
2533                         &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
2534
2535                 uiDefButBitS(block, TOG, USER_DUP_MBALL, 0, "Metaball",
2536                         (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y2,(spref+edgsp),buth,
2537                         &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
2538                 uiDefButBitS(block, TOG, USER_DUP_IPO, 0, "Ipo",
2539                         (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y1,(spref+edgsp),buth,
2540                         &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
2541         
2542         } else if(U.userpref == 2) { /* language & colors */
2543
2544 #ifdef INTERNATIONAL
2545                 uiDefButBitS(block, TOG, USER_DOTRANSLATE, B_DOLANGUIFONT, "International Fonts",
2546                         xpos,y2,mpref,buth,
2547                         &(U.transopts), 0, 0, 0, 0, "Activate international interface");
2548
2549                 if(U.transopts & USER_DOTRANSLATE) {
2550                         char curfont[320];
2551                         
2552                         sprintf(curfont, "Interface Font: ");
2553                         if(U.fontname[0]) strcat(curfont, U.fontname);
2554                         else strcat(curfont, "Built-in");
2555                         
2556                         uiDefBut(block, LABEL,0,curfont,
2557                                 (xpos),y3,4*mpref,buth,
2558                                 0, 0, 0, 0, 0, "");
2559
2560                         uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
2561                                 xpos,y1,mpref,buth,
2562                                 0, 0, 0, 0, 0, "Select a new font for the interface");
2563
2564                         uiDefButI(block, BUT, B_RESTOREFONT, "Restore to default",
2565                                           (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2566                                           &U.fontsize, 0, 0, 0, 0, "Restores to using the default included antialised font");
2567                         
2568                         uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
2569                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2570                                 &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
2571
2572 /*
2573                         uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
2574                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2575                                 &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
2576
2577
2578                         uiDefBut(block, LABEL,0,"Translate:",
2579                                 (xpos+edgsp+(2.1*mpref)+(2*midsp)),y3label,mpref,buth,
2580                                 0, 0, 0, 0, 0, "");
2581 */
2582
2583                         uiDefButBitS(block, TOG, USER_TR_TOOLTIPS, B_SETTRANSBUTS, "Tooltips",
2584                                 (xpos+edgsp+(2.2*mpref)+(3*midsp)),y1,spref,buth,
2585                                 &(U.transopts), 0, 0, 0, 0, "Translate tooltips");
2586
2587                         uiDefButBitS(block, TOG, USER_TR_BUTTONS, B_SETTRANSBUTS, "Buttons",
2588                                 (xpos+edgsp+(2.2*mpref)+(4*midsp)+spref),y1,spref,buth,
2589                                 &(U.transopts), 0, 0, 0, 0, "Translate button labels");
2590
2591                         uiDefButBitS(block, TOG, USER_TR_MENUS, B_SETTRANSBUTS, "Toolbox",
2592                                 (xpos+edgsp+(2.2*mpref)+(5*midsp)+(2*spref)),y1,spref,buth,
2593                                 &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
2594
2595                         uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
2596                                 (xpos+edgsp+(2.2*mpref)+(3*midsp)),y2,mpref+(0.5*mpref)+3,buth,
2597                                 &U.language, 0, 0, 0, 0, "Select interface language");
2598                                 
2599                         uiDefButBitS(block, TOG, USER_USETEXTUREFONT, B_USETEXTUREFONT, "Use Textured Fonts",
2600                                 (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
2601                                 &(U.transopts), 0, 0, 0, 0,
2602                                 "Use Textured Fonts");
2603                 }
2604
2605 /* end of INTERNATIONAL */
2606 #endif
2607
2608         } else if(U.userpref == 3) { /* auto save */
2609
2610
2611                 uiDefButS(block, NUM, 0, "Save Versions:",
2612                         (xpos+edgsp),y3,mpref,buth,
2613                         &U.versions, 0.0, 32.0, 0, 0,
2614                         "The number of old versions to maintain in the current directory, when manually saving");
2615
2616                 uiDefButBitS(block, TOG, USER_AUTOSAVE, B_RESETAUTOSAVE, "Auto Save Temp Files",
2617                         (xpos+edgsp+mpref+midsp),y3,mpref,buth,
2618                         &(U.flag), 0, 0, 0, 0,
2619                         "Enables automatic saving of temporary files");
2620
2621                 if(U.flag & USER_AUTOSAVE) {
2622
2623                         uiDefButI(block, NUM, B_RESETAUTOSAVE, "Minutes:",
2624                                 (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2625                                 &(U.savetime), 1.0, 60.0, 0, 0,
2626                                 "The time (in minutes) to wait between automatic temporary saves");
2627
2628                         uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
2629                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2630                                 0, 0, 0, 0, 0,"Open the most recently saved temporary file");
2631                 }
2632
2633         } else if (U.userpref == 4) { /* system & opengl */
2634                 uiDefBut(block, LABEL,0,"Solid OpenGL light:",
2635                         xpos+edgsp, y3label, mpref, buth,
2636                         0, 0, 0, 0, 0, "");
2637                 
2638                 uiDefButS(block, MENU, B_REDR, "Light1 %x0|Light2 %x1|Light3 %x2",
2639                         xpos+edgsp, y2, 2*mpref/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
2640                 uiBlockSetCol(block, TH_BUT_SETTING1);
2641                 uiDefButI(block, TOG|BIT|0, B_RECALCLIGHT, "On",
2642                         xpos+edgsp+2*mpref/6, y2, mpref/6, buth, 
2643                         &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "Enable this OpenGL light in Solid draw mode");
2644                         
2645                 uiBlockSetCol(block, TH_AUTO);
2646                 uiDefButS(block, ROW, B_REDR, "Vec",
2647                         xpos+edgsp+3*mpref/6, y2, mpref/6, buth, 
2648                         &cur_light_var, 123.0, 0.0, 0, 0, "Lamp vector for OpenGL light");
2649                 uiDefButS(block, ROW, B_REDR, "Col",
2650                         xpos+edgsp+4*mpref/6, y2, mpref/6, buth, 
2651                         &cur_light_var, 123.0, 1.0, 0, 0, "Diffuse Color for OpenGL light");
2652                 uiDefButS(block, ROW, B_REDR, "Spec",
2653                         xpos+edgsp+5*mpref/6, y2, mpref/6, buth, 
2654                         &cur_light_var, 123.0, 2.0, 0, 0, "Specular color for OpenGL light");
2655
2656                 if(cur_light_var==1) {
2657                         uiDefButF(block, NUM, B_RECALCLIGHT, "R ",
2658                                 xpos+edgsp, y1, mpref/3, buth, 
2659                                 U.light[cur_light].col, 0.0, 1.0, 100, 2, "");
2660                         uiDefButF(block, NUM, B_RECALCLIGHT, "G ",
2661                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2662                                 U.light[cur_light].col+1, 0.0, 1.0, 100, 2, "");
2663                         uiDefButF(block, NUM, B_RECALCLIGHT, "B ",
2664                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2665                                 U.light[cur_light].col+2, 0.0, 1.0, 100, 2, "");
2666                 }
2667                 else if(cur_light_var==2) {
2668                         uiDefButF(block, NUM, B_RECALCLIGHT, "sR ",
2669                                 xpos+edgsp, y1, mpref/3, buth, 
2670                                 U.light[cur_light].spec, 0.0, 1.0, 100, 2, "");
2671                         uiDefButF(block, NUM, B_RECALCLIGHT, "sG ",
2672                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2673                                 U.light[cur_light].spec+1, 0.0, 1.0, 100, 2, "");
2674                         uiDefButF(block, NUM, B_RECALCLIGHT, "sB ",
2675                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2676                                 U.light[cur_light].spec+2, 0.0, 1.0, 100, 2, "");
2677                 }
2678                 else if(cur_light_var==0) {
2679                         uiDefButF(block, NUM, B_RECALCLIGHT, "X ",
2680                                 xpos+edgsp, y1, mpref/3, buth, 
2681                                 U.light[cur_light].vec, -1.0, 1.0, 100, 2, "");
2682                         uiDefButF(block, NUM, B_RECALCLIGHT, "Y ",
2683                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2684                                 U.light[cur_light].vec+1, -1.0, 1.0, 100, 2, "");
2685                         uiDefButF(block, NUM, B_RECALCLIGHT, "Z ",
2686                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2687                                 U.light[cur_light].vec+2, -1.0, 1.0, 100, 2, "");
2688                 }
2689
2690 /*
2691                 uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
2692                         (xpos+edgsp),y2,lpref,buth,
2693                         &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
2694
2695                 uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
2696                         (xpos+edgsp), y1, lpref,buth,
2697                         &U.console_out, 0, 0, 0, 0, "Select console output method");
2698
2699                 uiDefButS(block, NUM, B_CONSOLENUMLINES, "Lines:",
2700                         (xpos+edgsp+lpref+midsp),y1,spref,buth,
2701                         &U.console_buffer, 1.0, 4000.0, 0, 0, "Maximum number of internal console lines");
2702 */
2703
2704 #ifdef _WIN32
2705                 uiDefBut(block, LABEL,0,"Win Codecs:",
2706                         (xpos+edgsp+(1*midsp)+(1*mpref)),y3label,mpref,buth,
2707                         0, 0, 0, 0, 0, "");
2708
2709                 uiDefButBitS(block, TOG, USER_ALLWINCODECS, 0, "Enable all codecs",
2710                         (xpos+edgsp+(1*mpref)+(1*midsp)),y2,mpref,buth,
2711                         &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
2712 #endif
2713
2714                 uiDefBut(block, LABEL,0,"Keyboard:",
2715                         (xpos+edgsp+(3*midsp)+(3*mpref)),y3label,mpref,buth,
2716                         0, 0, 0, 0, 0, "");
2717
2718                 uiDefButBitS(block, TOG, USER_NO_CAPSLOCK, B_U_CAPSLOCK, "Disable Caps Lock",
2719                         (xpos+edgsp+(3*midsp)+(3*mpref)),y1,mpref,buth,
2720                         &(U.flag), 0, 0, 0, 0,
2721                         "Disables the Caps Lock key when entering text");
2722
2723                 uiDefButBitS(block, TOG, USER_NONUMPAD, 0, "Emulate Numpad",
2724                         (xpos+edgsp+(3*midsp)+(3*mpref)),y2,mpref,buth,
2725                         &(U.flag), 0, 0, 0, 0,
2726                         "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
2727
2728
2729                 uiDefBut(block, LABEL,0,"System:",
2730                         (xpos+edgsp+(4*midsp)+(4*mpref)),y3label,mpref,buth,
2731                         0, 0, 0, 0, 0, "");
2732
2733                 uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Sound",
2734                         (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
2735                         &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
2736
2737                 uiDefButBitS(block, TOG, USER_FILTERFILEEXTS, 0, "Filter File Extensions",
2738                         (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
2739                         &(U.uiflag), 0, 0, 0, 0, "Display only files with extensions in the image select window");
2740
2741
2742                 uiDefBut(block, LABEL,0,"OpenGL:",
2743                         (xpos+edgsp+(5*midsp)+(5*mpref)),y3label,mpref,buth,
2744                         0, 0, 0, 0, 0, "");
2745
2746                 uiDefButBitI(block, TOGN, USER_DISABLE_MIPMAP, B_MIPMAPCHANGED, "Mipmaps",
2747                         (xpos+edgsp+(5*mpref)+(5*midsp)),y2,mpref,buth,
2748                         &(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
2749
2750                 uiDefButBitI(block, TOG, USER_VERTEX_ARRAYS, 0, "Vertex Arrays",
2751                         (xpos+edgsp+(5*mpref)+(5*midsp)),y1,mpref,buth,
2752                         &(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
2753
2754                 uiDefBut(block, LABEL,0,"Audio mixing buffer:",
2755                         (xpos+edgsp+(2*midsp)+(2*mpref)),y3label,mpref,buth,
2756                         0, 0, 0, 0, 0, "");
2757                 uiBlockBeginAlign(block);
2758                 uiDefButI(block, ROW, 0, "256",
2759                         (xpos+edgsp+(2*midsp)+(2*mpref)),y2,(mpref/4),buth,
2760                         &U.mixbufsize, 2.0, 256.0, 0, 0, "Set audio mixing buffer size to 256 samples");
2761                 uiDefButI(block, ROW, 0, "512",
2762                         (xpos+edgsp+(2*midsp)+(2*mpref)+(mpref/4)),y2,(mpref/4),buth,
2763                         &U.mixbufsize, 2.0, 512.0, 0, 0, "Set audio mixing buffer size to 512 samples");        
2764                 uiDefButI(block, ROW, 0, "1024",
2765                         (xpos+edgsp+(2*midsp)+(2*mpref)+(2*mpref/4)),y2,(mpref/4),buth,
2766                         &U.mixbufsize, 2.0, 1024.0, 0, 0, "Set audio mixing buffer size to 1024 samples");              
2767                 uiDefButI(block, ROW, 0, "2048",
2768                         (xpos+edgsp+(2*midsp)+(2*mpref)+(3*mpref/4)),y2,(mpref/4),buth,
2769                         &U.mixbufsize, 2.0, 2048.0, 0, 0, "Set audio mixing buffer size to 2048 samples");                      
2770                 uiBlockEndAlign(block);
2771
2772         } else if(U.userpref == 5) { /* file paths */
2773
2774                 /* yafray: (temporary) path button for yafray xml export, now with fileselect */
2775                 uiDefBut(block, TEX, 0, "YFexport: ",
2776                         (xpos+edgsp), y2+buth+rspace, lpref-smfileselbut, buth,
2777                         U.yfexportdir, 1.0, 63.0, 0, 0,
2778                         "The default directory for yafray xml export (must exist!)");
2779                 uiDefIconBut(block, BUT, B_YAFRAYDIRFILESEL, ICON_FILESEL,
2780                         (xpos+edgsp+lpref-smfileselbut), y2+buth+rspace, smfileselbut, buth,
2781                         0, 0, 0, 0, 0, "Select the default yafray export directory");
2782
2783                 uiDefBut(block, TEX, 0, "Fonts: ",
2784                         (xpos+edgsp),y2,(lpref-smfileselbut),buth,
2785                         U.fontdir, 1.0, 63.0, 0, 0,
2786                         "The default directory to search for loading fonts");
2787                 uiDefIconBut(block, BUT, B_FONTDIRFILESEL, ICON_FILESEL,
2788                         (xpos+edgsp+lpref-smfileselbut),y2,smfileselbut,buth,
2789                         0, 0, 0, 0, 0, "Select the default font directory");
2790
2791                 uiDefBut(block, TEX, 0, "Textures: ",
2792                         (xpos+edgsp+lpref+midsp),y2,(lpref-smfileselbut),buth,
2793         &