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