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