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