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