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