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