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