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