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