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