ca5e3ec102303587c579d35045b05e5c5e5f8f20
[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                                 break;
1019                         case FKEY:
1020                                 if(G.obedit) {
1021                                         if(G.obedit->type==OB_MESH) {
1022                                                 if((G.qual==LR_SHIFTKEY))
1023                                                         fill_mesh();
1024                                                 else if(G.qual==LR_ALTKEY)
1025                                                         beauty_fill();
1026                                                 else if(G.qual==LR_CTRLKEY)
1027                                                         edge_flip();
1028                                                 else if (G.qual==0)
1029                                                         addedgevlak_mesh();
1030                                         }
1031                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addsegment_nurb();
1032                                 }
1033                                 else if(G.qual==LR_CTRLKEY)
1034                                         sort_faces();
1035                                 else if((G.qual==LR_SHIFTKEY))
1036                                         fly();
1037                                 else {
1038                                                 set_faceselect();
1039                                         }
1040                                 
1041                                 break;
1042                         case GKEY:
1043                                 /* RMGRP if(G.qual & LR_CTRLKEY) add_selected_to_group();
1044                                 else if(G.qual & LR_ALTKEY) rem_selected_from_group(); */
1045                                 
1046                                 if((G.qual==LR_SHIFTKEY))
1047                                         select_group_menu();
1048                                 else if(G.qual==LR_ALTKEY)
1049                                         clear_object('g');
1050                                 else if((G.qual==0))
1051                                         transform('g');
1052                                 break;
1053                         case HKEY:
1054                                 if(G.obedit) {
1055                                         if(G.obedit->type==OB_MESH) {
1056                                                 if(G.qual==LR_ALTKEY)
1057                                                         reveal_mesh();
1058                                                 else if((G.qual==LR_SHIFTKEY))
1059                                                         hide_mesh(1);
1060                                                 else if((G.qual==0)) 
1061                                                         hide_mesh(0);
1062                                         }
1063                                         else if(G.obedit->type== OB_SURF) {
1064                                                 if(G.qual==LR_ALTKEY)
1065                                                         revealNurb();
1066                                                 else if((G.qual==LR_SHIFTKEY))
1067                                                         hideNurb(1);
1068                                                 else if((G.qual==0))
1069                                                         hideNurb(0);
1070                                         }
1071                                         else if(G.obedit->type==OB_CURVE) {
1072                                                 if(G.qual==LR_CTRLKEY)
1073                                                         autocalchandlesNurb_all(1);     /* flag=1, selected */
1074                                                 else if((G.qual==LR_SHIFTKEY))
1075                                                         sethandlesNurb(1);
1076                                                 else if((G.qual==0))
1077                                                         sethandlesNurb(3);
1078                                                 
1079                                                 makeDispList(G.obedit);
1080                                                 
1081                                                 allqueue(REDRAWVIEW3D, 0);
1082                                         }
1083                                 }
1084                                 else if(G.f & G_FACESELECT)
1085                                         hide_tface();
1086                                 else if(G.obpose) {
1087                                         if (G.qual==0)
1088                                                 hide_selected_pose_bones();
1089                                         else if (G.qual==LR_SHIFTKEY)
1090                                                 hide_unselected_pose_bones();
1091                                         else if (G.qual==LR_ALTKEY)
1092                                                 show_all_pose_bones();
1093                                 }
1094                                 break;
1095                         case IKEY:
1096                                 break;
1097                                 
1098                         case JKEY:
1099                                 if(G.qual==LR_CTRLKEY) {
1100                                         if( (ob= OBACT) ) {
1101                                                 if(ob->type == OB_MESH)
1102                                                         join_mesh();
1103                                                 else if(ob->type == OB_CURVE)
1104                                                         join_curve(OB_CURVE);
1105                                                 else if(ob->type == OB_SURF)
1106                                                         join_curve(OB_SURF);
1107                                                 else if(ob->type == OB_ARMATURE)
1108                                                         join_armature ();
1109                                         }
1110                                         else if ((G.obedit) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
1111                                                 addsegment_nurb();
1112                                 }
1113                                 else if(G.obedit) {
1114                                         if(G.obedit->type==OB_MESH) {
1115                                                 join_triangles();
1116                                         }
1117                                 }
1118
1119                                 break;
1120                         case KKEY:
1121                                 if(G.obedit) {
1122                                         if (G.obedit->type==OB_MESH) {
1123                                                 if (G.qual==LR_SHIFTKEY)
1124                                                         KnifeSubdivide(KNIFE_PROMPT);
1125                                                 else if (G.qual==0)
1126                                                         LoopMenu();
1127                                         }
1128                                         else if(G.obedit->type==OB_SURF)
1129                                                 printknots();
1130                                 }
1131                                 else {
1132                                         if((G.qual==LR_SHIFTKEY)) {
1133                                                 if(G.f & G_FACESELECT)
1134                                                         clear_vpaint_selectedfaces();
1135                                                 else if(G.f & G_VERTEXPAINT)
1136                                                         clear_vpaint();
1137                                                 else
1138                                                         select_select_keys();
1139                                         }
1140                                         else if(G.qual==LR_CTRLKEY)
1141                                                 make_skeleton();
1142 /*                                      else if(G.qual & LR_ALTKEY) delete_skeleton(); */
1143                                         else if (G.qual==0)
1144                                                 set_ob_ipoflags();
1145                                 }
1146                                 
1147                                 break;
1148                         case LKEY:
1149                                 if(G.obedit) {
1150                                         if(G.obedit->type==OB_MESH)
1151                                                 selectconnected_mesh(G.qual);
1152                                         if(G.obedit->type==OB_ARMATURE)
1153                                                 selectconnected_armature();
1154                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
1155                                                 selectconnected_nurb();
1156                                 }
1157                                 else if(G.obpose) {
1158                                         if(G.obpose->type==OB_ARMATURE)
1159                                                 selectconnected_posearmature();
1160                                 }
1161                                 else {
1162                                         if((G.qual==LR_SHIFTKEY))
1163                                                 selectlinks_menu();
1164                                         else if(G.qual==LR_CTRLKEY)
1165                                                 make_links_menu();
1166                                         else if(G.f & G_FACESELECT)
1167                                                 select_linked_tfaces();
1168                                         else if((G.qual==0))
1169                                                 make_local();
1170                                 }
1171                                 break;
1172                         case MKEY:
1173                                 if(G.obedit){
1174                                         if(G.qual==LR_ALTKEY) {
1175                                                 if(G.obedit->type==OB_MESH) {
1176                                                         mergemenu();
1177                                                         makeDispList(G.obedit);
1178                                                 }
1179                                         }
1180                                         else if((G.qual==0) || (G.qual==LR_CTRLKEY)) {
1181                                                 mirrormenu();
1182                                         }
1183                                         if(G.qual & (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY)) {
1184                                                 if(G.obedit->type==OB_MESH) select_non_manifold();
1185                                         }
1186                                 }
1187                                 else if(G.qual & LR_CTRLKEY) {
1188                                         mirrormenu();
1189                                 }
1190                                 else if(G.qual==0) {
1191                                      movetolayer();
1192                                 }
1193                                 break;
1194                         case NKEY:
1195                                 if((G.qual==0)) {
1196                                         toggle_blockhandler(curarea, VIEW3D_HANDLER_OBJECT, UI_PNL_TO_MOUSE);
1197                                         allqueue(REDRAWVIEW3D, 0);
1198                                 }
1199                                 else if(G.obedit) {
1200                                         switch (G.obedit->type){
1201                                         case OB_ARMATURE:
1202                                                 if(G.qual==LR_CTRLKEY){
1203                                                         if (okee("Recalculate bone roll angles")) {
1204                                                                 auto_align_armature();
1205                                                                 allqueue(REDRAWVIEW3D, 0);
1206                                                         }
1207                                                 }
1208                                                 break;
1209                                         case OB_MESH: 
1210                                                 if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
1211                                                         if(okee("Recalculate normals inside")) {
1212                                                                 undo_push_mesh("Recalculate normals inside");
1213                                                                 righthandfaces(2);
1214                                                                 allqueue(REDRAWVIEW3D, 0);
1215                                                         }
1216                                                 }
1217                                                 else if(G.qual==LR_CTRLKEY){
1218                                                         if(okee("Recalculate normals outside")) {
1219                                                                 undo_push_mesh("Recalculate normals outside");
1220                                                                 righthandfaces(1);
1221                                                                 allqueue(REDRAWVIEW3D, 0);
1222                                                         }
1223                                                 }
1224                                                 break;
1225                                         }
1226                                 }
1227                                 
1228                                 break;
1229                         case OKEY:
1230                                 ob= OBACT;
1231                                 if(G.obedit) {
1232                                         extern int prop_mode;
1233
1234                                         if (G.qual==LR_SHIFTKEY) {
1235                                                 prop_mode= !prop_mode;
1236                                                 allqueue(REDRAWHEADERS, 0);
1237                                         }
1238                                         else if((G.qual==0)) {
1239                                                 G.f ^= G_PROPORTIONAL;
1240                                                 allqueue(REDRAWHEADERS, 0);
1241                                         }
1242                                 }
1243                                 else if((G.qual==LR_SHIFTKEY)) {
1244                                         if(ob && ob->type == OB_MESH) {
1245                                                 flip_subdivison(ob, -1);
1246                                         }
1247                                 }
1248                                 else if(G.qual==LR_ALTKEY) clear_object('o');
1249                                 break;
1250
1251                         case PKEY:
1252                                 
1253                                 if(G.obedit) {
1254                                         if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
1255                                                 make_parent();
1256                                         else if((G.qual==0) && G.obedit->type==OB_MESH)
1257                                                 separatemenu();
1258                                         else if ((G.qual==0) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
1259                                                 separate_nurb();
1260                                 }
1261                                 else if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
1262                                         make_parent();
1263                                 else if(G.qual==LR_ALTKEY)
1264                                         clear_parent();
1265                                 else if((G.qual==0)) {
1266                         start_game();
1267                                 }
1268                                 break;                          
1269                         case RKEY:
1270                                 if((G.obedit==0) && (G.f & G_FACESELECT) && (G.qual==0))
1271                                         rotate_uv_tface();
1272                                 else if(G.qual==LR_ALTKEY)
1273                                         clear_object('r');
1274                                 else if (G.obedit) {
1275                                         if((G.qual==LR_SHIFTKEY)) {
1276                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF)                                     
1277                                                         selectrow_nurb();
1278                                                 else if (G.obedit->type==OB_MESH)
1279                                                         loopoperations(LOOP_SELECT);
1280                                         }
1281                                         else if(G.qual==LR_CTRLKEY) {
1282                                                 if (G.obedit->type==OB_MESH)
1283                                                         loopoperations(LOOP_CUT);
1284                                         }
1285                                         else if((G.qual==0))
1286                                                 transform('r');
1287                                 }
1288                                 else if((G.qual==0))
1289                                         transform('r');
1290                                 break;
1291                         case SKEY:
1292                                 if(G.obedit) {
1293                                         if(G.qual==LR_ALTKEY)
1294                                                 transform('N'); /* scale along normal */
1295                                         else if(G.qual==LR_CTRLKEY)
1296                                                 transform('S');
1297                                         else if(G.qual==LR_SHIFTKEY)
1298                                                 snapmenu();
1299                                         else if((G.qual==0))
1300                                                 transform('s');
1301                                 }
1302                                 else if(G.qual==LR_ALTKEY) {
1303                                         clear_object('s');
1304                                 }
1305                                 else if((G.qual==LR_SHIFTKEY))
1306                                         snapmenu();
1307                                 else if((G.qual==0))
1308                                         transform('s');
1309                                 break;
1310                         case TKEY:
1311                                 if(G.obedit){
1312                                         if((G.qual==LR_CTRLKEY) && G.obedit->type==OB_MESH) {
1313                                                 convert_to_triface(0);
1314                                                 allqueue(REDRAWVIEW3D, 0);
1315                                                 countall();
1316                                                 makeDispList(G.obedit);
1317                                         }
1318                                         else if((G.qual==LR_ALTKEY) && G.obedit->type==OB_CURVE)
1319                                                 clear_tilt();
1320                                         else if((G.qual==0))
1321                                                 transform('t');
1322                                 }
1323                                 else if(G.qual==LR_CTRLKEY) {
1324                                         make_track();
1325                                 }
1326                                 else if(G.qual==LR_ALTKEY) {
1327                                         clear_track();
1328                                 }
1329                                 else if((G.qual==0)){
1330                                         texspace_edit();
1331                                 }
1332                                 
1333                                 break;
1334                         case UKEY:
1335                                 if(G.obedit) {
1336                                         if(G.obedit->type==OB_MESH){
1337                                                 if (G.qual==LR_ALTKEY)
1338                                                         undo_menu_mesh();
1339                                                 else if (G.qual==LR_SHIFTKEY)
1340                                                         undo_redo_mesh();
1341                                                 else if((G.qual==0))
1342                                                         undo_pop_mesh(1);
1343                                         }
1344                                         else if(G.obedit->type==OB_ARMATURE)
1345                                                 remake_editArmature();
1346                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
1347                                                 remake_editNurb();
1348                                         else if(G.obedit->type==OB_LATTICE)
1349                                                 remake_editLatt();
1350                                 }
1351                                 else if((G.qual==0)){
1352                                         if (G.f & G_FACESELECT)
1353                                                 uv_autocalc_tface();
1354                                         else if(G.f & G_WEIGHTPAINT)
1355                                                 wpaint_undo();
1356                                         else if(G.f & G_VERTEXPAINT)
1357                                                 vpaint_undo();
1358                                         else
1359                                                 single_user();
1360                                 }
1361                                 
1362                                 break;
1363                         case VKEY:
1364                                 ob= OBACT;
1365                                 if((G.qual==LR_SHIFTKEY)) {
1366                                         if ((G.obedit) && G.obedit->type==OB_MESH) {
1367                                                 align_view_to_selected(v3d);
1368                                         }
1369                                         else if (G.f & G_FACESELECT) {
1370                                                 align_view_to_selected(v3d);
1371                                         }
1372                                 }
1373                                 else if(G.qual==LR_ALTKEY)
1374                                         image_aspect();
1375                                 else if (G.qual==0){
1376                                         if(G.obedit) {
1377                                                 if(G.obedit->type==OB_CURVE) {
1378                                                         sethandlesNurb(2);
1379                                                         makeDispList(G.obedit);
1380                                                         allqueue(REDRAWVIEW3D, 0);
1381                                                 }
1382                                         }
1383                                         else if(ob && ob->type == OB_MESH) 
1384                                                 set_vpaint();
1385                                 }
1386                                 break;
1387                         case WKEY:
1388                                 if((G.qual==LR_SHIFTKEY)) {
1389                                         transform('w');
1390                                 }
1391                                 else if(G.qual==LR_ALTKEY) {
1392                                         /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
1393                                 }
1394                                 else if(G.qual==LR_CTRLKEY) {
1395                                         if(G.obedit) {
1396                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF) {
1397                                                         switchdirectionNurb2();
1398                                                 }
1399                                         }
1400                                 }
1401                                 else if((G.qual==0))
1402                                         special_editmenu();
1403                                 
1404                                 break;
1405                         case XKEY:
1406                         case DELKEY:
1407                                 if(G.qual==0)
1408                                         delete_context_selected();
1409                                 break;
1410                         case YKEY:
1411                                 if((G.qual==0) && (G.obedit)) {
1412                                         if(G.obedit->type==OB_MESH) split_mesh();
1413                                 }
1414                                 break;
1415                         case ZKEY:
1416                                 toggle_shading();
1417                                 
1418                                 scrarea_queue_headredraw(curarea);
1419                                 scrarea_queue_winredraw(curarea);
1420                                 break;
1421                                 
1422                         
1423                         case HOMEKEY:
1424                                 if(G.qual==0)
1425                                         view3d_home(0);
1426                                 break;
1427                         case COMMAKEY:
1428                                 if(G.qual==LR_CTRLKEY) {
1429                                         G.vd->around= V3D_CENTROID;
1430                                 } else if(G.qual==0) {
1431                                         G.vd->around= V3D_CENTRE;
1432                                 }
1433                                 scrarea_queue_headredraw(curarea);
1434                                 break;
1435                                 
1436                         case PERIODKEY:
1437                                 if(G.qual==LR_CTRLKEY) {
1438                                         G.vd->around= V3D_LOCAL;
1439                                 } else if(G.qual==0) {
1440                                         G.vd->around= V3D_CURSOR;
1441                                 }
1442                                 scrarea_queue_headredraw(curarea);
1443                                 break;
1444                         
1445                         case PADSLASHKEY:
1446                                 if(G.qual==0) {
1447                                         if(G.vd->localview) {
1448                                                 G.vd->localview= 0;
1449                                                 endlocalview(curarea);
1450                                         }
1451                                         else {
1452                                                 G.vd->localview= 1;
1453                                                 initlocalview();
1454                                         }
1455                                         scrarea_queue_headredraw(curarea);
1456                                 }
1457                                 break;
1458                         case PADASTERKEY:       /* '*' */
1459                                 if(G.qual==0) {
1460                                         ob= OBACT;
1461                                         if(ob) {
1462                                                 obmat_to_viewmat(ob);
1463                                                 if(G.vd->persp==2) G.vd->persp= 1;
1464                                                 scrarea_queue_winredraw(curarea);
1465                                         }
1466                                 }
1467                                 break;
1468                         case PADPERIOD: /* '.' */
1469                                 if(G.qual==0)
1470                                         centreview();
1471                                 break;
1472                         
1473                         case PAGEUPKEY:
1474                                 if(G.qual==LR_CTRLKEY)
1475                                         movekey_obipo(1);
1476                                 else if((G.qual==0))
1477                                         nextkey_obipo(1);       /* in editipo.c */
1478                                 break;
1479
1480                         case PAGEDOWNKEY:
1481                                 if(G.qual==LR_CTRLKEY)
1482                                         movekey_obipo(-1);
1483                                 else if((G.qual==0))
1484                                         nextkey_obipo(-1);
1485                                 break;
1486                                 
1487                         case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
1488                         case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
1489                         case PADENTER:
1490                                 persptoetsen(event);
1491                                 doredraw= 1;
1492                                 break;
1493                         case PADMINUS:
1494                                 if ( (G.qual==LR_CTRLKEY)
1495                                          && (G.obedit) && (G.obedit->type==OB_MESH) )
1496                                         select_less();
1497                                 else {
1498                                         persptoetsen(event);
1499                                         doredraw= 1;
1500                                 }
1501                                 break;
1502
1503                         case PADPLUSKEY:
1504                                 if ( (G.qual==LR_CTRLKEY)
1505                                          && (G.obedit) && (G.obedit->type==OB_MESH) )
1506                                         select_more();
1507                                 else {
1508                                         persptoetsen(event);
1509                                         doredraw= 1;
1510                                 }
1511                                 break;
1512
1513                         case ESCKEY:
1514                                 if(G.qual==0) {
1515                                         if (G.vd->flag & V3D_DISPIMAGE) {
1516                                                 G.vd->flag &= ~V3D_DISPIMAGE;
1517                                                 doredraw= 1;
1518                                         }
1519                                 }
1520                                 break;
1521                         }
1522                 }
1523         }
1524         
1525         if(doredraw) {
1526                 scrarea_queue_winredraw(curarea);
1527                 scrarea_queue_headredraw(curarea);
1528         }
1529 }
1530
1531 void initview3d(ScrArea *sa)
1532 {
1533         View3D *vd;
1534         
1535         vd= MEM_callocN(sizeof(View3D), "initview3d");
1536         BLI_addhead(&sa->spacedata, vd);        /* addhead! not addtail */
1537
1538         vd->spacetype= SPACE_VIEW3D;
1539         vd->blockscale= 0.7;
1540         vd->viewquat[0]= 1.0;
1541         vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0;
1542         vd->persp= 1;
1543         vd->drawtype= OB_WIRE;
1544         vd->view= 7;
1545         vd->dist= 10.0;
1546         vd->lens= 35.0f;
1547         vd->near= 0.01f;
1548         vd->far= 500.0f;
1549         vd->grid= 1.0f;
1550         vd->gridlines= 16;
1551         vd->lay= vd->layact= 1;
1552         if(G.scene) {
1553                 vd->lay= vd->layact= G.scene->lay;
1554                 vd->camera= G.scene->camera;
1555         }
1556         vd->scenelock= 1;
1557         vd->gridflag |= V3D_SHOW_X;
1558         vd->gridflag |= V3D_SHOW_Y;
1559         vd->gridflag |= V3D_SHOW_FLOOR;
1560         vd->gridflag &= ~V3D_SHOW_Z;
1561 }
1562
1563
1564 /* ******************** SPACE: IPO ********************** */
1565
1566 static void changeview2dspace(ScrArea *sa, void *spacedata)
1567 {
1568         if(G.v2d==0) return;
1569
1570         test_view2d(G.v2d, curarea->winx, curarea->winy);
1571         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
1572 }
1573
1574 void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
1575 {
1576         extern void do_ipobuts(unsigned short event);   // drawipo.c
1577         unsigned short event= evt->event;
1578         short val= evt->val;
1579         SpaceIpo *sipo= curarea->spacedata.first;
1580         View2D *v2d= &sipo->v2d;
1581         float dx, dy;
1582         int cfra, doredraw= 0;
1583         short mval[2];
1584         
1585
1586         if(sa->win==0) return;
1587
1588         if(val) {
1589                 if( uiDoBlocks(&sa->uiblocks, event)!=UI_NOTHING ) event= 0;
1590
1591                 switch(event) {
1592                 case UI_BUT_EVENT:
1593                         /* note: bad bad code, will be cleaned! is because event queues are all shattered */
1594                         if(val>0 && val < 51) do_ipowin_buts(val-1);
1595                         else do_ipobuts(val);
1596                         break;
1597                         
1598                 case LEFTMOUSE:
1599                         if( in_ipo_buttons() ) {
1600                                 do_ipo_selectbuttons();
1601                                 doredraw= 1;
1602                         }                       
1603                         else if(G.qual & LR_CTRLKEY) add_vert_ipo();
1604                         else {
1605                                 do {
1606                                         getmouseco_areawin(mval);
1607                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
1608                                         
1609                                         cfra= (int)dx;
1610                                         if(cfra< 1) cfra= 1;
1611                                         
1612                                         if( cfra!=CFRA ) {
1613                                                 CFRA= cfra;
1614                                                 update_for_newframe();
1615                                                 force_draw_plus(SPACE_VIEW3D);
1616                                                 force_draw_plus(SPACE_ACTION);
1617                                                 force_draw_plus(SPACE_BUTS);    /* To make constraint sliders redraw */
1618                                         }
1619                                 
1620                                 } while(get_mbut()&L_MOUSE);
1621                         }
1622                         
1623                         break;
1624                 case MIDDLEMOUSE:
1625                         if(in_ipo_buttons()) {
1626                                 scroll_ipobuts();
1627                         }
1628                         else view2dmove(event); /* in drawipo.c */
1629                         break;
1630
1631                 case WHEELUPMOUSE:
1632                 case WHEELDOWNMOUSE:
1633                         view2dmove(event);      /* in drawipo.c */
1634                         break;
1635
1636                 case RIGHTMOUSE:
1637                         mouse_select_ipo();
1638                         allqueue (REDRAWACTION, 0);
1639                         allqueue(REDRAWNLA, 0);
1640                         break;
1641                 case PADPLUSKEY:
1642                         view2d_zoom(v2d, 0.1154, sa->winx, sa->winy);
1643                         doredraw= 1;
1644                         break;
1645                 case PADMINUS:
1646                         view2d_zoom(v2d, -0.15, sa->winx, sa->winy);
1647                         doredraw= 1;
1648                         break;
1649                 case PAGEUPKEY:
1650                         if(G.qual==LR_CTRLKEY)
1651                                 movekey_ipo(1);
1652                         else if((G.qual==0))
1653                                 nextkey_ipo(1);
1654                         break;
1655                 case PAGEDOWNKEY:
1656                         if(G.qual==LR_CTRLKEY)
1657                                 movekey_ipo(-1);
1658                         else if((G.qual==0))
1659                                 nextkey_ipo(-1);
1660                         break;
1661                 case HOMEKEY:
1662                         if((G.qual==0))
1663                                 do_ipo_buttons(B_IPOHOME);
1664                         break;
1665                         
1666                 case AKEY:
1667                         if((G.qual==0)) {
1668                                 if(in_ipo_buttons()) {
1669                                         swap_visible_editipo();
1670                                 }
1671                                 else swap_selectall_editipo();
1672                                 allspace (REMAKEIPO, 0);
1673                                 allqueue (REDRAWNLA, 0);
1674                                 allqueue (REDRAWACTION, 0);
1675                         }
1676                         break;
1677                 case BKEY:
1678                         if((G.qual==0))
1679                                 borderselect_ipo();
1680                         break;
1681                 case CKEY:
1682                         if((G.qual==0))
1683                                 move_to_frame();
1684                         break;
1685                 case DKEY:
1686                         if((G.qual==LR_SHIFTKEY))
1687                                 add_duplicate_editipo();
1688                         break;
1689                 case GKEY:
1690                         if((G.qual==0))
1691                                 transform_ipo('g');
1692                         break;
1693                 case HKEY:
1694                         if((G.qual==LR_SHIFTKEY))
1695                                 sethandles_ipo(HD_AUTO);
1696                         else if((G.qual==0))
1697                                 sethandles_ipo(HD_ALIGN);
1698                         break;
1699                 case JKEY:
1700                         if((G.qual==0))
1701                                 join_ipo_menu();
1702                         break;
1703                 case KKEY:
1704                         if((G.qual==0)) {
1705                                 ipo_toggle_showkey();
1706                                 scrarea_queue_headredraw(curarea);
1707                                 allqueue(REDRAWVIEW3D, 0);
1708                                 doredraw= 1;
1709                         }
1710                         break;
1711                 case NKEY:
1712                         toggle_blockhandler(sa, IPO_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
1713                         doredraw= 1;
1714                         break;
1715                 case RKEY:
1716                         if((G.qual==0))
1717                                 ipo_record();
1718                         break;
1719                 case SKEY:
1720                         if((G.qual==LR_SHIFTKEY)) {             
1721                                 ipo_snap_menu();
1722                         } else if((G.qual==0))
1723                                 transform_ipo('s');
1724                         break;
1725                 case TKEY:
1726                         if((G.qual==0))
1727                                 set_ipotype();
1728                         break;
1729                 case VKEY:
1730                         if((G.qual==0))
1731                                 sethandles_ipo(HD_VECT);
1732                         break;
1733                 case XKEY:
1734                 case DELKEY:
1735                         if((G.qual==LR_SHIFTKEY))
1736                                 delete_key();
1737                         else if((G.qual==0))
1738                                 del_ipo();
1739                         break;
1740                 }
1741         }
1742
1743         if(doredraw) scrarea_queue_winredraw(sa);
1744 }
1745
1746 void initipo(ScrArea *sa)
1747 {
1748         SpaceIpo *sipo;
1749         
1750         sipo= MEM_callocN(sizeof(SpaceIpo), "initipo");
1751         BLI_addhead(&sa->spacedata, sipo);
1752
1753         sipo->spacetype= SPACE_IPO;
1754         sipo->blockscale= 0.7;
1755         
1756         /* sipo space loopt van (0,-?) tot (??,?) */
1757         sipo->v2d.tot.xmin= 0.0;
1758         sipo->v2d.tot.ymin= -10.0;
1759         sipo->v2d.tot.xmax= G.scene->r.efra;
1760         sipo->v2d.tot.ymax= 10.0;
1761
1762         sipo->v2d.cur= sipo->v2d.tot;
1763
1764         sipo->v2d.min[0]= 0.01f;
1765         sipo->v2d.min[1]= 0.01f;
1766
1767         sipo->v2d.max[0]= 15000.0f;
1768         sipo->v2d.max[1]= 10000.0f;
1769         
1770         sipo->v2d.scroll= L_SCROLL+B_SCROLL;
1771         sipo->v2d.keeptot= 0;
1772
1773         sipo->blocktype= ID_OB;
1774 }
1775
1776 /* ******************** SPACE: INFO ********************** */
1777
1778 void space_mipmap_button_function(int event) {
1779         set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
1780
1781         allqueue(REDRAWVIEW3D, 0);
1782 }
1783
1784 void space_sound_button_function(int event)
1785 {
1786         int a;
1787         SYS_SystemHandle syshandle;
1788
1789         if ((syshandle = SYS_GetSystem()))
1790         {
1791                 a = (U.gameflags & USER_DISABLE_SOUND);
1792                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
1793         }
1794 }
1795
1796 #define B_ADD_THEME     3301
1797 #define B_DEL_THEME     3302
1798 #define B_NAME_THEME    3303
1799 #define B_THEMECOL              3304
1800 #define B_UPDATE_THEME  3305
1801 #define B_CHANGE_THEME  3306
1802 #define B_THEME_COPY    3307
1803 #define B_THEME_PASTE   3308
1804
1805 #define B_RECALCLIGHT   3310
1806
1807 // needed for event; choose new 'curmain' resets it...
1808 static short th_curcol= TH_BACK;
1809 static char *th_curcol_ptr= NULL;
1810 static char th_curcol_arr[4]={0, 0, 0, 255};
1811
1812 void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
1813 {
1814         bTheme *btheme, *bt;
1815         int spacetype= 0;
1816         static short cur=1, curmain=2;
1817         short a, tot=0, isbuiltin= 0;
1818         char string[20*32], *strp, *col;
1819         
1820         y3= y2+23;      // exception!
1821         
1822         /* count total, max 16! */
1823         for(bt= U.themes.first; bt; bt= bt->next) tot++;
1824         
1825         /* if cur not is 1; move that to front of list */
1826         if(cur!=1) {
1827                 a= 1;
1828                 for(bt= U.themes.first; bt; bt= bt->next, a++) {
1829                         if(a==cur) {
1830                                 BLI_remlink(&U.themes, bt);
1831                                 BLI_addhead(&U.themes, bt);
1832                                 allqueue(REDRAWALL, 0);
1833                                 cur= 1;
1834                                 break;
1835                         }
1836                 }
1837         }
1838         
1839         /* the current theme */
1840         btheme= U.themes.first;
1841         if(strcmp(btheme->name, "Default")==0) isbuiltin= 1;
1842
1843         /* construct popup script */
1844         string[0]= 0;
1845         for(bt= U.themes.first; bt; bt= bt->next) {
1846                 strcat(string, bt->name);
1847                 if(btheme->next) strcat(string, "   |");
1848         }
1849         uiDefButS(block, MENU, B_UPDATE_THEME, string,                  45,y3,200,20, &cur, 0, 0, 0, 0, "Current theme");
1850         
1851         /* add / delete / name */
1852
1853         if(tot<16)
1854                 uiDefBut(block, BUT, B_ADD_THEME, "Add",        45,y2,200,20, NULL, 0, 0, 0, 0, "Makes new copy of this theme");
1855         if(tot>1 && isbuiltin==0)
1856                 uiDefBut(block, BUT, B_DEL_THEME, "Delete", 45,y1,200,20, NULL, 0, 0, 0, 0, "Delete theme");
1857
1858         if(isbuiltin) return;
1859         
1860         /* name */
1861         uiDefBut(block, TEX, B_NAME_THEME, "",                  255,y3,200,20, btheme->name, 1.0, 30.0, 0, 0, "Rename theme");
1862
1863         /* main choices pup */
1864         uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|%l|3D View %x2|%l|Ipo Curve Editor %x3|Action Editor %x4|"
1865                 "NLA Editor %x5|%l|UV/Image Editor %x6|Video Sequence Editor %x7|Audio Timeline %x8|Text Editor %x9|%l|User Preferences %x10|"
1866                 "OOPS Schematic %x11|Buttons Window %x12|%l|File Browser %x13|Image Browser %x14",
1867                                                                                                         255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
1868         if(curmain==1) spacetype= 0;
1869         else if(curmain==2) spacetype= SPACE_VIEW3D;
1870         else if(curmain==3) spacetype= SPACE_IPO;
1871         else if(curmain==4) spacetype= SPACE_ACTION;
1872         else if(curmain==5) spacetype= SPACE_NLA;
1873         else if(curmain==6) spacetype= SPACE_IMAGE;
1874         else if(curmain==7) spacetype= SPACE_SEQ;
1875         else if(curmain==8) spacetype= SPACE_SOUND;
1876         else if(curmain==9) spacetype= SPACE_TEXT;
1877         else if(curmain==10) spacetype= SPACE_INFO;
1878         else if(curmain==11) spacetype= SPACE_OOPS;
1879         else if(curmain==12) spacetype= SPACE_BUTS;
1880         else if(curmain==13) spacetype= SPACE_FILE;
1881         else if(curmain==14) spacetype= SPACE_IMASEL;
1882         else return; // only needed while coding... when adding themes for more windows
1883         
1884         /* color choices pup */
1885         if(curmain==1) {
1886                 strp= BIF_ThemeColorsPup(0);
1887                 if(th_curcol==TH_BACK) th_curcol= TH_BUT_OUTLINE;  // switching main choices...
1888         }
1889         else strp= BIF_ThemeColorsPup(spacetype);
1890         
1891         uiDefButS(block, MENU, B_REDR, strp,                    255,y1,200,20, &th_curcol, 0, 0, 0, 0, "Current color");
1892         MEM_freeN(strp);
1893         
1894         th_curcol_ptr= col= BIF_ThemeGetColorPtr(btheme, spacetype, th_curcol);
1895         if(col==NULL) return;
1896         
1897         /* first handle exceptions, special single values, row selection, etc */
1898         if(th_curcol==TH_VERTEX_SIZE) {
1899                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Vertex size ", 465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
1900         }
1901         else if(th_curcol==TH_BUT_DRAWTYPE) {
1902                 uiBlockBeginAlign(block);
1903                 uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal",        465,y3,100,20,  col, 2.0, 0.0, 0, 0, "");
1904                 uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 565,y3,100,20,  col, 2.0, 1.0, 0, 0, "");
1905                 uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded",        465,y2,100,20,  col, 2.0, 2.0, 0, 0, "");
1906                 uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool",       565,y2,100,20,  col, 2.0, 3.0, 0, 0, "");
1907                 uiBlockEndAlign(block);
1908         }
1909         else {
1910                 uiBlockBeginAlign(block);
1911                 if ELEM3(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT) {
1912                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
1913                 }
1914                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
1915                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"G ",   465,y2,200,20,  col+1, 0.0, 255.0, B_THEMECOL, 0, "");
1916                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"B ",   465,y1,200,20,  col+2, 0.0, 255.0, B_THEMECOL, 0, "");
1917                 uiBlockEndAlign(block);
1918
1919                 uiDefButC(block, COL, B_THEMECOL, "",           675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
1920                                 
1921                 /* copy paste */
1922                 uiBlockBeginAlign(block);
1923                 uiDefBut(block, BUT, B_THEME_COPY, "Copy Color",        755,y2,120,20, NULL, 0, 0, 0, 0, "Stores current color in buffer");
1924                 uiDefBut(block, BUT, B_THEME_PASTE, "Paste Color",      755,y1,120,20, NULL, 0, 0, 0, 0, "Pastes buffer color");
1925                 uiBlockEndAlign(block);
1926                 
1927                 uiDefButC(block, COL, 0, "",                            885,y1,50,y2-y1+20, th_curcol_arr, 0, 0, 0, 0, "");
1928                 
1929         }
1930 }
1931
1932
1933 void drawinfospace(ScrArea *sa, void *spacedata)
1934 {
1935         uiBlock *block;
1936         static short cur_light=0, cur_light_var=0;
1937         float fac, col[3];
1938         short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y2label, y3label, y4label;
1939         short smallprefbut, medprefbut, largeprefbut, smfileselbut;
1940         short edgespace, midspace;
1941         char naam[32];
1942
1943         if(curarea->win==0) return;
1944
1945         BIF_GetThemeColor3fv(TH_BACK, col);
1946         glClearColor(col[0], col[1], col[2], 0.0);
1947         glClear(GL_COLOR_BUFFER_BIT);
1948
1949         fac= ((float)curarea->winx)/1280.0f;
1950         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
1951         
1952         sprintf(naam, "infowin %d", curarea->win);
1953         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->win);
1954
1955
1956         dx= (1280-90)/7;        /* spacing for use in equally dividing 'tab' row */
1957
1958         xpos = 45;              /* left padding */
1959         ypos = 50;              /* bottom padding for buttons */
1960         ypostab = 10;           /* bottom padding for 'tab' row */
1961
1962
1963         buth = 20;              /* standard button height */
1964
1965         smallprefbut = 94;      /* standard size for small preferences button */
1966         medprefbut = 193;       /* standard size for medium preferences button */
1967         largeprefbut = 292;     /* standard size for large preferences button */
1968         smfileselbut = buth;    /* standard size for fileselect button (square) */
1969
1970         edgespace = 3;          /* space from edge of end 'tab' to edge of end button */
1971         midspace = 5;           /* horizontal space between buttons */
1972
1973         rspace = 3;             /* default space between rows */
1974
1975         y1 = ypos;              /* bottom padding of 1st (bottom) button row */
1976         y2 = ypos+buth+rspace;  /* bottom padding of 2nd button row */
1977         y3 = ypos+2*(buth+rspace)+(3*rspace);   /* bottom padding of 3rd button row */
1978         y4 = ypos+3*(buth+rspace)+(3*rspace);   /* bottom padding of 4th button row */
1979
1980         y2label = y2-2;         /* adjustments to offset the labels down to align better */
1981         y3label = y3-(3*rspace)-2;      /* again for 3rd row */
1982         y4label = y4-2;         /* again for 4th row */
1983
1984
1985         /* set the colour to blue and draw the main 'tab' controls */
1986
1987         uiBlockSetCol(block, TH_BUT_SETTING1);
1988         uiBlockBeginAlign(block);
1989         
1990         uiDefButS(block, ROW,B_USERPREF,"View & Controls",
1991                 xpos,ypostab,(short)dx,buth,
1992                 &U.userpref,1.0,0.0, 0, 0,"");
1993                 
1994         uiDefButS(block, ROW,B_USERPREF,"Edit Methods",
1995                 (short)(xpos+dx),ypostab,(short)dx,buth,
1996                 &U.userpref,1.0,1.0, 0, 0,"");
1997
1998         uiDefButS(block, ROW,B_USERPREF,"Language & Font",
1999                 (short)(xpos+2*dx),ypostab,(short)dx,buth,
2000                 &U.userpref,1.0,2.0, 0, 0,"");
2001
2002         uiDefButS(block, ROW,B_USERPREF,"Themes",
2003                 (short)(xpos+3*dx),ypostab,(short)dx,buth,
2004                 &U.userpref,1.0,6.0, 0, 0,"");
2005
2006         uiDefButS(block, ROW,B_USERPREF,"Auto Save",
2007                 (short)(xpos+4*dx),ypostab,(short)dx,buth,
2008                 &U.userpref,1.0,3.0, 0, 0,"");
2009
2010         uiDefButS(block, ROW,B_USERPREF,"System & OpenGL",
2011                 (short)(xpos+5*dx),ypostab,(short)dx,buth,
2012                 &U.userpref,1.0,4.0, 0, 0,"");
2013                 
2014         uiDefButS(block, ROW,B_USERPREF,"File Paths",
2015                 (short)(xpos+6*dx),ypostab,(short)dx,buth,
2016                 &U.userpref,1.0,5.0, 0, 0,"");
2017
2018         uiBlockSetCol(block, TH_AUTO);
2019         uiBlockEndAlign(block);
2020         /* end 'tab' controls */
2021
2022         /* line 2: left x co-ord, top y co-ord, width, height */
2023
2024         if(U.userpref == 6) {
2025                 info_user_themebuts(block, y1, y2, y3);
2026         }
2027         else if (U.userpref == 0) { /* view & controls */
2028
2029                 uiDefBut(block, LABEL,0,"Display:",
2030                         xpos,y3label,medprefbut,buth,
2031                         0, 0, 0, 0, 0, "");
2032                 
2033                 uiDefButBitS(block, TOG, USER_TOOLTIPS, 0, "ToolTips",
2034                         (xpos+edgespace),y2,smallprefbut,buth,
2035                         &(U.flag), 0, 0, 0, 0,
2036                         "Displays tooltips (help tags) over buttons");
2037
2038                 uiDefButBitS(block, TOG, USER_DRAWVIEWINFO, B_DRAWINFO, "Object Info",
2039                         (xpos+edgespace+midspace+smallprefbut),y2,smallprefbut,buth,
2040                         &(U.uiflag), 0, 0, 0, 0,
2041                         "Displays current object name and frame number in the 3D viewport");
2042
2043                 uiDefButBitS(block, TOG, USER_SCENEGLOBAL, 0, "Global Scene",
2044                         (xpos+edgespace),y1,medprefbut,buth,
2045                         &(U.flag), 0, 0, 0, 0,
2046                         "Forces the current Scene to be displayed in all Screens");
2047
2048
2049                 uiDefBut(block, LABEL,0,"Snap to grid:",
2050                         (xpos+edgespace+medprefbut),y4label,medprefbut,buth,
2051                         0, 0, 0, 0, 0, "");
2052
2053                 uiDefButBitS(block, TOG, USER_AUTOGRABGRID, 0, "Grab",
2054                         (xpos+edgespace+medprefbut+midspace),y3,smallprefbut,buth,
2055                         &(U.flag), 0, 0, 0, 0,
2056                         "Move objects to grid units");
2057
2058                 uiDefButBitS(block, TOG, USER_AUTOSIZEGRID, 0, "Size",
2059                         (xpos+edgespace+medprefbut+midspace),y2,smallprefbut,buth,
2060                         &(U.flag), 0, 0, 0, 0,
2061                         "Scale objects to grid units");
2062
2063                 uiDefButBitS(block, TOG, USER_AUTOROTGRID, 0, "Rotate",
2064                         (xpos+edgespace+medprefbut+midspace),y1,smallprefbut,buth,
2065                         &(U.flag), 0, 0, 0, 0,
2066                         "Rotate objects to grid units");
2067
2068
2069                 uiDefBut(block, LABEL, 0, "Panel",
2070                         (xpos+edgespace+medprefbut+(2*midspace)+smallprefbut),y4label,smallprefbut,buth,
2071                         NULL, 0, 0, 0, 0,
2072                         "");
2073                 uiDefButBitS(block, TOG, USER_PANELPINNED, 0, "Pinned",
2074                         (xpos+edgespace+medprefbut+(2*midspace)+smallprefbut),y3,smallprefbut,buth,
2075                         &(U.uiflag), 0, 0, 0, 0,
2076                         "Hotkey enabled floating panels (e.g. NKEY) open at old location");
2077
2078
2079                 uiDefBut(block, LABEL,0,"Menu Buttons:",
2080                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y4label,medprefbut,buth,
2081                         0, 0, 0, 0, 0, "");
2082
2083                 uiDefButBitS(block, TOG, USER_MENUOPENAUTO, 0, "Auto Open",
2084                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y3,smallprefbut,buth,
2085                         &(U.uiflag), 0, 0, 0, 0,
2086                         "Automatic opening of menu buttons");
2087
2088                 uiDefButS(block, NUM, 0, "ThresA:",
2089                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y2,smallprefbut,buth,
2090                         &(U.menuthreshold1), 1, 40, 0, 0,
2091                         "Time in 1/10 seconds for auto open");
2092
2093                 uiDefButS(block, NUM, 0, "ThresB:",
2094                         (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y1,smallprefbut,buth,
2095                         &(U.menuthreshold2), 1, 40, 0, 0,
2096                         "Time in 1/10 seconds for auto open sublevels");
2097
2098
2099
2100                 uiDefBut(block, LABEL,0,"Toolb. Thresh.:",
2101                         (xpos+edgespace+medprefbut+(3*midspace)+(3*smallprefbut)),y4label,medprefbut,buth,
2102                         0, 0, 0, 0, 0, "");
2103
2104                 uiDefButS(block, NUM, 0, "LMB:",
2105                         (xpos+edgespace+medprefbut+(3*midspace)+(3*smallprefbut)),y2,smallprefbut,buth,
2106                         &(U.tb_leftmouse), 2, 40, 0, 0,
2107                         "Time in 1/10 seconds leftmouse hold to open toolbox");
2108
2109                 uiDefButS(block, NUM, 0, "RMB:",
2110                         (xpos+edgespace+medprefbut+(3*midspace)+(3*smallprefbut)),y1,smallprefbut,buth,
2111                         &(U.tb_rightmouse), 2, 40, 0, 0,
2112                         "Time in 1/10 seconds for rightmouse to open toolbox");
2113
2114
2115                 uiDefBut(block, LABEL,0,"View zoom:",
2116                         (xpos+edgespace+medprefbut+(3*midspace)+(4*smallprefbut)),y4label,medprefbut,buth,
2117                         0, 0, 0, 0, 0, "");
2118
2119                 uiDefButS(block, ROW, 0, "Continue",
2120                         (xpos+edgespace+medprefbut+(3*midspace)+(4*smallprefbut)),y3,smallprefbut,buth,
2121                         &(U.viewzoom), 40, USER_ZOOM_CONT, 0, 0,
2122                         "Old style zoom, continues while moving mouse up or down");
2123
2124                 uiDefButS(block, ROW, 0, "Dolly",
2125                         (xpos+edgespace+medprefbut+(3*midspace)+(4*smallprefbut)),y2,smallprefbut,buth,
2126                         &(U.viewzoom), 40, USER_ZOOM_DOLLY, 0, 0,
2127                         "Zooms in and out based on vertical mouse movement.");
2128
2129                 uiDefButS(block, ROW, 0, "Scale",
2130                         (xpos+edgespace+medprefbut+(3*midspace)+(4*smallprefbut)),y1,smallprefbut,buth,
2131                         &(U.viewzoom), 40, USER_ZOOM_SCALE, 0, 0,
2132                         "Zooms in and out like scaling the view, mouse movements relative to center.");
2133
2134
2135                         
2136                 uiDefBut(block, LABEL,0,"View rotation:",
2137                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y3label,medprefbut,buth,
2138                         0, 0, 0, 0, 0, "");
2139
2140                 uiDefButBitS(block, TOG, USER_TRACKBALL, B_DRAWINFO, "Trackball",
2141                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y2,(smallprefbut+2),buth,
2142                         &(U.flag), 0, 0, 0, 0,
2143                         "Use trackball style rotation with middle mouse button");
2144
2145                 uiDefButBitS(block, TOGN, USER_TRACKBALL, B_DRAWINFO, "Turntable",
2146                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y1,(smallprefbut+2),buth,
2147                         &(U.flag), 0, 0, 0, 0,
2148                         "Use turntable style rotation with middle mouse button");
2149
2150
2151
2152                 uiDefBut(block, LABEL,0,"Middle mouse button:",
2153                         (xpos+edgespace+(3*midspace)+(4*medprefbut)),y3label,medprefbut,buth,
2154                         0, 0, 0, 0, 0, "");
2155                 uiDefButBitS(block, TOGN, USER_VIEWMOVE, B_DRAWINFO, "Rotate View",
2156                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y2,(smallprefbut+2),buth,
2157                         &(U.flag), 0, 0, 0, 0, "Default action for the middle mouse button");
2158
2159                 uiDefButBitS(block, TOG, USER_VIEWMOVE, B_DRAWINFO, "Pan View",
2160                         (xpos+edgespace+(4*midspace)+(4*medprefbut)+smallprefbut+2),y2,(smallprefbut+2),buth,
2161                         &(U.flag), 0, 0, 0, 0, "Default action for the middle mouse button");
2162
2163                 uiDefButBitS(block, TOG, USER_TWOBUTTONMOUSE, 0, "Emulate 3 Buttons",
2164                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y1,medprefbut,buth,
2165                         &(U.flag), 0, 0, 0, 0,
2166                         "Emulates a middle mouse button with ALT+LeftMouse");
2167
2168
2169
2170                 uiDefBut(block, LABEL,0,"Mousewheel:",
2171                         (xpos+edgespace+(4*midspace)+(5*medprefbut)),y3label,smallprefbut+15,buth,
2172                         0, 0, 0, 0, 0, "");
2173                 uiDefButBitS(block, TOG, USER_WHEELZOOMDIR, 0, "Invert Wheel Zoom",
2174                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y1,smallprefbut+15,buth,
2175                         &(U.uiflag), 0, 0, 0, 0,
2176                         "Swaps mouse wheel zoom direction");
2177
2178
2179                 uiDefButI(block, NUM, 0, "Scroll Lines:",
2180                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y2,smallprefbut+15,buth,
2181                         &U.wheellinescroll, 0.0, 32.0, 0, 0,
2182                         "The number of lines scrolled at a time with the mouse wheel");
2183                 
2184 #ifndef __APPLE__       
2185                 uiDefBut(block, LABEL,0,"Cursor:",
2186                         (xpos+edgespace+(5*midspace)+(5*medprefbut)+smallprefbut+15),y3label,smallprefbut,buth,
2187                         0, 0, 0, 0, 0, "");             
2188                 uiDefButS(block, TOG|BIT|0, 0, "Large",
2189                         (xpos+edgespace+(6*midspace)+(5*medprefbut)+smallprefbut+15),y2,smallprefbut,buth,
2190                         &(U.curssize), 0, 0, 0, 0,
2191                         "Use Large cursors when available.");
2192 #else 
2193                 U.curssize=0; /*Small Cursor always for OSX for now */
2194 #endif
2195
2196         } else if (U.userpref == 1) { /* edit methods */
2197
2198
2199                 uiDefBut(block, LABEL,0,"Material linked to:",
2200                         xpos,y3label,medprefbut,buth,
2201                         0, 0, 0, 0, 0, "");
2202
2203                 uiDefButBitS(block, TOGN, USER_MAT_ON_OB, B_DRAWINFO, "ObData",
2204                         (xpos+edgespace),y2,(smallprefbut),buth,
2205                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
2206
2207                 uiDefButBitS(block, TOG, USER_MAT_ON_OB, B_DRAWINFO, "Object",
2208                         (xpos+edgespace+midspace+smallprefbut),y2,(smallprefbut),buth,
2209                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
2210
2211
2212
2213                 uiDefBut(block, LABEL,0,"Mesh Undo",
2214                         (xpos+edgespace+medprefbut),y3label, medprefbut,buth,
2215                         0, 0, 0, 0, 0, "");
2216
2217                 uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps:",
2218                         (xpos+edgespace+medprefbut+midspace),y2,(medprefbut),buth,
2219                                 &(U.undosteps), 2, 64, 0, 0, "Number of undo steps avail. in Editmode.  Smaller conserves memory.");
2220
2221
2222                 uiDefBut(block, LABEL,0,"Auto keyframe on:",
2223                         (xpos+edgespace+(2*medprefbut)+midspace),y3label,medprefbut,buth,
2224                         0, 0, 0, 0, 0, "");
2225
2226                 uiDefButBitS(block, TOG, USER_KEYINSERTACT, 0, "Action",
2227                         (xpos+edgespace+(2*medprefbut)+(2*midspace)),y2,smallprefbut,buth,
2228                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in action ipo curve");
2229
2230                 uiDefButBitS(block, TOG, USER_KEYINSERTOBJ, 0, "Object",
2231                         (xpos+edgespace+(2*medprefbut)+(3*midspace)+smallprefbut),y2,smallprefbut,buth,
2232                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in object ipo curve");
2233
2234
2235
2236                 uiDefBut(block, LABEL,0,"Duplicate with object:",
2237                         (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut),y3label,medprefbut,buth,
2238                         0, 0, 0, 0, 0, "");
2239
2240                 uiDefButBitS(block, TOG, USER_DUP_MESH, 0, "Mesh",
2241                         (xpos+edgespace+(4*midspace)+(3*medprefbut)+smallprefbut),y2,smallprefbut,buth,
2242                         &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
2243                 uiDefButBitS(block, TOG, USER_DUP_ARM, 0, "Armature",
2244                         (xpos+edgespace+(4*midspace)+(3*medprefbut)+smallprefbut),y1,smallprefbut,buth,
2245                         &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
2246
2247                 uiDefButBitS(block, TOG, USER_DUP_SURF, 0, "Surface",
2248                         (xpos+edgespace+(5*midspace)+(3*medprefbut)+(2*smallprefbut)),y2,smallprefbut,buth,
2249                         &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
2250                 uiDefButBitS(block, TOG, USER_DUP_LAMP, 0, "Lamp",
2251                         (xpos+edgespace+(5*midspace)+(3*medprefbut)+(2*smallprefbut)),y1,smallprefbut,buth,
2252                         &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
2253
2254                 uiDefButBitS(block, TOG, USER_DUP_CURVE, 0, "Curve",
2255                         (xpos+edgespace+(6*midspace)+(3*medprefbut)+(3*smallprefbut)),y2,smallprefbut,buth,
2256                         &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
2257                 uiDefButBitS(block, TOG, USER_DUP_MAT, 0, "Material",
2258                         (xpos+edgespace+(6*midspace)+(3*medprefbut)+(3*smallprefbut)),y1,smallprefbut,buth,
2259                         &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
2260
2261                 uiDefButBitS(block, TOG, USER_DUP_FONT, 0, "Text",
2262                         (xpos+edgespace+(7*midspace)+(3*medprefbut)+(4*smallprefbut)),y2,smallprefbut,buth,
2263                         &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
2264                 uiDefButBitS(block, TOG, USER_DUP_TEX, 0, "Texture",
2265                         (xpos+edgespace+(7*midspace)+(3*medprefbut)+(4*smallprefbut)),y1,smallprefbut,buth,
2266                         &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
2267
2268                 uiDefButBitS(block, TOG, USER_DUP_MBALL, 0, "Metaball",
2269                         (xpos+edgespace+(8*midspace)+(3*medprefbut)+(5*smallprefbut)),y2,smallprefbut,buth,
2270                         &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
2271                 uiDefButBitS(block, TOG, USER_DUP_IPO, 0, "Ipo",
2272                         (xpos+edgespace+(8*midspace)+(3*medprefbut)+(5*smallprefbut)),y1,smallprefbut,buth,
2273                         &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
2274         
2275         } else if(U.userpref == 2) { /* language & colors */
2276
2277 #ifdef INTERNATIONAL
2278                 char curfont[320];
2279
2280                 sprintf(curfont, "Interface Font: ");
2281                 strcat(curfont,U.fontname);
2282
2283                 uiDefButBitS(block, TOG, USER_DOTRANSLATE, B_DOLANGUIFONT, "International Fonts",
2284                         xpos,y2,medprefbut,buth,
2285                         &(U.transopts), 0, 0, 0, 0, "Activate international interface");
2286
2287                 if(U.transopts & USER_DOTRANSLATE) {
2288                         uiDefBut(block, LABEL,0,curfont,
2289                                 (xpos+edgespace+medprefbut+midspace),y2,medprefbut,buth,
2290                                 0, 0, 0, 0, 0, "");
2291
2292                         uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
2293                                 xpos,y1,medprefbut,buth,
2294                                 0, 0, 0, 0, 0, "Select a new font for the interface");
2295
2296
2297                         uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
2298                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
2299                                 &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
2300
2301 /*
2302                         uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
2303                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
2304                                 &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
2305
2306
2307                         uiDefBut(block, LABEL,0,"Translate:",
2308                                 (xpos+edgespace+(2.1*medprefbut)+(2*midspace)),y3label,medprefbut,buth,
2309                                 0, 0, 0, 0, 0, "");
2310 */
2311
2312                         uiDefButBitS(block, TOG, USER_TR_TOOLTIPS, B_SETTRANSBUTS, "Tooltips",
2313                                 (xpos+edgespace+(2.2*medprefbut)+(3*midspace)),y1,smallprefbut,buth,
2314                                 &(U.transopts), 0, 0, 0, 0, "Translate tooltips");
2315
2316                         uiDefButBitS(block, TOG, USER_TR_BUTTONS, B_SETTRANSBUTS, "Buttons",
2317                                 (xpos+edgespace+(2.2*medprefbut)+(4*midspace)+smallprefbut),y1,smallprefbut,buth,
2318                                 &(U.transopts), 0, 0, 0, 0, "Translate button labels");
2319
2320                         uiDefButBitS(block, TOG, USER_TR_MENUS, B_SETTRANSBUTS, "Toolbox",
2321                                 (xpos+edgespace+(2.2*medprefbut)+(5*midspace)+(2*smallprefbut)),y1,smallprefbut,buth,
2322                                 &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
2323
2324                         uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
2325                                 (xpos+edgespace+(2.2*medprefbut)+(3*midspace)),y2,medprefbut+(0.5*medprefbut)+3,buth,
2326                                 &U.language, 0, 0, 0, 0, "Select interface language");
2327                                 
2328                         /* uiDefButBitS(block, TOG, USER_TR_TEXTEDIT, B_SETTRANSBUTS, "FTF All windows",
2329                                 (xpos+edgespace+(4*medprefbut)+(4*midspace)),y1,medprefbut,buth,
2330                                 &(U.transopts), 0, 0, 0, 0,
2331                                 "Use FTF drawing for fileselect and textwindow "
2332                                 "(under construction)");
2333                         */
2334                 }
2335
2336 /* end of INTERNATIONAL */
2337 #endif
2338
2339         } else if(U.userpref == 3) { /* auto save */
2340
2341
2342                 uiDefButBitS(block, TOG, USER_AUTOSAVE, B_RESETAUTOSAVE, "Auto Save Temp Files",
2343                         (xpos+edgespace),y2,medprefbut,buth,
2344                         &(U.flag), 0, 0, 0, 0,
2345                         "Enables automatic saving of temporary files");
2346
2347                 if(U.flag & USER_AUTOSAVE) {
2348
2349                         uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
2350                                 (xpos+edgespace),y1,medprefbut,buth,
2351                                 0, 0, 0, 0, 0,"Opens the most recently saved temporary file");
2352
2353                         uiDefButI(block, NUM, B_RESETAUTOSAVE, "Minutes:",
2354                                 (xpos+edgespace+medprefbut+midspace),y2,medprefbut,buth,
2355                                 &(U.savetime), 1.0, 60.0, 0, 0,
2356                                 "The time (in minutes) to wait between automatic temporary saves");
2357
2358                         uiDefButS(block, NUM, 0, "Versions:",
2359                                 (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
2360                                 &U.versions, 0.0, 32.0, 0, 0,
2361                                 "The number of old versions to maintain when saving");
2362                 }
2363
2364         } else if (U.userpref == 4) { /* system & opengl */
2365                 uiDefBut(block, LABEL,0,"Solid OpenGL light:",
2366                         xpos+edgespace, y3label, medprefbut, buth,
2367                         0, 0, 0, 0, 0, "");
2368                 
2369                 uiDefButS(block, MENU, B_REDR, "Light1 %x0|Light2 %x1|Light3 %x2",
2370                         xpos+edgespace, y2, 2*medprefbut/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
2371                 uiBlockSetCol(block, TH_BUT_SETTING1);
2372                 uiDefButI(block, TOG|BIT|0, B_RECALCLIGHT, "On",
2373                         xpos+edgespace+2*medprefbut/6, y2, medprefbut/6, buth, 
2374                         &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "");
2375                         
2376                 uiBlockSetCol(block, TH_AUTO);
2377                 uiDefButS(block, ROW, B_REDR, "Vec",
2378                         xpos+edgespace+3*medprefbut/6, y2, medprefbut/6, buth, 
2379                         &cur_light_var, 123.0, 0.0, 0, 0, "");
2380                 uiDefButS(block, ROW, B_REDR, "Col",
2381                         xpos+edgespace+4*medprefbut/6, y2, medprefbut/6, buth, 
2382                         &cur_light_var, 123.0, 1.0, 0, 0, "");
2383                 uiDefButS(block, ROW, B_REDR, "Spec",
2384                         xpos+edgespace+5*medprefbut/6, y2, medprefbut/6, buth, 
2385                         &cur_light_var, 123.0, 2.0, 0, 0, "");
2386
2387                 if(cur_light_var==1) {
2388                         uiDefButF(block, NUM, B_RECALCLIGHT, "R ",
2389                                 xpos+edgespace, y1, medprefbut/3, buth, 
2390                                 U.light[cur_light].col, 0.0, 1.0, 100, 2, "");
2391                         uiDefButF(block, NUM, B_RECALCLIGHT, "G ",
2392                                 xpos+edgespace+medprefbut/3, y1, medprefbut/3, buth, 
2393                                 U.light[cur_light].col+1, 0.0, 1.0, 100, 2, "");
2394                         uiDefButF(block, NUM, B_RECALCLIGHT, "B ",
2395                                 xpos+edgespace+2*medprefbut/3, y1, medprefbut/3, buth, 
2396                                 U.light[cur_light].col+2, 0.0, 1.0, 100, 2, "");
2397                 }
2398                 else if(cur_light_var==2) {
2399                         uiDefButF(block, NUM, B_RECALCLIGHT, "sR ",
2400                                 xpos+edgespace, y1, medprefbut/3, buth, 
2401                                 U.light[cur_light].spec, 0.0, 1.0, 100, 2, "");
2402                         uiDefButF(block, NUM, B_RECALCLIGHT, "sG ",
2403                                 xpos+edgespace+medprefbut/3, y1, medprefbut/3, buth, 
2404                                 U.light[cur_light].spec+1, 0.0, 1.0, 100, 2, "");
2405                         uiDefButF(block, NUM, B_RECALCLIGHT, "sB ",
2406                                 xpos+edgespace+2*medprefbut/3, y1, medprefbut/3, buth, 
2407                                 U.light[cur_light].spec+2, 0.0, 1.0, 100, 2, "");
2408                 }
2409                 else if(cur_light_var==0) {
2410                         uiDefButF(block, NUM, B_RECALCLIGHT, "X ",
2411                                 xpos+edgespace, y1, medprefbut/3, buth, 
2412                                 U.light[cur_light].vec, -1.0, 1.0, 100, 2, "");
2413                         uiDefButF(block, NUM, B_RECALCLIGHT, "Y ",
2414                                 xpos+edgespace+medprefbut/3, y1, medprefbut/3, buth, 
2415                                 U.light[cur_light].vec+1, -1.0, 1.0, 100, 2, "");
2416                         uiDefButF(block, NUM, B_RECALCLIGHT, "Z ",
2417                                 xpos+edgespace+2*medprefbut/3, y1, medprefbut/3, buth, 
2418                                 U.light[cur_light].vec+2, -1.0, 1.0, 100, 2, "");
2419                 }
2420
2421 /*
2422                 uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
2423                         (xpos+edgespace),y2,largeprefbut,buth,
2424                         &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
2425
2426                 uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
2427                         (xpos+edgespace), y1, largeprefbut,buth,
2428                         &U.console_out, 0, 0, 0, 0, "Select console output method");
2429
2430                 uiDefButS(block, NUM, B_CONSOLENUMLINES, "Lines:",
2431                         (xpos+edgespace+largeprefbut+midspace),y1,smallprefbut,buth,
2432                         &U.console_buffer, 1.0, 4000.0, 0, 0, "Maximum number of internal console lines");
2433 */
2434
2435 #ifdef _WIN32
2436                 uiDefBut(block, LABEL,0,"Win Codecs:",
2437                         (xpos+edgespace+(1*midspace)+(1*medprefbut)),y3label,medprefbut,buth,
2438                         0, 0, 0, 0, 0, "");
2439
2440                 uiDefButBitS(block, TOG, USER_ALLWINCODECS, 0, "Enable all codecs",
2441                         (xpos+edgespace+(1*medprefbut)+(1*midspace)),y2,medprefbut,buth,
2442                         &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
2443 #endif
2444
2445                 uiDefBut(block, LABEL,0,"Keyboard:",
2446                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y3label,medprefbut,buth,
2447                         0, 0, 0, 0, 0, "");
2448
2449                 uiDefButBitS(block, TOG, USER_NO_CAPSLOCK, B_U_CAPSLOCK, "Disable Caps Lock",
2450                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y1,medprefbut,buth,
2451                         &(U.flag), 0, 0, 0, 0,
2452                         "Disables the Caps Lock key when entering text");
2453
2454                 uiDefButBitS(block, TOG, USER_NONUMPAD, 0, "Emulate Numpad",
2455                         (xpos+edgespace+(3*midspace)+(3*medprefbut)),y2,medprefbut,buth,
2456                         &(U.flag), 0, 0, 0, 0,
2457                         "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
2458
2459
2460                 uiDefBut(block, LABEL,0,"System:",
2461                         (xpos+edgespace+(4*midspace)+(4*medprefbut)),y3label,medprefbut,buth,
2462                         0, 0, 0, 0, 0, "");
2463
2464                 uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Sound",
2465                         (xpos+edgespace+(4*medprefbut)+(4*midspace)),y2,medprefbut,buth,
2466                         &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
2467
2468                 uiDefButBitS(block, TOG, USER_FILTERFILEEXTS, 0, "Filter File Extensions",
2469                         (xpos+edgespace+(4*medprefbut)+(4*midspace)),y1,medprefbut,buth,
2470                         &(U.uiflag), 0, 0, 0, 0, "Display only files with extensions in the image select window");
2471
2472
2473                 uiDefBut(block, LABEL,0,"OpenGL:",
2474                         (xpos+edgespace+(5*midspace)+(5*medprefbut)),y3label,medprefbut,buth,
2475                         0, 0, 0, 0, 0, "");
2476
2477                 uiDefButBitI(block, TOGN, USER_DISABLE_MIPMAP, B_MIPMAPCHANGED, "Mipmaps",
2478                         (xpos+edgespace+(5*medprefbut)+(5*midspace)),y2,medprefbut,buth,
2479                         &(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
2480
2481                 uiDefButBitI(block, TOG, USER_VERTEX_ARRAYS, 0, "Vertex Arrays",
2482                         (xpos+edgespace+(5*medprefbut)+(5*midspace)),y1,medprefbut,buth,
2483                         &(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
2484
2485                 uiDefBut(block, LABEL,0,"Audio:",
2486                         (xpos+edgespace+(2*midspace)+(2*medprefbut)),y3label,medprefbut,buth,
2487                         0, 0, 0, 0, 0, "");
2488
2489                 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");
2490                 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");      
2491                 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");               
2492                 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");                   
2493
2494         } else if(U.userpref == 5) { /* file paths */
2495
2496                 /* yafray: (temporary) path button for yafray xml export, now with fileselect */
2497                 uiDefBut(block, TEX, 0, "YFexport: ",
2498                         (xpos+edgespace), y2+buth+rspace, largeprefbut-smfileselbut, buth,
2499                         U.yfexportdir, 1.0, 63.0, 0, 0,
2500                         "The default directory for yafray xml export (must exist!)");
2501                 uiDefIconBut(block, BUT, B_YAFRAYDIRFILESEL, ICON_FILESEL,
2502                         (xpos+edgespace+largeprefbut-smfileselbut), y2+buth+rspace, smfileselbut, buth,
2503                         0, 0, 0, 0, 0, "Select the default yafray export directory");
2504
2505                 uiDefBut(block, TEX, 0, "Fonts: ",
2506                         (xpos+edgespace),y2,(largeprefbut-smfileselbut),buth,
2507                         U.fontdir, 1.0, 63.0, 0, 0,
2508                         "The default directory to search for loading fonts");
2509                 uiDefIconBut(block, BUT, B_FONTDIRFILESEL, ICON_FILESEL,
2510                         (xpos+edgespace+largeprefbut-smfileselbut),y2,smfileselbut,buth,
2511                         0, 0, 0, 0, 0, "Select the default font directory");
2512
2513                 uiDefBut(block, TEX, 0, "Textures: ",
2514                         (xpos+edgespace+largeprefbut+midspace),y2,(largeprefbut-smfileselbut),buth,
2515                         U.textudir, 1.0, 63.0, 0, 0, "The default directory to search for textures");
2516                 uiDefIconBut(block, BUT, B_TEXTUDIRFILESEL, ICON_FILESEL,
2517                         (xpos+edgespace+(2*largeprefbut)+midspace-smfileselbut),y2,smfileselbut,buth,
2518                         0, 0, 0, 0, 0, "Select the default texture location");
2519
2520
2521                 uiDefBut(block, TEX, 0, "Tex Plugins: ",
2522                         (xpos+edgespace+(2*largeprefbut)+(2*midspace)),y2,(largeprefbut-smfileselbut),buth,
2523                         U.plugtexdir, 1.0, 63.0, 0, 0, "The default directory to search for texture plugins");
2524                 uiDefIconBut(block, BUT, B_PLUGTEXDIRFILESEL, ICON_FILESEL,
2525                         (xpos+edgespace+(3*largeprefbut)+(2*midspace)-smfileselbut),y2,smfileselbut,buth,
2526                         0, 0, 0, 0, 0, "Select the default texture plugin location");
2527
2528                 uiDefBut(block, TEX, 0, "Seq Plugins: ",
2529                         (xpos+edgespace+(3*largeprefbut)+(3*midspace)),y2,(largeprefbut-smfileselbut),buth,
2530                         U.plugseqdir, 1.0, 63.0, 0, 0, "The default directory to search for sequence plugins");
2531                 uiDefIconBut(block, BUT, B_PLUGSEQDIRFILESEL, ICON_FILESEL,
2532                         (xpos+edgespace+(4*largeprefbut)+(3*midspace)-smfileselbut),y2,smfileselbut,buth,
2533                         0, 0, 0, 0, 0, "Select the default sequence plugin location");
2534
2535
2536                 uiDefBut(block, TEX, 0, "Render: ",
2537                         (xpos+edgespace),y1,(largeprefbut-smfileselbut),buth,
2538                         U.renderdir, 1.0, 63.0, 0, 0, "The default directory for rendering output");
2539                 uiDefIconBut(block, BUT, B_RENDERDIRFILESEL, ICON_FILESEL,
2540                         (xpos+edgespace+largeprefbut-smfileselbut),y1,smfileselbut,buth,
2541                         0, 0, 0, 0, 0, "Select the default render output location");
2542
2543                 uiDefBut(block, TEX, 0, "Python: ",
2544                         (xpos+edgespace+largeprefbut+midspace),y1,(largeprefbut-2*smfileselbut),buth,
2545                         U.pythondir, 1.0, 63.0, 0, 0, "The default directory to search for Python scripts");
2546                 uiDefIconBut(block, BUT, B_PYMENUEVAL, ICON_SCRIPT,
2547                         (xpos+edgespace+(2*largeprefbut)+midspace-2*smfileselbut),y1,smfileselbut,buth,
2548                         0, 0, 0, 0, 0, "Re-evaluate scripts registration in menus");
2549                 uiDefIconBut(block, BUT, B_PYTHONDIRFILESEL, ICON_FILESEL,
2550                         (xpos+edgespace+(2*largeprefbut)+midspace-smfileselbut),y1,smfileselbut,buth,
2551                         0, 0, 0, 0, 0, "Select the default Python script location");
2552
2553
2554                 uiDefBut(block, TEX, 0, "Sounds: ",
2555                         (xpos+edgespace+(2*largeprefbut)+(2*midspace)),y1,(largeprefbut-smfileselbut),buth,
2556                         U.sounddir, 1.0, 63.0, 0, 0, "The default directory to search for sounds");
2557                 uiDefIconBut(block, BUT, B_SOUNDDIRFILESEL, ICON_FILESEL,
2558                         (xpos+edgespace+(3*largeprefbut)+(2*midspace)-smfileselbut),y1,smfileselbut,buth,
2559                         0, 0, 0, 0, 0, "Select the default sound location");
2560
2561                 uiDefBut(block, TEX, 0, "Temp: ",
2562                          (xpos+edgespace+(3*largeprefbut)+(3*midspace)),y1,(largeprefbut-smfileselbut),buth,
2563                          U.tempdir, 1.0, 63.0, 0, 0, "The directory for storing temporary save files");
2564                 uiDefIconBut(block, BUT, B_TEMPDIRFILESEL, ICON_FILESEL,
2565                         (xpos+edgespace+(4*largeprefbut)+(3*midspace)-smfileselbut),y1,smfileselbut,buth,
2566                         0, 0, 0, 0, 0, "Select the default temporary save file location");
2567
2568         }
2569
2570         uiDrawBlock(block);
2571         
2572         myortho2(-0.375, (float)(sa->winx)-0.375, -0.375, (float)(sa->winy)-0.375);
2573         draw_area_emboss(sa);
2574         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2575         sa->win_swap= WIN_BACK_OK;
2576         
2577 }
2578
2579
2580 void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2581 {
2582         unsigned short event= evt->event;
2583         short val= evt->val;
2584         
2585         if(val) {
2586                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2587
2588                 switch(event) {
2589                 case UI_BUT_EVENT:
2590                         if(val==B_ADD_THEME) {
2591                                 bTheme *btheme, *new;
2592                                 
2593                                 btheme= U.themes.first;
2594                                 new= MEM_callocN(sizeof(bTheme), "theme");
2595                                 memcpy(new, btheme, sizeof(bTheme));
2596                                 BLI_addhead(&U.themes, new);
2597                                 strcpy(new->name, "New User Theme");
2598                                 addqueue(sa->win, REDRAW, 1);
2599                         }
2600                         else if(val==B_DEL_THEME) {
2601                                 bTheme *btheme= U.themes.first;
2602                                 BLI_remlink(&U.themes, btheme);
2603                                 MEM_freeN(btheme);
2604                                 BIF_SetTheme(sa); // prevent usage of old theme in calls        
2605                                 addqueue(sa->win, REDRAW, 1);
2606                         }
2607                         else if(val==B_NAME_THEME) {
2608                                 bTheme *btheme= U.themes.first;
2609                                 if(strcmp(btheme->name, "Default")==0) {
2610                                         strcpy(btheme->name, "New User Theme");
2611                                         addqueue(sa->win, REDRAW, 1);
2612                                 }
2613                         }
2614                         else if(val==B_UPDATE_THEME) {
2615                                 allqueue(REDRAWALL, 0);
2616                         }
2617                         else if(val==B_CHANGE_THEME) {
2618                                 th_curcol= TH_BACK;     // backdrop color is always there...
2619                                 addqueue(sa->win, REDRAW, 1);
2620                         }
2621                         else if(val==B_THEME_COPY) {
2622                                 if(th_curcol_ptr) {
2623                                         th_curcol_arr[0]= th_curcol_ptr[0];
2624                                         th_curcol_arr[1]= th_curcol_ptr[1];
2625                                         th_curcol_arr[2]= th_curcol_ptr[2];
2626                                         th_curcol_arr[3]= th_curcol_ptr[3];
2627                                         addqueue(sa->win, REDRAW, 1);
2628                                 }
2629                         }
2630                         else if(val==B_THEME_PASTE) {
2631                                 if(th_curcol_ptr) {
2632                                         th_curcol_ptr[0]= th_curcol_arr[0];
2633                                         th_curcol_ptr[1]= th_curcol_arr[1];
2634                                         th_curcol_ptr[2]= th_curcol_arr[2];
2635                                         th_curcol_ptr[3]= th_curcol_arr[3];
2636                                         allqueue(REDRAWALL, 0);
2637                                 }
2638                         }
2639                         else if(val==B_RECALCLIGHT) {
2640                                 if(U.light[0].flag==0 && U.light[1].flag==0 && U.light[2].flag==0)
2641                                         U.light[0].flag= 1;
2642                                 
2643                                 default_gl_light();
2644                                 addqueue(sa->win, REDRAW, 1);
2645                                 allqueue(REDRAWVIEW3D, 0);
2646                         }
2647                         else do_global_buttons(val);
2648                         
2649                         break;  
2650                 }
2651         }
2652 }
2653
2654 void init_infospace(ScrArea *sa)
2655 {
2656         SpaceInfo *sinfo;
2657         
2658         sinfo= MEM_callocN(sizeof(SpaceInfo), "initinfo");
2659         BLI_addhead(&sa->spacedata, sinfo);
2660
2661         sinfo->spacetype=SPACE_INFO;
2662 }
2663
2664 /* ******************** SPACE: BUTS ********************** */
2665
2666 extern void drawbutspace(ScrArea *sa, void *spacedata); /* buttons.c */
2667
2668 static void changebutspace(ScrArea *sa, void *spacedata)
2669 {
2670         if(G.v2d==0) return;
2671         
2672         test_view2d(G.v2d, curarea->winx, curarea->winy);
2673         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
2674 }
2675
2676 void winqreadbutspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2677 {
2678         unsigned short event= evt->event;
2679         short val= evt->val;
2680         SpaceButs *sbuts= curarea->spacedata.first;
2681         ScrArea *sa2, *sa3d;
2682         int nr, doredraw= 0;
2683
2684         if(val) {
2685                 
2686                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2687
2688                 switch(event) {
2689                 case UI_BUT_EVENT:
2690                         do_butspace(val);
2691                         break;
2692                         
2693                 case MIDDLEMOUSE:
2694                 case WHEELUPMOUSE:
2695                 case WHEELDOWNMOUSE:
2696                         view2dmove(event);      /* in drawipo.c */
2697                         break;
2698                 case PAGEUPKEY:
2699                         event= WHEELUPMOUSE;
2700                         view2dmove(event);      /* in drawipo.c */
2701                         break;
2702                 case PAGEDOWNKEY:
2703                         event= WHEELDOWNMOUSE;
2704                         view2dmove(event);      /* in drawipo.c */
2705                         break;
2706                         
2707                 case RIGHTMOUSE:
2708                         nr= pupmenu("Panel Alignment%t|Horizontal%x1|Vertical%x2|Free %x0");
2709                         if (nr>=0) {
2710                                 sbuts->align= nr;
2711                                 if(nr) {
2712                                         uiAlignPanelStep(sa, 1.0);
2713                                         do_buts_buttons(B_BUTSHOME);
2714                                 }
2715                         }
2716
2717                         break;
2718                 case PADPLUSKEY:
2719                         view2d_zoom(&sbuts->v2d, 0.06f, curarea->winx, curarea->winy);
2720                         scrarea_queue_winredraw(curarea);
2721                         break;
2722                 case PADMINUS:
2723                         view2d_zoom(&sbuts->v2d, -0.075f, curarea->winx, curarea->winy);
2724                         scrarea_queue_winredraw(curarea);
2725                         break;
2726                 case RENDERPREVIEW:
2727                         BIF_previewrender(sbuts);
2728                         break;
2729                 
2730                 case HOMEKEY:
2731                         do_buts_buttons(B_BUTSHOME);
2732                         break;
2733
2734
2735                 /* if only 1 view, also de persp, excluding arrowkeys */
2736                 case PAD0: case PAD1: case PAD3:
2737                 case PAD5: case PAD7: case PAD9:
2738                 case PADENTER: case ZKEY: case PKEY:
2739                         sa3d= 0;
2740                         sa2= G.curscreen->areabase.first;
2741                         while(sa2) {
2742                                 if(sa2->spacetype==SPACE_VIEW3D) {
2743                                         if(sa3d) return;
2744                                         sa3d= sa2;
2745                                 }
2746                                 sa2= sa2->next;
2747                         }
2748                         if(sa3d) {
2749                                 sa= curarea;
2750                                 areawinset(sa3d->win);
2751                                 
2752                                 if(event==PKEY) start_game();
2753                                 else if(event==ZKEY) toggle_shading();
2754                                 else persptoetsen(event);
2755                                 
2756                                 scrarea_queue_winredraw(sa3d);
2757                                 scrarea_queue_headredraw(sa3d);
2758                                 areawinset(sa->win);
2759                         }
2760                 }
2761         }
2762
2763         if(doredraw) scrarea_queue_winredraw(curarea);
2764 }
2765
2766 void set_rects_butspace(SpaceButs *buts)
2767 {
2768         /* buts space goes from (0,0) to (1280, 228) */
2769
2770         buts->v2d.tot.xmin= 0.0f;
2771         buts->v2d.tot.ymin= 0.0f;
2772         buts->v2d.tot.xmax= 1279.0f;
2773         buts->v2d.tot.ymax= 228.0f;
2774         
2775         buts->v2d.min[0]= 256.0f;
2776         buts->v2d.min[1]= 42.0f;
2777
2778         buts->v2d.max[0]= 2048.0f;
2779         buts->v2d.max[1]= 450.0f;
2780         
2781         buts->v2d.minzoom= 0.5f;
2782         buts->v2d.maxzoom= 1.21f;
2783         
2784         buts->v2d.scroll= 0;
2785         buts->v2d.keepaspect= 1;
2786         buts->v2d.keepzoom= 1;
2787         buts->v2d.keeptot= 1;
2788         
2789 }
2790
2791 void test_butspace(void)
2792 {
2793         ScrArea *area= curarea;
2794         int blocksmin= uiBlocksGetYMin(&area->uiblocks)-10.0;
2795         
2796         G.buts->v2d.tot.ymin= MIN2(0.0, blocksmin-10.0);
2797 }
2798
2799 void init_butspace(ScrArea *sa)
2800 {
2801         SpaceButs *buts;
2802         
2803         buts= MEM_callocN(sizeof(SpaceButs), "initbuts");
2804         BLI_addhead(&sa->spacedata, buts);
2805
2806         buts->spacetype= SPACE_BUTS;
2807         buts->scaflag= BUTS_SENS_LINK|BUTS_SENS_ACT|BUTS_CONT_ACT|BUTS_ACT_ACT|BUTS_ACT_LINK;
2808
2809         /* set_rects only does defaults, so after reading a file the cur has not changed */
2810         set_rects_butspace(buts);
2811         buts->v2d.cur= buts->v2d.tot;
2812 }
2813
2814 void extern_set_butspace(int fkey)
2815 {
2816         ScrArea *sa;
2817         SpaceButs *sbuts;
2818         
2819         /* when a f-key pressed: closest button window is initialized */
2820         if(curarea->spacetype==SPACE_BUTS) sa= curarea;
2821         else {
2822                 /* find area */
2823                 sa= G.curscreen->areabase.first;
2824                 while(sa) {
2825                         if(sa->spacetype==SPACE_BUTS) bre