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