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