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