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