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