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