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