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