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