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