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