fd936da8eaf01f666052c419400c260308f5ac2a
[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 SPACEKEY:
1062                                 G.vd->twflag ^= V3D_USE_MANIPULATOR;
1063                                 doredraw= 1;
1064                                 break;
1065                                 
1066                         case AKEY:
1067                                 if(G.qual & LR_CTRLKEY) apply_object(); // also with shift!
1068                                 else if((G.qual==LR_SHIFTKEY)) {
1069                                         toolbox_n_add();
1070                                 }
1071                                 else {
1072                                         if(G.obedit) {
1073                                                 if(G.obedit->type==OB_MESH)
1074                                                         deselectall_mesh();
1075                                                 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
1076                                                         deselectall_nurb();
1077                                                 else if(G.obedit->type==OB_MBALL)
1078                                                         deselectall_mball();
1079                                                 else if(G.obedit->type==OB_LATTICE)
1080                                                         deselectall_Latt();
1081                                                 else if(G.obedit->type==OB_ARMATURE)
1082                                                         deselectall_armature();
1083                                         }
1084                                         else if (G.obpose){
1085                                                 switch (G.obpose->type){
1086                                                 case OB_ARMATURE:
1087                                                         deselectall_posearmature(1);
1088                                                         break;
1089                                                 }
1090                                         }
1091                                         else {
1092                                                 if(G.f & G_FACESELECT) deselectall_tface();
1093                                                 else {
1094                                                         /* by design, the center of the active object 
1095                                                          * (which need not necessarily by selected) will
1096                                                          * still be drawn as if it were selected.
1097                                                          */
1098                                                         deselectall();
1099                                                 }
1100                                         }
1101                                 }
1102                                 break;
1103                         case BKEY:
1104                                 if((G.qual==LR_SHIFTKEY))
1105                                         set_render_border();
1106                                 else if((G.qual==LR_ALTKEY)){
1107                                         if(G.obedit && G.obedit->type==OB_MESH) {
1108                                                 /* Loop Select Operations */
1109                                                 /*   Vertexloop */
1110                                                 /*   Faceloop   */                                              
1111                                                 vertex_loop_select(); 
1112                                         }
1113                                 }
1114                                 else if((G.qual==0))
1115                                         borderselect();
1116                                 break;
1117                         case CKEY:
1118                                 if(G.qual==LR_CTRLKEY) {
1119                                         copy_attr_menu();
1120                                 }
1121                                 else if(G.qual==LR_ALTKEY) {
1122                                         convertmenu();  /* editobject.c */
1123                                 }
1124                                 else if((G.qual==LR_SHIFTKEY)) {
1125                                         view3d_home(1);
1126                                         curs= give_cursor();
1127                                         curs[0]=curs[1]=curs[2]= 0.0;
1128                                         allqueue(REDRAWVIEW3D, 0);
1129                                 }
1130                                 else if((G.obedit) && ELEM(G.obedit->type, OB_CURVE, OB_SURF) ) {
1131                                         makecyclicNurb();
1132                                         makeDispList(G.obedit);
1133                                         allqueue(REDRAWVIEW3D, 0);
1134                                 }
1135                                 else if((G.qual==0)){
1136                                         curs= give_cursor();
1137                                         G.vd->ofs[0]= -curs[0];
1138                                         G.vd->ofs[1]= -curs[1];
1139                                         G.vd->ofs[2]= -curs[2];
1140                                         scrarea_queue_winredraw(curarea);
1141                                 }
1142                         
1143                                 break;
1144                         case DKEY:
1145                                 if((G.qual==LR_SHIFTKEY)) {
1146                                         duplicate_context_selected();
1147                                 }
1148                                 else if(G.qual==LR_ALTKEY) {
1149                                         if(G.obpose)
1150                                                 error ("Duplicate not possible in posemode.");
1151                                         else if((G.obedit==0))
1152                                                 adduplicate(0);
1153                                 }
1154                                 else if(G.qual==LR_CTRLKEY) {
1155                                         imagestodisplist();
1156                                 }
1157                                 else if((G.qual==0)){
1158                                         pupval= pupmenu("Draw mode%t|BoundBox %x1|Wire %x2|OpenGL Solid %x3|Shaded Solid %x4|Textured Solid %x5");
1159                                         if(pupval>0) {
1160                                                 G.vd->drawtype= pupval;
1161                                                 doredraw= 1;
1162                                         
1163                                         }
1164                                 }
1165                                 
1166                                 break;
1167                         case EKEY:
1168                                 if (G.qual==0){
1169                                         if(G.obedit) {
1170                                                 if(G.obedit->type==OB_MESH)
1171                                                         extrude_mesh();
1172                                                 else if(G.obedit->type==OB_CURVE)
1173                                                         addvert_Nurb('e');
1174                                                 else if(G.obedit->type==OB_SURF)
1175                                                         extrude_nurb();
1176                                                 else if(G.obedit->type==OB_ARMATURE)
1177                                                         extrude_armature();
1178                                         }
1179                                         else {
1180                                                 ob= OBACT;
1181                                                 if(ob && ob->type==OB_IKA) if(okee("extrude IKA"))
1182                                                         extrude_ika(ob, 1);
1183                                         }
1184                                 }
1185                                 else if (G.qual==LR_CTRLKEY) {
1186                                         if(G.obedit && G.obedit->type==OB_MESH)
1187                                                 Edge_Menu();
1188                                 }
1189                                 else if (G.qual==LR_SHIFTKEY) {
1190                                         if (G.obedit && G.obedit->type==OB_MESH) {
1191                                                 transform('e');
1192                                         }
1193                                 }
1194                                 break;
1195                         case FKEY:
1196                                 if(G.obedit) {
1197                                         if(G.obedit->type==OB_MESH) {
1198                                                 if((G.qual==LR_SHIFTKEY))
1199                                                         fill_mesh();
1200                                                 else if(G.qual==LR_ALTKEY)
1201                                                         beauty_fill();
1202                                                 else if(G.qual==LR_CTRLKEY)
1203                                                         edge_flip();
1204                                                 else if (G.qual==0)
1205                                                         addedgeface_mesh();
1206                                         }
1207                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addsegment_nurb();
1208                                 }
1209                                 else if(G.qual==LR_CTRLKEY)
1210                                         sort_faces();
1211                                 else if((G.qual==LR_SHIFTKEY))
1212                                         fly();
1213                                 else {
1214                                                 set_faceselect();
1215                                         }
1216                                 
1217                                 break;
1218                         case GKEY:
1219                                 /* RMGRP if(G.qual & LR_CTRLKEY) add_selected_to_group();
1220                                 else if(G.qual & LR_ALTKEY) rem_selected_from_group(); */
1221                                 if((G.qual==LR_SHIFTKEY))
1222                                         select_group_menu();
1223                                 else if(G.qual==LR_ALTKEY) {
1224                                         if(okee("Clear location")) {
1225                                                 clear_object('g');
1226                                         }
1227                                 } else if((G.qual==0)) {
1228                                         Transform(TFM_TRANSLATION, CTX_NONE);
1229                                 }
1230                                 break;
1231                         case HKEY:
1232                                 if(G.obedit) {
1233                                         if(G.obedit->type==OB_MESH) {
1234                                                 if(G.qual==LR_CTRLKEY)
1235                                                         add_hook();
1236                                                 else if(G.qual==LR_ALTKEY)
1237                                                         reveal_mesh();
1238                                                 else if((G.qual==LR_SHIFTKEY))
1239                                                         hide_mesh(1);
1240                                                 else if((G.qual==0)) 
1241                                                         hide_mesh(0);
1242                                         }
1243                                         else if(G.obedit->type== OB_SURF) {
1244                                                 if(G.qual==LR_CTRLKEY)
1245                                                         add_hook();
1246                                                 else if(G.qual==LR_ALTKEY)
1247                                                         revealNurb();
1248                                                 else if((G.qual==LR_SHIFTKEY))
1249                                                         hideNurb(1);
1250                                                 else if((G.qual==0))
1251                                                         hideNurb(0);
1252                                         }
1253                                         else if(G.obedit->type==OB_CURVE) {
1254                                                 if(G.qual==LR_CTRLKEY)
1255                                                         add_hook();
1256                                                 else {
1257                                                         if(G.qual==LR_CTRLKEY)
1258                                                                 autocalchandlesNurb_all(1);     /* flag=1, selected */
1259                                                         else if((G.qual==LR_SHIFTKEY))
1260                                                                 sethandlesNurb(1);
1261                                                         else if((G.qual==0))
1262                                                                 sethandlesNurb(3);
1263                                                         
1264                                                         makeDispList(G.obedit);
1265                                                         BIF_undo_push("Handle change");
1266                                                         allqueue(REDRAWVIEW3D, 0);
1267                                                 }
1268                                         }
1269                                         else if(G.obedit->type==OB_LATTICE) {
1270                                                 if(G.qual==LR_CTRLKEY) add_hook();
1271                                         }
1272                                         else if(G.obedit->type==OB_MBALL) {
1273                                                 if(G.qual==LR_ALTKEY)
1274                                                         reveal_mball();
1275                                                 else if((G.qual==LR_SHIFTKEY))
1276                                                         hide_mball(1);
1277                                                 else if((G.qual==0)) 
1278                                                         hide_mball(0);
1279                                         }
1280                                 }
1281                                 else if(G.f & G_FACESELECT)
1282                                         hide_tface();
1283                                 else if(G.obpose) {
1284                                         if (G.qual==0)
1285                                                 hide_selected_pose_bones();
1286                                         else if (G.qual==LR_SHIFTKEY)
1287                                                 hide_unselected_pose_bones();
1288                                         else if (G.qual==LR_ALTKEY)
1289                                                 show_all_pose_bones();
1290                                 }
1291                                 break;
1292                         case IKEY:
1293                                 break;
1294                                 
1295                         case JKEY:
1296                                 if(G.qual==LR_CTRLKEY) {
1297                                         if( (ob= OBACT) ) {
1298                                                 if(ob->type == OB_MESH)
1299                                                         join_mesh();
1300                                                 else if(ob->type == OB_CURVE)
1301                                                         join_curve(OB_CURVE);
1302                                                 else if(ob->type == OB_SURF)
1303                                                         join_curve(OB_SURF);
1304                                                 else if(ob->type == OB_ARMATURE)
1305                                                         join_armature ();
1306                                         }
1307                                         else if ((G.obedit) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
1308                                                 addsegment_nurb();
1309                                 }
1310                                 else if(G.obedit) {
1311                                         if(G.obedit->type==OB_MESH) {
1312                                                 join_triangles();
1313                                         }
1314                                 }
1315
1316                                 break;
1317                         case KKEY:
1318                                 if(G.obedit) {
1319                                         if (G.obedit->type==OB_MESH) {
1320                                                 if (G.qual==LR_SHIFTKEY)
1321                                                         KnifeSubdivide(KNIFE_PROMPT);
1322                                                 else if (G.qual==0)
1323                                                         LoopMenu();
1324                                         }
1325                                         else if(G.obedit->type==OB_SURF)
1326                                                 printknots();
1327                                 }
1328                                 else {
1329                                         if((G.qual==LR_SHIFTKEY)) {
1330                                                 if(G.f & G_FACESELECT)
1331                                                         clear_vpaint_selectedfaces();
1332                                                 else if(G.f & G_VERTEXPAINT)
1333                                                         clear_vpaint();
1334                                                 else
1335                                                         select_select_keys();
1336                                         }
1337                                         else if(G.qual==LR_CTRLKEY)
1338                                                 make_skeleton();
1339 /*                                      else if(G.qual & LR_ALTKEY) delete_skeleton(); */
1340                                         else if (G.qual==0)
1341                                                 set_ob_ipoflags();
1342                                 }
1343                                 
1344                                 break;
1345                         case LKEY:
1346                                 if(G.obedit) {
1347                                         if(G.obedit->type==OB_MESH)
1348                                                 selectconnected_mesh(G.qual);
1349                                         if(G.obedit->type==OB_ARMATURE)
1350                                                 selectconnected_armature();
1351                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
1352                                                 selectconnected_nurb();
1353                                 }
1354                                 else if(G.obpose) {
1355                                         if(G.obpose->type==OB_ARMATURE)
1356                                                 selectconnected_posearmature();
1357                                 }
1358                                 else {
1359                                         if((G.qual==LR_SHIFTKEY))
1360                                                 selectlinks_menu();
1361                                         else if(G.qual==LR_CTRLKEY)
1362                                                 make_links_menu();
1363                                         else if(G.f & G_FACESELECT)
1364                                                 select_linked_tfaces();
1365                                         else if((G.qual==0))
1366                                                 make_local();
1367                                 }
1368                                 break;
1369                         case MKEY:
1370                                 if(G.obedit){
1371                                         if(G.qual==LR_ALTKEY) {
1372                                                 if(G.obedit->type==OB_MESH) {
1373                                                         mergemenu();
1374                                                         makeDispList(G.obedit);
1375                                                 }
1376                                         }
1377                                         else if((G.qual==0) || (G.qual==LR_CTRLKEY)) {
1378                                                 mirrormenu();
1379                                         }
1380                                         if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
1381                                                 if(G.obedit->type==OB_MESH) select_non_manifold();
1382                                         }
1383                                 }
1384                                 else if(G.qual & LR_CTRLKEY) {
1385                                         mirrormenu();
1386                                 }
1387                                 else if(G.qual==0) {
1388                                      movetolayer();
1389                                 }
1390                                 break;
1391                         case NKEY:
1392                                 if((G.qual==0)) {
1393                                         toggle_blockhandler(curarea, VIEW3D_HANDLER_OBJECT, UI_PNL_TO_MOUSE);
1394                                         allqueue(REDRAWVIEW3D, 0);
1395                                 }
1396                                 else if(G.obedit) {
1397                                         switch (G.obedit->type){
1398                                         case OB_ARMATURE:
1399                                                 if(G.qual==LR_CTRLKEY){
1400                                                         if (okee("Recalculate bone roll angles")) {
1401                                                                 auto_align_armature();
1402                                                                 allqueue(REDRAWVIEW3D, 0);
1403                                                         }
1404                                                 }
1405                                                 break;
1406                                         case OB_MESH: 
1407                                                 if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
1408                                                         if(okee("Recalculate normals inside")) {
1409                                                                 righthandfaces(2);
1410                                                                 allqueue(REDRAWVIEW3D, 0);
1411                                                                 BIF_undo_push("Recalculate normals inside");
1412                                                         }
1413                                                 }
1414                                                 else if(G.qual==LR_CTRLKEY){
1415                                                         if(okee("Recalculate normals outside")) {
1416                                                                 righthandfaces(1);
1417                                                                 allqueue(REDRAWVIEW3D, 0);
1418                                                                 BIF_undo_push("Recalculate normals outside");
1419                                                         }
1420                                                 }
1421                                                 break;
1422                                         }
1423                                 }
1424                                 
1425                                 break;
1426                         case OKEY:
1427                                 ob= OBACT;
1428                                 if (G.qual==LR_SHIFTKEY) {
1429                                         extern int prop_mode;
1430                                         prop_mode = (prop_mode+1)%5;
1431                                         allqueue(REDRAWHEADERS, 0);
1432                                 }
1433                                 else if((G.qual==0)) {
1434                                         G.f ^= G_PROPORTIONAL;
1435                                         allqueue(REDRAWHEADERS, 0);
1436                                 }
1437                                 else if((G.qual==LR_CTRLKEY)) {
1438                                         if(ob && ob->type == OB_MESH) {
1439                                                 flip_subdivison(ob, -1);
1440                                         }
1441                                 }
1442                                 else if(G.qual==LR_ALTKEY) {
1443                                         if(okee("Clear origin")) {
1444                                                 clear_object('o');
1445                                         }
1446                                 }
1447                                 break;
1448
1449                         case PKEY:
1450                                 if(G.obedit) {
1451                                         if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
1452                                                 make_parent();
1453                                         else if((G.qual==0) && G.obedit->type==OB_MESH)
1454                                                 separatemenu();
1455                                         else if ((G.qual==0) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
1456                                                 separate_nurb();
1457                                         else if (G.qual==LR_SHIFTKEY)
1458                                                 Transform(TFM_PUSHPULL, CTX_NONE);
1459                                 }
1460                                 else if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
1461                                         make_parent();
1462                                 else if(G.qual==LR_SHIFTKEY)
1463                                         Transform(TFM_PUSHPULL, CTX_NONE);
1464                                 else if(G.qual==LR_ALTKEY)
1465                                         clear_parent();
1466                                 else if((G.qual==0)) {
1467                         start_game();
1468                                 }
1469                                 break;                          
1470                         case RKEY:
1471                                 if((G.obedit==0) && (G.f & G_FACESELECT) && (G.qual==0))
1472                                         rotate_uv_tface();
1473                                 else if(G.qual==LR_ALTKEY) {
1474                                         if(okee("Clear rotation")) {
1475                                                 clear_object('r');
1476                                         }
1477                                 } else if (G.obedit) {
1478                                         if((G.qual==LR_SHIFTKEY)) {
1479                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF)                                     
1480                                                         selectrow_nurb();
1481                                                 else if (G.obedit->type==OB_MESH)
1482                                                         loopoperations(LOOP_SELECT);
1483                                         }
1484                                         else if(G.qual==LR_CTRLKEY) {
1485                                                 if (G.obedit->type==OB_MESH)
1486                                                         loopoperations(LOOP_CUT);
1487                                         }
1488                                         else if((G.qual==0)) {
1489                                                 Transform(TFM_ROTATION, CTX_NONE);
1490                                         }
1491                                 }
1492                                 else if((G.qual==0)) {
1493                                         Transform(TFM_ROTATION, CTX_NONE);
1494                                 }
1495                                 break;
1496                         case SKEY:
1497                                 if(G.obedit) {
1498                                         if(G.qual==LR_ALTKEY)
1499                                                 Transform(TFM_SHRINKFATTEN, CTX_NONE);
1500                                         else if(G.qual==LR_CTRLKEY)
1501                                                 Transform(TFM_SHEAR, CTX_NONE);
1502                                         else if(G.qual==(LR_CTRLKEY|LR_ALTKEY))
1503                                                 Transform(TFM_SHEAR, CTX_NONE);
1504                                         else if(G.qual==LR_SHIFTKEY)
1505                                                 snapmenu();
1506                                         else if(G.qual==0) {
1507                                                 Transform(TFM_RESIZE, CTX_NONE);
1508                                         }
1509                                         else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)){
1510                                                 Transform(TFM_TOSPHERE, CTX_NONE);
1511                                         }
1512                                         
1513                                 }
1514                                 else if(G.qual==LR_ALTKEY) {
1515                                         if(okee("Clear size")) {
1516                                                 clear_object('s');
1517                                         }
1518                                 }
1519                                 else if(G.qual==LR_SHIFTKEY) {
1520                                         snapmenu();
1521                                 }
1522                                 else if((G.qual==0)) {
1523                                         Transform(TFM_RESIZE, CTX_NONE);
1524                                 }
1525                                 else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
1526                                         Transform(TFM_TOSPHERE, CTX_NONE);
1527                                 else if(G.qual==(LR_CTRLKEY|LR_ALTKEY))
1528                                         Transform(TFM_SHEAR, CTX_NONE);
1529                                 break;
1530                         case TKEY:
1531                                 if(G.obedit){
1532                                         if((G.qual==LR_CTRLKEY) && G.obedit->type==OB_MESH) {
1533                                                 convert_to_triface(0);
1534                                                 allqueue(REDRAWVIEW3D, 0);
1535                                                 countall();
1536                                                 makeDispList(G.obedit);
1537                                         }
1538                                         if (G.obedit->type==OB_CURVE) {
1539                                                 if (G.qual==LR_ALTKEY) {
1540                                                         clear_tilt();
1541                                                 }
1542                                                 else if (G.qual==0) {
1543                                                         Transform(TFM_TILT, CTX_NONE);
1544                                                 }
1545                                         }
1546                                 }
1547                                 else if(G.qual==LR_CTRLKEY) {
1548                                         make_track();
1549                                 }
1550                                 else if(G.qual==LR_ALTKEY) {
1551                                         clear_track();
1552                                 }
1553                                 else if((G.qual==0)){
1554                                         texspace_edit();
1555                                 }
1556                                 
1557                                 break;
1558                         case UKEY:
1559                                 if(G.obedit) {
1560                                         if(G.obedit->type==OB_MESH) {
1561                                                 if(G.qual==0) BIF_undo(); else BIF_redo();
1562                                         }
1563                                         else if(G.obedit->type==OB_ARMATURE)
1564                                                 remake_editArmature();
1565                                         else if ELEM4(G.obedit->type, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE) {
1566                                                 if(G.qual==0) BIF_undo(); else BIF_redo();
1567                                         }
1568                                 }
1569                                 else if((G.qual==0)) {
1570                                         if (G.f & G_FACESELECT)
1571                                                 uv_autocalc_tface();
1572                                         else if(G.f & G_WEIGHTPAINT)
1573                                                 wpaint_undo();
1574                                         else if(G.f & G_VERTEXPAINT)
1575                                                 vpaint_undo();
1576                                         else {
1577                                                 single_user();
1578                                         }
1579                                 }
1580                                         
1581                                 break;
1582                         case VKEY:
1583                                 ob= OBACT;
1584                                 if((G.qual==LR_SHIFTKEY)) {
1585                                         if ((G.obedit) && G.obedit->type==OB_MESH) {
1586                                                 align_view_to_selected(v3d);
1587                                         }
1588                                         else if (G.f & G_FACESELECT) {
1589                                                 align_view_to_selected(v3d);
1590                                         }
1591                                 }
1592                                 else if(G.qual==LR_ALTKEY)
1593                                         image_aspect();
1594                                 else if (G.qual==0){
1595                                         if(G.obedit) {
1596                                                 if(G.obedit->type==OB_CURVE) {
1597                                                         sethandlesNurb(2);
1598                                                         makeDispList(G.obedit);
1599                                                         allqueue(REDRAWVIEW3D, 0);
1600                                                         BIF_undo_push("Handle change");
1601                                                 }
1602                                         }
1603                                         else if(ob && ob->type == OB_MESH) 
1604                                                 set_vpaint();
1605                                 }
1606                                 break;
1607                         case WKEY:
1608                                 if((G.qual==LR_SHIFTKEY)) {
1609                                         Transform(TFM_WARP, CTX_NONE);
1610                                 }
1611                                 else if(G.qual==LR_ALTKEY) {
1612                                         /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
1613                                 }
1614                                 else if(G.qual==LR_CTRLKEY) {
1615                                         if(G.obedit) {
1616                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF) {
1617                                                         switchdirectionNurb2();
1618                                                 }
1619                                         }
1620                                 }
1621                                 else if((G.qual==0))
1622                                         special_editmenu();
1623                                 
1624                                 break;
1625                         case XKEY:
1626                         case DELKEY:
1627                                 if(G.qual==0)
1628                                         delete_context_selected();
1629                                 break;
1630                         case YKEY:
1631                                 if((G.qual==0) && (G.obedit)) {
1632                                         if(G.obedit->type==OB_MESH) split_mesh();
1633                                 }
1634                                 break;
1635                         case ZKEY:
1636                                 toggle_shading();
1637                                 
1638                                 scrarea_queue_headredraw(curarea);
1639                                 scrarea_queue_winredraw(curarea);
1640                                 break;
1641                         
1642                         case HOMEKEY:
1643                                 if(G.qual==0)
1644                                         view3d_home(0);
1645                                 break;
1646                         case COMMAKEY:
1647                                 if(G.qual==LR_CTRLKEY) {
1648                                         G.vd->around= V3D_CENTROID;
1649                                 } else if(G.qual==LR_SHIFTKEY) {
1650                                         G.vd->around= V3D_CENTROID;
1651                                 } else if(G.qual==0) {
1652                                         G.vd->around= V3D_CENTRE;
1653                                 }
1654                                 handle_view3d_around();
1655                                 
1656                                 scrarea_queue_headredraw(curarea);
1657                                 break;
1658                                 
1659                         case PERIODKEY:
1660                                 if(G.qual==LR_CTRLKEY) {
1661                                         G.vd->around= V3D_LOCAL;
1662                                 }       else if(G.qual==0) {
1663                                         G.vd->around= V3D_CURSOR;
1664                                 }
1665                                 handle_view3d_around();
1666                                 
1667                                 scrarea_queue_headredraw(curarea);
1668                                 break;
1669                         
1670                         case PADSLASHKEY:
1671                                 if(G.qual==0) {
1672                                         if(G.vd->localview) {
1673                                                 G.vd->localview= 0;
1674                                                 endlocalview(curarea);
1675                                         }
1676                                         else {
1677                                                 G.vd->localview= 1;
1678                                                 initlocalview();
1679                                         }
1680                                         scrarea_queue_headredraw(curarea);
1681                                 }
1682                                 break;
1683                         case PADASTERKEY:       /* '*' */
1684                                 if(G.qual==0) {
1685                                         ob= OBACT;
1686                                         if(ob) {
1687                                                 if ((G.obedit) && (G.obedit->type == OB_MESH)) {
1688                                                         editmesh_align_view_to_selected(G.vd, 2);
1689                                                 } 
1690                                                 else if (G.f & G_FACESELECT) {
1691                                                         if(ob->type==OB_MESH) {
1692                                                                 Mesh *me= ob->data;
1693                                                                 faceselect_align_view_to_selected(G.vd, me, 2);
1694                                                         }
1695                                                 }
1696                                                 else
1697                                                         obmat_to_viewmat(ob);
1698                                                 
1699                                                 if(G.vd->persp==2) G.vd->persp= 1;
1700                                                 scrarea_queue_winredraw(curarea);
1701                                         }
1702                                 }
1703                                 break;
1704                         case PADPERIOD: /* '.' */
1705                                 if(G.qual==0)
1706                                         centreview();
1707                                 break;
1708                         
1709                         case PAGEUPKEY:
1710                                 if(G.qual==LR_CTRLKEY)
1711                                         movekey_obipo(1);
1712                                 else if((G.qual==0))
1713                                         nextkey_obipo(1);       /* in editipo.c */
1714                                 break;
1715
1716                         case PAGEDOWNKEY:
1717                                 if(G.qual==LR_CTRLKEY)
1718                                         movekey_obipo(-1);
1719                                 else if((G.qual==0))
1720                                         nextkey_obipo(-1);
1721                                 break;
1722                                 
1723                         case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
1724                         case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
1725                         case PADENTER:
1726                                 persptoetsen(event);
1727                                 doredraw= 1;
1728                                 break;
1729                         case PADMINUS:
1730                                 if ( (G.qual==LR_CTRLKEY)
1731                                          && (G.obedit) && (G.obedit->type==OB_MESH) )
1732                                         select_less();
1733                                 else {
1734                                         persptoetsen(event);
1735                                         doredraw= 1;
1736                                 }
1737                                 break;
1738
1739                         case PADPLUSKEY:
1740                                 if ( (G.qual==LR_CTRLKEY)
1741                                          && (G.obedit) && (G.obedit->type==OB_MESH) )
1742                                         select_more();
1743                                 else {
1744                                         persptoetsen(event);
1745                                         doredraw= 1;
1746                                 }
1747                                 break;
1748
1749                         case ESCKEY:
1750                                 if(G.qual==0) {
1751                                         if (G.vd->flag & V3D_DISPIMAGE) {
1752                                                 G.vd->flag &= ~V3D_DISPIMAGE;
1753                                                 doredraw= 1;
1754                                         }
1755                                 }
1756                                 break;
1757                         }
1758                 }
1759         }
1760         else {  // val==0, hotkeys for ctrl/alt/shift
1761                 if(prev_event==event) {
1762                         switch(event) {
1763                                 
1764                         case RIGHTCTRLKEY: 
1765                         case LEFTCTRLKEY:
1766                                 if(v3d->twflag & V3D_USE_MANIPULATOR) {
1767                                         if(v3d->twtype & V3D_MANIP_SCALE) 
1768                                                 v3d->twtype= V3D_MANIP_TRANSLATE;
1769                                         else if(v3d->twtype & V3D_MANIP_TRANSLATE)
1770                                                 v3d->twtype= V3D_MANIP_ROTATE;
1771                                         else if(v3d->twtype & V3D_MANIP_ROTATE)
1772                                                 v3d->twtype= V3D_MANIP_SCALE;
1773                                         
1774                                         doredraw= 1;
1775                                 }
1776                                 break;
1777                         }
1778                 }
1779         }
1780         
1781         if(doredraw) {
1782                 scrarea_queue_winredraw(curarea);
1783                 scrarea_queue_headredraw(curarea);
1784         }
1785 }
1786
1787 static void initview3d(ScrArea *sa)
1788 {
1789         View3D *vd;
1790         
1791         vd= MEM_callocN(sizeof(View3D), "initview3d");
1792         BLI_addhead(&sa->spacedata, vd);        /* addhead! not addtail */
1793
1794         vd->spacetype= SPACE_VIEW3D;
1795         vd->blockscale= 0.7;
1796         vd->viewquat[0]= 1.0;
1797         vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0;
1798         vd->persp= 1;
1799         vd->drawtype= OB_WIRE;
1800         vd->view= 7;
1801         vd->dist= 10.0;
1802         vd->lens= 35.0f;
1803         vd->near= 0.01f;
1804         vd->far= 500.0f;
1805         vd->grid= 1.0f;
1806         vd->gridlines= 16;
1807         vd->lay= vd->layact= 1;
1808         if(G.scene) {
1809                 vd->lay= vd->layact= G.scene->lay;
1810                 vd->camera= G.scene->camera;
1811         }
1812         vd->scenelock= 1;
1813         vd->gridflag |= V3D_SHOW_X;
1814         vd->gridflag |= V3D_SHOW_Y;
1815         vd->gridflag |= V3D_SHOW_FLOOR;
1816         vd->gridflag &= ~V3D_SHOW_Z;
1817 }
1818
1819
1820 /* ******************** SPACE: IPO ********************** */
1821
1822 static void changeview2dspace(ScrArea *sa, void *spacedata)
1823 {
1824         if(G.v2d==0) return;
1825
1826         test_view2d(G.v2d, curarea->winx, curarea->winy);
1827         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
1828 }
1829
1830 static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
1831 {
1832         extern void do_ipobuts(unsigned short event);   // drawipo.c
1833         unsigned short event= evt->event;
1834         short val= evt->val;
1835         SpaceIpo *sipo= curarea->spacedata.first;
1836         View2D *v2d= &sipo->v2d;
1837         float dx, dy;
1838         int cfra, doredraw= 0;
1839         short mval[2];
1840         short mousebut = L_MOUSE;
1841         
1842         if(sa->win==0) return;
1843
1844         if(val) {
1845                 if( uiDoBlocks(&sa->uiblocks, event)!=UI_NOTHING ) event= 0;
1846
1847                 /* swap mouse buttons based on user preference */
1848                 if (U.flag & USER_LMOUSESELECT) {
1849                         if (event == LEFTMOUSE) {
1850                                 event = RIGHTMOUSE;
1851                                 mousebut = L_MOUSE;
1852                         } else if (event == RIGHTMOUSE) {
1853                                 event = LEFTMOUSE;
1854                                 mousebut = R_MOUSE;
1855                         }
1856                 }
1857
1858                 switch(event) {
1859                 case UI_BUT_EVENT:
1860                         /* note: bad bad code, will be cleaned! is because event queues are all shattered */
1861                         if(val>0 && val < 65) do_ipowin_buts(val-1);
1862                         else do_ipobuts(val);
1863                         break;
1864                         
1865                 case LEFTMOUSE:
1866                         if( in_ipo_buttons() ) {
1867                                 do_ipo_selectbuttons();
1868                                 doredraw= 1;
1869                         }
1870                         else if(view2dmove(LEFTMOUSE)); // only checks for sliders
1871                         else if(G.qual & LR_CTRLKEY) add_vert_ipo();
1872                         else {
1873                                 do {
1874                                         getmouseco_areawin(mval);
1875                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
1876                                         
1877                                         cfra= (int)dx;
1878                                         if(cfra< 1) cfra= 1;
1879                                         
1880                                         if( cfra!=CFRA ) {
1881                                                 CFRA= cfra;
1882                                                 update_for_newframe();
1883                                                 force_draw_all(0); /* To make constraint sliders redraw */
1884                                         }
1885                                         else PIL_sleep_ms(30);
1886                                 
1887                                 } while(get_mbut() & mousebut);
1888                         }
1889                         break;
1890                 case RIGHTMOUSE:
1891                         mouse_select_ipo();
1892                         allqueue (REDRAWACTION, 0);
1893                         allqueue(REDRAWNLA, 0);
1894                         break;
1895                 case MIDDLEMOUSE:
1896                         if(in_ipo_buttons()) {
1897                                 scroll_ipobuts();
1898                         }
1899                         else view2dmove(event); /* in drawipo.c */
1900                         break;
1901                 case WHEELUPMOUSE:
1902                 case WHEELDOWNMOUSE:
1903                         view2dmove(event);      /* in drawipo.c */
1904                         break;
1905                 case PADPLUSKEY:
1906                         view2d_zoom(v2d, 0.1154, sa->winx, sa->winy);
1907                         doredraw= 1;
1908                         break;
1909                 case PADMINUS:
1910                         view2d_zoom(v2d, -0.15, sa->winx, sa->winy);
1911                         doredraw= 1;
1912                         break;
1913                 case PAGEUPKEY:
1914                         if(G.qual==LR_CTRLKEY)
1915                                 movekey_ipo(1);
1916                         else if((G.qual==0))
1917                                 nextkey_ipo(1);
1918                         break;
1919                 case PAGEDOWNKEY:
1920                         if(G.qual==LR_CTRLKEY)
1921                                 movekey_ipo(-1);
1922                         else if((G.qual==0))
1923                                 nextkey_ipo(-1);
1924                         break;
1925                 case HOMEKEY:
1926                         if((G.qual==0))
1927                                 do_ipo_buttons(B_IPOHOME);
1928                         break;
1929                         
1930                 case AKEY:
1931                         if((G.qual==0)) {
1932                                 if(in_ipo_buttons()) {
1933                                         swap_visible_editipo();
1934                                 }
1935                                 else {
1936                                         swap_selectall_editipo();
1937                                 }
1938                                 allspace (REMAKEIPO, 0);
1939                                 allqueue (REDRAWNLA, 0);
1940                                 allqueue (REDRAWACTION, 0);
1941                         }
1942                         break;
1943                 case BKEY:
1944                         if((G.qual==0))
1945                                 borderselect_ipo();
1946                         break;
1947                 case CKEY:
1948                         if((G.qual==0))
1949                                 move_to_frame();
1950                         break;
1951                 case DKEY:
1952                         if((G.qual==LR_SHIFTKEY))
1953                                 add_duplicate_editipo();
1954                         break;
1955                 case GKEY:
1956                         if((G.qual==0))
1957                                 transform_ipo('g');
1958                         break;
1959                 case HKEY:
1960                         if((G.qual==LR_SHIFTKEY))
1961                                 sethandles_ipo(HD_AUTO);
1962                         else if((G.qual==0))
1963                                 sethandles_ipo(HD_ALIGN);
1964                         break;
1965                 case JKEY:
1966                         if((G.qual==0))
1967                                 join_ipo_menu();
1968                         break;
1969                 case KKEY:
1970                         if((G.qual==0)) {
1971                                 ipo_toggle_showkey();
1972                                 scrarea_queue_headredraw(curarea);
1973                                 allqueue(REDRAWVIEW3D, 0);
1974                                 doredraw= 1;
1975                         }
1976                         break;
1977                 case NKEY:
1978                         toggle_blockhandler(sa, IPO_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
1979                         doredraw= 1;
1980                         break;
1981                 case RKEY:
1982                         if((G.qual==0))
1983                                 ipo_record();
1984                         break;
1985                 case SKEY:
1986                         if((G.qual==LR_SHIFTKEY)) {             
1987                                 ipo_snap_menu();
1988                         } else if((G.qual==0))
1989                                 transform_ipo('s');
1990                         break;
1991                 case TKEY:
1992                         if((G.qual==0))
1993                                 set_ipotype();
1994                         break;
1995                 case VKEY:
1996                         if((G.qual==0))
1997                                 sethandles_ipo(HD_VECT);
1998                         break;
1999                 case XKEY:
2000                 case DELKEY:
2001                         if((G.qual==LR_SHIFTKEY))
2002                                 delete_key();
2003                         else if((G.qual==0))
2004                                 del_ipo();
2005                         break;
2006                 }
2007         }
2008
2009         if(doredraw) scrarea_queue_winredraw(sa);
2010 }
2011
2012 void initipo(ScrArea *sa)
2013 {
2014         SpaceIpo *sipo;
2015         
2016         sipo= MEM_callocN(sizeof(SpaceIpo), "initipo");
2017         BLI_addhead(&sa->spacedata, sipo);
2018
2019         sipo->spacetype= SPACE_IPO;
2020         sipo->blockscale= 0.7;
2021         
2022         /* sipo space loopt van (0,-?) tot (??,?) */
2023         sipo->v2d.tot.xmin= 0.0;
2024         sipo->v2d.tot.ymin= -10.0;
2025         sipo->v2d.tot.xmax= G.scene->r.efra;
2026         sipo->v2d.tot.ymax= 10.0;
2027
2028         sipo->v2d.cur= sipo->v2d.tot;
2029
2030         sipo->v2d.min[0]= 0.01f;
2031         sipo->v2d.min[1]= 0.01f;
2032
2033         sipo->v2d.max[0]= 15000.0f;
2034         sipo->v2d.max[1]= 10000.0f;
2035         
2036         sipo->v2d.scroll= L_SCROLL+B_SCROLL;
2037         sipo->v2d.keeptot= 0;
2038
2039         sipo->blocktype= ID_OB;
2040 }
2041
2042 /* ******************** SPACE: INFO ********************** */
2043
2044 void space_mipmap_button_function(int event) {
2045         set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
2046
2047         allqueue(REDRAWVIEW3D, 0);
2048 }
2049
2050 #if 0
2051 static void space_sound_button_function(int event)
2052 {
2053         int a;
2054         SYS_SystemHandle syshandle;
2055
2056         if ((syshandle = SYS_GetSystem()))
2057         {
2058                 a = (U.gameflags & USER_DISABLE_SOUND);
2059                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
2060         }
2061 }
2062 #endif
2063
2064 #define B_ADD_THEME     3301
2065 #define B_DEL_THEME     3302
2066 #define B_NAME_THEME    3303
2067 #define B_THEMECOL              3304
2068 #define B_UPDATE_THEME  3305
2069 #define B_CHANGE_THEME  3306
2070 #define B_THEME_COPY    3307
2071 #define B_THEME_PASTE   3308
2072
2073 #define B_RECALCLIGHT   3310
2074
2075 // needed for event; choose new 'curmain' resets it...
2076 static short th_curcol= TH_BACK;
2077 static char *th_curcol_ptr= NULL;
2078 static char th_curcol_arr[4]={0, 0, 0, 255};
2079
2080 static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
2081 {
2082         bTheme *btheme, *bt;
2083         int spacetype= 0;
2084         static short cur=1, curmain=2;
2085         short a, tot=0, isbuiltin= 0;
2086         char string[21*32], *strp, *col;
2087         
2088         y3= y2+23;      // exception!
2089         
2090         /* count total, max 16! */
2091         for(bt= U.themes.first; bt; bt= bt->next) tot++;
2092         
2093         /* if cur not is 1; move that to front of list */
2094         if(cur!=1) {
2095                 a= 1;
2096                 for(bt= U.themes.first; bt; bt= bt->next, a++) {
2097                         if(a==cur) {
2098                                 BLI_remlink(&U.themes, bt);
2099                                 BLI_addhead(&U.themes, bt);
2100                                 allqueue(REDRAWALL, 0);
2101                                 cur= 1;
2102                                 break;
2103                         }
2104                 }
2105         }
2106         
2107         /* the current theme */
2108         btheme= U.themes.first;
2109         if(strcmp(btheme->name, "Default")==0) isbuiltin= 1;
2110
2111         /* construct popup script */
2112         string[0]= 0;
2113         for(bt= U.themes.first; bt; bt= bt->next) {
2114                 strcat(string, bt->name);
2115                 if(btheme->next) strcat(string, "   |");
2116         }
2117         uiDefButS(block, MENU, B_UPDATE_THEME, string,                  45,y3,200,20, &cur, 0, 0, 0, 0, "Current theme");
2118         
2119         /* add / delete / name */
2120
2121         if(tot<16)
2122                 uiDefBut(block, BUT, B_ADD_THEME, "Add",        45,y2,200,20, NULL, 0, 0, 0, 0, "Makes new copy of this theme");
2123         if(tot>1 && isbuiltin==0)
2124                 uiDefBut(block, BUT, B_DEL_THEME, "Delete", 45,y1,200,20, NULL, 0, 0, 0, 0, "Delete theme");
2125
2126         if(isbuiltin) return;
2127         
2128         /* name */
2129         uiDefBut(block, TEX, B_NAME_THEME, "",                  255,y3,200,20, btheme->name, 1.0, 30.0, 0, 0, "Rename theme");
2130
2131         /* main choices pup */
2132         uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|%l|3D View %x2|%l|Ipo Curve Editor %x3|Action Editor %x4|"
2133                 "NLA Editor %x5|%l|UV/Image Editor %x6|Video Sequence Editor %x7|Audio Timeline %x8|Text Editor %x9|%l|User Preferences %x10|"
2134                 "Outliner %x11|Buttons Window %x12|%l|File Browser %x13|Image Browser %x14",
2135                                                                                                         255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
2136         if(curmain==1) spacetype= 0;
2137         else if(curmain==2) spacetype= SPACE_VIEW3D;
2138         else if(curmain==3) spacetype= SPACE_IPO;
2139         else if(curmain==4) spacetype= SPACE_ACTION;
2140         else if(curmain==5) spacetype= SPACE_NLA;
2141         else if(curmain==6) spacetype= SPACE_IMAGE;
2142         else if(curmain==7) spacetype= SPACE_SEQ;
2143         else if(curmain==8) spacetype= SPACE_SOUND;
2144         else if(curmain==9) spacetype= SPACE_TEXT;
2145         else if(curmain==10) spacetype= SPACE_INFO;
2146         else if(curmain==11) spacetype= SPACE_OOPS;
2147         else if(curmain==12) spacetype= SPACE_BUTS;
2148         else if(curmain==13) spacetype= SPACE_FILE;
2149         else if(curmain==14) spacetype= SPACE_IMASEL;
2150         else return; // only needed while coding... when adding themes for more windows
2151         
2152         /* color choices pup */
2153         if(curmain==1) {
2154                 strp= BIF_ThemeColorsPup(0);
2155                 if(th_curcol==TH_BACK) th_curcol= TH_BUT_OUTLINE;  // switching main choices...
2156         }
2157         else strp= BIF_ThemeColorsPup(spacetype);
2158         
2159         uiDefButS(block, MENU, B_REDR, strp,                    255,y1,200,20, &th_curcol, 0, 0, 0, 0, "Current color");
2160         MEM_freeN(strp);
2161         
2162         th_curcol_ptr= col= BIF_ThemeGetColorPtr(btheme, spacetype, th_curcol);
2163         if(col==NULL) return;
2164         
2165         /* first handle exceptions, special single values, row selection, etc */
2166         if(th_curcol==TH_VERTEX_SIZE) {
2167                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Vertex size ", 465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
2168         }
2169         else if(th_curcol==TH_FACEDOT_SIZE) {
2170                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Face dot size ",       465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
2171         }
2172         else if(th_curcol==TH_BUT_DRAWTYPE) {
2173                 uiBlockBeginAlign(block);
2174                 uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal",        465,y3,100,20,  col, 2.0, 0.0, 0, 0, "");
2175                 uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 565,y3,100,20,  col, 2.0, 1.0, 0, 0, "");
2176                 uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded",        465,y2,100,20,  col, 2.0, 2.0, 0, 0, "");
2177                 uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool",       565,y2,100,20,  col, 2.0, 3.0, 0, 0, "");
2178                 uiBlockEndAlign(block);
2179         }
2180         else {
2181                 uiBlockBeginAlign(block);
2182                 if ELEM6(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT, TH_MENU_BACK, TH_MENU_HILITE, TH_MENU_ITEM) {
2183                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
2184                 }
2185                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
2186                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"G ",   465,y2,200,20,  col+1, 0.0, 255.0, B_THEMECOL, 0, "");
2187                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"B ",   465,y1,200,20,  col+2, 0.0, 255.0, B_THEMECOL, 0, "");
2188                 uiBlockEndAlign(block);
2189
2190                 uiDefButC(block, COL, B_UPDATE_THEME, "",               675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
2191                                 
2192                 /* copy paste */
2193                 uiBlockBeginAlign(block);
2194                 uiDefBut(block, BUT, B_THEME_COPY, "Copy Color",        755,y2,120,20, NULL, 0, 0, 0, 0, "Stores current color in buffer");
2195                 uiDefBut(block, BUT, B_THEME_PASTE, "Paste Color",      755,y1,120,20, NULL, 0, 0, 0, 0, "Pastes buffer color");
2196                 uiBlockEndAlign(block);
2197                 
2198                 uiDefButC(block, COL, 0, "",                            885,y1,50,y2-y1+20, th_curcol_arr, 0, 0, 0, 0, "");
2199                 
2200         }
2201 }
2202
2203
2204 void drawinfospace(ScrArea *sa, void *spacedata)
2205 {
2206         uiBlock *block;
2207         static short cur_light=0, cur_light_var=0;
2208         float fac, col[3];
2209         short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y5, y6;
2210         short y2label, y3label, y4label, y5label, y6label;
2211         short spref, mpref, lpref, smfileselbut;
2212         short edgsp, midsp;
2213         char naam[32];
2214
2215         if(curarea->win==0) return;
2216
2217         BIF_GetThemeColor3fv(TH_BACK, col);
2218         glClearColor(col[0], col[1], col[2], 0.0);
2219         glClear(GL_COLOR_BUFFER_BIT);
2220
2221         if(curarea->winx<=1280.0) {
2222                 fac= ((float)curarea->winx)/1280.0f;
2223                 myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2224         }
2225         else {
2226                 myortho2(0.0, (float)curarea->winx, 0.0, (float)curarea->winy);
2227         }
2228         
2229         sprintf(naam, "infowin %d", curarea->win);
2230         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->win);
2231
2232
2233         /* Vars for nice grid alignment */ 
2234         dx= (1280-90)/7;        /* spacing for use in equally dividing 'tab' row */
2235
2236         xpos = 45;              /* left padding */
2237         ypos = 50;              /* bottom padding for buttons */
2238         ypostab = 10;           /* bottom padding for 'tab' row */
2239
2240         buth = 20;              /* standard button height */
2241
2242         spref = 90;     /* standard size for small preferences button */
2243         mpref = 189;    /* standard size for medium preferences button */
2244         lpref = 288;    /* standard size for large preferences button */
2245         smfileselbut = buth;    /* standard size for fileselect button (square) */
2246
2247         edgsp = 3;              /* space from edge of end 'tab' to edge of end button */
2248         midsp = 9;              /* horizontal space between buttons */
2249
2250         rspace = 3;             /* default space between rows */
2251
2252         y1 = ypos;              /* grid alignment for each row of buttons */
2253         y2 = ypos+buth+rspace;
2254         y3 = ypos+2*(buth+rspace);
2255         y4 = ypos+3*(buth+rspace);
2256         y5 = ypos+4*(buth+rspace);
2257         y6 = ypos+5*(buth+rspace);
2258
2259
2260         y2label = y2-2;         /* adjustments to offset the labels down to align better */
2261         y3label = y3-2;
2262         y4label = y4-2;
2263         y5label = y5-2;
2264         y6label = y6-2;
2265
2266
2267         /* set the colour to blue and draw the main 'tab' controls */
2268
2269         uiBlockSetCol(block, TH_BUT_SETTING1);
2270         uiBlockBeginAlign(block);
2271         
2272         uiDefButS(block, ROW,B_USERPREF,"View & Controls",
2273                 xpos,ypostab,(short)dx,buth,
2274                 &U.userpref,1.0,0.0, 0, 0,"");
2275                 
2276         uiDefButS(block, ROW,B_USERPREF,"Edit Methods",
2277                 (short)(xpos+dx),ypostab,(short)dx,buth,
2278                 &U.userpref,1.0,1.0, 0, 0,"");
2279
2280         uiDefButS(block, ROW,B_USERPREF,"Language & Font",
2281                 (short)(xpos+2*dx),ypostab,(short)dx,buth,
2282                 &U.userpref,1.0,2.0, 0, 0,"");
2283
2284         uiDefButS(block, ROW,B_USERPREF,"Themes",
2285                 (short)(xpos+3*dx),ypostab,(short)dx,buth,
2286                 &U.userpref,1.0,6.0, 0, 0,"");
2287
2288         uiDefButS(block, ROW,B_USERPREF,"Auto Save",
2289                 (short)(xpos+4*dx),ypostab,(short)dx,buth,
2290                 &U.userpref,1.0,3.0, 0, 0,"");
2291
2292         uiDefButS(block, ROW,B_USERPREF,"System & OpenGL",
2293                 (short)(xpos+5*dx),ypostab,(short)dx,buth,
2294                 &U.userpref,1.0,4.0, 0, 0,"");
2295                 
2296         uiDefButS(block, ROW,B_USERPREF,"File Paths",
2297                 (short)(xpos+6*dx),ypostab,(short)dx,buth,
2298                 &U.userpref,1.0,5.0, 0, 0,"");
2299
2300         uiBlockSetCol(block, TH_AUTO);
2301         uiBlockEndAlign(block);
2302         /* end 'tab' controls */
2303
2304         /* line 2: left x co-ord, top y co-ord, width, height */
2305
2306         if(U.userpref == 6) {
2307                 info_user_themebuts(block, y1, y2, y3);
2308         }
2309         else if (U.userpref == 0) { /* view & controls */
2310
2311                 uiDefBut(block, LABEL,0,"Display:",
2312                         xpos,y6label,spref,buth,
2313                         0, 0, 0, 0, 0, "");     
2314                 uiDefButBitS(block, TOG, USER_TOOLTIPS, 0, "ToolTips",
2315                         (xpos+edgsp),y5,spref,buth,
2316                         &(U.flag), 0, 0, 0, 0,
2317                         "Display tooltips (help tags) over buttons");
2318                 uiDefButBitS(block, TOG, USER_DRAWVIEWINFO, B_DRAWINFO, "Object Info",
2319                         (xpos+edgsp),y4,spref,buth,
2320                         &(U.uiflag), 0, 0, 0, 0,
2321                         "Display active object name and frame number in the 3D View");
2322                 uiDefButBitS(block, TOG, USER_SCENEGLOBAL, 0, "Global Scene",
2323                         (xpos+edgsp),y3,spref,buth,
2324                         &(U.flag), 0, 0, 0, 0,
2325                         "Forces the current Scene to be displayed in all Screens");
2326 #ifndef __APPLE__       
2327                 uiDefButS(block, TOG|BIT|0, 0, "Large Cursors",
2328                         (xpos+edgsp),y2,spref,buth,
2329                         &(U.curssize), 0, 0, 0, 0,
2330                         "Use large mouse cursors when available");
2331 #else 
2332                 U.curssize=0; /*Small Cursor always for OS X for now */
2333 #endif
2334
2335                 uiDefBut(block, LABEL,0,"Menus:",
2336                         (xpos+(2*edgsp)+spref),y6label,spref,buth,
2337                         0, 0, 0, 0, 0, "");
2338                 uiDefButBitS(block, TOG, USER_MENUOPENAUTO, 0, "Open on Mouse Over",
2339                         (xpos+edgsp+spref+midsp),y5,mpref,buth,
2340                         &(U.uiflag), 0, 0, 0, 0,
2341                         "Open menu buttons and pulldowns automatically when the mouse is hovering");
2342                 uiDefButS(block, NUM, 0, "Top Level:",
2343                         (xpos+edgsp+spref+midsp),y4,spref+edgsp,buth,
2344                         &(U.menuthreshold1), 1, 40, 0, 0,
2345                         "Time delay in 1/10 seconds before automatically opening top level menus");
2346                 uiDefButS(block, NUM, 0, "Sublevels:",
2347                         (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y4,spref+edgsp,buth,
2348                         &(U.menuthreshold2), 1, 40, 0, 0,
2349                         "Time delay in 1/10 seconds before automatically opening menu sublevels");
2350
2351                 uiDefBut(block, LABEL,0,"Toolbox click-hold delay:",
2352                         (xpos+(2*edgsp)+spref),y3label,mpref,buth,
2353                         0, 0, 0, 0, 0, "");
2354                 uiDefButS(block, NUM, 0, "LMB:",
2355                         (xpos+edgsp+spref+midsp),y2,spref+edgsp,buth,
2356                         &(U.tb_leftmouse), 2, 40, 0, 0,
2357                         "Time in 1/10 seconds to hold the Left Mouse Button before opening the toolbox");
2358                 uiDefButS(block, NUM, 0, "RMB:",
2359                         (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y2,spref+edgsp,buth,
2360                         &(U.tb_rightmouse), 2, 40, 0, 0,
2361                         "Time in 1/10 seconds to hold the Right Mouse Button before opening the toolbox");      
2362                 uiDefButBitS(block, TOG, USER_PANELPINNED, 0, "Pin Floating Panels",
2363                         (xpos+edgsp+spref+midsp),y1,mpref,buth,
2364                         &(U.uiflag), 0, 0, 0, 0,
2365                         "Make floating panels invoked by a hotkey (eg. N Key) open at the previous location");
2366                 
2367                 
2368                 uiDefBut(block, LABEL,0,"Snap to grid:",
2369                         (xpos+(2*edgsp)+spref+midsp+mpref),y6label,mpref,buth,
2370                         0, 0, 0, 0, 0, "");
2371                 uiDefButBitS(block, TOG, USER_AUTOGRABGRID, 0, "Grab/Move",
2372                         (xpos+edgsp+mpref+spref+(2*midsp)),y5,spref,buth,
2373                         &(U.flag), 0, 0, 0, 0,
2374                         "Snap objects and sub-objects to grid units when moving");
2375                 uiDefButBitS(block, TOG, USER_AUTOROTGRID, 0, "Rotate",
2376                         (xpos+edgsp+mpref+spref+(2*midsp)),y4,spref,buth,
2377                         &(U.flag), 0, 0, 0, 0,
2378                         "Snap objects and sub-objects to grid units when rotating");
2379                 uiDefButBitS(block, TOG, USER_AUTOSIZEGRID, 0, "Scale",
2380                         (xpos+edgsp+mpref+spref+(2*midsp)),y3,spref,buth,
2381                         &(U.flag), 0, 0, 0, 0,
2382                         "Snap objects and sub-objects to grid units when scaling");
2383                 
2384                 uiDefButBitS(block, TOG, USER_LOCKAROUND, B_DRAWINFO, "Global Pivot",
2385                         (xpos+edgsp+mpref+spref+(2*midsp)),y1,spref,buth,
2386                         &(U.uiflag), 0, 0, 0, 0,
2387                         "Lock the same rotation/scaling pivot in all 3D Views");        
2388                 
2389                 uiDefBut(block, LABEL,0,"View zoom:",
2390                         (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y6label,mpref,buth,
2391                         0, 0, 0, 0, 0, "");
2392                 uiBlockBeginAlign(block);
2393                 uiDefButS(block, ROW, 0, "Continue",
2394                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y5,(mpref/3),buth,
2395                         &(U.viewzoom), 40, USER_ZOOM_CONT, 0, 0,
2396                         "Old style zoom, continues while moving mouse up or down");
2397                 uiDefButS(block, ROW, 0, "Dolly",
2398                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/3)),y5,(mpref/3),buth,
2399                         &(U.viewzoom), 40, USER_ZOOM_DOLLY, 0, 0,
2400                         "Zooms in and out based on vertical mouse movement.");
2401                 uiDefButS(block, ROW, 0, "Scale",
2402                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(2*mpref/3)),y5,(mpref/3),buth,
2403                         &(U.viewzoom), 40, USER_ZOOM_SCALE, 0, 0,
2404                         "Zooms in and out like scaling the view, mouse movements relative to center.");
2405                 uiBlockEndAlign(block);
2406                 
2407                 uiDefBut(block, LABEL,0,"View rotation:",
2408                         (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y4label,mpref,buth,
2409                         0, 0, 0, 0, 0, "");
2410                 uiBlockBeginAlign(block);
2411                 uiDefButBitS(block, TOG, USER_TRACKBALL, B_DRAWINFO, "Trackball",
2412                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y3,(mpref/2),buth,
2413                         &(U.flag), 0, 0, 0, 0,
2414                         "Allow the view to tumble freely when orbiting with the Middle Mouse Button");
2415                 uiDefButBitS(block, TOGN, USER_TRACKBALL, B_DRAWINFO, "Turntable",
2416                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/2)),y3,(mpref/2),buth,
2417                         &(U.flag), 0, 0, 0, 0,
2418                         "Keep the Global Z axis pointing upwards when orbiting the view with the Middle Mouse Button");
2419                 uiBlockEndAlign(block);
2420                 
2421                 uiDefButBitS(block, TOG, USER_AUTOPERSP, B_DRAWINFO, "Auto Perspective",
2422                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y1,spref,buth,
2423                         &(U.uiflag), 0, 0, 0, 0,
2424                         "Automatically switch between orthographic and perspective when changing from top/front/side views");
2425
2426                 uiDefBut(block, LABEL,0,"Select with:",
2427                         (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y6label,mpref,buth,
2428                         0, 0, 0, 0, 0, "");
2429                 uiBlockBeginAlign(block);
2430                 uiDefButBitS(block, TOG, USER_LMOUSESELECT, B_DRAWINFO, "Left Mouse",
2431                         (xpos+edgsp+(3*mpref)+(4*midsp)),y5,(mpref/2),buth,
2432                         &(U.flag), 0, 0, 0, 0, "Use the Left Mouse Button for selection");
2433                 uiDefButBitS(block, TOGN, USER_LMOUSESELECT, B_DRAWINFO, "Right Mouse",
2434                         (xpos+edgsp+(3*mpref)+(4*midsp)+(mpref/2)),y5,(mpref/2),buth,
2435                         &(U.flag), 0, 0, 0, 0, "Use the Right Mouse Button for selection");
2436                 uiBlockEndAlign(block);
2437                 
2438                 
2439                 if(U.flag & USER_LMOUSESELECT) {
2440                         uiDefBut(block, LABEL,0,"Cursor with: Right Mouse",
2441                                 (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
2442                                 0, 0, 0, 0, 0, "");
2443                 } else {
2444                         uiDefBut(block, LABEL,0,"Cursor with: Left Mouse",
2445                                 (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
2446                                 0, 0, 0, 0, 0, "");
2447                 }
2448                 
2449                 /* illegal combo... */
2450                 if (U.flag & USER_LMOUSESELECT) 
2451                         U.flag &= ~USER_TWOBUTTONMOUSE;
2452                 
2453                 uiDefButBitS(block, TOG, USER_TWOBUTTONMOUSE, B_DRAWINFO, "Emulate 3 Button Mouse",
2454                         (xpos+edgsp+(3*mpref)+(4*midsp)),y3,mpref,buth,
2455                         &(U.flag), 0, 0, 0, 0,
2456                         "Emulates Middle Mouse with Alt+LeftMouse (doesnt work with Left Mouse Select option)");
2457                 
2458                         
2459                 uiDefBut(block, LABEL,0,"Middle Mouse Button:",
2460                         (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y6label,mpref,buth,
2461                         0, 0, 0, 0, 0, "");
2462                 uiBlockBeginAlign(block);
2463                 uiDefButBitS(block, TOGN, USER_VIEWMOVE, B_DRAWINFO, "Rotate View",
2464                         (xpos+edgsp+(4*mpref)+(5*midsp)),y5,(mpref/2),buth,
2465                         &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
2466                 uiDefButBitS(block, TOG, USER_VIEWMOVE, B_DRAWINFO, "Pan View",
2467                         (xpos+edgsp+(4*mpref)+(5*midsp)+(mpref/2)),y5,(mpref/2),buth,
2468                         &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
2469                 uiBlockEndAlign(block);
2470                         
2471                 uiDefBut(block, LABEL,0,"Mouse Wheel:",
2472                         (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y4label,mpref,buth,
2473                         0, 0, 0, 0, 0, "");
2474                 uiDefButBitS(block, TOG, USER_WHEELZOOMDIR, 0, "Invert Zoom",
2475                         (xpos+edgsp+(4*mpref)+(5*midsp)),y3,spref,buth,
2476                         &(U.uiflag), 0, 0, 0, 0,
2477                         "Swap the Mouse Wheel zoom direction");
2478                 uiDefButI(block, NUM, 0, "Scroll Lines:",
2479                         (xpos+edgsp+(4*mpref)+(6*midsp)+spref-edgsp),y3,spref+edgsp,buth,
2480                         &U.wheellinescroll, 0.0, 32.0, 0, 0,
2481                         "The number of lines scrolled at a time with the mouse wheel"); 
2482
2483
2484                 uiDefBut(block, LABEL,0,"3D Transform Widget:",
2485                                  (xpos+(2*edgsp)+(5*mpref)+(5*midsp)),y6label,mpref,buth,
2486                                  0, 0, 0, 0, 0, "");
2487                 uiBlockBeginAlign(block);
2488                 uiDefButS(block, NUM, B_REDRCURW3D, "Size:",
2489                                          (xpos+edgsp+(5*mpref)+(6*midsp)),y5,(mpref/2),buth,
2490                                          &(U.tw_size), 2, 40, 0, 0, "Size of widget as percentage of window size");
2491                 uiDefButS(block, NUM, B_REDRCURW3D, "Handle:",
2492                                          (xpos+edgsp+(5*mpref)+(6*midsp)+(mpref/2)),y5,(mpref/2),buth,
2493                                          &(U.tw_handlesize), 2, 40, 0, 0, "Size of widget handles as percentage of widget radius");
2494                 uiDefButS(block, NUM, B_REDRCURW3D, "Hotspot:",
2495                                   (xpos+edgsp+(5*mpref)+(6*midsp)),y4,(mpref/2),buth,
2496                                   &(U.tw_hotspot), 4, 40, 0, 0, "Hotspot in pixels for clicking widget handles");
2497                 uiDefButBitS(block, TOG, U_TW_ABSOLUTE, B_REDRCURW3D, "Fixed Size",
2498                                   (xpos+edgsp+(5*mpref)+(6*midsp)+(mpref/2)),y4,(mpref/2),buth,
2499                                   &(U.tw_flag), 2, 40, 0, 0, "Size of widget based on fixed window size (1000 pixels)");
2500                 uiBlockEndAlign(block);
2501                 
2502         } else if (U.userpref == 1) { /* edit methods */
2503
2504
2505                 uiDefBut(block, LABEL,0,"Material linked to:",
2506                         xpos,y3label,mpref,buth,
2507                         0, 0, 0, 0, 0, "");
2508                 uiBlockBeginAlign(block);
2509                 uiDefButBitS(block, TOGN, USER_MAT_ON_OB, B_DRAWINFO, "ObData",
2510                         (xpos+edgsp),y2,(mpref/2),buth,
2511                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
2512                 uiDefButBitS(block, TOG, USER_MAT_ON_OB, B_DRAWINFO, "Object",
2513                         (xpos+edgsp+(mpref/2)),y2,(mpref/2),buth,
2514                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
2515                 uiBlockEndAlign(block);
2516
2517
2518                 uiDefBut(block, LABEL,0,"Editmode undo:",
2519                         (xpos+(2*edgsp)+mpref),y3label, mpref,buth,
2520                         0, 0, 0, 0, 0, "");
2521                 uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps:",
2522                         (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2523                         &(U.undosteps), 2, 64, 0, 0, "Number of undo steps available in Edit Mode (smaller values conserve memory)");
2524
2525                 uiDefButBitS(block, TOG, USER_GLOBALUNDO, B_DRAWINFO, "Global undo",
2526                         (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2527                         &(U.uiflag), 2, 64, 0, 0, "");
2528
2529
2530                 uiDefBut(block, LABEL,0,"Auto keyframe on:",
2531                         (xpos+(2*edgsp)+(2*mpref)+midsp),y3label,mpref,buth,
2532                         0, 0, 0, 0, 0, "");
2533                 uiDefButBitS(block, TOG, USER_KEYINSERTACT, 0, "Action",
2534                         (xpos+edgsp+(2*mpref)+(2*midsp)),y2,(spref+edgsp),buth,
2535                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Action Ipo curve");
2536                 uiDefButBitS(block, TOG, USER_KEYINSERTOBJ, 0, "Object",
2537                         (xpos+edgsp+(2*mpref)+(3*midsp)+spref-edgsp),y2,(spref+edgsp),buth,
2538                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Object Ipo curve");
2539
2540
2541                 uiDefBut(block, LABEL,0,"Duplicate with object:",
2542                         (xpos+(2*edgsp)+(3*midsp)+(3*mpref)+spref),y3label,mpref,buth,
2543                         0, 0, 0, 0, 0, "");
2544
2545                 uiDefButBitS(block, TOG, USER_DUP_MESH, 0, "Mesh",
2546                         (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y2,(spref+edgsp),buth,
2547                         &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
2548                 uiDefButBitS(block, TOG, USER_DUP_ARM, 0, "Armature",
2549                         (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y1,(spref+edgsp),buth,
2550                         &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
2551
2552                 uiDefButBitS(block, TOG, USER_DUP_SURF, 0, "Surface",
2553                         (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y2,(spref+edgsp),buth,
2554                         &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
2555                 uiDefButBitS(block, TOG, USER_DUP_LAMP, 0, "Lamp",
2556                         (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y1,(spref+edgsp),buth,
2557                         &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
2558
2559                 uiDefButBitS(block, TOG, USER_DUP_CURVE, 0, "Curve",
2560                         (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y2,(spref+edgsp),buth,
2561                         &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
2562                 uiDefButBitS(block, TOG, USER_DUP_MAT, 0, "Material",
2563                         (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y1,(spref+edgsp),buth,
2564                         &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
2565
2566                 uiDefButBitS(block, TOG, USER_DUP_FONT, 0, "Text",
2567                         (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y2,(spref+edgsp),buth,
2568                         &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
2569                 uiDefButBitS(block, TOG, USER_DUP_TEX, 0, "Texture",
2570                         (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y1,(spref+edgsp),buth,
2571                         &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
2572
2573                 uiDefButBitS(block, TOG, USER_DUP_MBALL, 0, "Metaball",
2574                         (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y2,(spref+edgsp),buth,
2575                         &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
2576                 uiDefButBitS(block, TOG, USER_DUP_IPO, 0, "Ipo",
2577                         (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y1,(spref+edgsp),buth,
2578                         &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
2579         
2580         } else if(U.userpref == 2) { /* language & colors */
2581
2582 #ifdef INTERNATIONAL
2583                 uiDefButBitS(block, TOG, USER_DOTRANSLATE, B_DOLANGUIFONT, "International Fonts",
2584                         xpos,y2,mpref,buth,
2585                         &(U.transopts), 0, 0, 0, 0, "Activate international interface");
2586
2587                 if(U.transopts & USER_DOTRANSLATE) {
2588                         char curfont[320];
2589                         
2590                         sprintf(curfont, "Interface Font: ");
2591                         if(U.fontname[0]) strcat(curfont, U.fontname);
2592                         else strcat(curfont, "Built-in");
2593                         
2594                         uiDefBut(block, LABEL,0,curfont,
2595                                 (xpos),y3,4*mpref,buth,
2596                                 0, 0, 0, 0, 0, "");
2597
2598                         uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
2599                                 xpos,y1,mpref,buth,
2600                                 0, 0, 0, 0, 0, "Select a new font for the interface");
2601
2602                         uiDefButI(block, BUT, B_RESTOREFONT, "Restore to default",
2603                                           (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2604                                           &U.fontsize, 0, 0, 0, 0, "Restores to using the default included antialised font");
2605                         
2606                         uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
2607                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2608                                 &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
2609
2610 /*
2611                         uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
2612                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2613                                 &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
2614
2615
2616                         uiDefBut(block, LABEL,0,"Translate:",
2617                                 (xpos+edgsp+(2.1*mpref)+(2*midsp)),y3label,mpref,buth,
2618                                 0, 0, 0, 0, 0, "");
2619 */
2620
2621                         uiDefButBitS(block, TOG, USER_TR_TOOLTIPS, B_SETTRANSBUTS, "Tooltips",
2622                                 (xpos+edgsp+(2.2*mpref)+(3*midsp)),y1,spref,buth,
2623                                 &(U.transopts), 0, 0, 0, 0, "Translate tooltips");
2624
2625                         uiDefButBitS(block, TOG, USER_TR_BUTTONS, B_SETTRANSBUTS, "Buttons",
2626                                 (xpos+edgsp+(2.2*mpref)+(4*midsp)+spref),y1,spref,buth,
2627                                 &(U.transopts), 0, 0, 0, 0, "Translate button labels");
2628
2629                         uiDefButBitS(block, TOG, USER_TR_MENUS, B_SETTRANSBUTS, "Toolbox",
2630                                 (xpos+edgsp+(2.2*mpref)+(5*midsp)+(2*spref)),y1,spref,buth,
2631                                 &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
2632
2633                         uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
2634                                 (xpos+edgsp+(2.2*mpref)+(3*midsp)),y2,mpref+(0.5*mpref)+3,buth,
2635                                 &U.language, 0, 0, 0, 0, "Select interface language");
2636                                 
2637                         uiDefButBitS(block, TOG, USER_USETEXTUREFONT, B_USETEXTUREFONT, "Use Textured Fonts",
2638                                 (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
2639                                 &(U.transopts), 0, 0, 0, 0,
2640                                 "Use Textured Fonts");
2641                 }
2642
2643 /* end of INTERNATIONAL */
2644 #endif
2645
2646         } else if(U.userpref == 3) { /* auto save */
2647
2648
2649                 uiDefButS(block, NUM, 0, "Save Versions:",
2650                         (xpos+edgsp),y3,mpref,buth,
2651                         &U.versions, 0.0, 32.0, 0, 0,
2652                         "The number of old versions to maintain in the current directory, when manually saving");
2653
2654                 uiDefButBitS(block, TOG, USER_AUTOSAVE, B_RESETAUTOSAVE, "Auto Save Temp Files",
2655                         (xpos+edgsp+mpref+midsp),y3,mpref,buth,
2656                         &(U.flag), 0, 0, 0, 0,
2657                         "Enables automatic saving of temporary files");
2658
2659                 if(U.flag & USER_AUTOSAVE) {
2660
2661                         uiDefButI(block, NUM, B_RESETAUTOSAVE, "Minutes:",
2662                                 (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2663                                 &(U.savetime), 1.0, 60.0, 0, 0,
2664                                 "The time (in minutes) to wait between automatic temporary saves");
2665
2666                         uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
2667                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2668                                 0, 0, 0, 0, 0,"Open the most recently saved temporary file");
2669                 }
2670
2671         } else if (U.userpref == 4) { /* system & opengl */
2672                 uiDefBut(block, LABEL,0,"Solid OpenGL light:",
2673                         xpos+edgsp, y3label, mpref, buth,
2674                         0, 0, 0, 0, 0, "");
2675                 
2676                 uiDefButS(block, MENU, B_REDR, "Light1 %x0|Light2 %x1|Light3 %x2",
2677                         xpos+edgsp, y2, 2*mpref/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
2678                 uiBlockSetCol(block, TH_BUT_SETTING1);
2679                 uiDefButI(block, TOG|BIT|0, B_RECALCLIGHT, "On",
2680                         xpos+edgsp+2*mpref/6, y2, mpref/6, buth, 
2681                         &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "Enable this OpenGL light in Solid draw mode");
2682                         
2683                 uiBlockSetCol(block, TH_AUTO);
2684                 uiDefButS(block, ROW, B_REDR, "Vec",
2685                         xpos+edgsp+3*mpref/6, y2, mpref/6, buth, 
2686                         &cur_light_var, 123.0, 0.0, 0, 0, "Lamp vector for OpenGL light");
2687                 uiDefButS(block, ROW, B_REDR, "Col",
2688                         xpos+edgsp+4*mpref/6, y2, mpref/6, buth, 
2689                         &cur_light_var, 123.0, 1.0, 0, 0, "Diffuse Color for OpenGL light");
2690                 uiDefButS(block, ROW, B_REDR, "Spec",
2691                         xpos+edgsp+5*mpref/6, y2, mpref/6, buth, 
2692                         &cur_light_var, 123.0, 2.0, 0, 0, "Specular color for OpenGL light");
2693
2694                 if(cur_light_var==1) {
2695                         uiDefButF(block, NUM, B_RECALCLIGHT, "R ",
2696                                 xpos+edgsp, y1, mpref/3, buth, 
2697                                 U.light[cur_light].col, 0.0, 1.0, 100, 2, "");
2698                         uiDefButF(block, NUM, B_RECALCLIGHT, "G ",
2699                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2700                                 U.light[cur_light].col+1, 0.0, 1.0, 100, 2, "");
2701                         uiDefButF(block, NUM, B_RECALCLIGHT, "B ",
2702                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2703                                 U.light[cur_light].col+2, 0.0, 1.0, 100, 2, "");
2704                 }
2705                 else if(cur_light_var==2) {
2706                         uiDefButF(block, NUM, B_RECALCLIGHT, "sR ",
2707                                 xpos+edgsp, y1, mpref/3, buth, 
2708                                 U.light[cur_light].spec, 0.0, 1.0, 100, 2, "");
2709                         uiDefButF(block, NUM, B_RECALCLIGHT, "sG ",
2710                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2711                                 U.light[cur_light].spec+1, 0.0, 1.0, 100, 2, "");
2712                         uiDefButF(block, NUM, B_RECALCLIGHT, "sB ",
2713                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2714                                 U.light[cur_light].spec+2, 0.0, 1.0, 100, 2, "");
2715                 }
2716                 else if(cur_light_var==0) {
2717                         uiDefButF(block, NUM, B_RECALCLIGHT, "X ",
2718                                 xpos+edgsp, y1, mpref/3, buth, 
2719                                 U.light[cur_light].vec, -1.0, 1.0, 100, 2, "");
2720                         uiDefButF(block, NUM, B_RECALCLIGHT, "Y ",
2721                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2722                                 U.light[cur_light].vec+1, -1.0, 1.0, 100, 2, "");
2723                         uiDefButF(block, NUM, B_RECALCLIGHT, "Z ",
2724                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2725                                 U.light[cur_light].vec+2, -1.0, 1.0, 100, 2, "");
2726                 }
2727
2728 /*
2729                 uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
2730                         (xpos+edgsp),y2,lpref,buth,
2731                         &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
2732
2733                 uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
2734                         (xpos+edgsp), y1, lpref,buth,
2735                         &U.console_out, 0, 0, 0, 0, "Select console output method");
2736
2737                 uiDefButS(block, NUM, B_CONSOLENUMLINES, "Lines:",
2738                         (xpos+edgsp+lpref+midsp),y1,spref,buth,
2739                         &U.console_buffer, 1.0, 4000.0, 0, 0, "Maximum number of internal console lines");
2740 */
2741
2742 #ifdef _WIN32
2743                 uiDefBut(block, LABEL,0,"Win Codecs:",
2744                         (xpos+edgsp+(1*midsp)+(1*mpref)),y3label,mpref,buth,
2745                         0, 0, 0, 0, 0, "");
2746
2747                 uiDefButBitS(block, TOG, USER_ALLWINCODECS, 0, "Enable all codecs",
2748                         (xpos+edgsp+(1*mpref)+(1*midsp)),y2,mpref,buth,
2749                         &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
2750 #endif
2751
2752                 uiDefBut(block, LABEL,0,"Keyboard:",
2753                         (xpos+edgsp+(3*midsp)+(3*mpref)),y3label,mpref,buth,
2754                         0, 0, 0, 0, 0, "");
2755
2756                 uiDefButBitS(block, TOG, USER_NO_CAPSLOCK, B_U_CAPSLOCK, "Disable Caps Lock",
2757                         (xpos+edgsp+(3*midsp)+(3*mpref)),y1,mpref,buth,
2758                         &(U.flag), 0, 0, 0, 0,
2759                         "Disables the Caps Lock key when entering text");
2760
2761                 uiDefButBitS(block, TOG, USER_NONUMPAD, 0, "Emulate Numpad",
2762                         (xpos+edgsp+(3*midsp)+(3*mpref)),y2,mpref,buth,
2763                         &(U.flag), 0, 0, 0, 0,
2764                         "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
2765
2766
2767                 uiDefBut(block, LABEL,0,"System:",
2768                         (xpos+edgsp+(4*midsp)+(4*mpref)),y3label,mpref,buth,
2769                         0, 0, 0, 0, 0, "");
2770
2771                 uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Sound",
2772                         (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,