Got rid of many #include "BPY_extern.h"
[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_linklist.h"
59
60 #include "DNA_action_types.h"
61 #include "DNA_curve_types.h"
62 #include "DNA_image_types.h"
63 #include "DNA_ipo_types.h"
64 #include "DNA_mesh_types.h"
65 #include "DNA_object_types.h"
66 #include "DNA_scene_types.h"
67 #include "DNA_screen_types.h"
68 #include "DNA_sequence_types.h"
69 #include "DNA_sound_types.h"
70 #include "DNA_space_types.h"
71 #include "DNA_userdef_types.h"
72 #include "DNA_view2d_types.h"
73 #include "DNA_view3d_types.h"
74
75 #include "BKE_blender.h"
76 #include "BKE_curve.h"
77 #include "BKE_displist.h"
78 #include "BKE_global.h"
79 #include "BKE_ipo.h"
80 #include "BKE_main.h"
81 #include "BKE_scene.h"
82 #include "BKE_utildefines.h"
83
84 #include "BIF_butspace.h"
85 #include "BIF_drawimage.h"
86 #include "BIF_drawseq.h"
87 #include "BIF_drawtext.h"
88 #include "BIF_editarmature.h"
89 #include "BIF_editfont.h"
90 #include "BIF_editika.h"
91 #include "BIF_editkey.h"
92 #include "BIF_editlattice.h"
93 #include "BIF_editmesh.h"
94 #include "BIF_editoops.h"
95 #include "BIF_editseq.h"
96 #include "BIF_editsima.h"
97 #include "BIF_editsound.h"
98 #include "BIF_editview.h"
99 #include "BIF_gl.h"
100 #include "BIF_imasel.h"
101 #include "BIF_interface.h"
102 #include "BIF_mywindow.h"
103 #include "BIF_oops.h"
104 #include "BIF_resources.h"
105 #include "BIF_screen.h"
106 #include "BIF_space.h"
107 #include "BIF_spacetypes.h"
108 #include "BIF_toets.h"
109 #include "BIF_toolbox.h"
110 #include "BIF_usiblender.h"
111 #include "BIF_previewrender.h"
112
113 #include "BSE_edit.h"
114 #include "BSE_view.h"
115 #include "BSE_editipo.h"
116 #include "BSE_drawipo.h"
117 #include "BSE_drawview.h"
118 #include "BSE_drawnla.h"
119 #include "BSE_filesel.h"
120 #include "BSE_headerbuttons.h"
121 #include "BSE_editnla_types.h"
122
123 #include "BDR_vpaint.h"
124 #include "BDR_editmball.h"
125 #include "BDR_editobject.h"
126 #include "BDR_editcurve.h"
127 #include "BDR_editface.h"
128 #include "BDR_drawmesh.h"
129 #include "BDR_drawobject.h"
130
131 #include "BLO_readfile.h" /* for BLO_blendhandle_close */
132
133 #include "mydevice.h"
134 #include "blendef.h"
135 #include "datatoc.h"
136
137 #include "TPT_DependKludge.h"
138 #ifdef NAN_TPT
139 #include "BSE_trans_types.h"
140 #include "IMG_Api.h"
141 #endif /* NAN_TPT */
142
143 #include "SYS_System.h" /* for the user def menu ... should move elsewhere. */
144
145 extern void StartKetsjiShell(ScrArea *area, char* startscenename, struct Main* maggie, int always_use_expand_framing);
146
147 /**
148  * When the mipmap setting changes, we want to redraw the view right
149  * away to reflect this setting.
150  */
151 void space_mipmap_button_function(int event);
152
153 unsigned short convert_for_nonumpad(unsigned short event);
154 void free_soundspace(SpaceSound *ssound);
155
156 /* *************************************** */
157
158 /* don't know yet how the handlers will evolve, for simplicity
159    i choose for an array with eventcodes, this saves in a file!
160    */
161 void add_blockhandler(ScrArea *sa, short eventcode, short val)
162 {
163         SpaceLink *sl= sa->spacedata.first;
164         short a;
165         
166         // find empty spot
167         for(a=0; a<SPACE_MAXHANDLER; a+=2) {
168                 if( sl->blockhandler[a]==eventcode ) {
169                         sl->blockhandler[a+1]= val;
170                         break;
171                 }
172                 else if( sl->blockhandler[a]==0) {
173                         sl->blockhandler[a]= eventcode;
174                         sl->blockhandler[a+1]= val;
175                         break;
176                 }
177         }
178         if(a==SPACE_MAXHANDLER) printf("error; max (4) blockhandlers reached!\n");
179 }
180
181 void rem_blockhandler(ScrArea *sa, short eventcode)
182 {
183         SpaceLink *sl= sa->spacedata.first;
184         short a;
185         
186         for(a=0; a<SPACE_MAXHANDLER; a+=2) {
187                 if( sl->blockhandler[a]==eventcode) {
188                         sl->blockhandler[a]= 0;
189                         break;
190                 }
191         }
192 }
193
194
195
196
197 /* ************* SPACE: VIEW3D  ************* */
198
199 /*  extern void drawview3dspace(ScrArea *sa, void *spacedata); BSE_drawview.h */
200
201
202 void copy_view3d_lock(short val)
203 {
204         bScreen *sc;
205         int bit;
206         
207         /* from G.scene copy to the other views */
208         sc= G.main->screen.first;
209         
210         while(sc) {
211                 if(sc->scene==G.scene) {
212                         ScrArea *sa= sc->areabase.first;
213                         while(sa) {
214                                 SpaceLink *sl= sa->spacedata.first;
215                                 while(sl) {
216                                         if(sl->spacetype==SPACE_OOPS && val==REDRAW) {
217                                                 if(sa->win) scrarea_queue_winredraw(sa);
218                                         }
219                                         else if(sl->spacetype==SPACE_VIEW3D) {
220                                                 View3D *vd= (View3D*) sl;
221                                                 if(vd->scenelock && vd->localview==0) {
222                                                         vd->lay= G.scene->lay;
223                                                         vd->camera= G.scene->camera;
224                                                         
225                                                         if(vd->camera==0 && vd->persp>1) vd->persp= 1;
226                                                         
227                                                         if( (vd->lay & vd->layact) == 0) {
228                                                                 bit= 0;
229                                                                 while(bit<32) {
230                                                                         if(vd->lay & (1<<bit)) {
231                                                                                 vd->layact= 1<<bit;
232                                                                                 break;
233                                                                         }
234                                                                         bit++;
235                                                                 }
236                                                         }
237                                                         
238                                                         if(val==REDRAW && vd==sa->spacedata.first) {
239                                                                 if(sa->win) scrarea_queue_redraw(sa);
240                                                         }
241                                                 }
242                                         }
243                                         sl= sl->next;
244                                 }
245                                 sa= sa->next;
246                         }
247                 }
248                 sc= sc->id.next;
249         }
250 }
251
252 void handle_view3d_lock()
253 {
254         if (G.vd != NULL) {
255                 if(G.vd->localview==0 && G.vd->scenelock && curarea->spacetype==SPACE_VIEW3D) {
256
257                         /* copy to scene */
258                         G.scene->lay= G.vd->lay;
259                         G.scene->camera= G.vd->camera;
260         
261                         copy_view3d_lock(REDRAW);
262                 }
263         }
264 }
265
266 void space_set_commmandline_options(void) {
267         SYS_SystemHandle syshandle;
268         int a;
269                 
270         if ( (syshandle = SYS_GetSystem()) ) {
271                 /* User defined settings */
272                 a= (U.gameflags & USERDEF_VERTEX_ARRAYS);
273                 SYS_WriteCommandLineInt(syshandle, "vertexarrays", a);
274
275                 a= (U.gameflags & USERDEF_DISABLE_SOUND);
276                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
277
278                 a= (U.gameflags & USERDEF_DISABLE_MIPMAP);
279                 set_mipmap(!a);
280                 SYS_WriteCommandLineInt(syshandle, "nomipmap", a);
281
282                 /* File specific settings: */
283                 /* Only test the first one. These two are switched
284                  * simultaneously. */
285                 a= (G.fileflags & G_FILE_SHOW_FRAMERATE);
286                 SYS_WriteCommandLineInt(syshandle, "show_framerate", a);
287                 SYS_WriteCommandLineInt(syshandle, "show_profile", a);
288
289                 /* When in wireframe mode, always draw debug props. */
290                 if (G.vd) {
291                         a = ( (G.fileflags & G_FILE_SHOW_DEBUG_PROPS) 
292                                   || (G.vd->drawtype == OB_WIRE)          
293                                   || (G.vd->drawtype == OB_SOLID)         );
294                         SYS_WriteCommandLineInt(syshandle, "show_properties", a);
295                 }
296
297                 a= (G.fileflags & G_FILE_ENABLE_ALL_FRAMES);
298                 SYS_WriteCommandLineInt(syshandle, "fixedtime", a);
299         }
300 }
301
302 #if GAMEBLENDER == 1
303         /**
304          * These two routines imported from the gameengine, 
305          * I suspect a lot of the resetting stuff is cruft
306          * and can be removed, but it should be checked.
307          */
308 static void SaveState(void)
309 {
310         glPushAttrib(GL_ALL_ATTRIB_BITS);
311
312         init_realtime_GL();
313         init_gl_stuff();
314
315         if(G.scene->camera==0 || G.scene->camera->type!=OB_CAMERA)
316                 error("no (correct) camera");
317
318         waitcursor(1);
319 }
320
321 static void RestoreState(void)
322 {
323         curarea->win_swap = 0;
324         curarea->head_swap=0;
325         allqueue(REDRAWVIEW3D, 0);
326         allqueue(REDRAWBUTSALL, 0);
327         reset_slowparents();
328         waitcursor(0);
329         G.qual= 0;
330         glPopAttrib();
331 }
332
333 static LinkNode *save_and_reset_all_scene_cfra(void)
334 {
335         LinkNode *storelist= NULL;
336         Scene *sc;
337         
338         for (sc= G.main->scene.first; sc; sc= sc->id.next) {
339                 BLI_linklist_prepend(&storelist, (void*) (long) sc->r.cfra);
340                 sc->r.cfra= 1;
341
342                 set_scene_bg(sc);
343         }
344         
345         BLI_linklist_reverse(&storelist);
346         
347         return storelist;
348 }
349
350 static void restore_all_scene_cfra(LinkNode *storelist) {
351         LinkNode *sc_store= storelist;
352         Scene *sc;
353         
354         for (sc= G.main->scene.first; sc; sc= sc->id.next) {
355                 int stored_cfra= (int) sc_store->link;
356                 
357                 sc->r.cfra= stored_cfra;
358                 set_scene_bg(sc);
359                 
360                 sc_store= sc_store->next;
361         }
362         
363         BLI_linklist_free(storelist, NULL);
364 }
365 #endif
366
367 void start_game(void)
368 {
369 #if GAMEBLENDER == 1
370         Scene *sc, *startscene = G.scene;
371         LinkNode *scene_cfra_store;
372
373                 /* XXX, silly code -  the game engine can
374                  * access any scene through logic, so we try 
375                  * to make sure each scene has a valid camera, 
376                  * just in case the game engine tries to use it.
377                  * 
378                  * Better would be to make a better routine
379                  * in the game engine for finding the camera.
380                  *  - zr
381                  */
382         for (sc= G.main->scene.first; sc; sc= sc->id.next) {
383                 if (!sc->camera) {
384                         Base *base;
385         
386                         for (base= sc->base.first; base; base= base->next)
387                                 if (base->object->type==OB_CAMERA)
388                                         break;
389                         
390                         sc->camera= base?base->object:NULL;
391                 }
392         }
393
394         /* these two lines make sure front and backbuffer are equal. for swapbuffers */
395         markdirty_all();
396         screen_swapbuffers();
397
398         /* can start from header */
399         mywinset(curarea->win);
400     
401         scene_cfra_store= save_and_reset_all_scene_cfra();
402         
403         BPY_end_python();
404
405         sound_stop_all_sounds();
406
407         /* Before jumping into Ketsji, we configure some settings. */
408         space_set_commmandline_options();
409
410         SaveState();
411         StartKetsjiShell(curarea, startscene->id.name+2, G.main, 1);
412         RestoreState();
413
414         BPY_start_python();
415
416         restore_all_scene_cfra(scene_cfra_store);
417         set_scene_bg(startscene);
418         
419         if (G.flags & G_FLAGS_AUTOPLAY)
420                 exit_usiblender();
421
422                 /* groups could have changed ipo */
423         allqueue(REDRAWNLA, 0);
424         allqueue(REDRAWACTION, 0);
425         allspace(REMAKEIPO, 0);
426         allqueue(REDRAWIPO, 0);
427 #else
428         notice("Game engine is disabled in this release!");
429 #endif
430 }
431
432 static void changeview3dspace(ScrArea *sa, void *spacedata)
433 {
434         setwinmatrixview3d(0);  /* 0= no pick rect */
435 }
436
437         /* Callable from editmode and faceselect mode from the
438          * moment, would be nice (and is easy) to generalize
439          * to any mode.
440          */
441 static void align_view_to_selected(View3D *v3d)
442 {
443         int nr= pupmenu("Align view%t|To selection (top)%x2|To selection (front)%x1|To selection (side)%x0");
444
445         if (nr!=-1) {
446                 int axis= nr;
447
448                 if ((G.obedit) && (G.obedit->type == OB_MESH)) {
449                         editmesh_align_view_to_selected(v3d, axis);
450                         addqueue(v3d->area->win, REDRAW, 1);
451                 } else if (G.f & G_FACESELECT) {
452                         Object *obact= OBACT;
453                         if (obact && obact->type==OB_MESH) {
454                                 Mesh *me= obact->data;
455
456                                 if (me->tface) {
457                                         faceselect_align_view_to_selected(v3d, me, axis);
458                                         addqueue(v3d->area->win, REDRAW, 1);
459                                 }
460                         }
461                 }
462         }
463 }
464
465 void select_children(Object *ob, int recursive)
466 {
467         Base *base;
468
469         for (base= FIRSTBASE; base; base= base->next)
470                 if (ob == base->object->parent) {
471                         base->flag |= SELECT;
472                         base->object->flag |= SELECT;
473                         if (recursive) select_children(base->object, 1);
474                 }
475 }
476
477 void select_parent(void)        /* Makes parent active and de-selected OBACT */
478 {
479         Base *base, *startbase, *basact=NULL, *oldbasact;
480
481         if (!(OBACT->parent)) return;
482         BASACT->flag &= (~SELECT);
483         BASACT->object->flag &= (~SELECT);
484         startbase=  FIRSTBASE;
485         if(BASACT && BASACT->next) startbase= BASACT->next;
486         base = startbase;
487         while(base) {
488                 if(base->object==BASACT->object->parent) { basact=base; break; }
489                 base=base->next;
490                 if(base==0) base= FIRSTBASE;
491                 if(base==startbase) break;
492         }
493         oldbasact = BASACT;
494         BASACT = basact;
495         basact->flag |= SELECT;         
496         if(oldbasact) if(oldbasact != basact) draw_object_ext(oldbasact);
497         basact->object->flag= basact->flag;
498         draw_object_ext(basact);
499         set_active_base(basact);
500 }
501
502 void group_menu(void)
503 {
504         Base *base;
505         short nr;
506         char *str;
507
508         /* make menu string */
509         
510         str= MEM_mallocN(160, "groupmenu");
511         strcpy(str, "Group selection%t|Children%x1|"
512                     "Immediate children%x2|Parent%x3|"
513                     "Objects on shared layers%x4");
514
515         /* here we go */
516         
517         nr= pupmenu(str);
518         MEM_freeN(str);
519
520         if(nr==4) {
521                 base= FIRSTBASE;
522                 while(base) {
523                         if (base->lay & OBACT->lay) {
524                                 base->flag |= SELECT;
525                                 base->object->flag |= SELECT;
526                         }
527                         base= base->next;
528                 }               
529         }
530         else if(nr==2) select_children(OBACT, 0);
531         else if(nr==1) select_children(OBACT, 1);
532         else if(nr==3) select_parent();
533         
534         allqueue(REDRAWVIEW3D, 0);
535         allqueue(REDRAWBUTSOBJECT, 0);
536         allspace(REMAKEIPO, 0);
537         allqueue(REDRAWIPO, 0);
538 }
539
540 void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
541 {
542         unsigned short event= evt->event;
543         short val= evt->val;
544         char ascii= evt->ascii;
545         View3D *v3d= curarea->spacedata.first;
546         Object *ob;
547         float *curs;
548         int doredraw= 0, pupval;
549         
550         if(curarea->win==0) return;     /* when it comes from sa->headqread() */
551         
552         
553         if(val) {
554
555                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
556                 if(event==MOUSEY) return;
557                 
558                 if(event==UI_BUT_EVENT) do_butspace(val); // temporal, view3d deserves own queue?
559
560                 
561                 /* TEXTEDITING?? */
562                 if((G.obedit) && G.obedit->type==OB_FONT) {
563                         switch(event) {
564                         
565                         case LEFTMOUSE:
566                                 mouse_cursor();
567                                 break;
568                         case MIDDLEMOUSE:
569                                 /* use '&' here, because of alt+leftmouse which emulates middlemouse */
570                                 if(U.flag & VIEWMOVE) {
571                                         if((G.qual==LR_SHIFTKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
572                                                 viewmove(0);
573                                         else if((G.qual==LR_CTRLKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
574                                                 viewmove(2);
575                                         else if((G.qual==0) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==LR_ALTKEY)))
576                                                 viewmove(1);
577                                 }
578                                 else {
579                                         if((G.qual==LR_SHIFTKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
580                                                 viewmove(1);
581                                         else if((G.qual==LR_CTRLKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
582                                                 viewmove(2);
583                                         else
584                                                 viewmove(0);
585                                 }
586                                 break;
587                                 
588                         case WHEELUPMOUSE:
589                                 /* Regular:   Zoom in */
590                                 /* Shift:     Scroll up */
591                                 /* Ctrl:      Scroll right */
592                                 /* Alt-Shift: Rotate up */
593                                 /* Alt-Ctrl:  Rotate right */
594
595                                 if( G.qual & LR_SHIFTKEY ) {
596                                         if( G.qual & LR_ALTKEY ) { 
597                                                 G.qual &= ~LR_SHIFTKEY;
598                                                 persptoetsen(PAD2);
599                                                 G.qual |= LR_SHIFTKEY;
600                                         } else {
601                                                 persptoetsen(PAD2);
602                                         }
603                                 } else if( G.qual & LR_CTRLKEY ) {
604                                         if( G.qual & LR_ALTKEY ) { 
605                                                 G.qual &= ~LR_CTRLKEY;
606                                                 persptoetsen(PAD4);
607                                                 G.qual |= LR_CTRLKEY;
608                                         } else {
609                                                 persptoetsen(PAD4);
610                                         }
611                                 } else if(U.uiflag & WHEELZOOMDIR) 
612                                         persptoetsen(PADMINUS);
613                                 else
614                                         persptoetsen(PADPLUSKEY);
615
616                                 doredraw= 1;
617                                 break;
618
619                         case WHEELDOWNMOUSE:
620                                 /* Regular:   Zoom out */
621                                 /* Shift:     Scroll down */
622                                 /* Ctrl:      Scroll left */
623                                 /* Alt-Shift: Rotate down */
624                                 /* Alt-Ctrl:  Rotate left */
625
626                                 if( G.qual & LR_SHIFTKEY ) {
627                                         if( G.qual & LR_ALTKEY ) { 
628                                                 G.qual &= ~LR_SHIFTKEY;
629                                                 persptoetsen(PAD8);
630                                                 G.qual |= LR_SHIFTKEY;
631                                         } else {
632                                                 persptoetsen(PAD8);
633                                         }
634                                 } else if( G.qual & LR_CTRLKEY ) {
635                                         if( G.qual & LR_ALTKEY ) { 
636                                                 G.qual &= ~LR_CTRLKEY;
637                                                 persptoetsen(PAD6);
638                                                 G.qual |= LR_CTRLKEY;
639                                         } else {
640                                                 persptoetsen(PAD6);
641                                         }
642                                 } else if(U.uiflag & WHEELZOOMDIR) 
643                                         persptoetsen(PADPLUSKEY);
644                                 else
645                                         persptoetsen(PADMINUS);
646                                 
647                                 doredraw= 1;
648                                 break;
649
650                         case UKEY:
651                                 if(G.qual==LR_ALTKEY) {
652                                         remake_editText();
653                                         doredraw= 1;
654                                 } 
655                                 else {
656                                         do_textedit(event, val, ascii);
657                                 }
658                                 break;
659                         case VKEY:
660                                 if(G.qual==LR_ALTKEY) {
661                                         paste_editText();
662                                         doredraw= 1;
663                                 } 
664                                 else {
665                                         do_textedit(event, val, ascii);
666                                 }
667                                 break;
668                         case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
669                         case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
670                         case PADENTER:
671                                 persptoetsen(event);
672                                 doredraw= 1;
673                                 break;
674                                 
675                         default:
676                                 do_textedit(event, val, ascii);
677                                 break;
678                         }
679                 }
680                 else {
681                         switch(event) {
682                         
683                         case BACKBUFDRAW:
684                                 backdrawview3d(1);
685                                 break;
686                                 
687                         case LEFTMOUSE:
688                                 if ((G.obedit) || !(G.f&(G_VERTEXPAINT|G_WEIGHTPAINT|G_TEXTUREPAINT))) {
689                                         mouse_cursor();
690                                 }
691                                 else if (G.f & G_VERTEXPAINT) {
692                                         vertex_paint();
693                                 }
694                                 else if (G.f & G_WEIGHTPAINT){
695                                         weight_paint();
696                                 }
697                                 else if (G.f & G_TEXTUREPAINT) {
698                                         face_draw();
699                                 }
700                                 break;
701                         case MIDDLEMOUSE:
702                                 /* use '&' here, because of alt+leftmouse which emulates middlemouse */
703                                 if(U.flag & VIEWMOVE) {
704                                         if((G.qual==LR_SHIFTKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
705                                                 viewmove(0);
706                                         else if((G.qual==LR_CTRLKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
707                                                 viewmove(2);
708                                         else if((G.qual==0) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==LR_ALTKEY)))
709                                                 viewmove(1);
710                                 }
711                                 else {
712                                         if((G.qual==LR_SHIFTKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
713                                                 viewmove(1);
714                                         else if((G.qual==LR_CTRLKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
715                                                 viewmove(2);
716                                         else if((G.qual==0) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==LR_ALTKEY)))
717                                                 viewmove(0);
718                                 }
719                                 break;
720                         case RIGHTMOUSE:
721                                 if((G.obedit) && (G.qual & LR_CTRLKEY)==0) {
722                                         if(G.obedit->type==OB_MESH)
723                                                 mouse_mesh();
724                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
725                                                 mouse_nurb();
726                                         else if(G.obedit->type==OB_MBALL)
727                                                 mouse_mball();
728                                         else if(G.obedit->type==OB_LATTICE)
729                                                 mouse_lattice();
730                                         else if(G.obedit->type==OB_ARMATURE)
731                                                 mouse_armature();
732                                 }
733                                 else if((G.obedit) && (G.qual & (LR_CTRLKEY|LR_ALTKEY)))
734                                         mouse_mesh();   // edge select
735                                 else if(G.obpose) { 
736                                         if (G.obpose->type==OB_ARMATURE)
737                                                 mousepose_armature();
738                                 }
739                                 else if(G.qual==LR_CTRLKEY)
740                                         mouse_select();
741                                 else if(G.f & G_FACESELECT)
742                                         face_select();
743                                 else if( G.f & (G_VERTEXPAINT|G_TEXTUREPAINT))
744                                         sample_vpaint();
745                                 else
746                                         mouse_select();
747                                 break;
748
749                         case WHEELUPMOUSE:
750                                 /* Regular:   Zoom in */
751                                 /* Shift:     Scroll up */
752                                 /* Ctrl:      Scroll right */
753                                 /* Alt-Shift: Rotate up */
754                                 /* Alt-Ctrl:  Rotate right */
755
756                                 if( G.qual & LR_SHIFTKEY ) {
757                                         if( G.qual & LR_ALTKEY ) { 
758                                                 G.qual &= ~LR_SHIFTKEY;
759                                                 persptoetsen(PAD2);
760                                                 G.qual |= LR_SHIFTKEY;
761                                         } else {
762                                                 persptoetsen(PAD2);
763                                         }
764                                 } else if( G.qual & LR_CTRLKEY ) {
765                                         if( G.qual & LR_ALTKEY ) { 
766                                                 G.qual &= ~LR_CTRLKEY;
767                                                 persptoetsen(PAD4);
768                                                 G.qual |= LR_CTRLKEY;
769                                         } else {
770                                                 persptoetsen(PAD4);
771                                         }
772                                 } else if(U.uiflag & WHEELZOOMDIR) 
773                                         persptoetsen(PADMINUS);
774                                 else
775                                         persptoetsen(PADPLUSKEY);
776
777                                 doredraw= 1;
778                                 break;
779                         case WHEELDOWNMOUSE:
780                                 /* Regular:   Zoom out */
781                                 /* Shift:     Scroll down */
782                                 /* Ctrl:      Scroll left */
783                                 /* Alt-Shift: Rotate down */
784                                 /* Alt-Ctrl:  Rotate left */
785
786                                 if( G.qual & LR_SHIFTKEY ) {
787                                         if( G.qual & LR_ALTKEY ) { 
788                                                 G.qual &= ~LR_SHIFTKEY;
789                                                 persptoetsen(PAD8);
790                                                 G.qual |= LR_SHIFTKEY;
791                                         } else {
792                                                 persptoetsen(PAD8);
793                                         }
794                                 } else if( G.qual & LR_CTRLKEY ) {
795                                         if( G.qual & LR_ALTKEY ) { 
796                                                 G.qual &= ~LR_CTRLKEY;
797                                                 persptoetsen(PAD6);
798                                                 G.qual |= LR_CTRLKEY;
799                                         } else {
800                                                 persptoetsen(PAD6);
801                                         }
802                                 } else if(U.uiflag & WHEELZOOMDIR) 
803                                         persptoetsen(PADPLUSKEY);
804                                 else
805                                         persptoetsen(PADMINUS);
806                                 
807                                 doredraw= 1;
808                                 break;
809                         
810                         case ONEKEY:
811                                 ob= OBACT;
812                                 if(G.qual==LR_CTRLKEY) {
813                                         if(G.obedit) {
814                                                         flip_subdivison(G.obedit, 1);
815                                         }
816                                         else if(ob->type == OB_MESH) {
817                                                 flip_subdivison(ob, 1);
818                                         }
819                                 }
820                                 else
821                                         do_layer_buttons(0); break;
822                         case TWOKEY:
823                                 ob= OBACT;
824                                 if(G.qual==LR_CTRLKEY) {
825                                         if(G.obedit) {
826                                                         flip_subdivison(G.obedit, 2);
827                                         }
828                                         else if(ob->type == OB_MESH) {
829                                                 flip_subdivison(ob, 2);
830                                         }
831                                 }
832                                 else
833                                         do_layer_buttons(1); 
834                                 break;
835                         case THREEKEY:
836                                 ob= OBACT;
837                                 if(G.qual==LR_CTRLKEY) {
838                                         if(G.obedit) {
839                                                         flip_subdivison(G.obedit, 3);
840                                         }
841                                         else if(ob->type == OB_MESH) {
842                                                 flip_subdivison(ob, 3);
843                                         }
844                                 }
845                                 else
846                                         do_layer_buttons(2); break;
847                         case FOURKEY:
848                                 ob= OBACT;
849                                 if(G.qual & LR_CTRLKEY) {
850                                         if(G.obedit) {
851                                                         flip_subdivison(G.obedit, 4);
852                                         }
853                                         else if(ob->type == OB_MESH) {
854                                                 flip_subdivison(ob, 4);
855                                         }
856                                 }
857                                 else
858                                 do_layer_buttons(3); break;
859                         case FIVEKEY:
860                                 do_layer_buttons(4); break;
861                         case SIXKEY:
862                                 do_layer_buttons(5); break;
863                         case SEVENKEY:
864                                 do_layer_buttons(6); break;
865                         case EIGHTKEY:
866                                 do_layer_buttons(7); break;
867                         case NINEKEY:
868                                 do_layer_buttons(8); break;
869                         case ZEROKEY:
870                                 do_layer_buttons(9); break;
871                         case MINUSKEY:
872                                 do_layer_buttons(10); break;
873                         case EQUALKEY:
874                                 do_layer_buttons(11); break;
875                         case ACCENTGRAVEKEY:
876                                 do_layer_buttons(-1); break;
877                                 
878                         case AKEY:
879                                 if(G.qual & LR_CTRLKEY) apply_object(); // also with shift!
880                                 else if((G.qual==LR_SHIFTKEY)) {
881                                         toolbox_n_add();
882                                 }
883                                 else {
884                                         if(G.obedit) {
885                                                 if(G.obedit->type==OB_MESH)
886                                                         deselectall_mesh();
887                                                 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
888                                                         deselectall_nurb();
889                                                 else if(G.obedit->type==OB_MBALL)
890                                                         deselectall_mball();
891                                                 else if(G.obedit->type==OB_LATTICE)
892                                                         deselectall_Latt();
893                                                 else if(G.obedit->type==OB_ARMATURE)
894                                                         deselectall_armature();
895                                         }
896                                         else if (G.obpose){
897                                                 switch (G.obpose->type){
898                                                 case OB_ARMATURE:
899                                                         deselectall_posearmature(1);
900                                                         break;
901                                                 }
902                                         }
903                                         else {
904                                                 if(G.f & G_FACESELECT) deselectall_tface();
905                                                 else {
906                                                         /* by design, the center of the active object 
907                                                          * (which need not necessarily by selected) will
908                                                          * still be drawn as if it were selected.
909                                                          */
910                                                         deselectall();
911                                                 }
912                                         }
913                                 }
914                                 break;
915                         case BKEY:
916                                 if((G.qual==LR_SHIFTKEY))
917                                         set_render_border();
918                                 else if((G.qual==0))
919                                         borderselect();
920                                 break;
921                         case CKEY:
922                                 if(G.qual==LR_CTRLKEY) {
923                                         copymenu();
924                                 }
925                                 else if(G.qual==LR_ALTKEY) {
926                                         convertmenu();  /* editobject.c */
927                                 }
928                                 else if((G.qual==LR_SHIFTKEY)) {
929                                         view3d_home(1);
930                                         curs= give_cursor();
931                                         curs[0]=curs[1]=curs[2]= 0.0;
932                                         allqueue(REDRAWVIEW3D, 0);
933                                 }
934                                 else if((G.obedit) && ELEM(G.obedit->type, OB_CURVE, OB_SURF) ) {
935                                         makecyclicNurb();
936                                         makeDispList(G.obedit);
937                                         allqueue(REDRAWVIEW3D, 0);
938                                 }
939                                 else if((G.qual==0)){
940                                         curs= give_cursor();
941                                         G.vd->ofs[0]= -curs[0];
942                                         G.vd->ofs[1]= -curs[1];
943                                         G.vd->ofs[2]= -curs[2];
944                                         scrarea_queue_winredraw(curarea);
945                                 }
946                         
947                                 break;
948                         case DKEY:
949                                 if((G.qual==LR_SHIFTKEY)) {
950                                         duplicate_context_selected();
951                                 }
952                                 else if(G.qual==LR_ALTKEY) {
953                                         if(G.obpose)
954                                                 error ("Duplicate not possible in posemode.");
955                                         else if((G.obedit==0))
956                                                 adduplicate(0);
957                                 }
958                                 else if(G.qual==LR_CTRLKEY) {
959                                         imagestodisplist();
960                                 }
961                                 else if((G.qual==0)){
962                                         pupval= pupmenu("Draw mode%t|BoundBox %x1|Wire %x2|OpenGL Solid %x3|Shaded Solid %x4|Textured Solid %x5");
963                                         if(pupval>0) {
964                                                 G.vd->drawtype= pupval;
965                                                 doredraw= 1;
966                                         
967                                         }
968                                 }
969                                 
970                                 break;
971                         case EKEY:
972                                 if (G.qual==0){
973                                         if(G.obedit) {
974                                                 if(G.obedit->type==OB_MESH)
975                                                         extrude_mesh();
976                                                 else if(G.obedit->type==OB_CURVE)
977                                                         addvert_Nurb('e');
978                                                 else if(G.obedit->type==OB_SURF)
979                                                         extrude_nurb();
980                                                 else if(G.obedit->type==OB_ARMATURE)
981                                                         extrude_armature();
982                                         }
983                                         else {
984                                                 ob= OBACT;
985                                                 if(ob && ob->type==OB_IKA) if(okee("extrude IKA"))
986                                                         extrude_ika(ob, 1);
987                                         }
988                                 }
989                                 break;
990                         case FKEY:
991                                 if(G.obedit) {
992                                         if(G.obedit->type==OB_MESH) {
993                                                 if((G.qual==LR_SHIFTKEY))
994                                                         fill_mesh();
995                                                 else if(G.qual==LR_ALTKEY)
996                                                         beauty_fill();
997                                                 else if(G.qual==LR_CTRLKEY)
998                                                         edge_flip();
999                                                 else if (G.qual==0)
1000                                                         addedgevlak_mesh();
1001                                         }
1002                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addsegment_nurb();
1003                                 }
1004                                 else if(G.qual==LR_CTRLKEY)
1005                                         sort_faces();
1006                                 else if((G.qual==LR_SHIFTKEY))
1007                                         fly();
1008                                 else {
1009                                                 set_faceselect();
1010                                         }
1011                                 
1012                                 break;
1013                         case GKEY:
1014                                 /* RMGRP if(G.qual & LR_CTRLKEY) add_selected_to_group();
1015                                 else if(G.qual & LR_ALTKEY) rem_selected_from_group(); */
1016                                 
1017                                 if((G.qual==LR_SHIFTKEY))
1018                                         group_menu();
1019                                 else if(G.qual==LR_ALTKEY)
1020                                         clear_object('g');
1021                                 else if((G.qual==0))
1022                                         transform('g');
1023                                 break;
1024                         case HKEY:
1025                                 if(G.obedit) {
1026                                         if(G.obedit->type==OB_MESH) {
1027                                                 if(G.qual==LR_ALTKEY)
1028                                                         reveal_mesh();
1029                                                 else if((G.qual==LR_SHIFTKEY))
1030                                                         hide_mesh(1);
1031                                                 else if((G.qual==0)) 
1032                                                         hide_mesh(0);
1033                                         }
1034                                         else if(G.obedit->type== OB_SURF) {
1035                                                 if(G.qual==LR_ALTKEY)
1036                                                         revealNurb();
1037                                                 else if((G.qual==LR_SHIFTKEY))
1038                                                         hideNurb(1);
1039                                                 else if((G.qual==0))
1040                                                         hideNurb(0);
1041                                         }
1042                                         else if(G.obedit->type==OB_CURVE) {
1043                                                 if(G.qual==LR_CTRLKEY)
1044                                                         autocalchandlesNurb_all(1);     /* flag=1, selected */
1045                                                 else if((G.qual==LR_SHIFTKEY))
1046                                                         sethandlesNurb(1);
1047                                                 else if((G.qual==0))
1048                                                         sethandlesNurb(3);
1049                                                 
1050                                                 makeDispList(G.obedit);
1051                                                 
1052                                                 allqueue(REDRAWVIEW3D, 0);
1053                                         }
1054                                 }
1055                                 else if(G.f & G_FACESELECT)
1056                                         hide_tface();
1057                                 
1058                                 break;
1059                         case IKEY:
1060                                 break;
1061                                 
1062                         case JKEY:
1063                                 if(G.qual==LR_CTRLKEY) {
1064                                         if( (ob= OBACT) ) {
1065                                                 if(ob->type == OB_MESH)
1066                                                         join_mesh();
1067                                                 else if(ob->type == OB_CURVE)
1068                                                         join_curve(OB_CURVE);
1069                                                 else if(ob->type == OB_SURF)
1070                                                         join_curve(OB_SURF);
1071                                                 else if(ob->type == OB_ARMATURE)
1072                                                         join_armature ();
1073                                         }
1074                                         else if ((G.obedit) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
1075                                                 addsegment_nurb();
1076                                 }
1077                                 else if(G.obedit) {
1078                                         if(G.obedit->type==OB_MESH) {
1079                                                 join_triangles();
1080                                         }
1081                                 }
1082
1083                                 break;
1084                         case KKEY:
1085                                 if(G.obedit) {
1086                                         if (G.obedit->type==OB_MESH) {
1087                                                 if (G.qual==LR_SHIFTKEY)
1088                                                         KnifeSubdivide(KNIFE_PROMPT);
1089                                                 else if (G.qual==0)
1090                                                         LoopMenu();
1091                                         }
1092                                         else if(G.obedit->type==OB_SURF)
1093                                                 printknots();
1094                                 }
1095                                 else {
1096                                         if((G.qual==LR_SHIFTKEY)) {
1097                                                 if(G.f & G_FACESELECT)
1098                                                         clear_vpaint_selectedfaces();
1099                                                 else if(G.f & G_VERTEXPAINT)
1100                                                         clear_vpaint();
1101                                                 else
1102                                                         select_select_keys();
1103                                         }
1104                                         else if(G.qual==LR_CTRLKEY)
1105                                                 make_skeleton();
1106 /*                                      else if(G.qual & LR_ALTKEY) delete_skeleton(); */
1107                                         else if (G.qual==0)
1108                                                 set_ob_ipoflags();
1109                                 }
1110                                 
1111                                 break;
1112                         case LKEY:
1113                                 if(G.obedit) {
1114                                         if(G.obedit->type==OB_MESH)
1115                                                 selectconnected_mesh(G.qual);
1116                                         if(G.obedit->type==OB_ARMATURE)
1117                                                 selectconnected_armature();
1118                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
1119                                                 selectconnected_nurb();
1120                                 }
1121                                 else if(G.obpose) {
1122                                         if(G.obpose->type==OB_ARMATURE)
1123                                                 selectconnected_posearmature();
1124                                 }
1125                                 else {
1126                                         if((G.qual==LR_SHIFTKEY))
1127                                                 selectlinks();
1128                                         else if(G.qual==LR_CTRLKEY)
1129                                                 linkmenu();
1130                                         else if(G.f & G_FACESELECT)
1131                                                 select_linked_tfaces();
1132                                         else if((G.qual==0))
1133                                                 make_local();
1134                                 }
1135                                 break;
1136                         case MKEY:
1137                                 if(G.obedit){
1138                                         if(G.qual==LR_ALTKEY) {
1139                                                 if(G.obedit->type==OB_MESH) {
1140                                                         undo_push_mesh("Merge");
1141                                                         mergemenu();
1142                                                 }
1143                                         }
1144                                         else if((G.qual==0)) {
1145                                                 if(G.obedit->type==OB_MESH) {
1146                                                         undo_push_mesh("Mirror");
1147                                                         mirrormenu();
1148                                                 }
1149                                         }
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                 uiBlockBeginAlign(block);
1833                 uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal",        465,y3,100,20,  col, 2.0, 0.0, 0, 0, "");
1834                 uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 565,y3,100,20,  col, 2.0, 1.0, 0, 0, "");
1835                 uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded",        465,y2,100,20,  col, 2.0, 2.0, 0, 0, "");
1836                 uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool",       565,y2,100,20,  col, 2.0, 3.0, 0, 0, "");
1837                 uiBlockEndAlign(block);
1838         }
1839         else {
1840                 uiBlockBeginAlign(block);
1841                 if ELEM3(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT) {
1842                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
1843                 }
1844                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
1845                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"G ",   465,y2,200,20,  col+1, 0.0, 255.0, B_THEMECOL, 0, "");
1846                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"B ",   465,y1,200,20,  col+2, 0.0, 255.0, B_THEMECOL, 0, "");
1847                 uiBlockEndAlign(block);
1848
1849                 uiDefButC(block, COL, B_THEMECOL, "",           675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
1850                                 
1851                 /* copy paste */
1852                 uiBlockBeginAlign(block);
1853                 uiDefBut(block, BUT, B_THEME_COPY, "Copy Color",        755,y2,120,20, NULL, 0, 0, 0, 0, "Stores current color in buffer");
1854                 uiDefBut(block, BUT, B_THEME_PASTE, "Paste Color",      755,y1,120,20, NULL, 0, 0, 0, 0, "Pastes buffer color");
1855                 uiBlockEndAlign(block);
1856                 
1857                 uiDefButC(block, COL, 0, "",                            885,y1,50,y2-y1+20, th_curcol_arr, 0, 0, 0, 0, "");
1858                 
1859         }
1860 }
1861
1862
1863 void drawinfospace(ScrArea *sa, void *spacedata)
1864 {
1865         uiBlock *block;
1866         static short cur_light=0, cur_light_var=0;
1867         float fac, col[3];
1868         short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y2label, y3label, y4label;
1869         short smallprefbut, medprefbut, largeprefbut, smfileselbut;
1870         short edgespace, midspace;
1871         char naam[32];
1872
1873         if(curarea->win==0) return;
1874
1875         BIF_GetThemeColor3fv(TH_BACK, col);
1876         glClearColor(col[0], col[1], col[2], 0.0);
1877         glClear(GL_COLOR_BUFFER_BIT);
1878
1879         fac= ((float)curarea->winx)/1280.0f;
1880         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
1881         
1882         sprintf(naam, "infowin %d", curarea->win);
1883         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->win);
1884
1885
1886         dx= (1280-90)/7;        /* spacing for use in equally dividing 'tab' row */
1887
1888         xpos = 45;              /* left padding */
1889         ypos = 50;              /* bottom padding for buttons */
1890         ypostab = 10;           /* bottom padding for 'tab' row */
1891
1892
1893         buth = 20;              /* standard button height */
1894
1895         smallprefbut = 94;      /* standard size for small preferences button */
1896         medprefbut = 193;       /* standard size for medium preferences button */
1897         largeprefbut = 292;     /* standard size for large preferences button */
1898         smfileselbut = buth;    /* standard size for fileselect button (square) */
1899         
1900         edgespace = 3;          /* space from edge of end 'tab' to edge of end button */
1901         midspace = 5;           /* horizontal space between buttons */
1902
1903         rspace = 3;             /* default space between rows */
1904
1905         y1 = ypos;              /* bottom padding of 1st (bottom) button row */
1906         y2 = ypos+buth+rspace;  /* bottom padding of 2nd button row */
1907         y3 = ypos+2*(buth+rspace)+(3*rspace);   /* bottom padding of 3rd button row */
1908         y4 = ypos+3*(buth+rspace)+(3*rspace);   /* bottom padding of 4th button row */
1909
1910         y2label = y2-2;         /* adjustments to offset the labels down to align better */
1911         y3label = y3-(3*rspace)-2;      /* again for 3rd row */
1912         y4label = y4-2;         /* again for 4th row */
1913
1914
1915         /* set the colour to blue and draw the main 'tab' controls */
1916
1917         uiBlockSetCol(block, TH_BUT_SETTING1);
1918         uiBlockBeginAlign(block);
1919         
1920         uiDefButI(block, ROW,B_USERPREF,"View & Controls",
1921                 xpos,ypostab,(short)dx,buth,
1922                 &U.userpref,1.0,0.0, 0, 0,"");
1923                 
1924         uiDefButI(block, ROW,B_USERPREF,"Edit Methods",
1925                 (short)(xpos+dx),ypostab,(short)dx,buth,
1926                 &U.userpref,1.0,1.0, 0, 0,"");
1927
1928         uiDefButI(block, ROW,B_USERPREF,"Language & Font",
1929                 (short)(xpos+2*dx),ypostab,(short)dx,buth,
1930                 &U.userpref,1.0,2.0, 0, 0,"");
1931
1932         uiDefButI(block, ROW,B_USERPREF,"Themes",
1933                 (short)(xpos+3*dx),ypostab,(short)dx,buth,
1934                 &U.userpref,1.0,6.0, 0, 0,"");
1935
1936         uiDefButI(block, ROW,B_USERPREF,"Auto Save",
1937                 (short)(xpos+4*dx),ypostab,(short)dx,buth,
1938                 &U.userpref,1.0,3.0, 0, 0,"");
1939
1940         uiDefButI(block, ROW,B_USERPREF,"System & OpenGL",
1941                 (short)(xpos+5*dx),ypostab,(short)dx,buth,
1942                 &U.userpref,1.0,4.0, 0, 0,"");
1943                 
1944         uiDefButI(block, ROW,B_USERPREF,"File Paths",
1945                 (short)(xpos+6*dx),ypostab,(short)dx,buth,
1946                 &U.userpref,1.0,5.0, 0, 0,"");
1947
1948         uiBlockSetCol(block, TH_AUTO);
1949         uiBlockEndAlign(block);
1950         /* end 'tab' controls */
1951
1952         /* line 2: left x co-ord, top y co-ord, width, height */
1953
1954         if(U.userpref == 6) {
1955                 info_user_themebuts(block, y1, y2, y3);
1956         }
1957         else if (U.userpref == 0) { /* view & controls */
1958
1959                 uiDefBut(block, LABEL,0,"Display:",
1960                         xpos,y3label,medprefbut,buth,
1961                         0, 0, 0, 0, 0, "");
1962                 
1963                 uiDefButS(block, TOG|BIT|11, 0, "ToolTips",
1964                         (xpos+edgespace),y2,smallprefbut,buth,
1965                         &(U.flag), 0, 0, 0, 0,
1966                         "Displays tooltips (help tags) over buttons");
1967
1968                 uiDefButS(block, TOG|BIT|4, B_DRAWINFO, "Object Info",
1969                         (xpos+edgespace+midspace+smallprefbut),y2,smallprefbut,buth,
1970                         &(U.uiflag), 0, 0, 0, 0,
1971                         "Displays current object name and frame number in the 3D viewport");
1972
1973                 uiDefButS(block, TOG|BIT|4, 0, "Global Scene",
1974                         (xpos+edgespace),y1,medprefbut,buth,
1975                         &(U.flag), 0, 0, 0, 0,
1976                         "Forces the current Scene to be displayed in all Screens");
1977
1978
1979                 uiDefBut(block, LABEL,0,"Snap to grid:",
1980                         (xpos+edgespace+medprefbut),y3label,medprefbut,buth,
1981                         0, 0, 0, 0, 0, "");
1982
1983                 uiDefButS(block, TOG|BIT|1, 0, "Grab",
1984                         (xpos+edgespace+medprefbut+midspace),y2,smallprefbut,buth,
1985                         &(U.flag), 0, 0, 0, 0,
1986                         "Move objects to grid units");
1987
1988                 uiDefButS(block, TOG|BIT|3, 0, "Size",
1989                         (xpos+edgespace+medprefbut+midspace),y1,smallprefbut,buth,
1990                         &(U.flag), 0, 0, 0, 0,
1991                         "Scale objects to grid units");
1992
1993                 uiDefButS(block, TOG|BIT|2, 0, "Rotate",
1994                         (xpos+edgespace+medprefbut+(2*midspace)+smallprefbut),y2,smallprefbut,buth,
1995                         &(U.flag), 0, 0, 0, 0,
1996                         "Rotate objects to grid units");
1997
1998
1999
2000                 uiDefBut(block, LABEL,0,"Menu Buttons:",
2001                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y3label,medprefbut,buth,
2002                         0, 0, 0, 0, 0, "");
2003
2004                 uiDefButS(block, TOG|BIT|9, 0, "Auto Open",
2005                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y2,smallprefbut,buth,
2006                         &(U.uiflag), 0, 0, 0, 0,
2007                         "Automatic opening of menu buttons");
2008
2009                 uiDefButS(block, NUM, 0, "ThresA:",
2010                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y1,smallprefbut,buth,
2011                         &(U.menuthreshold1), 1, 40, 0, 0,
2012                         "Time in 1/10 seconds for auto open");
2013
2014                 uiDefButS(block, NUM, 0, "ThresB:",
2015                         (xpos+edgespace+medprefbut+(4*midspace)+(3*smallprefbut)),y1,smallprefbut,buth,
2016                         &(U.menuthreshold2), 1, 40, 0, 0,
2017                         "Time in 1/10 seconds for auto open sublevels");
2018
2019
2020                 uiDefBut(block, LABEL,0,"Toolbox Thresh.:",
2021                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y3label,medprefbut,buth,
2022                         0, 0, 0, 0, 0, "");
2023
2024                 uiDefButS(block, NUM, 0, "LMB:",
2025                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y2,smallprefbut,buth,
2026                         &(U.tb_leftmouse), 2, 40, 0, 0,
2027                         "Time in 1/10 seconds leftmouse hold to open toolbox");
2028
2029                 uiDefButS(block, NUM, 0, "RMB:",
2030                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y1,smallprefbut,buth,
2031                         &(U.tb_rightmouse), 2, 40, 0, 0,
2032                         "Time in 1/10 seconds for rightmouse to open toolbox");
2033
2034                         
2035                 uiDefBut(block, LABEL,0,"View rotation:",
2036                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y3label,medprefbut,buth,
2037                         0, 0, 0, 0, 0, "");
2038
2039                 uiDefButS(block, TOG|BIT|5, B_DRAWINFO, "Trackball",
2040                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y2,(smallprefbut+2),buth,
2041                         &(U.flag), 0, 0, 0, 0,
2042                         "Use trackball style rotation with middle mouse button");
2043
2044                 uiDefButS(block, TOGN|BIT|5, B_DRAWINFO, "Turntable",
2045                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y1,(smallprefbut+2),buth,
2046                         &(U.flag), 0, 0, 0, 0,
2047                         "Use turntable style rotation with middle mouse button");
2048
2049
2050
2051                 uiDefButS(block, TOGN|BIT|10, B_DRAWINFO, "Rotate View",
2052                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y2,(smallprefbut+2),buth,
2053                         &(U.flag), 0, 0, 0, 0, "Default action for the middle mouse button");
2054
2055                 uiDefButS(block, TOG|BIT|10, B_DRAWINFO, "Pan View",
2056                         (xpos+edgespace+(4*midspace)+(4*medprefbut)+smallprefbut+2),y2,(smallprefbut+2),buth,
2057                         &(U.flag), 0, 0, 0, 0, "Default action for the middle mouse button");
2058
2059                 uiDefBut(block, LABEL,0,"Middle mouse button:",
2060                         (xpos+edgespace+(3*midspace)+(4*medprefbut)),y3label,medprefbut,buth,
2061                         0, 0, 0, 0, 0, "");
2062                 uiDefButS(block, TOG|BIT|12, 0, "Emulate 3 Buttons",
2063                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y1,medprefbut,buth,
2064                         &(U.flag), 0, 0, 0, 0,
2065                         "Emulates a middle mouse button with ALT+LeftMouse");
2066
2067
2068
2069
2070                 uiDefBut(block, LABEL,0,"Mousewheel:",
2071                         (xpos+edgespace+(4*midspace)+(5*medprefbut)),y3label,medprefbut,buth,
2072                         0, 0, 0, 0, 0, "");
2073                 uiDefButS(block, TOG|BIT|2, 0, "Invert Wheel Zoom",
2074                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y1,medprefbut,buth,
2075                         &(U.uiflag), 0, 0, 0, 0,
2076                         "Swaps mouse wheel zoom direction");
2077
2078
2079                 uiDefButI(block, NUM, 0, "Scroll Lines:",
2080                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y2,medprefbut,buth,
2081                         &U.wheellinescroll, 0.0, 32.0, 0, 0,
2082                         "The number of lines scrolled at a time with the mouse wheel");
2083
2084
2085         } else if (U.userpref == 1) { /* edit methods */
2086
2087
2088                 uiDefBut(block, LABEL,0,"Material linked to:",
2089                         xpos,y3label,medprefbut,buth,
2090                         0, 0, 0, 0, 0, "");
2091
2092                 uiDefButS(block, TOGN|BIT|8, B_DRAWINFO, "ObData",
2093                         (xpos+edgespace),y2,(smallprefbut),buth,
2094                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
2095
2096                 uiDefButS(block, TOG|BIT|8, B_DRAWINFO, "Object",
2097                         (xpos+edgespace+midspace+smallprefbut),y2,(smallprefbut),buth,
2098                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
2099
2100
2101
2102                 uiDefBut(block, LABEL,0,"Mesh Undo",
2103                         (xpos+edgespace+medprefbut),y3label, medprefbut,buth,
2104                         0, 0, 0, 0, 0, "");
2105
2106                 uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps:",
2107                         (xpos+edgespace+medprefbut+midspace),y2,(medprefbut),buth,
2108                                 &(U.undosteps), 1, 64, 0, 0, "Number of undo steps avail. in Editmode.  Smaller conserves memory.");
2109
2110
2111                 uiDefBut(block, LABEL,0,"Auto keyframe on:",
2112                         (xpos+edgespace+(2*medprefbut)+midspace),y3label,medprefbut,buth,
2113                         0, 0, 0, 0, 0, "");
2114
2115                 uiDefButS(block, TOG|BIT|0, 0, "Action",
2116                         (xpos+edgespace+(2*medprefbut)+(2*midspace)),y2,smallprefbut,buth,
2117                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in action ipo curve");
2118
2119                 uiDefButS(block, TOG|BIT|1, 0, "Object",
2120                         (xpos+edgespace+(2*medprefbut)+(3*midspace)+smallprefbut),y2,smallprefbut,buth,
2121                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in object ipo curve");
2122
2123
2124
2125                 uiDefBut(block, LABEL,0,"Duplicate with object:",
2126                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut),y3label,medprefbut,buth,
2127                         0, 0, 0, 0, 0, "");
2128
2129                 uiDefButS(block, TOG|BIT|0, 0, "Mesh",
2130                         (xpos+edgespace+(4*midspace)+(3*medprefbut)+smallprefbut),y2,smallprefbut,buth,
2131                         &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
2132                 uiDefButS(block, TOG|BIT|9, 0, "Armature",
2133                         (xpos+edgespace+(4*midspace)+(3*medprefbut)+smallprefbut),y1,smallprefbut,buth,
2134                         &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
2135
2136                 uiDefButS(block, TOG|BIT|2, 0, "Surface",
2137                         (xpos+edgespace+(5*midspace)+(3*medprefbut)+(2*smallprefbut)),y2,smallprefbut,buth,
2138                         &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
2139                 uiDefButS(block, TOG|BIT|5, 0, "Lamp",
2140                         (xpos+edgespace+(5*midspace)+(3*medprefbut)+(2*smallprefbut)),y1,smallprefbut,buth,
2141                         &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
2142
2143                 uiDefButS(block, TOG|BIT|1, 0, "Curve",
2144                         (xpos+edgespace+(6*midspace)+(3*medprefbut)+(3*smallprefbut)),y2,smallprefbut,buth,
2145                         &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
2146                 uiDefButS(block, TOG|BIT|7, 0, "Material",
2147                         (xpos+edgespace+(6*midspace)+(3*medprefbut)+(3*smallprefbut)),y1,smallprefbut,buth,
2148                         &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
2149
2150                 uiDefButS(block, TOG|BIT|3, 0, "Text",
2151                         (xpos+edgespace+(7*midspace)+(3*medprefbut)+(4*smallprefbut)),y2,smallprefbut,buth,
2152                         &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
2153                 uiDefButS(block, TOG|BIT|8, 0, "Texture",
2154                         (xpos+edgespace+(7*midspace)+(3*medprefbut)+(4*smallprefbut)),y1,smallprefbut,buth,
2155                         &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
2156
2157                 uiDefButS(block, TOG|BIT|4, 0, "Metaball",
2158                         (xpos+edgespace+(8*midspace)+(3*medprefbut)+(5*smallprefbut)),y2,smallprefbut,buth,
2159                         &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
2160                 uiDefButS(block, TOG|BIT|6, 0, "Ipo",
2161                         (xpos+edgespace+(8*midspace)+(3*medprefbut)+(5*smallprefbut)),y1,smallprefbut,buth,
2162                         &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
2163         
2164         } else if(U.userpref == 2) { /* language & colors */
2165
2166 #ifdef INTERNATIONAL
2167                 char curfont[320];
2168
2169                 sprintf(curfont, "Interface Font: ");
2170                 strcat(curfont,U.fontname);
2171
2172                 uiDefButS(block, TOG|BIT|5, B_DOLANGUIFONT, "International Fonts",
2173                         xpos,y2,medprefbut,buth,
2174                         &(U.transopts), 0, 0, 0, 0, "Activate international interface");
2175
2176                 if(U.transopts & TR_ALL) {
2177                         uiDefBut(block, LABEL,0,curfont,
2178                                 (xpos+edgespace+medprefbut+midspace),y2,medprefbut,buth,
2179                                 0, 0, 0, 0, 0, "");
2180
2181                         uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
2182                                 xpos,y1,medprefbut,buth,
2183                                 0, 0, 0, 0, 0, "Select a new font for the interface");
2184
2185
2186                         uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
2187                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
2188                                 &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
2189
2190 /*
2191                         uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
2192                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
2193                                 &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
2194
2195
2196                         uiDefBut(block, LABEL,0,"Translate:",
2197                                 (xpos+edgespace+(2.1*medprefbut)+(2*midspace)),y3label,medprefbut,buth,
2198                                 0, 0, 0, 0, 0, "");
2199 */
2200
2201                         uiDefButS(block, TOG|BIT|0, B_SETTRANSBUTS, "Tooltips",
2202                                 (xpos+edgespace+(2.2*medprefbut)+(3*midspace)),y1,smallprefbut,buth,
2203                                 &(U.transopts), 0, 0, 0, 0, "Translate tooltips");
2204
2205                         uiDefButS(block, TOG|BIT|1, B_SETTRANSBUTS, "Buttons",
2206                                 (xpos+edgespace+(2.2*medprefbut)+(4*midspace)+smallprefbut),y1,smallprefbut,buth,
2207                                 &(U.transopts), 0, 0, 0, 0, "Translate button labels");
2208
2209                         uiDefButS(block, TOG|BIT|2, B_SETTRANSBUTS, "Toolbox",
2210                                 (xpos+edgespace+(2.2*medprefbut)+(5*midspace)+(2*smallprefbut)),y1,smallprefbut,buth,
2211                                 &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
2212
2213                         uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
2214                                 (xpos+edgespace+(2.2*medprefbut)+(3*midspace)),y2,medprefbut+(0.5*medprefbut)+3,buth,
2215                                 &U.language, 0, 0, 0, 0, "Select interface language");
2216                                 
2217                         /* uiDefButS(block, TOG|BIT|3, B_SETTRANSBUTS, "FTF All windows",
2218                                 (xpos+edgespace+(4*medprefbut)+(4*midspace)),y1,medprefbut,buth,
2219                                 &(U.transopts), 0, 0, 0, 0,
2220                                 "Use FTF drawing for fileselect and textwindow "
2221                                 "(under construction)");
2222                         */
2223                 }
2224
2225 /* end of INTERNATIONAL */
2226 #endif
2227
2228         } else if(U.userpref == 3) { /* auto save */
2229
2230
2231                 uiDefButS(block, TOG|BIT|0, B_RESETAUTOSAVE, "Auto Save Temp Files",
2232                         (xpos+edgespace),y2,medprefbut,buth,
2233                         &(U.flag), 0, 0, 0, 0,
2234                         "Enables automatic saving of temporary files");
2235
2236                 if(U.flag & AUTOSAVE) {
2237
2238                         uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
2239                                 (xpos+edgespace),y1,medprefbut,buth,
2240                                 0, 0, 0, 0, 0,"Opens the most recently saved temporary file");
2241
2242                         uiDefButI(block, NUM, B_RESETAUTOSAVE, "Minutes:",
2243                                 (xpos+edgespace+medprefbut+midspace),y2,medprefbut,buth,
2244                                 &(U.savetime), 1.0, 60.0, 0, 0,
2245                                 "The time (in minutes) to wait between automatic temporary saves");
2246
2247                         uiDefButS(block, NUM, 0, "Versions:",
2248                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
2249                                 &U.versions, 0.0, 32.0, 0, 0,
2250                                 "The number of old versions to maintain when saving");
2251                 }
2252
2253         } else if (U.userpref == 4) { /* system & opengl */
2254                 uiDefBut(block, LABEL,0,"Solid OpenGL light:",
2255                         xpos+edgespace, y3label, medprefbut, buth,
2256                         0, 0, 0, 0, 0, "");
2257                 
2258                 uiDefButS(block, MENU, B_REDR, "Light1 %x0|Light2 %x1|Light3 %x2",
2259                         xpos+edgespace, y2, 2*medprefbut/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
2260                 uiBlockSetCol(block, TH_BUT_SETTING1);
2261                 uiDefButI(block, TOG|BIT|0, B_RECALCLIGHT, "On",
2262                         xpos+edgespace+2*medprefbut/6, y2, medprefbut/6, buth, 
2263                         &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "");
2264                         
2265                 uiBlockSetCol(block, TH_AUTO);
2266                 uiDefButS(block, ROW, B_REDR, "Vec",
2267                         xpos+edgespace+3*medprefbut/6, y2, medprefbut/6, buth, 
2268                         &cur_light_var, 123.0, 0.0, 0, 0, "");
2269                 uiDefButS(block, ROW, B_REDR, "Col",
2270                         xpos+edgespace+4*medprefbut/6, y2, medprefbut/6, buth, 
2271                         &cur_light_var, 123.0, 1.0, 0, 0, "");
2272                 uiDefButS(block, ROW, B_REDR, "Spec",
2273                         xpos+edgespace+5*medprefbut/6, y2, medprefbut/6, buth, 
2274                         &cur_light_var, 123.0, 2.0, 0, 0, "");
2275
2276                 if(cur_light_var==1) {
2277                         uiDefButF(block, NUM, B_RECALCLIGHT, "R ",
2278                                 xpos+edgespace, y1, medprefbut/3, buth, 
2279                                 U.light[cur_light].col, 0.0, 1.0, 100, 2, "");
2280                         uiDefButF(block, NUM, B_RECALCLIGHT, "G ",
2281                                 xpos+edgespace+medprefbut/3, y1, medprefbut/3, buth, 
2282                                 U.light[cur_light].col+1, 0.0, 1.0, 100, 2, "");
2283                         uiDefButF(block, NUM, B_RECALCLIGHT, "B ",
2284                                 xpos+edgespace+2*medprefbut/3, y1, medprefbut/3, buth, 
2285                                 U.light[cur_light].col+2, 0.0, 1.0, 100, 2, "");
2286                 }
2287                 else if(cur_light_var==2) {
2288                         uiDefButF(block, NUM, B_RECALCLIGHT, "sR ",
2289                                 xpos+edgespace, y1, medprefbut/3, buth, 
2290                                 U.light[cur_light].spec, 0.0, 1.0, 100, 2, "");
2291                         uiDefButF(block, NUM, B_RECALCLIGHT, "sG ",
2292                                 xpos+edgespace+medprefbut/3, y1, medprefbut/3, buth, 
2293                                 U.light[cur_light].spec+1, 0.0, 1.0, 100, 2, "");
2294                         uiDefButF(block, NUM, B_RECALCLIGHT, "sB ",
2295                                 xpos+edgespace+2*medprefbut/3, y1, medprefbut/3, buth, 
2296                                 U.light[cur_light].spec+2, 0.0, 1.0, 100, 2, "");
2297                 }
2298                 else if(cur_light_var==0) {
2299                         uiDefButF(block, NUM, B_RECALCLIGHT, "X ",
2300                                 xpos+edgespace, y1, medprefbut/3, buth, 
2301                                 U.light[cur_light].vec, -1.0, 1.0, 100, 2, "");
2302                         uiDefButF(block, NUM, B_RECALCLIGHT, "Y ",
2303                                 xpos+edgespace+medprefbut/3, y1, medprefbut/3, buth, 
2304                                 U.light[cur_light].vec+1, -1.0, 1.0, 100, 2, "");
2305                         uiDefButF(block, NUM, B_RECALCLIGHT, "Z ",
2306                                 xpos+edgespace+2*medprefbut/3, y1, medprefbut/3, buth, 
2307                                 U.light[cur_light].vec+2, -1.0, 1.0, 100, 2, "");
2308                 }
2309
2310 /*
2311                 uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
2312                         (xpos+edgespace),y2,largeprefbut,buth,
2313                         &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
2314
2315                 uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
2316                         (xpos+edgespace), y1, largeprefbut,buth,
2317                         &U.console_out, 0, 0, 0, 0, "Select console output method");
2318
2319                 uiDefButS(block, NUM, B_CONSOLENUMLINES, "Lines:",
2320                         (xpos+edgespace+largeprefbut+midspace),y1,smallprefbut,buth,
2321                         &U.console_buffer, 1.0, 4000.0, 0, 0, "Maximum number of internal console lines");
2322 */
2323
2324 #ifdef _WIN32
2325                 uiDefBut(block, LABEL,0,"Win Codecs:",
2326                         (xpos+edgespace+(1*midspace)+(1*medprefbut)),y3label,medprefbut,buth,
2327                         0, 0, 0, 0, 0, "");
2328
2329                 uiDefButS(block, TOG|BIT|8, 0, "Enable all codecs",
2330                         (xpos+edgespace+(1*medprefbut)+(1*midspace)),y2,medprefbut,buth,
2331                         &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
2332 #endif
2333
2334                 uiDefBut(block, LABEL,0,"Keyboard:",
2335                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y3label,medprefbut,buth,
2336                         0, 0, 0, 0, 0, "");
2337
2338                 uiDefButS(block, TOG|BIT|9, B_U_CAPSLOCK, "Disable Caps Lock",
2339                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y1,medprefbut,buth,
2340                         &(U.flag), 0, 0, 0, 0,
2341                         "Disables the Caps Lock key when entering text");
2342
2343                 uiDefButS(block, TOG|BIT|13, 0, "Emulate Numpad",
2344                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y2,medprefbut,buth,
2345                         &(U.flag), 0, 0, 0, 0,
2346                         "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
2347
2348
2349                 uiDefBut(block, LABEL,0,"System:",
2350                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y3label,medprefbut,buth,
2351                         0, 0, 0, 0, 0, "");
2352
2353                 uiDefButI(block, TOG|BIT|USERDEF_DISABLE_SOUND_BIT, B_SOUNDTOGGLE, "Disable Sound",
2354                         (xpos+edgespace+(4*medprefbut)+(4*midspace)),y2,medprefbut,buth,
2355                         &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
2356
2357                 uiDefButS(block, TOG|BIT|3, 0, "Filter File Extensions",
2358                         (xpos+edgespace+(4*medprefbut)+(4*midspace)),y1,medprefbut,buth,
2359                         &(U.uiflag), 0, 0, 0, 0, "Display only files with extensions in the image select window");
2360
2361
2362                 uiDefBut(block, LABEL,0,"OpenGL:",
2363                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y3label,medprefbut,buth,
2364                         0, 0, 0, 0, 0, "");
2365
2366                 uiDefButI(block, TOGN|BIT|USERDEF_DISABLE_MIPMAP_BIT, B_MIPMAPCHANGED, "Mipmaps",
2367                         (xpos+edgespace+(5*medprefbut)+(5*midspace)),y2,medprefbut,buth,
2368                         &(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
2369
2370                 uiDefButI(block, TOG|BIT|USERDEF_VERTEX_ARRAYS_BIT, 0, "Vertex Arrays",
2371                         (xpos+edgespace+(5*medprefbut)+(5*midspace)),y1,medprefbut,buth,
2372                         &(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
2373
2374                 uiDefBut(block, LABEL,0,"Audio:",
2375                         (xpos+edgespace+(2*midspace)+(2*medprefbut)),y3label,medprefbut,buth,
2376                         0, 0, 0, 0, 0, "");
2377
2378                 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");
2379                 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");      
2380                 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");               
2381                 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");                   
2382
2383         } else if(U.userpref == 5) { /* file paths */
2384
2385
2386                 uiDefBut(block, TEX, 0, "Fonts: ",
2387                         (xpos+edgespace),y2,(largeprefbut-smfileselbut),buth,
2388                         U.fontdir, 1.0, 63.0, 0, 0,
2389                         "The default directory to search for loading fonts");
2390                 uiDefIconBut(block, BUT, B_FONTDIRFILESEL, ICON_FILESEL,
2391                         (xpos+edgespace+largeprefbut-smfileselbut),y2,smfileselbut,buth,
2392                         0, 0, 0, 0, 0, "Select the default font directory");
2393
2394                 uiDefBut(block, TEX, 0, "Textures: ",
2395                         (xpos+edgespace+largeprefbut+midspace),y2,(largeprefbut-smfileselbut),buth,
2396                         U.textudir, 1.0, 63.0, 0, 0, "The default directory to search for textures");
2397                 uiDefIconBut(block, BUT, B_TEXTUDIRFILESEL, ICON_FILESEL,
2398                         (xpos+edgespace+(2*largeprefbut)+midspace-smfileselbut),y2,smfileselbut,buth,
2399                         0, 0, 0, 0, 0, "Select the default texture location");
2400
2401
2402                 uiDefBut(block, TEX, 0, "Tex Plugins: ",
2403                         (xpos+edgespace+(2*largeprefbut)+(2*midspace)),y2,(largeprefbut-smfileselbut),buth,
2404                         U.plugtexdir, 1.0, 63.0, 0, 0, "The default directory to search for texture plugins");
2405                 uiDefIconBut(block, BUT, B_PLUGTEXDIRFILESEL, ICON_FILESEL,
2406                         (xpos+edgespace+(3*largeprefbut)+(2*midspace)-smfileselbut),y2,smfileselbut,buth,
2407                         0, 0, 0, 0, 0, "Select the default texture plugin location");
2408
2409                 uiDefBut(block, TEX, 0, "Seq Plugins: ",
2410                         (xpos+edgespace+(3*largeprefbut)+(3*midspace)),y2,(largeprefbut-smfileselbut),buth,
2411                         U.plugseqdir, 1.0, 63.0, 0, 0, "The default directory to search for sequence plugins");
2412                 uiDefIconBut(block, BUT, B_PLUGSEQDIRFILESEL, ICON_FILESEL,
2413                         (xpos+edgespace+(4*largeprefbut)+(3*midspace)-smfileselbut),y2,smfileselbut,buth,
2414                         0, 0, 0, 0, 0, "Select the default sequence plugin location");
2415
2416
2417                 uiDefBut(block, TEX, 0, "Render: ",
2418                         (xpos+edgespace),y1,(largeprefbut-smfileselbut),buth,
2419                         U.renderdir, 1.0, 63.0, 0, 0, "The default directory for rendering output");
2420                 uiDefIconBut(block, BUT, B_RENDERDIRFILESEL, ICON_FILESEL,
2421                         (xpos+edgespace+largeprefbut-smfileselbut),y1,smfileselbut,buth,
2422                         0, 0, 0, 0, 0, "Select the default render output location");
2423
2424                 uiDefBut(block, TEX, 0, "Python: ",
2425                         (xpos+edgespace+largeprefbut+midspace),y1,(largeprefbut-smfileselbut),buth,
2426                         U.pythondir, 1.0, 63.0, 0, 0, "The default directory to search for Python scripts");
2427                 uiDefIconBut(block, BUT, B_PYTHONDIRFILESEL, ICON_FILESEL,
2428                         (xpos+edgespace+(2*largeprefbut)+midspace-smfileselbut),y1,smfileselbut,buth,
2429                         0, 0, 0, 0, 0, "Select the default Python script location");
2430
2431
2432                 uiDefBut(block, TEX, 0, "Sounds: ",
2433                         (xpos+edgespace+(2*largeprefbut)+(2*midspace)),y1,(largeprefbut-smfileselbut),buth,
2434                         U.sounddir, 1.0, 63.0, 0, 0, "The default directory to search for sounds");
2435                 uiDefIconBut(block, BUT, B_SOUNDDIRFILESEL, ICON_FILESEL,
2436                         (xpos+edgespace+(3*largeprefbut)+(2*midspace)-smfileselbut),y1,smfileselbut,buth,
2437                         0, 0, 0, 0, 0, "Select the default sound location");
2438
2439                 uiDefBut(block, TEX, 0, "Temp: ",
2440                          (xpos+edgespace+(3*largeprefbut)+(3*midspace)),y1,(largeprefbut-smfileselbut),buth,
2441                          U.tempdir, 1.0, 63.0, 0, 0, "The directory for storing temporary save files");
2442                 uiDefIconBut(block, BUT, B_TEMPDIRFILESEL, ICON_FILESEL,
2443                         (xpos+edgespace+(4*largeprefbut)+(3*midspace)-smfileselbut),y1,smfileselbut,buth,
2444                         0, 0, 0, 0, 0, "Select the default temporary save file location");
2445
2446         }
2447
2448         uiDrawBlock(block);
2449         
2450         myortho2(-0.375, (float)(sa->winx)-0.375, -0.375, (float)(sa->winy)-0.375);
2451         draw_area_emboss(sa);
2452         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2453         sa->win_swap= WIN_BACK_OK;
2454         
2455 }
2456
2457
2458 void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2459 {
2460         unsigned short event= evt->event;
2461         short val= evt->val;
2462         
2463         if(val) {
2464                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2465
2466                 switch(event) {
2467                 case UI_BUT_EVENT:
2468                         if(val==B_ADD_THEME) {
2469                                 bTheme *btheme, *new;
2470                                 
2471                                 btheme= U.themes.first;
2472                                 new= MEM_callocN(sizeof(bTheme), "theme");
2473                                 memcpy(new, btheme, sizeof(bTheme));
2474                                 BLI_addhead(&U.themes, new);
2475                                 strcpy(new->name, "New User Theme");
2476                                 addqueue(sa->win, REDRAW, 1);
2477                         }
2478                         else if(val==B_DEL_THEME) {
2479                                 bTheme *btheme= U.themes.first;
2480                                 BLI_remlink(&U.themes, btheme);
2481                                 MEM_freeN(btheme);
2482                                 BIF_SetTheme(curarea); // prevent usage of old theme in calls   
2483                                 addqueue(sa->win, REDRAW, 1);
2484                         }
2485                         else if(val==B_NAME_THEME) {
2486                                 bTheme *btheme= U.themes.first;
2487                                 if(strcmp(btheme->name, "Default")==0) {
2488                                         strcpy(btheme->name, "New User Theme");
2489                                         addqueue(sa->win, REDRAW, 1);
2490                                 }
2491                         }
2492                         else if(val==B_UPDATE_THEME) {
2493                                 allqueue(REDRAWALL, 0);
2494                         }
2495                         else if(val==B_CHANGE_THEME) {
2496                                 th_curcol= TH_BACK;     // backdrop color is always there...
2497                                 addqueue(sa->win, REDRAW, 1);
2498                         }
2499                         else if(val==B_THEME_COPY) {
2500                                 if(th_curcol_ptr) {
2501                                         th_curcol_arr[0]= th_curcol_ptr[0];
2502                                         th_curcol_arr[1]= th_curcol_ptr[1];
2503                                         th_curcol_arr[2]= th_curcol_ptr[2];
2504                                         th_curcol_arr[3]= th_curcol_ptr[3];
2505                                         addqueue(sa->win, REDRAW, 1);
2506                                 }
2507                         }
2508                         else if(val==B_THEME_PASTE) {
2509                                 if(th_curcol_ptr) {
2510                                         th_curcol_ptr[0]= th_curcol_arr[0];
2511                                         th_curcol_ptr[1]= th_curcol_arr[1];
2512                                         th_curcol_ptr[2]= th_curcol_arr[2];
2513                                         th_curcol_ptr[3]= th_curcol_arr[3];
2514                                         allqueue(REDRAWALL, 0);
2515                                 }
2516                         }
2517                         else if(val==B_RECALCLIGHT) {
2518                                 if(U.light[0].flag==0 && U.light[1].flag==0 && U.light[2].flag==0)
2519                                         U.light[0].flag= 1;
2520                                 
2521                                 default_gl_light();
2522                                 addqueue(sa->win, REDRAW, 1);
2523                                 allqueue(REDRAWVIEW3D, 0);
2524                         }
2525                         else do_global_buttons(val);
2526                         
2527                         break;  
2528                 }
2529         }
2530 }
2531
2532 void init_infospace(ScrArea *sa)
2533 {
2534         SpaceInfo *sinfo;
2535         
2536         sinfo= MEM_callocN(sizeof(SpaceInfo), "initinfo");
2537         BLI_addhead(&sa->spacedata, sinfo);
2538
2539         sinfo->spacetype=SPACE_INFO;
2540 }
2541
2542 /* ******************** SPACE: BUTS ********************** */
2543
2544 extern void drawbutspace(ScrArea *sa, void *spacedata); /* buttons.c */
2545
2546 static void changebutspace(ScrArea *sa, void *spacedata)
2547 {
2548         if(G.v2d==0) return;
2549         
2550         test_view2d(G.v2d, curarea->winx, curarea->winy);
2551         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
2552 }
2553
2554 void winqreadbutspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2555 {
2556         unsigned short event= evt->event;
2557         short val= evt->val;
2558         SpaceButs *sbuts= curarea->spacedata.first;
2559         ScrArea *sa2, *sa3d;
2560         int nr, doredraw= 0;
2561
2562         if(val) {
2563                 
2564                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2565
2566                 switch(event) {
2567                 case UI_BUT_EVENT:
2568                         do_butspace(val);
2569                         break;
2570                         
2571                 case MIDDLEMOUSE:
2572                 case WHEELUPMOUSE:
2573                 case WHEELDOWNMOUSE:
2574                         view2dmove(event);      /* in drawipo.c */
2575                         break;
2576                 case PAGEUPKEY:
2577                         event= WHEELUPMOUSE;
2578                         view2dmove(event);      /* in drawipo.c */
2579                         break;
2580                 case PAGEDOWNKEY:
2581                         event= WHEELDOWNMOUSE;
2582                         view2dmove(event);      /* in drawipo.c */
2583                         break;
2584                         
2585                 case RIGHTMOUSE:
2586                         nr= pupmenu("Align buttons%t|Free %x0|Horizontal%x1|Vertical%x2");
2587                         if (nr>=0) {
2588                                 sbuts->align= nr;
2589                                 if(nr) {
2590                                         uiAlignPanelStep(sa, 1.0);
2591                                         do_buts_buttons(B_BUTSHOME);
2592                                 }
2593                         }
2594
2595                         break;
2596                 case PADPLUSKEY:
2597                         view2d_zoom(&sbuts->v2d, 0.06f, curarea->winx, curarea->winy);
2598                         scrarea_queue_winredraw(curarea);
2599                         break;
2600                 case PADMINUS:
2601                         view2d_zoom(&sbuts->v2d, -0.075f, curarea->winx, curarea->winy);
2602                         scrarea_queue_winredraw(curarea);
2603                         break;
2604                 case RENDERPREVIEW:
2605                         BIF_previewrender(sbuts);
2606                         break;
2607                 
2608                 case HOMEKEY:
2609                         do_buts_buttons(B_BUTSHOME);
2610                         break;
2611
2612
2613                 /* if only 1 view, also de persp, excluding arrowkeys */
2614                 case PAD0: case PAD1: case PAD3:
2615                 case PAD5: case PAD7: case PAD9:
2616                 case PADENTER: case ZKEY: case PKEY:
2617                         sa3d= 0;
2618                         sa2= G.curscreen->areabase.first;
2619                         while(sa2) {
2620                                 if(sa2->spacetype==SPACE_VIEW3D) {
2621                                         if(sa3d) return;
2622                                         sa3d= sa2;
2623                                 }
2624                                 sa2= sa2->next;
2625                         }
2626                         if(sa3d) {
2627                                 sa= curarea;
2628                                 areawinset(sa3d->win);
2629                                 
2630                                 if(event==PKEY) start_game();
2631                                 else if(event==ZKEY) toggle_shading();
2632                                 else persptoetsen(event);
2633                                 
2634                                 scrarea_queue_winredraw(sa3d);
2635                                 scrarea_queue_headredraw(sa3d);
2636                                 areawinset(sa->win);
2637                         }
2638                 }
2639         }
2640
2641         if(doredraw) scrarea_queue_winredraw(curarea);
2642 }
2643
2644 void set_rects_butspace(SpaceButs *buts)
2645 {
2646         /* buts space goes from (0,0) to (1280, 228) */
2647
2648         buts->v2d.tot.xmin= 0.0f;
2649         buts->v2d.tot.ymin= 0.0f;
2650         buts->v2d.tot.xmax= 1279.0f;
2651         buts->v2d.tot.ymax= 228.0f;
2652         
2653         buts->v2d.min[0]= 256.0f;
2654         buts->v2d.min[1]= 42.0f;
2655
2656         buts->v2d.max[0]= 2048.0f;
2657         buts->v2d.max[1]= 450.0f;
2658         
2659         buts->v2d.minzoom= 0.5f;
2660         buts->v2d.maxzoom= 1.21f;
2661         
2662         buts->v2d.scroll= 0;
2663         buts->v2d.keepaspect= 1;
2664         buts->v2d.keepzoom= 1;
2665         buts->v2d.keeptot= 1;
2666         
2667 }
2668
2669 void test_butspace(void)
2670 {
2671         ScrArea *area= curarea;
2672         int blocksmin= uiBlocksGetYMin(&area->uiblocks)-10.0;
2673         
2674         G.buts->v2d.tot.ymin= MIN2(0.0, blocksmin-10.0);
2675 }
2676
2677 void init_butspace(ScrArea *sa)
2678 {
2679         SpaceButs *buts;
2680         
2681         buts= MEM_callocN(sizeof(SpaceButs), "initbuts");
2682         BLI_addhead(&sa->spacedata, buts);
2683
2684         buts->spacetype= SPACE_BUTS;
2685         buts->scaflag= BUTS_SENS_LINK|BUTS_SENS_ACT|BUTS_CONT_ACT|BUTS_ACT_ACT|BUTS_ACT_LINK;
2686
2687         /* set_rects only does defaults, so after reading a file the cur has not changed */
2688         set_rects_butspace(buts);
2689         buts->v2d.cur= buts->v2d.tot;
2690 }
2691
2692 void extern_set_butspace(int fkey)
2693 {
2694         ScrArea *sa;
2695         SpaceButs *sbuts;
2696         
2697         /* when a f-key pressed: closest button window is initialized */
2698         if(curarea->spacetype==SPACE_BUTS) sa= curarea;
2699         else {
2700                 /* find area */
2701                 sa= G.curscreen->areabase.first;
2702                 while(sa) {
2703                         if(sa->spacetype==SPACE_BUTS) break;
2704                         sa= sa->next;
2705                 }
2706         }
2707         
2708         if(sa==0) return;
2709         
2710         if(sa!=curarea) areawinset(sa->win);
2711         
2712         sbuts= sa->spacedata.first;
2713         
2714         if(fkey==F4KEY) {
2715                 sbuts->mainb= CONTEXT_LOGIC;
2716         }
2717         else if(fkey==F5KEY) {
2718                 sbuts->mainb= CONTEXT_SHADING;
2719                 if(OBACT) {
2720                         if(OBACT->type==OB_CAMERA) 
2721                                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_WORLD;
2722                         else if(OBACT->type==OB_LAMP) 
2723                                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_LAMP;
2724                         else  
2725                                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
2726                 }
2727                 else sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
2728         }
2729         else if(fkey==F6KEY) {
2730                 sbuts->mainb= CONTEXT_SHADING;
2731                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_TEX;
2732         }
2733         else if(fkey==F7KEY) sbuts->mainb= CONTEXT_OBJECT;
2734         else if(fkey==F8KEY) {
2735                 sbuts->mainb= CONTEXT_SHADING;
2736                 sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_WORLD;
2737         }
2738         else if(fkey==F9KEY) sbuts->mainb= CONTEXT_EDITING;
2739         else if(fkey==F10KEY) sbuts->mainb= CONTEXT_SCENE;
2740
2741         scrarea_queue_headredraw(sa);
2742         scrarea_queue_winredraw(sa);
2743         BIF_preview_changed(sbuts);
2744 }
2745
2746 /* ******************** SPACE: SEQUENCE ********************** */
2747
2748 /*  extern void drawseqspace(ScrArea *sa, void *spacedata); BIF_drawseq.h */
2749
2750 void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2751 {
2752         unsigned short event= evt->event;
2753         short val= evt->val;
2754         SpaceSeq *sseq= curarea->spacedata.first;
2755         View2D *v2d= &sseq->v2d;
2756         extern Sequence *last_seq;
2757         float dx, dy;
2758         int doredraw= 0, cfra, first;
2759         short mval[2];
2760         
2761         if(curarea->win==0) return;
2762
2763         if(val) {
2764                 
2765                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2766
2767                 switch(event) {
2768                 case LEFTMOUSE:
2769                         if(sseq->mainb || view2dmove(event)==0) {
2770                                 
2771                                 first= 1;               
2772                                 set_special_seq_update(1);
2773
2774                                 do {
2775                                         getmouseco_areawin(mval);
2776                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
2777                                         
2778                                         cfra= (int)dx;
2779                                         if(cfra< 1) cfra= 1;
2780                                         /* else if(cfra> EFRA) cfra= EFRA; */
2781                                         
2782                                         if( cfra!=CFRA || first ) {
2783                                                 first= 0;
2784                                 
2785                                                 CFRA= cfra;
2786                                                 force_draw();
2787                                                 update_for_newframe();  /* for audio scrubbing */                                               
2788                                         }
2789                                 
2790                                 } while(get_mbut()&L_MOUSE);
2791                                 
2792                                 set_special_seq_update(0);
2793                                 
2794                                 update_for_newframe();
2795                         }
2796                         break;
2797                 case MIDDLEMOUSE:
2798                 case WHEELUPMOUSE:
2799                 case WHEELDOWNMOUSE:
2800                         if(sseq->mainb) break;
2801                         view2dmove(event);      /* in drawipo.c */
2802                         break;
2803                 case RIGHTMOUSE:
2804                         if(sseq->mainb) break;
2805                         mouse_select_seq();
2806                         break;
2807                 case PADPLUSKEY:
2808                         if(sseq->mainb) {
2809                                 sseq->zoom++;
2810                                 if(sseq->zoom>8) sseq->zoom= 8;
2811                         }
2812                         else {
2813                                 if((G.qual==0)) {
2814                                         dx= 0.1154*(v2d->cur.xmax-v2d->cur.xmin);
2815                                         v2d->cur.xmin+= dx;
2816                                         v2d->cur.xmax-= dx;
2817                                         test_view2d(G.v2d, curarea->winx, curarea->winy);
2818                                 }
2819                                 else if((G.qual==LR_SHIFTKEY)) {
2820                                         insert_gap(25, CFRA);
2821                                         allqueue(REDRAWSEQ, 0);
2822                                 }
2823                                 else if(G.qual==LR_ALTKEY) {
2824                                         insert_gap(250, CFRA);
2825                                         allqueue(REDRAWSEQ, 0);
2826                                 }
2827                         }
2828                         doredraw= 1;
2829                         break;
2830                 case PADMINUS:
2831                         if(sseq->mainb) {
2832                                 sseq->zoom--;
2833                                 if(sseq->zoom<1) sseq->zoom= 1;