- finished some minor drawing stuff which i couldnt complete last friday:
[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                                         }
1147                                         else if((G.qual==0)) {
1148                                                 if(G.obedit->type==OB_MESH) {
1149                                                         undo_push_mesh("Mirror");
1150                                                         mirrormenu();
1151                                                 }
1152                                         }
1153                                 }
1154                                 else if((G.qual==0)){
1155                                      movetolayer();
1156                                 }
1157                                 break;
1158                         case NKEY:
1159                                 if((G.qual==0)) {
1160                                         add_blockhandler(curarea, VIEW3D_HANDLER_OBJECT, UI_PNL_TO_MOUSE);
1161                                         allqueue(REDRAWVIEW3D, 0);
1162                                 }
1163                                 else if(G.obedit) {
1164                                         switch (G.obedit->type){
1165                                         case OB_ARMATURE:
1166                                                 if(G.qual==LR_CTRLKEY){
1167                                                         if (okee("Recalc bone roll angles")) {
1168                                                                 auto_align_armature();
1169                                                                 allqueue(REDRAWVIEW3D, 0);
1170                                                         }
1171                                                 }
1172                                                 break;
1173                                         case OB_MESH: 
1174                                                 if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
1175                                                         if(okee("Recalc normals inside")) {
1176                                                                 undo_push_mesh("Recalc normals inside");
1177                                                                 righthandfaces(2);
1178                                                                 allqueue(REDRAWVIEW3D, 0);
1179                                                         }
1180                                                 }
1181                                                 else if(G.qual==LR_CTRLKEY){
1182                                                         if(okee("Recalc normals outside")) {
1183                                                                 undo_push_mesh("Recalc normals outside");
1184                                                                 righthandfaces(1);
1185                                                                 allqueue(REDRAWVIEW3D, 0);
1186                                                         }
1187                                                 }
1188                                                 break;
1189                                         }
1190                                 }
1191                                 
1192                                 break;
1193                         case OKEY:
1194                                 ob= OBACT;
1195                                 if(G.obedit) {
1196                                         extern int prop_mode;
1197
1198                                         if (G.qual==LR_SHIFTKEY) {
1199                                                 prop_mode= !prop_mode;
1200                                                 allqueue(REDRAWHEADERS, 0);
1201                                         }
1202                                         else if((G.qual==0)) {
1203                                                 G.f ^= G_PROPORTIONAL;
1204                                                 allqueue(REDRAWHEADERS, 0);
1205                                         }
1206                                 }
1207                                 else if((G.qual==LR_SHIFTKEY)) {
1208                                         if(ob && ob->type == OB_MESH) {
1209                                                 flip_subdivison(ob, 0);
1210                                         }
1211                                 }
1212                                 else if(G.qual==LR_ALTKEY) clear_object('o');
1213                                 break;
1214
1215                         case PKEY:
1216                                 
1217                                 if(G.obedit) {
1218                                         if(G.qual==LR_CTRLKEY)
1219                                                 make_parent();
1220                                         else if((G.qual==0) && G.obedit->type==OB_MESH)
1221                                                 separatemenu();
1222                                         else if ((G.qual==0) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
1223                                                 separate_nurb();
1224                                 }
1225                                 else if(G.qual==LR_CTRLKEY)
1226                                         make_parent();
1227                                 else if(G.qual==LR_ALTKEY)
1228                                         clear_parent();
1229                                 else if((G.qual==0)) {
1230                         start_game();
1231                                 }
1232                                 break;                          
1233                         case RKEY:
1234                                 if((G.obedit==0) && (G.f & G_FACESELECT) && (G.qual==0))
1235                                         rotate_uv_tface();
1236                                 else if(G.qual==LR_ALTKEY)
1237                                         clear_object('r');
1238                                 else if (G.obedit) {
1239                                         if((G.qual==LR_SHIFTKEY)) {
1240                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF)                                     
1241                                                         selectrow_nurb();
1242                                                 else if (G.obedit->type==OB_MESH)
1243                                                         loop('s');
1244                                         }
1245                                         else if(G.qual==LR_CTRLKEY) {
1246                                                 if (G.obedit->type==OB_MESH)
1247                                                         loop('c');
1248                                         }
1249                                         else if((G.qual==0))
1250                                                 transform('r');
1251                                 }
1252                                 else if((G.qual==0))
1253                                         transform('r');
1254                                 break;
1255                         case SKEY:
1256                                 if(G.obedit) {
1257                                         if(G.qual==LR_ALTKEY)
1258                                                 transform('N'); /* scale along normal */
1259                                         else if(G.qual==LR_CTRLKEY)
1260                                                 transform('S');
1261                                         else if(G.qual==LR_SHIFTKEY)
1262                                                 snapmenu();
1263                                         else if((G.qual==0))
1264                                                 transform('s');
1265                                 }
1266                                 else if(G.qual==LR_ALTKEY) {
1267                                         clear_object('s');
1268                                 }
1269                                 else if((G.qual==LR_SHIFTKEY))
1270                                         snapmenu();
1271                                 else if((G.qual==0))
1272                                         transform('s');
1273                                 break;
1274                         case TKEY:
1275                                 if(G.obedit){
1276                                         if((G.qual==LR_CTRLKEY) && G.obedit->type==OB_MESH) {
1277                                                 convert_to_triface(0);
1278                                                 allqueue(REDRAWVIEW3D, 0);
1279                                                 countall();
1280                                                 makeDispList(G.obedit);
1281                                         }
1282                                         else if((G.qual==LR_ALTKEY) && G.obedit->type==OB_CURVE)
1283                                                 clear_tilt();
1284                                         else if((G.qual==0))
1285                                                 transform('t');
1286                                 }
1287                                 else if(G.qual==LR_CTRLKEY) {
1288                                         make_track();
1289                                 }
1290                                 else if(G.qual==LR_ALTKEY) {
1291                                         clear_track();
1292                                 }
1293                                 else if((G.qual==0)){
1294                                         texspace_edit();
1295                                 }
1296                                 
1297                                 break;
1298                         case UKEY:
1299                                 if(G.obedit) {
1300                                         if(G.obedit->type==OB_MESH){
1301                                                 if (G.qual==LR_ALTKEY)
1302                                                         undo_menu_mesh();
1303                                                 else if (G.qual==LR_SHIFTKEY)
1304                                                         undo_redo_mesh();
1305                                                 else if((G.qual==0))
1306                                                         undo_pop_mesh(1);
1307                                         }
1308                                         else if(G.obedit->type==OB_ARMATURE)
1309                                                 remake_editArmature();
1310                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
1311                                                 remake_editNurb();
1312                                         else if(G.obedit->type==OB_LATTICE)
1313                                                 remake_editLatt();
1314                                 }
1315                                 else if((G.qual==0)){
1316                                         if (G.f & G_FACESELECT)
1317                                                 uv_autocalc_tface();
1318                                         else if(G.f & G_WEIGHTPAINT)
1319                                                 wpaint_undo();
1320                                         else if(G.f & G_VERTEXPAINT)
1321                                                 vpaint_undo();
1322                                         else
1323                                                 single_user();
1324                                 }
1325                                 
1326                                 break;
1327                         case VKEY:
1328                                 ob= OBACT;
1329                                 if((G.qual==LR_SHIFTKEY)) {
1330                                         if ((G.obedit) && G.obedit->type==OB_MESH) {
1331                                                 align_view_to_selected(v3d);
1332                                         }
1333                                         else if (G.f & G_FACESELECT) {
1334                                                 align_view_to_selected(v3d);
1335                                         }
1336                                 }
1337                                 else if(G.qual==LR_ALTKEY)
1338                                         image_aspect();
1339                                 else if (G.qual==0){
1340                                         if(G.obedit) {
1341                                                 if(G.obedit->type==OB_CURVE) {
1342                                                         sethandlesNurb(2);
1343                                                         makeDispList(G.obedit);
1344                                                         allqueue(REDRAWVIEW3D, 0);
1345                                                 }
1346                                         }
1347                                         else if(ob && ob->type == OB_MESH) 
1348                                                 set_vpaint();
1349                                 }
1350                                 break;
1351                         case WKEY:
1352                                 if((G.qual==LR_SHIFTKEY)) {
1353                                         transform('w');
1354                                 }
1355                                 else if(G.qual==LR_ALTKEY) {
1356                                         /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
1357                                 }
1358                                 else if(G.qual==LR_CTRLKEY) {
1359                                         if(G.obedit) {
1360                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF) {
1361                                                         switchdirectionNurb2();
1362                                                 }
1363                                         }
1364                                 }
1365                                 else if((G.qual==0))
1366                                         special_editmenu();
1367                                 
1368                                 break;
1369                         case XKEY:
1370                         case DELKEY:
1371                                 if(G.qual==0)
1372                                         delete_context_selected();
1373                                 break;
1374                         case YKEY:
1375                                 if((G.qual==0) && (G.obedit)) {
1376                                         if(G.obedit->type==OB_MESH) split_mesh();
1377                                 }
1378                                 break;
1379                         case ZKEY:
1380                                 toggle_shading();
1381                                 
1382                                 scrarea_queue_headredraw(curarea);
1383                                 scrarea_queue_winredraw(curarea);
1384                                 break;
1385                                 
1386                         
1387                         case HOMEKEY:
1388                                 if(G.qual==0)
1389                                         view3d_home(0);
1390                                 break;
1391                         case COMMAKEY:
1392                                 if(G.qual==0) {
1393                                         G.vd->around= V3D_CENTRE;
1394                                         scrarea_queue_headredraw(curarea);
1395                                 }
1396                                 break;
1397                                 
1398                         case PERIODKEY:
1399                                 if(G.qual==0) {
1400                                         G.vd->around= V3D_CURSOR;
1401                                         scrarea_queue_headredraw(curarea);
1402                                 }
1403                                 break;
1404                         
1405                         case PADSLASHKEY:
1406                                 if(G.qual==0) {
1407                                         if(G.vd->localview) {
1408                                                 G.vd->localview= 0;
1409                                                 endlocalview(curarea);
1410                                         }
1411                                         else {
1412                                                 G.vd->localview= 1;
1413                                                 initlocalview();
1414                                         }
1415                                         scrarea_queue_headredraw(curarea);
1416                                 }
1417                                 break;
1418                         case PADASTERKEY:       /* '*' */
1419                                 if(G.qual==0) {
1420                                         ob= OBACT;
1421                                         if(ob) {
1422                                                 obmat_to_viewmat(ob);
1423                                                 if(G.vd->persp==2) G.vd->persp= 1;
1424                                                 scrarea_queue_winredraw(curarea);
1425                                         }
1426                                 }
1427                                 break;
1428                         case PADPERIOD: /* '.' */
1429                                 if(G.qual==0)
1430                                         centreview();
1431                                 break;
1432                         
1433                         case PAGEUPKEY:
1434                                 if(G.qual==LR_CTRLKEY)
1435                                         movekey_obipo(1);
1436                                 else if((G.qual==0))
1437                                         nextkey_obipo(1);       /* in editipo.c */
1438                                 break;
1439
1440                         case PAGEDOWNKEY:
1441                                 if(G.qual==LR_CTRLKEY)
1442                                         movekey_obipo(-1);
1443                                 else if((G.qual==0))
1444                                         nextkey_obipo(-1);
1445                                 break;
1446                                 
1447                         case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
1448                         case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
1449                         case PADMINUS: case PADPLUSKEY: case PADENTER:
1450                                 persptoetsen(event);
1451                                 doredraw= 1;
1452                                 break;
1453                         
1454                         case ESCKEY:
1455                                 if(G.qual==0) {
1456                                         if (G.vd->flag & V3D_DISPIMAGE) {
1457                                                 G.vd->flag &= ~V3D_DISPIMAGE;
1458                                                 doredraw= 1;
1459                                         }
1460                                 }
1461                                 break;
1462                         }
1463                 }
1464         }
1465         
1466         if(doredraw) {
1467                 scrarea_queue_winredraw(curarea);
1468                 scrarea_queue_headredraw(curarea);
1469         }
1470 }
1471
1472 void initview3d(ScrArea *sa)
1473 {
1474         View3D *vd;
1475         
1476         vd= MEM_callocN(sizeof(View3D), "initview3d");
1477         BLI_addhead(&sa->spacedata, vd);        /* addhead! not addtail */
1478
1479         vd->spacetype= SPACE_VIEW3D;
1480         vd->viewquat[0]= 1.0;
1481         vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0;
1482         vd->persp= 1;
1483         vd->drawtype= OB_WIRE;
1484         vd->view= 7;
1485         vd->dist= 10.0;
1486         vd->lens= 35.0f;
1487         vd->near= 0.01f;
1488         vd->far= 500.0f;
1489         vd->grid= 1.0f;
1490         vd->gridlines= 16;
1491         vd->lay= vd->layact= 1;
1492         if(G.scene) {
1493                 vd->lay= vd->layact= G.scene->lay;
1494                 vd->camera= G.scene->camera;
1495         }
1496         vd->scenelock= 1;
1497 }
1498
1499
1500 /* ******************** SPACE: IPO ********************** */
1501
1502 static void changeview2dspace(ScrArea *sa, void *spacedata)
1503 {
1504         if(G.v2d==0) return;
1505
1506         test_view2d(G.v2d, curarea->winx, curarea->winy);
1507         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
1508 }
1509
1510 void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
1511 {
1512         extern void do_ipobuts(unsigned short event);   // drawipo.c
1513         unsigned short event= evt->event;
1514         short val= evt->val;
1515         SpaceIpo *sipo= curarea->spacedata.first;
1516         View2D *v2d= &sipo->v2d;
1517         float dx, dy;
1518         int cfra, doredraw= 0;
1519         short mval[2];
1520         
1521
1522         if(sa->win==0) return;
1523
1524         if(val) {
1525                 if( uiDoBlocks(&sa->uiblocks, event)!=UI_NOTHING ) event= 0;
1526
1527                 switch(event) {
1528                 case UI_BUT_EVENT:
1529                         /* note: bad bad code, will be cleaned! is because event queues are all shattered */
1530                         if(val>0 && val < 32) do_ipowin_buts(val-1);
1531                         else do_ipobuts(val);
1532                         break;
1533                         
1534                 case LEFTMOUSE:
1535                         if( in_ipo_buttons() ) {
1536                                 do_ipo_selectbuttons();
1537                                 doredraw= 1;
1538                         }                       
1539                         else if(G.qual & LR_CTRLKEY) add_vert_ipo();
1540                         else {
1541                                 do {
1542                                         getmouseco_areawin(mval);
1543                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
1544                                         
1545                                         cfra= (int)dx;
1546                                         if(cfra< 1) cfra= 1;
1547                                         
1548                                         if( cfra!=CFRA ) {
1549                                                 CFRA= cfra;
1550                                                 update_for_newframe();
1551                                                 force_draw_plus(SPACE_VIEW3D);
1552                                                 force_draw_plus(SPACE_ACTION);
1553                                                 force_draw_plus(SPACE_BUTS);    /* To make constraint sliders redraw */
1554                                         }
1555                                 
1556                                 } while(get_mbut()&L_MOUSE);
1557                         }
1558                         
1559                         break;
1560                 case MIDDLEMOUSE:
1561                         if(in_ipo_buttons()) {
1562                                 scroll_ipobuts();
1563                         }
1564                         else view2dmove(event); /* in drawipo.c */
1565                         break;
1566
1567                 case WHEELUPMOUSE:
1568                 case WHEELDOWNMOUSE:
1569                         view2dmove(event);      /* in drawipo.c */
1570                         break;
1571
1572                 case RIGHTMOUSE:
1573                         mouse_select_ipo();
1574                         allqueue (REDRAWACTION, 0);
1575                         allqueue(REDRAWNLA, 0);
1576                         break;
1577                 case PADPLUSKEY:
1578                         view2d_zoom(v2d, 0.1154, sa->winx, sa->winy);
1579                         doredraw= 1;
1580                         break;
1581                 case PADMINUS:
1582                         view2d_zoom(v2d, -0.15, sa->winx, sa->winy);
1583                         doredraw= 1;
1584                         break;
1585                 case PAGEUPKEY:
1586                         if(G.qual==LR_CTRLKEY)
1587                                 movekey_ipo(1);
1588                         else if((G.qual==0))
1589                                 nextkey_ipo(1);
1590                         break;
1591                 case PAGEDOWNKEY:
1592                         if(G.qual==LR_CTRLKEY)
1593                                 movekey_ipo(-1);
1594                         else if((G.qual==0))
1595                                 nextkey_ipo(-1);
1596                         break;
1597                 case HOMEKEY:
1598                         if((G.qual==0))
1599                                 do_ipo_buttons(B_IPOHOME);
1600                         break;
1601                         
1602                 case AKEY:
1603                         if((G.qual==0)) {
1604                                 if(in_ipo_buttons()) {
1605                                         swap_visible_editipo();
1606                                 }
1607                                 else swap_selectall_editipo();
1608                                 allspace (REMAKEIPO, 0);
1609                                 allqueue (REDRAWNLA, 0);
1610                                 allqueue (REDRAWACTION, 0);
1611                         }
1612                         break;
1613                 case BKEY:
1614                         if((G.qual==0))
1615                                 borderselect_ipo();
1616                         break;
1617                 case CKEY:
1618                         if((G.qual==0))
1619                                 move_to_frame();
1620                         break;
1621                 case DKEY:
1622                         if((G.qual==LR_SHIFTKEY))
1623                                 add_duplicate_editipo();
1624                         break;
1625                 case GKEY:
1626                         if((G.qual==0))
1627                                 transform_ipo('g');
1628                         break;
1629                 case HKEY:
1630                         if((G.qual==LR_SHIFTKEY))
1631                                 sethandles_ipo(HD_AUTO);
1632                         else if((G.qual==0))
1633                                 sethandles_ipo(HD_ALIGN);
1634                         break;
1635                 case JKEY:
1636                         if((G.qual==0))
1637                                 join_ipo();
1638                         break;
1639                 case KKEY:
1640                         if((G.qual==0)) {
1641                                 ipo_toggle_showkey();
1642                                 scrarea_queue_headredraw(curarea);
1643                                 allqueue(REDRAWVIEW3D, 0);
1644                                 doredraw= 1;
1645                         }
1646                         break;
1647                 case NKEY:
1648                         add_blockhandler(sa, IPO_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
1649                         doredraw= 1;
1650                         break;
1651                 case RKEY:
1652                         if((G.qual==0))
1653                                 ipo_record();
1654                         break;
1655                 case SKEY:
1656                         if((G.qual==LR_SHIFTKEY))
1657                                 ipo_snapmenu();
1658                         else if((G.qual==0))
1659                                 transform_ipo('s');
1660                         break;
1661                 case TKEY:
1662                         if((G.qual==0))
1663                                 set_ipotype();
1664                         break;
1665                 case VKEY:
1666                         if((G.qual==0))
1667                                 sethandles_ipo(HD_VECT);
1668                         break;
1669                 case XKEY:
1670                 case DELKEY:
1671                         if((G.qual==LR_SHIFTKEY))
1672                                 delete_key();
1673                         else if((G.qual==0))
1674                                 del_ipo();
1675                         break;
1676                 }
1677         }
1678
1679         if(doredraw) scrarea_queue_winredraw(sa);
1680 }
1681
1682 void initipo(ScrArea *sa)
1683 {
1684         SpaceIpo *sipo;
1685         
1686         sipo= MEM_callocN(sizeof(SpaceIpo), "initipo");
1687         BLI_addhead(&sa->spacedata, sipo);
1688
1689         sipo->spacetype= SPACE_IPO;
1690         /* sipo space loopt van (0,-?) tot (??,?) */
1691         sipo->v2d.tot.xmin= 0.0;
1692         sipo->v2d.tot.ymin= -10.0;
1693         sipo->v2d.tot.xmax= G.scene->r.efra;
1694         sipo->v2d.tot.ymax= 10.0;
1695
1696         sipo->v2d.cur= sipo->v2d.tot;
1697
1698         sipo->v2d.min[0]= 0.01f;
1699         sipo->v2d.min[1]= 0.01f;
1700
1701         sipo->v2d.max[0]= 15000.0f;
1702         sipo->v2d.max[1]= 10000.0f;
1703         
1704         sipo->v2d.scroll= L_SCROLL+B_SCROLL;
1705         sipo->v2d.keeptot= 0;
1706
1707         sipo->blocktype= ID_OB;
1708 }
1709
1710 /* ******************** SPACE: INFO ********************** */
1711
1712 void space_mipmap_button_function(int event) {
1713         set_mipmap(!(U.gameflags & USERDEF_DISABLE_MIPMAP));
1714
1715         allqueue(REDRAWVIEW3D, 0);
1716 }
1717
1718 void space_sound_button_function(int event)
1719 {
1720         int a;
1721         SYS_SystemHandle syshandle;
1722
1723         if ((syshandle = SYS_GetSystem()))
1724         {
1725                 a = (U.gameflags & USERDEF_DISABLE_SOUND);
1726                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
1727         }
1728 }
1729
1730 #define B_ADD_THEME     3301
1731 #define B_DEL_THEME     3302
1732 #define B_NAME_THEME    3303
1733 #define B_THEMECOL              3304
1734 #define B_UPDATE_THEME  3305
1735 #define B_CHANGE_THEME  3306
1736 #define B_THEME_COPY    3307
1737 #define B_THEME_PASTE   3308
1738
1739 #define B_RECALCLIGHT   3310
1740
1741 // needed for event; choose new 'curmain' resets it...
1742 static short th_curcol= TH_BACK;
1743 static char *th_curcol_ptr= NULL;
1744 static char th_curcol_arr[4]={0, 0, 0, 255};
1745
1746 void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
1747 {
1748         bTheme *btheme, *bt;
1749         int spacetype= 0;
1750         static short cur=1, curmain=2;
1751         short a, tot=0, isbuiltin= 0;
1752         char string[20*32], *strp, *col;
1753         
1754         y3= y2+23;      // exception!
1755         
1756         /* count total, max 16! */
1757         for(bt= U.themes.first; bt; bt= bt->next) tot++;
1758         
1759         /* if cur not is 1; move that to front of list */
1760         if(cur!=1) {
1761                 a= 1;
1762                 for(bt= U.themes.first; bt; bt= bt->next, a++) {
1763                         if(a==cur) {
1764                                 BLI_remlink(&U.themes, bt);
1765                                 BLI_addhead(&U.themes, bt);
1766                                 cur= 1;
1767                                 break;
1768                         }
1769                 }
1770         }
1771         
1772         /* the current theme */
1773         btheme= U.themes.first;
1774         if(strcmp(btheme->name, "Default")==0) isbuiltin= 1;
1775
1776         /* construct popup script */
1777         string[0]= 0;
1778         for(bt= U.themes.first; bt; bt= bt->next) {
1779                 strcat(string, bt->name);
1780                 if(btheme->next) strcat(string, "   |");
1781         }
1782         uiDefButS(block, MENU, B_UPDATE_THEME, string,                  45,y3,200,20, &cur, 0, 0, 0, 0, "Current theme");
1783         
1784         /* add / delete / name */
1785
1786         if(tot<16)
1787                 uiDefBut(block, BUT, B_ADD_THEME, "Add",        45,y2,200,20, NULL, 0, 0, 0, 0, "Makes new copy of this theme");
1788         if(tot>1 && isbuiltin==0)
1789                 uiDefBut(block, BUT, B_DEL_THEME, "Delete", 45,y1,200,20, NULL, 0, 0, 0, 0, "Delete theme");
1790
1791         if(isbuiltin) return;
1792         
1793         /* name */
1794         uiDefBut(block, TEX, B_NAME_THEME, "",                  255,y3,200,20, btheme->name, 1.0, 30.0, 0, 0, "Rename theme");
1795
1796         /* main choices pup */
1797         uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|3D View %x2|Ipo Curve Editor %x3|Action Editor %x4|"
1798                 "NLA Editor %x5|UV/Image Editor %x6|Sequence Editor %x7|Sound Editor %x8|Text Editor %x9|User Preferences %x10|"
1799                 "OOPS Schematic %x11|Buttons Window %x12|File Window %x13|Image Browser %x14",
1800                                                                                                         255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
1801         if(curmain==1) spacetype= 0;
1802         else if(curmain==2) spacetype= SPACE_VIEW3D;
1803         else if(curmain==3) spacetype= SPACE_IPO;
1804         else if(curmain==4) spacetype= SPACE_ACTION;
1805         else if(curmain==5) spacetype= SPACE_NLA;
1806         else if(curmain==6) spacetype= SPACE_IMAGE;
1807         else if(curmain==7) spacetype= SPACE_SEQ;
1808         else if(curmain==8) spacetype= SPACE_SOUND;
1809         else if(curmain==9) spacetype= SPACE_TEXT;
1810         else if(curmain==10) spacetype= SPACE_INFO;
1811         else if(curmain==11) spacetype= SPACE_OOPS;
1812         else if(curmain==12) spacetype= SPACE_BUTS;
1813         else if(curmain==13) spacetype= SPACE_FILE;
1814         else if(curmain==14) spacetype= SPACE_IMASEL;
1815         else return; // only needed while coding... when adding themes for more windows
1816         
1817         /* color choices pup */
1818         if(curmain==1) {
1819                 strp= BIF_ThemeColorsPup(0);
1820                 if(th_curcol==TH_BACK) th_curcol= TH_BUT_NEUTRAL;  // switching main choices...
1821         }
1822         else strp= BIF_ThemeColorsPup(spacetype);
1823         
1824         uiDefButS(block, MENU, B_REDR, strp,                    255,y1,200,20, &th_curcol, 0, 0, 0, 0, "Current color");
1825         MEM_freeN(strp);
1826         
1827         th_curcol_ptr= col= BIF_ThemeGetColorPtr(btheme, spacetype, th_curcol);
1828         if(col==NULL) return;
1829         
1830         /* first handle exceptions, special single values, row selection, etc */
1831         if(th_curcol==TH_VERTEX_SIZE) {
1832                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Vertex size ", 465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
1833         }
1834         else if(th_curcol==TH_BUT_DRAWTYPE) {
1835                 uiBlockBeginAlign(block);
1836                 uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal",        465,y3,100,20,  col, 2.0, 0.0, 0, 0, "");
1837                 uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 565,y3,100,20,  col, 2.0, 1.0, 0, 0, "");
1838                 uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded",        465,y2,100,20,  col, 2.0, 2.0, 0, 0, "");
1839                 uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool",       565,y2,100,20,  col, 2.0, 3.0, 0, 0, "");
1840                 uiBlockEndAlign(block);
1841         }
1842         else {
1843                 uiBlockBeginAlign(block);
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                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
1848                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"G ",   465,y2,200,20,  col+1, 0.0, 255.0, B_THEMECOL, 0, "");
1849                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"B ",   465,y1,200,20,  col+2, 0.0, 255.0, B_THEMECOL, 0, "");
1850                 uiBlockEndAlign(block);
1851
1852                 uiDefButC(block, COL, B_THEMECOL, "",           675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
1853                                 
1854                 /* copy paste */
1855                 uiBlockBeginAlign(block);
1856                 uiDefBut(block, BUT, B_THEME_COPY, "Copy Color",        755,y2,120,20, NULL, 0, 0, 0, 0, "Stores current color in buffer");
1857                 uiDefBut(block, BUT, B_THEME_PASTE, "Paste Color",      755,y1,120,20, NULL, 0, 0, 0, 0, "Pastes buffer color");
1858                 uiBlockEndAlign(block);
1859                 
1860                 uiDefButC(block, COL, 0, "",                            885,y1,50,y2-y1+20, th_curcol_arr, 0, 0, 0, 0, "");
1861                 
1862         }
1863 }
1864
1865
1866 void drawinfospace(ScrArea *sa, void *spacedata)
1867 {
1868         uiBlock *block;
1869         static short cur_light=0, cur_light_var=0;
1870         float fac, col[3];
1871         short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y2label, y3label, y4label;
1872         short smallprefbut, medprefbut, largeprefbut, smfileselbut;
1873         short edgespace, midspace;
1874         char naam[32];
1875
1876         if(curarea->win==0) return;
1877
1878         BIF_GetThemeColor3fv(TH_BACK, col);
1879         glClearColor(col[0], col[1], col[2], 0.0);
1880         glClear(GL_COLOR_BUFFER_BIT);
1881
1882         fac= ((float)curarea->winx)/1280.0f;
1883         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
1884         
1885         sprintf(naam, "infowin %d", curarea->win);
1886         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->win);
1887
1888
1889         dx= (1280-90)/7;        /* spacing for use in equally dividing 'tab' row */
1890
1891         xpos = 45;              /* left padding */
1892         ypos = 50;              /* bottom padding for buttons */
1893         ypostab = 10;           /* bottom padding for 'tab' row */
1894
1895
1896         buth = 20;              /* standard button height */
1897
1898         smallprefbut = 94;      /* standard size for small preferences button */
1899         medprefbut = 193;       /* standard size for medium preferences button */
1900         largeprefbut = 292;     /* standard size for large preferences button */
1901         smfileselbut = buth;    /* standard size for fileselect button (square) */
1902         
1903         edgespace = 3;          /* space from edge of end 'tab' to edge of end button */
1904         midspace = 5;           /* horizontal space between buttons */
1905
1906         rspace = 3;             /* default space between rows */
1907
1908         y1 = ypos;              /* bottom padding of 1st (bottom) button row */
1909         y2 = ypos+buth+rspace;  /* bottom padding of 2nd button row */
1910         y3 = ypos+2*(buth+rspace)+(3*rspace);   /* bottom padding of 3rd button row */
1911         y4 = ypos+3*(buth+rspace)+(3*rspace);   /* bottom padding of 4th button row */
1912
1913         y2label = y2-2;         /* adjustments to offset the labels down to align better */
1914         y3label = y3-(3*rspace)-2;      /* again for 3rd row */
1915         y4label = y4-2;         /* again for 4th row */
1916
1917
1918         /* set the colour to blue and draw the main 'tab' controls */
1919
1920         uiBlockSetCol(block, TH_BUT_SETTING1);
1921         uiBlockBeginAlign(block);
1922         
1923         uiDefButI(block, ROW,B_USERPREF,"View & Controls",
1924                 xpos,ypostab,(short)dx,buth,
1925                 &U.userpref,1.0,0.0, 0, 0,"");
1926                 
1927         uiDefButI(block, ROW,B_USERPREF,"Edit Methods",
1928                 (short)(xpos+dx),ypostab,(short)dx,buth,
1929                 &U.userpref,1.0,1.0, 0, 0,"");
1930
1931         uiDefButI(block, ROW,B_USERPREF,"Language & Font",
1932                 (short)(xpos+2*dx),ypostab,(short)dx,buth,
1933                 &U.userpref,1.0,2.0, 0, 0,"");
1934
1935         uiDefButI(block, ROW,B_USERPREF,"Themes",
1936                 (short)(xpos+3*dx),ypostab,(short)dx,buth,
1937                 &U.userpref,1.0,6.0, 0, 0,"");
1938
1939         uiDefButI(block, ROW,B_USERPREF,"Auto Save",
1940                 (short)(xpos+4*dx),ypostab,(short)dx,buth,
1941                 &U.userpref,1.0,3.0, 0, 0,"");
1942
1943         uiDefButI(block, ROW,B_USERPREF,"System & OpenGL",
1944                 (short)(xpos+5*dx),ypostab,(short)dx,buth,
1945                 &U.userpref,1.0,4.0, 0, 0,"");
1946                 
1947         uiDefButI(block, ROW,B_USERPREF,"File Paths",
1948                 (short)(xpos+6*dx),ypostab,(short)dx,buth,
1949                 &U.userpref,1.0,5.0, 0, 0,"");
1950
1951         uiBlockSetCol(block, TH_AUTO);
1952         uiBlockEndAlign(block);
1953         /* end 'tab' controls */
1954
1955         /* line 2: left x co-ord, top y co-ord, width, height */
1956
1957         if(U.userpref == 6) {
1958                 info_user_themebuts(block, y1, y2, y3);
1959         }
1960         else if (U.userpref == 0) { /* view & controls */
1961
1962                 uiDefBut(block, LABEL,0,"Display:",
1963                         xpos,y3label,medprefbut,buth,
1964                         0, 0, 0, 0, 0, "");
1965                 
1966                 uiDefButS(block, TOG|BIT|11, 0, "ToolTips",
1967                         (xpos+edgespace),y2,smallprefbut,buth,
1968                         &(U.flag), 0, 0, 0, 0,
1969                         "Displays tooltips (help tags) over buttons");
1970
1971                 uiDefButS(block, TOG|BIT|4, B_DRAWINFO, "Object Info",
1972                         (xpos+edgespace+midspace+smallprefbut),y2,smallprefbut,buth,
1973                         &(U.uiflag), 0, 0, 0, 0,
1974                         "Displays current object name and frame number in the 3D viewport");
1975
1976                 uiDefButS(block, TOG|BIT|4, 0, "Global Scene",
1977                         (xpos+edgespace),y1,medprefbut,buth,
1978                         &(U.flag), 0, 0, 0, 0,
1979                         "Forces the current Scene to be displayed in all Screens");
1980
1981
1982                 uiDefBut(block, LABEL,0,"Snap to grid:",
1983                         (xpos+edgespace+medprefbut),y3label,medprefbut,buth,
1984                         0, 0, 0, 0, 0, "");
1985
1986                 uiDefButS(block, TOG|BIT|1, 0, "Grab",
1987                         (xpos+edgespace+medprefbut+midspace),y2,smallprefbut,buth,
1988                         &(U.flag), 0, 0, 0, 0,
1989                         "Move objects to grid units");
1990
1991                 uiDefButS(block, TOG|BIT|3, 0, "Size",
1992                         (xpos+edgespace+medprefbut+midspace),y1,smallprefbut,buth,
1993                         &(U.flag), 0, 0, 0, 0,
1994                         "Scale objects to grid units");
1995
1996                 uiDefButS(block, TOG|BIT|2, 0, "Rotate",
1997                         (xpos+edgespace+medprefbut+(2*midspace)+smallprefbut),y2,smallprefbut,buth,
1998                         &(U.flag), 0, 0, 0, 0,
1999                         "Rotate objects to grid units");
2000
2001
2002
2003                 uiDefBut(block, LABEL,0,"Menu Buttons:",
2004                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y3label,medprefbut,buth,
2005                         0, 0, 0, 0, 0, "");
2006
2007                 uiDefButS(block, TOG|BIT|9, 0, "Auto Open",
2008                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y2,smallprefbut,buth,
2009                         &(U.uiflag), 0, 0, 0, 0,
2010                         "Automatic opening of menu buttons");
2011
2012                 uiDefButS(block, NUM, 0, "ThresA:",
2013                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y1,smallprefbut,buth,
2014                         &(U.menuthreshold1), 1, 40, 0, 0,
2015                         "Time in 1/10 seconds for auto open");
2016
2017                 uiDefButS(block, NUM, 0, "ThresB:",
2018                         (xpos+edgespace+medprefbut+(4*midspace)+(3*smallprefbut)),y1,smallprefbut,buth,
2019                         &(U.menuthreshold2), 1, 40, 0, 0,
2020                         "Time in 1/10 seconds for auto open sublevels");
2021
2022
2023                 uiDefBut(block, LABEL,0,"Toolbox Thresh.:",
2024                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y3label,medprefbut,buth,
2025                         0, 0, 0, 0, 0, "");
2026
2027                 uiDefButS(block, NUM, 0, "LMB:",
2028                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y2,smallprefbut,buth,
2029                         &(U.tb_leftmouse), 2, 40, 0, 0,
2030                         "Time in 1/10 seconds leftmouse hold to open toolbox");
2031
2032                 uiDefButS(block, NUM, 0, "RMB:",
2033                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y1,smallprefbut,buth,
2034                         &(U.tb_rightmouse), 2, 40, 0, 0,
2035                         "Time in 1/10 seconds for rightmouse to open toolbox");
2036
2037                         
2038                 uiDefBut(block, LABEL,0,"View rotation:",
2039                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y3label,medprefbut,buth,
2040                         0, 0, 0, 0, 0, "");
2041
2042                 uiDefButS(block, TOG|BIT|5, B_DRAWINFO, "Trackball",
2043                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y2,(smallprefbut+2),buth,
2044                         &(U.flag), 0, 0, 0, 0,
2045                         "Use trackball style rotation with middle mouse button");
2046
2047                 uiDefButS(block, TOGN|BIT|5, B_DRAWINFO, "Turntable",
2048                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y1,(smallprefbut+2),buth,
2049                         &(U.flag), 0, 0, 0, 0,
2050                         "Use turntable style rotation with middle mouse button");
2051
2052
2053
2054                 uiDefButS(block, TOGN|BIT|10, B_DRAWINFO, "Rotate View",
2055                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y2,(smallprefbut+2),buth,
2056                         &(U.flag), 0, 0, 0, 0, "Default action for the middle mouse button");
2057
2058                 uiDefButS(block, TOG|BIT|10, B_DRAWINFO, "Pan View",
2059                         (xpos+edgespace+(4*midspace)+(4*medprefbut)+smallprefbut+2),y2,(smallprefbut+2),buth,
2060                         &(U.flag), 0, 0, 0, 0, "Default action for the middle mouse button");
2061
2062                 uiDefBut(block, LABEL,0,"Middle mouse button:",
2063                         (xpos+edgespace+(3*midspace)+(4*medprefbut)),y3label,medprefbut,buth,
2064                         0, 0, 0, 0, 0, "");
2065                 uiDefButS(block, TOG|BIT|12, 0, "Emulate 3 Buttons",
2066                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y1,medprefbut,buth,
2067                         &(U.flag), 0, 0, 0, 0,
2068                         "Emulates a middle mouse button with ALT+LeftMouse");
2069
2070
2071
2072
2073                 uiDefBut(block, LABEL,0,"Mousewheel:",
2074                         (xpos+edgespace+(4*midspace)+(5*medprefbut)),y3label,medprefbut,buth,
2075                         0, 0, 0, 0, 0, "");
2076                 uiDefButS(block, TOG|BIT|2, 0, "Invert Wheel Zoom",
2077                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y1,medprefbut,buth,
2078                         &(U.uiflag), 0, 0, 0, 0,
2079                         "Swaps mouse wheel zoom direction");
2080
2081
2082                 uiDefButI(block, NUM, 0, "Scroll Lines:",
2083                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y2,medprefbut,buth,
2084                         &U.wheellinescroll, 0.0, 32.0, 0, 0,
2085                         "The number of lines scrolled at a time with the mouse wheel");
2086
2087
2088         } else if (U.userpref == 1) { /* edit methods */
2089
2090
2091                 uiDefBut(block, LABEL,0,"Material linked to:",
2092                         xpos,y3label,medprefbut,buth,
2093                         0, 0, 0, 0, 0, "");
2094
2095                 uiDefButS(block, TOGN|BIT|8, B_DRAWINFO, "ObData",
2096                         (xpos+edgespace),y2,(smallprefbut),buth,
2097                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
2098
2099                 uiDefButS(block, TOG|BIT|8, B_DRAWINFO, "Object",
2100                         (xpos+edgespace+midspace+smallprefbut),y2,(smallprefbut),buth,
2101                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
2102
2103
2104
2105                 uiDefBut(block, LABEL,0,"Mesh Undo",
2106                         (xpos+edgespace+medprefbut),y3label, medprefbut,buth,
2107                         0, 0, 0, 0, 0, "");
2108
2109                 uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps:",
2110                         (xpos+edgespace+medprefbut+midspace),y2,(medprefbut),buth,
2111                                 &(U.undosteps), 1, 64, 0, 0, "Number of undo steps avail. in Editmode.  Smaller conserves memory.");
2112
2113
2114                 uiDefBut(block, LABEL,0,"Auto keyframe on:",
2115                         (xpos+edgespace+(2*medprefbut)+midspace),y3label,medprefbut,buth,
2116                         0, 0, 0, 0, 0, "");
2117
2118                 uiDefButS(block, TOG|BIT|0, 0, "Action",
2119                         (xpos+edgespace+(2*medprefbut)+(2*midspace)),y2,smallprefbut,buth,
2120                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in action ipo curve");
2121
2122                 uiDefButS(block, TOG|BIT|1, 0, "Object",
2123                         (xpos+edgespace+(2*medprefbut)+(3*midspace)+smallprefbut),y2,smallprefbut,buth,
2124                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in object ipo curve");
2125
2126
2127
2128                 uiDefBut(block, LABEL,0,"Duplicate with object:",
2129                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut),y3label,medprefbut,buth,
2130                         0, 0, 0, 0, 0, "");
2131
2132                 uiDefButS(block, TOG|BIT|0, 0, "Mesh",
2133                         (xpos+edgespace+(4*midspace)+(3*medprefbut)+smallprefbut),y2,smallprefbut,buth,
2134                         &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
2135                 uiDefButS(block, TOG|BIT|9, 0, "Armature",
2136                         (xpos+edgespace+(4*midspace)+(3*medprefbut)+smallprefbut),y1,smallprefbut,buth,
2137                         &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
2138
2139                 uiDefButS(block, TOG|BIT|2, 0, "Surface",
2140                         (xpos+edgespace+(5*midspace)+(3*medprefbut)+(2*smallprefbut)),y2,smallprefbut,buth,
2141                         &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
2142                 uiDefButS(block, TOG|BIT|5, 0, "Lamp",
2143                         (xpos+edgespace+(5*midspace)+(3*medprefbut)+(2*smallprefbut)),y1,smallprefbut,buth,
2144                         &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
2145
2146                 uiDefButS(block, TOG|BIT|1, 0, "Curve",
2147                         (xpos+edgespace+(6*midspace)+(3*medprefbut)+(3*smallprefbut)),y2,smallprefbut,buth,
2148                         &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
2149                 uiDefButS(block, TOG|BIT|7, 0, "Material",
2150                         (xpos+edgespace+(6*midspace)+(3*medprefbut)+(3*smallprefbut)),y1,smallprefbut,buth,
2151                         &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
2152
2153                 uiDefButS(block, TOG|BIT|3, 0, "Text",
2154                         (xpos+edgespace+(7*midspace)+(3*medprefbut)+(4*smallprefbut)),y2,smallprefbut,buth,
2155                         &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
2156                 uiDefButS(block, TOG|BIT|8, 0, "Texture",
2157                         (xpos+edgespace+(7*midspace)+(3*medprefbut)+(4*smallprefbut)),y1,smallprefbut,buth,
2158                         &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
2159
2160                 uiDefButS(block, TOG|BIT|4, 0, "Metaball",
2161                         (xpos+edgespace+(8*midspace)+(3*medprefbut)+(5*smallprefbut)),y2,smallprefbut,buth,
2162                         &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
2163                 uiDefButS(block, TOG|BIT|6, 0, "Ipo",
2164                         (xpos+edgespace+(8*midspace)+(3*medprefbut)+(5*smallprefbut)),y1,smallprefbut,buth,
2165                         &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
2166         
2167         } else if(U.userpref == 2) { /* language & colors */
2168
2169 #ifdef INTERNATIONAL
2170                 char curfont[320];
2171
2172                 sprintf(curfont, "Interface Font: ");
2173                 strcat(curfont,U.fontname);
2174
2175                 uiDefButS(block, TOG|BIT|5, B_DOLANGUIFONT, "International Fonts",
2176                         xpos,y2,medprefbut,buth,
2177                         &(U.transopts), 0, 0, 0, 0, "Activate international interface");
2178
2179                 if(U.transopts & TR_ALL) {
2180                         uiDefBut(block, LABEL,0,curfont,
2181                                 (xpos+edgespace+medprefbut+midspace),y2,medprefbut,buth,
2182                                 0, 0, 0, 0, 0, "");
2183
2184                         uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
2185                                 xpos,y1,medprefbut,buth,
2186                                 0, 0, 0, 0, 0, "Select a new font for the interface");
2187
2188
2189                         uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
2190                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
2191                                 &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
2192
2193 /*
2194                         uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
2195                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
2196                                 &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
2197
2198
2199                         uiDefBut(block, LABEL,0,"Translate:",
2200                                 (xpos+edgespace+(2.1*medprefbut)+(2*midspace)),y3label,medprefbut,buth,
2201                                 0, 0, 0, 0, 0, "");
2202 */
2203
2204                         uiDefButS(block, TOG|BIT|0, B_SETTRANSBUTS, "Tooltips",
2205                                 (xpos+edgespace+(2.2*medprefbut)+(3*midspace)),y1,smallprefbut,buth,
2206                                 &(U.transopts), 0, 0, 0, 0, "Translate tooltips");
2207
2208                         uiDefButS(block, TOG|BIT|1, B_SETTRANSBUTS, "Buttons",
2209                                 (xpos+edgespace+(2.2*medprefbut)+(4*midspace)+smallprefbut),y1,smallprefbut,buth,
2210                                 &(U.transopts), 0, 0, 0, 0, "Translate button labels");
2211
2212                         uiDefButS(block, TOG|BIT|2, B_SETTRANSBUTS, "Toolbox",
2213                                 (xpos+edgespace+(2.2*medprefbut)+(5*midspace)+(2*smallprefbut)),y1,smallprefbut,buth,
2214                                 &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
2215
2216                         uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
2217                                 (xpos+edgespace+(2.2*medprefbut)+(3*midspace)),y2,medprefbut+(0.5*medprefbut)+3,buth,
2218                                 &U.language, 0, 0, 0, 0, "Select interface language");
2219                                 
2220                         /* uiDefButS(block, TOG|BIT|3, B_SETTRANSBUTS, "FTF All windows",
2221                                 (xpos+edgespace+(4*medprefbut)+(4*midspace)),y1,medprefbut,buth,
2222                                 &(U.transopts), 0, 0, 0, 0,
2223                                 "Use FTF drawing for fileselect and textwindow "
2224                                 "(under construction)");
2225                         */
2226                 }
2227
2228 /* end of INTERNATIONAL */
2229 #endif
2230
2231         } else if(U.userpref == 3) { /* auto save */
2232
2233
2234                 uiDefButS(block, TOG|BIT|0, B_RESETAUTOSAVE, "Auto Save Temp Files",
2235                         (xpos+edgespace),y2,medprefbut,buth,
2236                         &(U.flag), 0, 0, 0, 0,
2237                         "Enables automatic saving of temporary files");
2238
2239                 if(U.flag & AUTOSAVE) {
2240
2241                         uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
2242                                 (xpos+edgespace),y1,medprefbut,buth,
2243                                 0, 0, 0, 0, 0,"Opens the most recently saved temporary file");
2244
2245                         uiDefButI(block, NUM, B_RESETAUTOSAVE, "Minutes:",
2246                                 (xpos+edgespace+medprefbut+midspace),y2,medprefbut,buth,
2247                                 &(U.savetime), 1.0, 60.0, 0, 0,
2248                                 "The time (in minutes) to wait between automatic temporary saves");
2249
2250                         uiDefButS(block, NUM, 0, "Versions:",
2251                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
2252                                 &U.versions, 0.0, 32.0, 0, 0,
2253                                 "The number of old versions to maintain when saving");
2254                 }
2255
2256         } else if (U.userpref == 4) { /* system & opengl */
2257                 uiDefBut(block, LABEL,0,"Solid OpenGL light:",
2258                         xpos+edgespace, y3label, medprefbut, buth,
2259                         0, 0, 0, 0, 0, "");
2260                 
2261                 uiDefButS(block, MENU, B_REDR, "Light1 %x0|Light2 %x1|Light3 %x2",
2262                         xpos+edgespace, y2, 2*medprefbut/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
2263                 uiBlockSetCol(block, TH_BUT_SETTING1);
2264                 uiDefButI(block, TOG|BIT|0, B_RECALCLIGHT, "On",
2265                         xpos+edgespace+2*medprefbut/6, y2, medprefbut/6, buth, 
2266                         &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "");
2267                         
2268                 uiBlockSetCol(block, TH_AUTO);
2269                 uiDefButS(block, ROW, B_REDR, "Vec",
2270                         xpos+edgespace+3*medprefbut/6, y2, medprefbut/6, buth, 
2271                         &cur_light_var, 123.0, 0.0, 0, 0, "");
2272                 uiDefButS(block, ROW, B_REDR, "Col",
2273                         xpos+edgespace+4*medprefbut/6, y2, medprefbut/6, buth, 
2274                         &cur_light_var, 123.0, 1.0, 0, 0, "");
2275                 uiDefButS(block, ROW, B_REDR, "Spec",
2276                         xpos+edgespace+5*medprefbut/6, y2, medprefbut/6, buth, 
2277                         &cur_light_var, 123.0, 2.0, 0, 0, "");
2278
2279                 if(cur_light_var==1) {
2280                         uiDefButF(block, NUM, B_RECALCLIGHT, "R ",
2281                                 xpos+edgespace, y1, medprefbut/3, buth, 
2282                                 U.light[cur_light].col, 0.0, 1.0, 100, 2, "");
2283                         uiDefButF(block, NUM, B_RECALCLIGHT, "G ",
2284                                 xpos+edgespace+medprefbut/3, y1, medprefbut/3, buth, 
2285                                 U.light[cur_light].col+1, 0.0, 1.0, 100, 2, "");
2286                         uiDefButF(block, NUM, B_RECALCLIGHT, "B ",
2287                                 xpos+edgespace+2*medprefbut/3, y1, medprefbut/3, buth, 
2288                                 U.light[cur_light].col+2, 0.0, 1.0, 100, 2, "");
2289                 }
2290                 else if(cur_light_var==2) {
2291                         uiDefButF(block, NUM, B_RECALCLIGHT, "sR ",
2292                                 xpos+edgespace, y1, medprefbut/3, buth, 
2293                                 U.light[cur_light].spec, 0.0, 1.0, 100, 2, "");
2294                         uiDefButF(block, NUM, B_RECALCLIGHT, "sG ",
2295                                 xpos+edgespace+medprefbut/3, y1, medprefbut/3, buth, 
2296                                 U.light[cur_light].spec+1, 0.0, 1.0, 100, 2, "");
2297                         uiDefButF(block, NUM, B_RECALCLIGHT, "sB ",
2298                                 xpos+edgespace+2*medprefbut/3, y1, medprefbut/3, buth, 
2299                                 U.light[cur_light].spec+2, 0.0, 1.0, 100, 2, "");
2300                 }
2301                 else if(cur_light_var==0) {
2302                         uiDefButF(block, NUM, B_RECALCLIGHT, "X ",
2303                                 xpos+edgespace, y1, medprefbut/3, buth, 
2304                                 U.light[cur_light].vec, -1.0, 1.0, 100, 2, "");
2305                         uiDefButF(block, NUM, B_RECALCLIGHT, "Y ",
2306                                 xpos+edgespace+medprefbut/3, y1, medprefbut/3, buth, 
2307                                 U.light[cur_light].vec+1, -1.0, 1.0, 100, 2, "");
2308                         uiDefButF(block, NUM, B_RECALCLIGHT, "Z ",
2309                                 xpos+edgespace+2*medprefbut/3, y1, medprefbut/3, buth, 
2310                                 U.light[cur_light].vec+2, -1.0, 1.0, 100, 2, "");
2311                 }
2312
2313 /*
2314                 uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
2315                         (xpos+edgespace),y2,largeprefbut,buth,
2316                         &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
2317
2318                 uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
2319                         (xpos+edgespace), y1, largeprefbut,buth,
2320                         &U.console_out, 0, 0, 0, 0, "Select console output method");
2321
2322                 uiDefButS(block, NUM, B_CONSOLENUMLINES, "Lines:",
2323                         (xpos+edgespace+largeprefbut+midspace),y1,smallprefbut,buth,
2324                         &U.console_buffer, 1.0, 4000.0, 0, 0, "Maximum number of internal console lines");
2325 */
2326
2327 #ifdef _WIN32
2328                 uiDefBut(block, LABEL,0,"Win Codecs:",
2329                         (xpos+edgespace+(1*midspace)+(1*medprefbut)),y3label,medprefbut,buth,
2330                         0, 0, 0, 0, 0, "");
2331
2332                 uiDefButS(block, TOG|BIT|8, 0, "Enable all codecs",
2333                         (xpos+edgespace+(1*medprefbut)+(1*midspace)),y2,medprefbut,buth,
2334                         &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
2335 #endif
2336
2337                 uiDefBut(block, LABEL,0,"Keyboard:",
2338                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y3label,medprefbut,buth,
2339                         0, 0, 0, 0, 0, "");
2340
2341                 uiDefButS(block, TOG|BIT|9, B_U_CAPSLOCK, "Disable Caps Lock",
2342                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y1,medprefbut,buth,
2343                         &(U.flag), 0, 0, 0, 0,
2344                         "Disables the Caps Lock key when entering text");
2345
2346                 uiDefButS(block, TOG|BIT|13, 0, "Emulate Numpad",
2347                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y2,medprefbut,buth,
2348                         &(U.flag), 0, 0, 0, 0,
2349                         "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
2350
2351
2352                 uiDefBut(block, LABEL,0,"System:",
2353                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y3label,medprefbut,buth,
2354                         0, 0, 0, 0, 0, "");
2355
2356                 uiDefButI(block, TOG|BIT|USERDEF_DISABLE_SOUND_BIT, B_SOUNDTOGGLE, "Disable Sound",
2357                         (xpos+edgespace+(4*medprefbut)+(4*midspace)),y2,medprefbut,buth,
2358                         &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
2359
2360                 uiDefButS(block, TOG|BIT|3, 0, "Filter File Extensions",
2361                         (xpos+edgespace+(4*medprefbut)+(4*midspace)),y1,medprefbut,buth,
2362                         &(U.uiflag), 0, 0, 0, 0, "Display only files with extensions in the image select window");
2363
2364
2365                 uiDefBut(block, LABEL,0,"OpenGL:",
2366                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y3label,medprefbut,buth,
2367                         0, 0, 0, 0, 0, "");
2368
2369                 uiDefButI(block, TOGN|BIT|USERDEF_DISABLE_MIPMAP_BIT, B_MIPMAPCHANGED, "Mipmaps",
2370                         (xpos+edgespace+(5*medprefbut)+(5*midspace)),y2,medprefbut,buth,
2371                         &(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
2372
2373                 uiDefButI(block, TOG|BIT|USERDEF_VERTEX_ARRAYS_BIT, 0, "Vertex Arrays",
2374                         (xpos+edgespace+(5*medprefbut)+(5*midspace)),y1,medprefbut,buth,
2375                         &(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
2376
2377                 uiDefBut(block, LABEL,0,"Audio:",
2378                         (xpos+edgespace+(2*midspace)+(2*medprefbut)),y3label,medprefbut,buth,
2379                         0, 0, 0, 0, 0, "");
2380
2381                 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");
2382                 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");      
2383                 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");               
2384                 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");                   
2385
2386         } else if(U.userpref == 5) { /* file paths */
2387
2388
2389                 uiDefBut(block, TEX, 0, "Fonts: ",
2390                         (xpos+edgespace),y2,(largeprefbut-smfileselbut),buth,
2391                         U.fontdir, 1.0, 63.0, 0, 0,
2392                         "The default directory to search for loading fonts");
2393                 uiDefIconBut(block, BUT, B_FONTDIRFILESEL, ICON_FILESEL,
2394                         (xpos+edgespace+largeprefbut-smfileselbut),y2,smfileselbut,buth,
2395                         0, 0, 0, 0, 0, "Select the default font directory");
2396
2397                 uiDefBut(block, TEX, 0, "Textures: ",
2398                         (xpos+edgespace+largeprefbut+midspace),y2,(largeprefbut-smfileselbut),buth,
2399                         U.textudir, 1.0, 63.0, 0, 0, "The default directory to search for textures");
2400                 uiDefIconBut(block, BUT, B_TEXTUDIRFILESEL, ICON_FILESEL,
2401                         (xpos+edgespace+(2*largeprefbut)+midspace-smfileselbut),y2,smfileselbut,buth,
2402                         0, 0, 0, 0, 0, "Select the default texture location");
2403
2404
2405                 uiDefBut(block, TEX, 0, "Tex Plugins: ",
2406                         (xpos+edgespace+(2*largeprefbut)+(2*midspace)),y2,(largeprefbut-smfileselbut),buth,
2407                         U.plugtexdir, 1.0, 63.0, 0, 0, "The default directory to search for texture plugins");
2408                 uiDefIconBut(block, BUT, B_PLUGTEXDIRFILESEL, ICON_FILESEL,
2409                         (xpos+edgespace+(3*largeprefbut)+(2*midspace)-smfileselbut),y2,smfileselbut,buth,
2410                         0, 0, 0, 0, 0, "Select the default texture plugin location");
2411
2412                 uiDefBut(block, TEX, 0, "Seq Plugins: ",
2413                         (xpos+edgespace+(3*largeprefbut)+(3*midspace)),y2,(largeprefbut-smfileselbut),buth,
2414                         U.plugseqdir, 1.0, 63.0, 0, 0, "The default directory to search for sequence plugins");
2415                 uiDefIconBut(block, BUT, B_PLUGSEQDIRFILESEL, ICON_FILESEL,
2416                         (xpos+edgespace+(4*largeprefbut)+(3*midspace)-smfileselbut),y2,smfileselbut,buth,
2417                         0, 0, 0, 0, 0, "Select the default sequence plugin location");
2418
2419
2420                 uiDefBut(block, TEX, 0, "Render: ",
2421                         (xpos+edgespace),y1,(largeprefbut-smfileselbut),buth,
2422                         U.renderdir, 1.0, 63.0, 0, 0, "The default directory for rendering output");
2423                 uiDefIconBut(block, BUT, B_RENDERDIRFILESEL, ICON_FILESEL,
2424                         (xpos+edgespace+largeprefbut-smfileselbut),y1,smfileselbut,buth,
2425                         0, 0, 0, 0, 0, "Select the default render output location");
2426
2427                 uiDefBut(block, TEX, 0, "Python: ",
2428                         (xpos+edgespace+largeprefbut+midspace),y1,(largeprefbut-smfileselbut),buth,
2429                         U.pythondir, 1.0, 63.0, 0, 0, "The default directory to search for Python scripts");
2430                 uiDefIconBut(block, BUT, B_PYTHONDIRFILESEL, ICON_FILESEL,
2431                         (xpos+edgespace+(2*largeprefbut)+midspace-smfileselbut),y1,smfileselbut,buth,
2432                         0, 0, 0, 0, 0, "Select the default Python script location");
2433
2434
2435                 uiDefBut(block, TEX, 0, "Sounds: ",
2436                         (xpos+edgespace+(2*largeprefbut)+(2*midspace)),y1,(largeprefbut-smfileselbut),buth,
2437                         U.sounddir, 1.0, 63.0, 0, 0, "The default directory to search for sounds");
2438                 uiDefIconBut(block, BUT, B_SOUNDDIRFILESEL, ICON_FILESEL,
2439                         (xpos+edgespace+(3*largeprefbut)+(2*midspace)-smfileselbut),y1,smfileselbut,buth,
2440                         0, 0, 0, 0, 0, "Select the default sound location");
2441
2442                 uiDefBut(block, TEX, 0, "Temp: ",
2443                          (xpos+edgespace+(3*largeprefbut)+(3*midspace)),y1,(largeprefbut-smfileselbut),buth,
2444                          U.tempdir, 1.0, 63.0, 0, 0, "The directory for storing temporary save files");
2445                 uiDefIconBut(block, BUT, B_TEMPDIRFILESEL, ICON_FILESEL,
2446                         (xpos+edgespace+(4*largeprefbut)+(3*midspace)-smfileselbut),y1,smfileselbut,buth,
2447                         0, 0, 0, 0, 0, "Select the default temporary save file location");
2448
2449         }
2450
2451         uiDrawBlock(block);
2452         
2453         myortho2(-0.5, (float)(sa->winx)-0.5, -0.5, (float)(sa->winy)-0.5);
2454         draw_area_emboss(sa);
2455         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2456         sa->win_swap= WIN_BACK_OK;
2457         
2458 }
2459
2460
2461 void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2462 {
2463         unsigned short event= evt->event;
2464         short val= evt->val;
2465         
2466         if(val) {
2467                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2468
2469                 switch(event) {
2470                 case UI_BUT_EVENT:
2471                         if(val==B_ADD_THEME) {
2472                                 bTheme *btheme, *new;
2473                                 
2474                                 btheme= U.themes.first;
2475                                 new= MEM_callocN(sizeof(bTheme), "theme");
2476                                 memcpy(new, btheme, sizeof(bTheme));
2477                                 BLI_addhead(&U.themes, new);
2478                                 strcpy(new->name, "New User Theme");
2479                                 addqueue(sa->win, REDRAW, 1);
2480                         }
2481                         else if(val==B_DEL_THEME) {
2482                                 bTheme *btheme= U.themes.first;
2483                                 BLI_remlink(&U.themes, btheme);
2484                                 MEM_freeN(btheme);
2485                                 BIF_SetTheme(curarea); // prevent usage of old theme in calls   
2486                                 addqueue(sa->win, REDRAW, 1);
2487                         }
2488                         else if(val==B_NAME_THEME) {
2489                                 bTheme *btheme= U.themes.first;
2490                                 if(strcmp(btheme->name, "Default")==0) {
2491                                         strcpy(btheme->name, "New User Theme");
2492                                         addqueue(sa->win, REDRAW, 1);
2493                                 }
2494                         }
2495                         else if(val==B_UPDATE_THEME) {
2496                                 allqueue(REDRAWALL, 0);
2497                         }
2498                         else if(val==B_CHANGE_THEME) {
2499                                 th_curcol= TH_BACK;     // backdrop color is always there...
2500                                 addqueue(sa->win, REDRAW, 1);
2501                         }
2502                         else if(val==B_THEME_COPY) {
2503                                 if(th_curcol_ptr) {
2504                                         th_curcol_arr[0]= th_curcol_ptr[0];
2505                                         th_curcol_arr[1]= th_curcol_ptr[1];
2506                                         th_curcol_arr[2]= th_curcol_ptr[2];
2507                                         th_curcol_arr[3]= th_curcol_ptr[3];
2508                                         addqueue(sa->win, REDRAW, 1);
2509                                 }
2510                         }
2511                         else if(val==B_THEME_PASTE) {
2512                                 if(th_curcol_ptr) {
2513                                         th_curcol_ptr[0]= th_curcol_arr[0];
2514                                         th_curcol_ptr[1]= th_curcol_arr[1];
2515                                         th_curcol_ptr[2]= th_curcol_arr[2];
2516                                         th_curcol_ptr[3]= th_curcol_arr[3];
2517                                         allqueue(REDRAWALL, 0);
2518                                 }
2519                         }
2520                         else if(val==B_RECALCLIGHT) {
2521                                 if(U.light[0].flag==0 && U.light[1].flag==0 && U.light[2].flag==0)
2522                                         U.light[0].flag= 1;
2523                                 
2524                                 default_gl_light();
2525                                 addqueue(sa->win, REDRAW, 1);
2526                                 allqueue(REDRAWVIEW3D, 0);
2527                         }
2528                         else do_global_buttons(val);
2529                         
2530                         break;  
2531                 }
2532         }
2533 }
2534
2535 void init_infospace(ScrArea *sa)
2536 {
2537         SpaceInfo *sinfo;
2538         
2539         sinfo= MEM_callocN(sizeof(SpaceInfo), "initinfo");
2540         BLI_addhead(&sa->spacedata, sinfo);
2541
2542         sinfo->spacetype=SPACE_INFO;
2543 }
2544
2545 /* ******************** SPACE: BUTS ********************** */
2546
2547 extern void drawbutspace(ScrArea *sa, void *spacedata); /* buttons.c */
2548
2549 static void changebutspace(ScrArea *sa, void *spacedata)
2550 {
2551         if(G.v2d==0) return;
2552         
2553         test_view2d(G.v2d, curarea->winx, curarea->winy);
2554         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
2555 }
2556
2557 void winqreadbutspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2558 {
2559         unsigned short event= evt->event;
2560         short val= evt->val;
2561         SpaceButs *sbuts= curarea->spacedata.first;
2562         ScrArea *sa2, *sa3d;
2563         int nr, doredraw= 0;
2564
2565         if(val) {
2566                 
2567                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2568
2569                 switch(event) {
2570                 case UI_BUT_EVENT:
2571                         do_butspace(val);
2572                         break;
2573                         
2574                 case MIDDLEMOUSE:
2575                 case WHEELUPMOUSE:
2576                 case WHEELDOWNMOUSE:
2577                         view2dmove(event);      /* in drawipo.c */
2578                         break;
2579                 case PAGEUPKEY:
2580                         event= WHEELUPMOUSE;
2581                         view2dmove(event);      /* in drawipo.c */
2582                         break;
2583                 case PAGEDOWNKEY:
2584                         event= WHEELDOWNMOUSE;
2585                         view2dmove(event);      /* in drawipo.c */
2586                         break;
2587                         
2588                 case RIGHTMOUSE:
2589                         nr= pupmenu("Align buttons%t|Free %x0|Horizontal%x1|Vertical%x2");
2590                         if (nr>=0) {
2591                                 sbuts->align= nr;
2592                                 if(nr) {
2593                                         uiAlignPanelStep(sa, 1.0);
2594                                         do_buts_buttons(B_BUTSHOME);
2595                                 }
2596                         }
2597
2598                         break;
2599                 case PADPLUSKEY:
2600                         view2d_zoom(&sbuts->v2d, 0.06f, curarea->winx, curarea->winy);
2601                         scrarea_queue_winredraw(curarea);
2602                         break;
2603                 case PADMINUS:
2604                         view2d_zoom(&sbuts->v2d, -0.075f, curarea->winx, curarea->winy);
2605                         scrarea_queue_winredraw(curarea);
2606                         break;
2607                 case RENDERPREVIEW:
2608                         BIF_previewrender(sbuts);
2609                         break;
2610                 
2611                 case HOMEKEY:
2612                         do_buts_buttons(B_BUTSHOME);
2613                         break;
2614
2615
2616                 /* if only 1 view, also de persp, excluding arrowkeys */
2617                 case PAD0: case PAD1: case PAD3:
2618                 case PAD5: case PAD7: case PAD9:
2619                 case PADENTER: case ZKEY: case PKEY:
2620                         sa3d= 0;
2621                         sa2= G.curscreen->areabase.first;
2622                         while(sa2) {
2623                                 if(sa2->spacetype==SPACE_VIEW3D) {
2624                                         if(sa3d) return;
2625                                         sa3d= sa2;
2626                                 }
2627                                 sa2= sa2->next;
2628                         }
2629                         if(sa3d) {
2630                                 sa= curarea;
2631                                 areawinset(sa3d->win);
2632                                 
2633                                 if(event==PKEY) start_game();
2634                                 else if(event==ZKEY) toggle_shading();
2635                                 else persptoetsen(event);
2636                                 
2637                                 scrarea_queue_winredraw(sa3d);
2638                                 scrarea_queue_headredraw(sa3d);
2639                                 areawinset(sa->win);
2640                         }
2641                 }
2642         }
2643
2644         if(doredraw) scrarea_queue_winredraw(curarea);
2645 }
2646
2647 void set_rects_butspace(SpaceButs *buts)
2648 {
2649         /* buts space goes from (0,0) to (1280, 228) */
2650
2651         buts->v2d.tot.xmin= 0.0f;
2652         buts->v2d.tot.ymin= 0.0f;
2653         buts->v2d.tot.xmax= 1279.0f;
2654         buts->v2d.tot.ymax= 228.0f;
2655         
2656         buts->v2d.min[0]= 256.0f;
2657         buts->v2d.min[1]= 42.0f;
2658
2659         buts->v2d.max[0]= 2048.0f;
2660         buts->v2d.max[1]= 450.0f;
2661         
2662         buts->v2d.minzoom= 0.5f;
2663         buts->v2d.maxzoom= 1.21f;
2664         
2665         buts->v2d.scroll= 0;
2666         buts->v2d.keepaspect= 1;
2667         buts->v2d.keepzoom= 1;
2668         buts->v2d.keeptot= 1;
2669         
2670 }
2671
2672 void test_butspace(void)
2673 {
2674         ScrArea *area= curarea;
2675         int blocksmin= uiBlocksGetYMin(&area->uiblocks)-10.0;
2676         
2677         G.buts->v2d.tot.ymin= MIN2(0.0, blocksmin-10.0);
2678 }
2679
2680 void init_butspace(ScrArea *sa)
2681 {
2682         SpaceButs *buts;
2683         
2684         buts= MEM_callocN(sizeof(SpaceButs), "initbuts");
2685         BLI_addhead(&sa->spacedata, buts);
2686
2687         buts->spacetype= SPACE_BUTS;
2688         buts->scaflag= BUTS_SENS_LINK|BUTS_SENS_ACT|BUTS_CONT_ACT|BUTS_ACT_ACT|BUTS_ACT_LINK;
2689
2690         /* set_rects only does defaults, so after reading a file the cur has not changed */
2691         set_rects_butspace(buts);
2692         buts->v2d.cur= buts->v2d.tot;
2693 }
2694
2695 void extern_set_butspace(int fkey)
2696 {
2697         ScrArea *sa;
2698         SpaceButs *sbuts;
2699         
2700         /* when a f-key pressed: closest button window is initialized */
2701         if(curarea->spacetype==SPACE_BUTS) sa= curarea;
2702         else {
2703                 /* find area */
2704                 sa= G.curscreen->areabase.first;
2705                 while(sa) {
2706                         if(sa->spacetype==SPACE_BUTS) break;
2707                         sa= sa->next;
2708                 }
2709         }
2710         
2711         if(sa==0) return;
2712         
2713         if(sa!=curarea) areawinset(sa->win);
2714         
2715         sbuts= sa->spacedata.first;
2716         
2717         if(fkey==F4KEY) {
2718                 sbuts->mainb= CONTEXT_LOGIC;
2719         }
2720         else if(fkey==F5KEY) {
2721                 sbuts->mainb= CONTEXT_SHADING;
2722                 if(OBACT) {
2723                         if(OBACT->type==OB_CAMERA) 
2724                                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_WORLD;
2725                         else if(OBACT->type==OB_LAMP) 
2726                                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_LAMP;
2727                         else  
2728                                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
2729                 }
2730                 else sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
2731         }
2732         else if(fkey==F6KEY) {
2733                 sbuts->mainb= CONTEXT_SHADING;
2734                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_TEX;
2735         }
2736         else if(fkey==F7KEY) sbuts->mainb= CONTEXT_OBJECT;
2737         else if(fkey==F8KEY) {
2738                 sbuts->mainb= CONTEXT_SHADING;
2739                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_WORLD;
2740         }
2741         else if(fkey==F9KEY) sbuts->mainb= CONTEXT_EDITING;
2742         else if(fkey==F10KEY) sbuts->mainb= CONTEXT_SCENE;
2743
2744         scrarea_queue_headredraw(sa);
2745         scrarea_queue_winredraw(sa);
2746         BIF_preview_changed(sbuts);
2747 }
2748
2749 /* ******************** SPACE: SEQUENCE ********************** */
2750
2751 /*  extern void drawseqspace(ScrArea *sa, void *spacedata); BIF_drawseq.h */
2752
2753 void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2754 {
2755         unsigned short event= evt->event;
2756         short val= evt->val;
2757         SpaceSeq *sseq= curarea->spacedata.first;
2758         View2D *v2d= &sseq->v2d;
2759         extern Sequence *last_seq;
2760         float dx, dy;
2761         int doredraw= 0, cfra, first;
2762         short mval[2];
2763         
2764         if(curarea->win==0) return;
2765
2766         if(val) {
2767                 
2768                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2769
2770                 switch(event) {
2771                 case LEFTMOUSE:
2772                         if(sseq->mainb || view2dmove(event)==0) {
2773                                 
2774                                 first= 1;               
2775                                 set_special_seq_update(1);
2776
2777                                 do {
2778                                         getmouseco_areawin(mval);
2779                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
2780                                         
2781                                         cfra= (int)dx;
2782                                         if(cfra< 1) cfra= 1;
2783                                         /* else if(cfra> EFRA) cfra= EFRA; */
2784                                         
2785                                         if( cfra!=CFRA || first ) {
2786                                                 first= 0;
2787                                 
2788                                                 CFRA= cfra;
2789                                                 force_draw();
2790                                                 update_for_newframe();  /* for audio scrubbing */                                               
2791                                         }
2792                                 
2793                                 } while(get_mbut()&L_MOUSE);
2794                                 
2795                                 set_special_seq_update(0);
2796                                 
2797                                 update_for_newframe();
2798                         }
2799                         break;
2800                 case MIDDLEMOUSE:
2801                 case WHEELUPMOUSE:
2802                 case WHEELDOWNMOUSE:
2803                         if(sseq->mainb) break;
2804                         view2dmove(event);      /* in drawipo.c */
2805                         break;
2806                 case RIGHTMOUSE:
2807                         if(sseq->mainb) break;
2808                         mouse_select_seq();
2809                         break;
2810                 case PADPLUSKEY:
2811                         if(sseq->mainb) {
2812                                 sseq->zoom++;
2813                                 if(sseq->zoom>8) sseq->zoom= 8;
2814                         }
2815                         else {
2816                                 if((G.qual==0)) {
2817                                         dx= 0.1154*(v2d->cur.xmax-v2d->cur.xmin);
2818                                         v2d->cur.xmin+= dx;
2819                                         v2d->cur.xmax-= dx;
2820                                         test_view2d(G.v2d, curarea->winx, curarea->winy);
2821                                 }
2822                                 else if((G.qual==LR_SHIFTKEY)) {
2823                                         insert_gap(25, CFRA);
2824                                         allqueue(REDRAWSEQ, 0);
2825                                 }
2826                                 else if(G.qual==LR_ALTKEY) {
2827                                         insert_gap(250, CFRA);
2828                                         allqueue(REDRAWSEQ, 0);
2829                                 }
2830                         }
2831                         doredraw= 1;
2832                         break;
2833                 case PADMINUS:
2834                         if(sseq->mainb) {