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