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