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