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