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