Pooh pooh! This backbuffer system for selection codes works much easier on
[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_all();/* To make constraint sliders redraw */
1798                                         }
1799                                 
1800                                 } while(get_mbut() & mousebut);
1801                         }
1802                         break;
1803                 case RIGHTMOUSE:
1804                         mouse_select_ipo();
1805                         allqueue (REDRAWACTION, 0);
1806                         allqueue(REDRAWNLA, 0);
1807                         break;
1808                 case MIDDLEMOUSE:
1809                         if(in_ipo_buttons()) {
1810                                 scroll_ipobuts();
1811                         }
1812                         else view2dmove(event); /* in drawipo.c */
1813                         break;
1814                 case WHEELUPMOUSE:
1815                 case WHEELDOWNMOUSE:
1816                         view2dmove(event);      /* in drawipo.c */
1817                         break;
1818                 case PADPLUSKEY:
1819                         view2d_zoom(v2d, 0.1154, sa->winx, sa->winy);
1820                         doredraw= 1;
1821                         break;
1822                 case PADMINUS:
1823                         view2d_zoom(v2d, -0.15, sa->winx, sa->winy);
1824                         doredraw= 1;
1825                         break;
1826                 case PAGEUPKEY:
1827                         if(G.qual==LR_CTRLKEY)
1828                                 movekey_ipo(1);
1829                         else if((G.qual==0))
1830                                 nextkey_ipo(1);
1831                         break;
1832                 case PAGEDOWNKEY:
1833                         if(G.qual==LR_CTRLKEY)
1834                                 movekey_ipo(-1);
1835                         else if((G.qual==0))
1836                                 nextkey_ipo(-1);
1837                         break;
1838                 case HOMEKEY:
1839                         if((G.qual==0))
1840                                 do_ipo_buttons(B_IPOHOME);
1841                         break;
1842                         
1843                 case AKEY:
1844                         if((G.qual==0)) {
1845                                 if(in_ipo_buttons()) {
1846                                         swap_visible_editipo();
1847                                 }
1848                                 else swap_selectall_editipo();
1849                                 allspace (REMAKEIPO, 0);
1850                                 allqueue (REDRAWNLA, 0);
1851                                 allqueue (REDRAWACTION, 0);
1852                         }
1853                         break;
1854                 case BKEY:
1855                         if((G.qual==0))
1856                                 borderselect_ipo();
1857                         break;
1858                 case CKEY:
1859                         if((G.qual==0))
1860                                 move_to_frame();
1861                         break;
1862                 case DKEY:
1863                         if((G.qual==LR_SHIFTKEY))
1864                                 add_duplicate_editipo();
1865                         break;
1866                 case GKEY:
1867                         if((G.qual==0))
1868                                 transform_ipo('g');
1869                         break;
1870                 case HKEY:
1871                         if((G.qual==LR_SHIFTKEY))
1872                                 sethandles_ipo(HD_AUTO);
1873                         else if((G.qual==0))
1874                                 sethandles_ipo(HD_ALIGN);
1875                         break;
1876                 case JKEY:
1877                         if((G.qual==0))
1878                                 join_ipo_menu();
1879                         break;
1880                 case KKEY:
1881                         if((G.qual==0)) {
1882                                 ipo_toggle_showkey();
1883                                 scrarea_queue_headredraw(curarea);
1884                                 allqueue(REDRAWVIEW3D, 0);
1885                                 doredraw= 1;
1886                         }
1887                         break;
1888                 case NKEY:
1889                         toggle_blockhandler(sa, IPO_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
1890                         doredraw= 1;
1891                         break;
1892                 case RKEY:
1893                         if((G.qual==0))
1894                                 ipo_record();
1895                         break;
1896                 case SKEY:
1897                         if((G.qual==LR_SHIFTKEY)) {             
1898                                 ipo_snap_menu();
1899                         } else if((G.qual==0))
1900                                 transform_ipo('s');
1901                         break;
1902                 case TKEY:
1903                         if((G.qual==0))
1904                                 set_ipotype();
1905                         break;
1906                 case VKEY:
1907                         if((G.qual==0))
1908                                 sethandles_ipo(HD_VECT);
1909                         break;
1910                 case XKEY:
1911                 case DELKEY:
1912                         if((G.qual==LR_SHIFTKEY))
1913                                 delete_key();
1914                         else if((G.qual==0))
1915                                 del_ipo();
1916                         break;
1917                 }
1918         }
1919
1920         if(doredraw) scrarea_queue_winredraw(sa);
1921 }
1922
1923 void initipo(ScrArea *sa)
1924 {
1925         SpaceIpo *sipo;
1926         
1927         sipo= MEM_callocN(sizeof(SpaceIpo), "initipo");
1928         BLI_addhead(&sa->spacedata, sipo);
1929
1930         sipo->spacetype= SPACE_IPO;
1931         sipo->blockscale= 0.7;
1932         
1933         /* sipo space loopt van (0,-?) tot (??,?) */
1934         sipo->v2d.tot.xmin= 0.0;
1935         sipo->v2d.tot.ymin= -10.0;
1936         sipo->v2d.tot.xmax= G.scene->r.efra;
1937         sipo->v2d.tot.ymax= 10.0;
1938
1939         sipo->v2d.cur= sipo->v2d.tot;
1940
1941         sipo->v2d.min[0]= 0.01f;
1942         sipo->v2d.min[1]= 0.01f;
1943
1944         sipo->v2d.max[0]= 15000.0f;
1945         sipo->v2d.max[1]= 10000.0f;
1946         
1947         sipo->v2d.scroll= L_SCROLL+B_SCROLL;
1948         sipo->v2d.keeptot= 0;
1949
1950         sipo->blocktype= ID_OB;
1951 }
1952
1953 /* ******************** SPACE: INFO ********************** */
1954
1955 void space_mipmap_button_function(int event) {
1956         set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
1957
1958         allqueue(REDRAWVIEW3D, 0);
1959 }
1960
1961 void space_sound_button_function(int event)
1962 {
1963         int a;
1964         SYS_SystemHandle syshandle;
1965
1966         if ((syshandle = SYS_GetSystem()))
1967         {
1968                 a = (U.gameflags & USER_DISABLE_SOUND);
1969                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
1970         }
1971 }
1972
1973 #define B_ADD_THEME     3301
1974 #define B_DEL_THEME     3302
1975 #define B_NAME_THEME    3303
1976 #define B_THEMECOL              3304
1977 #define B_UPDATE_THEME  3305
1978 #define B_CHANGE_THEME  3306
1979 #define B_THEME_COPY    3307
1980 #define B_THEME_PASTE   3308
1981
1982 #define B_RECALCLIGHT   3310
1983
1984 // needed for event; choose new 'curmain' resets it...
1985 static short th_curcol= TH_BACK;
1986 static char *th_curcol_ptr= NULL;
1987 static char th_curcol_arr[4]={0, 0, 0, 255};
1988
1989 void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
1990 {
1991         bTheme *btheme, *bt;
1992         int spacetype= 0;
1993         static short cur=1, curmain=2;
1994         short a, tot=0, isbuiltin= 0;
1995         char string[21*32], *strp, *col;
1996         
1997         y3= y2+23;      // exception!
1998         
1999         /* count total, max 16! */
2000         for(bt= U.themes.first; bt; bt= bt->next) tot++;
2001         
2002         /* if cur not is 1; move that to front of list */
2003         if(cur!=1) {
2004                 a= 1;
2005                 for(bt= U.themes.first; bt; bt= bt->next, a++) {
2006                         if(a==cur) {
2007                                 BLI_remlink(&U.themes, bt);
2008                                 BLI_addhead(&U.themes, bt);
2009                                 allqueue(REDRAWALL, 0);
2010                                 cur= 1;
2011                                 break;
2012                         }
2013                 }
2014         }
2015         
2016         /* the current theme */
2017         btheme= U.themes.first;
2018         if(strcmp(btheme->name, "Default")==0) isbuiltin= 1;
2019
2020         /* construct popup script */
2021         string[0]= 0;
2022         for(bt= U.themes.first; bt; bt= bt->next) {
2023                 strcat(string, bt->name);
2024                 if(btheme->next) strcat(string, "   |");
2025         }
2026         uiDefButS(block, MENU, B_UPDATE_THEME, string,                  45,y3,200,20, &cur, 0, 0, 0, 0, "Current theme");
2027         
2028         /* add / delete / name */
2029
2030         if(tot<16)
2031                 uiDefBut(block, BUT, B_ADD_THEME, "Add",        45,y2,200,20, NULL, 0, 0, 0, 0, "Makes new copy of this theme");
2032         if(tot>1 && isbuiltin==0)
2033                 uiDefBut(block, BUT, B_DEL_THEME, "Delete", 45,y1,200,20, NULL, 0, 0, 0, 0, "Delete theme");
2034
2035         if(isbuiltin) return;
2036         
2037         /* name */
2038         uiDefBut(block, TEX, B_NAME_THEME, "",                  255,y3,200,20, btheme->name, 1.0, 30.0, 0, 0, "Rename theme");
2039
2040         /* main choices pup */
2041         uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|%l|3D View %x2|%l|Ipo Curve Editor %x3|Action Editor %x4|"
2042                 "NLA Editor %x5|%l|UV/Image Editor %x6|Video Sequence Editor %x7|Audio Timeline %x8|Text Editor %x9|%l|User Preferences %x10|"
2043                 "OOPS Schematic %x11|Buttons Window %x12|%l|File Browser %x13|Image Browser %x14",
2044                                                                                                         255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
2045         if(curmain==1) spacetype= 0;
2046         else if(curmain==2) spacetype= SPACE_VIEW3D;
2047         else if(curmain==3) spacetype= SPACE_IPO;
2048         else if(curmain==4) spacetype= SPACE_ACTION;
2049         else if(curmain==5) spacetype= SPACE_NLA;
2050         else if(curmain==6) spacetype= SPACE_IMAGE;
2051         else if(curmain==7) spacetype= SPACE_SEQ;
2052         else if(curmain==8) spacetype= SPACE_SOUND;
2053         else if(curmain==9) spacetype= SPACE_TEXT;
2054         else if(curmain==10) spacetype= SPACE_INFO;
2055         else if(curmain==11) spacetype= SPACE_OOPS;
2056         else if(curmain==12) spacetype= SPACE_BUTS;
2057         else if(curmain==13) spacetype= SPACE_FILE;
2058         else if(curmain==14) spacetype= SPACE_IMASEL;
2059         else return; // only needed while coding... when adding themes for more windows
2060         
2061         /* color choices pup */
2062         if(curmain==1) {
2063                 strp= BIF_ThemeColorsPup(0);
2064                 if(th_curcol==TH_BACK) th_curcol= TH_BUT_OUTLINE;  // switching main choices...
2065         }
2066         else strp= BIF_ThemeColorsPup(spacetype);
2067         
2068         uiDefButS(block, MENU, B_REDR, strp,                    255,y1,200,20, &th_curcol, 0, 0, 0, 0, "Current color");
2069         MEM_freeN(strp);
2070         
2071         th_curcol_ptr= col= BIF_ThemeGetColorPtr(btheme, spacetype, th_curcol);
2072         if(col==NULL) return;
2073         
2074         /* first handle exceptions, special single values, row selection, etc */
2075         if(th_curcol==TH_VERTEX_SIZE) {
2076                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Vertex size ", 465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
2077         }
2078         else if(th_curcol==TH_FACEDOT_SIZE) {
2079                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Face dot size ",       465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
2080         }
2081         else if(th_curcol==TH_BUT_DRAWTYPE) {
2082                 uiBlockBeginAlign(block);
2083                 uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal",        465,y3,100,20,  col, 2.0, 0.0, 0, 0, "");
2084                 uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 565,y3,100,20,  col, 2.0, 1.0, 0, 0, "");
2085                 uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded",        465,y2,100,20,  col, 2.0, 2.0, 0, 0, "");
2086                 uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool",       565,y2,100,20,  col, 2.0, 3.0, 0, 0, "");
2087                 uiBlockEndAlign(block);
2088         }
2089         else {
2090                 uiBlockBeginAlign(block);
2091                 if ELEM3(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT) {
2092                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
2093                 }
2094                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
2095                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"G ",   465,y2,200,20,  col+1, 0.0, 255.0, B_THEMECOL, 0, "");
2096                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"B ",   465,y1,200,20,  col+2, 0.0, 255.0, B_THEMECOL, 0, "");
2097                 uiBlockEndAlign(block);
2098
2099                 uiDefButC(block, COL, B_UPDATE_THEME, "",               675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
2100                                 
2101                 /* copy paste */
2102                 uiBlockBeginAlign(block);
2103                 uiDefBut(block, BUT, B_THEME_COPY, "Copy Color",        755,y2,120,20, NULL, 0, 0, 0, 0, "Stores current color in buffer");
2104                 uiDefBut(block, BUT, B_THEME_PASTE, "Paste Color",      755,y1,120,20, NULL, 0, 0, 0, 0, "Pastes buffer color");
2105                 uiBlockEndAlign(block);
2106                 
2107                 uiDefButC(block, COL, 0, "",                            885,y1,50,y2-y1+20, th_curcol_arr, 0, 0, 0, 0, "");
2108                 
2109         }
2110 }
2111
2112
2113 void drawinfospace(ScrArea *sa, void *spacedata)
2114 {
2115         uiBlock *block;
2116         static short cur_light=0, cur_light_var=0;
2117         float fac, col[3];
2118         short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y5, y6;
2119         short y2label, y3label, y4label, y5label, y6label;
2120         short spref, mpref, lpref, smfileselbut;
2121         short edgsp, midsp;
2122         char naam[32];
2123
2124         if(curarea->win==0) return;
2125
2126         BIF_GetThemeColor3fv(TH_BACK, col);
2127         glClearColor(col[0], col[1], col[2], 0.0);
2128         glClear(GL_COLOR_BUFFER_BIT);
2129
2130         fac= ((float)curarea->winx)/1280.0f;
2131         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2132         
2133         sprintf(naam, "infowin %d", curarea->win);
2134         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->win);
2135
2136
2137         /* Vars for nice grid alignment */ 
2138         dx= (1280-90)/7;        /* spacing for use in equally dividing 'tab' row */
2139
2140         xpos = 45;              /* left padding */
2141         ypos = 50;              /* bottom padding for buttons */
2142         ypostab = 10;           /* bottom padding for 'tab' row */
2143
2144         buth = 20;              /* standard button height */
2145
2146         spref = 90;     /* standard size for small preferences button */
2147         mpref = 189;    /* standard size for medium preferences button */
2148         lpref = 288;    /* standard size for large preferences button */
2149         smfileselbut = buth;    /* standard size for fileselect button (square) */
2150
2151         edgsp = 3;              /* space from edge of end 'tab' to edge of end button */
2152         midsp = 9;              /* horizontal space between buttons */
2153
2154         rspace = 3;             /* default space between rows */
2155
2156         y1 = ypos;              /* grid alignment for each row of buttons */
2157         y2 = ypos+buth+rspace;
2158         y3 = ypos+2*(buth+rspace);
2159         y4 = ypos+3*(buth+rspace);
2160         y5 = ypos+4*(buth+rspace);
2161         y6 = ypos+5*(buth+rspace);
2162
2163
2164         y2label = y2-2;         /* adjustments to offset the labels down to align better */
2165         y3label = y3-2;
2166         y4label = y4-2;
2167         y5label = y5-2;
2168         y6label = y6-2;
2169
2170
2171         /* set the colour to blue and draw the main 'tab' controls */
2172
2173         uiBlockSetCol(block, TH_BUT_SETTING1);
2174         uiBlockBeginAlign(block);
2175         
2176         uiDefButS(block, ROW,B_USERPREF,"View & Controls",
2177                 xpos,ypostab,(short)dx,buth,
2178                 &U.userpref,1.0,0.0, 0, 0,"");
2179                 
2180         uiDefButS(block, ROW,B_USERPREF,"Edit Methods",
2181                 (short)(xpos+dx),ypostab,(short)dx,buth,
2182                 &U.userpref,1.0,1.0, 0, 0,"");
2183
2184         uiDefButS(block, ROW,B_USERPREF,"Language & Font",
2185                 (short)(xpos+2*dx),ypostab,(short)dx,buth,
2186                 &U.userpref,1.0,2.0, 0, 0,"");
2187
2188         uiDefButS(block, ROW,B_USERPREF,"Themes",
2189                 (short)(xpos+3*dx),ypostab,(short)dx,buth,
2190                 &U.userpref,1.0,6.0, 0, 0,"");
2191
2192         uiDefButS(block, ROW,B_USERPREF,"Auto Save",
2193                 (short)(xpos+4*dx),ypostab,(short)dx,buth,
2194                 &U.userpref,1.0,3.0, 0, 0,"");
2195
2196         uiDefButS(block, ROW,B_USERPREF,"System & OpenGL",
2197                 (short)(xpos+5*dx),ypostab,(short)dx,buth,
2198                 &U.userpref,1.0,4.0, 0, 0,"");
2199                 
2200         uiDefButS(block, ROW,B_USERPREF,"File Paths",
2201                 (short)(xpos+6*dx),ypostab,(short)dx,buth,
2202                 &U.userpref,1.0,5.0, 0, 0,"");
2203
2204         uiBlockSetCol(block, TH_AUTO);
2205         uiBlockEndAlign(block);
2206         /* end 'tab' controls */
2207
2208         /* line 2: left x co-ord, top y co-ord, width, height */
2209
2210         if(U.userpref == 6) {
2211                 info_user_themebuts(block, y1, y2, y3);
2212         }
2213         else if (U.userpref == 0) { /* view & controls */
2214
2215                 uiDefBut(block, LABEL,0,"Display:",
2216                         xpos,y6label,spref,buth,
2217                         0, 0, 0, 0, 0, "");     
2218                 uiDefButBitS(block, TOG, USER_TOOLTIPS, 0, "ToolTips",
2219                         (xpos+edgsp),y5,spref,buth,
2220                         &(U.flag), 0, 0, 0, 0,
2221                         "Display tooltips (help tags) over buttons");
2222                 uiDefButBitS(block, TOG, USER_DRAWVIEWINFO, B_DRAWINFO, "Object Info",
2223                         (xpos+edgsp),y4,spref,buth,
2224                         &(U.uiflag), 0, 0, 0, 0,
2225                         "Display active object name and frame number in the 3D View");
2226                 uiDefButBitS(block, TOG, USER_SCENEGLOBAL, 0, "Global Scene",
2227                         (xpos+edgsp),y3,spref,buth,
2228                         &(U.flag), 0, 0, 0, 0,
2229                         "Forces the current Scene to be displayed in all Screens");
2230 #ifndef __APPLE__       
2231                 uiDefButS(block, TOG|BIT|0, 0, "Large Cursors",
2232                         (xpos+edgsp),y2,spref,buth,
2233                         &(U.curssize), 0, 0, 0, 0,
2234                         "Use large mouse cursors when available");
2235 #else 
2236                 U.curssize=0; /*Small Cursor always for OS X for now */
2237 #endif
2238
2239                 uiDefBut(block, LABEL,0,"Menus:",
2240                         (xpos+(2*edgsp)+spref),y6label,spref,buth,
2241                         0, 0, 0, 0, 0, "");
2242                 uiDefButBitS(block, TOG, USER_MENUOPENAUTO, 0, "Open on Mouse Over",
2243                         (xpos+edgsp+spref+midsp),y5,mpref,buth,
2244                         &(U.uiflag), 0, 0, 0, 0,
2245                         "Open menu buttons and pulldowns automatically when the mouse is hovering");
2246                 uiDefButS(block, NUM, 0, "Top Level:",
2247                         (xpos+edgsp+spref+midsp),y4,spref+edgsp,buth,
2248                         &(U.menuthreshold1), 1, 40, 0, 0,
2249                         "Time delay in 1/10 seconds before automatically opening top level menus");
2250                 uiDefButS(block, NUM, 0, "Sublevels:",
2251                         (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y4,spref+edgsp,buth,
2252                         &(U.menuthreshold2), 1, 40, 0, 0,
2253                         "Time delay in 1/10 seconds before automatically opening menu sublevels");
2254
2255                 uiDefBut(block, LABEL,0,"Toolbox click-hold delay:",
2256                         (xpos+(2*edgsp)+spref),y3label,mpref,buth,
2257                         0, 0, 0, 0, 0, "");
2258                 uiDefButS(block, NUM, 0, "LMB:",
2259                         (xpos+edgsp+spref+midsp),y2,spref+edgsp,buth,
2260                         &(U.tb_leftmouse), 2, 40, 0, 0,
2261                         "Time in 1/10 seconds to hold the Left Mouse Button before opening the toolbox");
2262                 uiDefButS(block, NUM, 0, "RMB:",
2263                         (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y2,spref+edgsp,buth,
2264                         &(U.tb_rightmouse), 2, 40, 0, 0,
2265                         "Time in 1/10 seconds to hold the Right Mouse Button before opening the toolbox");      
2266                 uiDefButBitS(block, TOG, USER_PANELPINNED, 0, "Pin Floating Panels",
2267                         (xpos+edgsp+spref+midsp),y1,mpref,buth,
2268                         &(U.uiflag), 0, 0, 0, 0,
2269                         "Make floating panels invoked by a hotkey (eg. N Key) open at the previous location");
2270                 
2271                 
2272                 uiDefBut(block, LABEL,0,"Snap to grid:",
2273                         (xpos+(2*edgsp)+spref+midsp+mpref),y6label,mpref,buth,
2274                         0, 0, 0, 0, 0, "");
2275                 uiDefButBitS(block, TOG, USER_AUTOGRABGRID, 0, "Grab/Move",
2276                         (xpos+edgsp+mpref+spref+(2*midsp)),y5,spref,buth,
2277                         &(U.flag), 0, 0, 0, 0,
2278                         "Snap objects and sub-objects to grid units when moving");
2279                 uiDefButBitS(block, TOG, USER_AUTOROTGRID, 0, "Rotate",
2280                         (xpos+edgsp+mpref+spref+(2*midsp)),y4,spref,buth,
2281                         &(U.flag), 0, 0, 0, 0,
2282                         "Snap objects and sub-objects to grid units when rotating");
2283                 uiDefButBitS(block, TOG, USER_AUTOSIZEGRID, 0, "Scale",
2284                         (xpos+edgsp+mpref+spref+(2*midsp)),y3,spref,buth,
2285                         &(U.flag), 0, 0, 0, 0,
2286                         "Snap objects and sub-objects to grid units when scaling");
2287                 
2288                 uiDefButBitS(block, TOG, USER_LOCKAROUND, B_DRAWINFO, "Global Pivot",
2289                         (xpos+edgsp+mpref+spref+(2*midsp)),y1,spref,buth,
2290                         &(U.uiflag), 0, 0, 0, 0,
2291                         "Lock the same rotation/scaling pivot in all 3D Views");        
2292                 
2293                 uiDefBut(block, LABEL,0,"View zoom:",
2294                         (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y6label,mpref,buth,
2295                         0, 0, 0, 0, 0, "");
2296                 uiBlockBeginAlign(block);
2297                 uiDefButS(block, ROW, 0, "Continue",
2298                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y5,(mpref/3),buth,
2299                         &(U.viewzoom), 40, USER_ZOOM_CONT, 0, 0,
2300                         "Old style zoom, continues while moving mouse up or down");
2301                 uiDefButS(block, ROW, 0, "Dolly",
2302                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/3)),y5,(mpref/3),buth,
2303                         &(U.viewzoom), 40, USER_ZOOM_DOLLY, 0, 0,
2304                         "Zooms in and out based on vertical mouse movement.");
2305                 uiDefButS(block, ROW, 0, "Scale",
2306                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(2*mpref/3)),y5,(mpref/3),buth,
2307                         &(U.viewzoom), 40, USER_ZOOM_SCALE, 0, 0,
2308                         "Zooms in and out like scaling the view, mouse movements relative to center.");
2309                 uiBlockEndAlign(block);
2310                 
2311                 uiDefBut(block, LABEL,0,"View rotation:",
2312                         (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y4label,mpref,buth,
2313                         0, 0, 0, 0, 0, "");
2314                 uiBlockBeginAlign(block);
2315                 uiDefButBitS(block, TOG, USER_TRACKBALL, B_DRAWINFO, "Trackball",
2316                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y3,(mpref/2),buth,
2317                         &(U.flag), 0, 0, 0, 0,
2318                         "Allow the view to tumble freely when orbiting with the Middle Mouse Button");
2319                 uiDefButBitS(block, TOGN, USER_TRACKBALL, B_DRAWINFO, "Turntable",
2320                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/2)),y3,(mpref/2),buth,
2321                         &(U.flag), 0, 0, 0, 0,
2322                         "Keep the Global Z axis pointing upwards when orbiting the view with the Middle Mouse Button");
2323                 uiBlockEndAlign(block);
2324                 
2325                 uiDefButBitS(block, TOG, USER_AUTOPERSP, B_DRAWINFO, "Auto Perspective",
2326                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y1,spref,buth,
2327                         &(U.uiflag), 0, 0, 0, 0,
2328                         "Automatically switch between orthographic and perspective when changing from top/front/side views");
2329
2330                 uiDefBut(block, LABEL,0,"Select with:",
2331                         (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y6label,mpref,buth,
2332                         0, 0, 0, 0, 0, "");
2333                 uiBlockBeginAlign(block);
2334                 uiDefButBitS(block, TOG, USER_LMOUSESELECT, B_DRAWINFO, "Left Mouse",
2335                         (xpos+edgsp+(3*mpref)+(4*midsp)),y5,(mpref/2),buth,
2336                         &(U.flag), 0, 0, 0, 0, "Use the Left Mouse Button for selection");
2337                 uiDefButBitS(block, TOGN, USER_LMOUSESELECT, B_DRAWINFO, "Right Mouse",
2338                         (xpos+edgsp+(3*mpref)+(4*midsp)+(mpref/2)),y5,(mpref/2),buth,
2339                         &(U.flag), 0, 0, 0, 0, "Use the Right Mouse Button for selection");
2340                 uiBlockEndAlign(block);
2341                 
2342                 
2343                 if(U.flag & USER_LMOUSESELECT) {
2344                         uiDefBut(block, LABEL,0,"Cursor with: Right Mouse",
2345                                 (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
2346                                 0, 0, 0, 0, 0, "");
2347                 } else {
2348                         uiDefBut(block, LABEL,0,"Cursor with: Left Mouse",
2349                                 (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
2350                                 0, 0, 0, 0, 0, "");
2351                 }
2352
2353                 uiDefButBitS(block, TOG, USER_TWOBUTTONMOUSE, 0, "Emulate 3 Button Mouse",
2354                         (xpos+edgsp+(3*mpref)+(4*midsp)),y3,mpref,buth,
2355                         &(U.flag), 0, 0, 0, 0,
2356                         "Emulates a middle mouse button with Alt LeftMouse");
2357                 
2358                         
2359                 uiDefBut(block, LABEL,0,"Middle Mouse Button:",
2360                         (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y6label,mpref,buth,
2361                         0, 0, 0, 0, 0, "");
2362                 uiBlockBeginAlign(block);
2363                 uiDefButBitS(block, TOGN, USER_VIEWMOVE, B_DRAWINFO, "Rotate View",
2364                         (xpos+edgsp+(4*mpref)+(5*midsp)),y5,(mpref/2),buth,
2365                         &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
2366                 uiDefButBitS(block, TOG, USER_VIEWMOVE, B_DRAWINFO, "Pan View",
2367                         (xpos+edgsp+(4*mpref)+(5*midsp)+(mpref/2)),y5,(mpref/2),buth,
2368                         &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
2369                 uiBlockEndAlign(block);
2370                         
2371                 uiDefBut(block, LABEL,0,"Mouse Wheel:",
2372                         (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y4label,mpref,buth,
2373                         0, 0, 0, 0, 0, "");
2374                 uiDefButBitS(block, TOG, USER_WHEELZOOMDIR, 0, "Invert Zoom",
2375                         (xpos+edgsp+(4*mpref)+(5*midsp)),y3,spref,buth,
2376                         &(U.uiflag), 0, 0, 0, 0,
2377                         "Swap the Mouse Wheel zoom direction");
2378                 uiDefButI(block, NUM, 0, "Scroll Lines:",
2379                         (xpos+edgsp+(4*mpref)+(6*midsp)+spref-edgsp),y3,spref+edgsp,buth,
2380                         &U.wheellinescroll, 0.0, 32.0, 0, 0,
2381                         "The number of lines scrolled at a time with the mouse wheel"); 
2382
2383
2384         } else if (U.userpref == 1) { /* edit methods */
2385
2386
2387                 uiDefBut(block, LABEL,0,"Material linked to:",
2388                         xpos,y3label,mpref,buth,
2389                         0, 0, 0, 0, 0, "");
2390                 uiBlockBeginAlign(block);
2391                 uiDefButBitS(block, TOGN, USER_MAT_ON_OB, B_DRAWINFO, "ObData",
2392                         (xpos+edgsp),y2,(mpref/2),buth,
2393                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
2394                 uiDefButBitS(block, TOG, USER_MAT_ON_OB, B_DRAWINFO, "Object",
2395                         (xpos+edgsp+(mpref/2)),y2,(mpref/2),buth,
2396                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
2397                 uiBlockEndAlign(block);
2398
2399
2400                 uiDefBut(block, LABEL,0,"Editmode undo:",
2401                         (xpos+(2*edgsp)+mpref),y3label, mpref,buth,
2402                         0, 0, 0, 0, 0, "");
2403                 uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps:",
2404                         (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2405                         &(U.undosteps), 2, 64, 0, 0, "Number of undo steps available in Edit Mode (smaller values conserve memory)");
2406
2407                 uiDefButBitS(block, TOG, USER_GLOBALUNDO, B_DRAWINFO, "Global undo",
2408                         (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2409                         &(U.uiflag), 2, 64, 0, 0, "");
2410
2411
2412                 uiDefBut(block, LABEL,0,"Auto keyframe on:",
2413                         (xpos+(2*edgsp)+(2*mpref)+midsp),y3label,mpref,buth,
2414                         0, 0, 0, 0, 0, "");
2415                 uiDefButBitS(block, TOG, USER_KEYINSERTACT, 0, "Action",
2416                         (xpos+edgsp+(2*mpref)+(2*midsp)),y2,(spref+edgsp),buth,
2417                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Action Ipo curve");
2418                 uiDefButBitS(block, TOG, USER_KEYINSERTOBJ, 0, "Object",
2419                         (xpos+edgsp+(2*mpref)+(3*midsp)+spref-edgsp),y2,(spref+edgsp),buth,
2420                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Object Ipo curve");
2421
2422
2423                 uiDefBut(block, LABEL,0,"Duplicate with object:",
2424                         (xpos+(2*edgsp)+(3*midsp)+(3*mpref)+spref),y3label,mpref,buth,
2425                         0, 0, 0, 0, 0, "");
2426
2427                 uiDefButBitS(block, TOG, USER_DUP_MESH, 0, "Mesh",
2428                         (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y2,(spref+edgsp),buth,
2429                         &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
2430                 uiDefButBitS(block, TOG, USER_DUP_ARM, 0, "Armature",
2431                         (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y1,(spref+edgsp),buth,
2432                         &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
2433
2434                 uiDefButBitS(block, TOG, USER_DUP_SURF, 0, "Surface",
2435                         (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y2,(spref+edgsp),buth,
2436                         &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
2437                 uiDefButBitS(block, TOG, USER_DUP_LAMP, 0, "Lamp",
2438                         (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y1,(spref+edgsp),buth,
2439                         &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
2440
2441                 uiDefButBitS(block, TOG, USER_DUP_CURVE, 0, "Curve",
2442                         (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y2,(spref+edgsp),buth,
2443                         &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
2444                 uiDefButBitS(block, TOG, USER_DUP_MAT, 0, "Material",
2445                         (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y1,(spref+edgsp),buth,
2446                         &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
2447
2448                 uiDefButBitS(block, TOG, USER_DUP_FONT, 0, "Text",
2449                         (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y2,(spref+edgsp),buth,
2450                         &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
2451                 uiDefButBitS(block, TOG, USER_DUP_TEX, 0, "Texture",
2452                         (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y1,(spref+edgsp),buth,
2453                         &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
2454
2455                 uiDefButBitS(block, TOG, USER_DUP_MBALL, 0, "Metaball",
2456                         (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y2,(spref+edgsp),buth,
2457                         &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
2458                 uiDefButBitS(block, TOG, USER_DUP_IPO, 0, "Ipo",
2459                         (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y1,(spref+edgsp),buth,
2460                         &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
2461         
2462         } else if(U.userpref == 2) { /* language & colors */
2463
2464 #ifdef INTERNATIONAL
2465                 char curfont[320];
2466
2467                 sprintf(curfont, "Interface Font: ");
2468                 strcat(curfont,U.fontname);
2469
2470                 uiDefButBitS(block, TOG, USER_DOTRANSLATE, B_DOLANGUIFONT, "International Fonts",
2471                         xpos,y2,mpref,buth,
2472                         &(U.transopts), 0, 0, 0, 0, "Activate international interface");
2473
2474                 if(U.transopts & USER_DOTRANSLATE) {
2475                         uiDefBut(block, LABEL,0,curfont,
2476                                 (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2477                                 0, 0, 0, 0, 0, "");
2478
2479                         uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
2480                                 xpos,y1,mpref,buth,
2481                                 0, 0, 0, 0, 0, "Select a new font for the interface");
2482
2483
2484                         uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
2485                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2486                                 &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
2487
2488 /*
2489                         uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
2490                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2491                                 &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
2492
2493
2494                         uiDefBut(block, LABEL,0,"Translate:",
2495                                 (xpos+edgsp+(2.1*mpref)+(2*midsp)),y3label,mpref,buth,
2496                                 0, 0, 0, 0, 0, "");
2497 */
2498
2499                         uiDefButBitS(block, TOG, USER_TR_TOOLTIPS, B_SETTRANSBUTS, "Tooltips",
2500                                 (xpos+edgsp+(2.2*mpref)+(3*midsp)),y1,spref,buth,
2501                                 &(U.transopts), 0, 0, 0, 0, "Translate tooltips");
2502
2503                         uiDefButBitS(block, TOG, USER_TR_BUTTONS, B_SETTRANSBUTS, "Buttons",
2504                                 (xpos+edgsp+(2.2*mpref)+(4*midsp)+spref),y1,spref,buth,
2505                                 &(U.transopts), 0, 0, 0, 0, "Translate button labels");
2506
2507                         uiDefButBitS(block, TOG, USER_TR_MENUS, B_SETTRANSBUTS, "Toolbox",
2508                                 (xpos+edgsp+(2.2*mpref)+(5*midsp)+(2*spref)),y1,spref,buth,
2509                                 &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
2510
2511                         uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
2512                                 (xpos+edgsp+(2.2*mpref)+(3*midsp)),y2,mpref+(0.5*mpref)+3,buth,
2513                                 &U.language, 0, 0, 0, 0, "Select interface language");
2514                                 
2515                         /* uiDefButBitS(block, TOG, USER_TR_TEXTEDIT, B_SETTRANSBUTS, "FTF All windows",
2516                                 (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
2517                                 &(U.transopts), 0, 0, 0, 0,
2518                                 "Use FTF drawing for fileselect and textwindow "
2519                                 "(under construction)");
2520                         */
2521                 }
2522
2523 /* end of INTERNATIONAL */
2524 #endif
2525
2526         } else if(U.userpref == 3) { /* auto save */
2527
2528
2529                 uiDefButS(block, NUM, 0, "Save Versions:",
2530                         (xpos+edgsp),y3,mpref,buth,
2531                         &U.versions, 0.0, 32.0, 0, 0,
2532                         "The number of old versions to maintain in the current directory, when manually saving");
2533
2534                 uiDefButBitS(block, TOG, USER_AUTOSAVE, B_RESETAUTOSAVE, "Auto Save Temp Files",
2535                         (xpos+edgsp+mpref+midsp),y3,mpref,buth,
2536                         &(U.flag), 0, 0, 0, 0,
2537                         "Enables automatic saving of temporary files");
2538
2539                 if(U.flag & USER_AUTOSAVE) {
2540
2541                         uiDefButI(block, NUM, B_RESETAUTOSAVE, "Minutes:",
2542                                 (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2543                                 &(U.savetime), 1.0, 60.0, 0, 0,
2544                                 "The time (in minutes) to wait between automatic temporary saves");
2545
2546                         uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
2547                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2548                                 0, 0, 0, 0, 0,"Open the most recently saved temporary file");
2549                 }
2550
2551         } else if (U.userpref == 4) { /* system & opengl */
2552                 uiDefBut(block, LABEL,0,"Solid OpenGL light:",
2553                         xpos+edgsp, y3label, mpref, buth,
2554                         0, 0, 0, 0, 0, "");
2555                 
2556                 uiDefButS(block, MENU, B_REDR, "Light1 %x0|Light2 %x1|Light3 %x2",
2557                         xpos+edgsp, y2, 2*mpref/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
2558                 uiBlockSetCol(block, TH_BUT_SETTING1);
2559                 uiDefButI(block, TOG|BIT|0, B_RECALCLIGHT, "On",
2560                         xpos+edgsp+2*mpref/6, y2, mpref/6, buth, 
2561                         &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "");
2562                         
2563                 uiBlockSetCol(block, TH_AUTO);
2564                 uiDefButS(block, ROW, B_REDR, "Vec",
2565                         xpos+edgsp+3*mpref/6, y2, mpref/6, buth, 
2566                         &cur_light_var, 123.0, 0.0, 0, 0, "");
2567                 uiDefButS(block, ROW, B_REDR, "Col",
2568                         xpos+edgsp+4*mpref/6, y2, mpref/6, buth, 
2569                         &cur_light_var, 123.0, 1.0, 0, 0, "");
2570                 uiDefButS(block, ROW, B_REDR, "Spec",
2571                         xpos+edgsp+5*mpref/6, y2, mpref/6, buth, 
2572                         &cur_light_var, 123.0, 2.0, 0, 0, "");
2573
2574                 if(cur_light_var==1) {
2575                         uiDefButF(block, NUM, B_RECALCLIGHT, "R ",
2576                                 xpos+edgsp, y1, mpref/3, buth, 
2577                                 U.light[cur_light].col, 0.0, 1.0, 100, 2, "");
2578                         uiDefButF(block, NUM, B_RECALCLIGHT, "G ",
2579                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2580                                 U.light[cur_light].col+1, 0.0, 1.0, 100, 2, "");
2581                         uiDefButF(block, NUM, B_RECALCLIGHT, "B ",
2582                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2583                                 U.light[cur_light].col+2, 0.0, 1.0, 100, 2, "");
2584                 }
2585                 else if(cur_light_var==2) {
2586                         uiDefButF(block, NUM, B_RECALCLIGHT, "sR ",
2587                                 xpos+edgsp, y1, mpref/3, buth, 
2588                                 U.light[cur_light].spec, 0.0, 1.0, 100, 2, "");
2589                         uiDefButF(block, NUM, B_RECALCLIGHT, "sG ",
2590                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2591                                 U.light[cur_light].spec+1, 0.0, 1.0, 100, 2, "");
2592                         uiDefButF(block, NUM, B_RECALCLIGHT, "sB ",
2593                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2594                                 U.light[cur_light].spec+2, 0.0, 1.0, 100, 2, "");
2595                 }
2596                 else if(cur_light_var==0) {
2597                         uiDefButF(block, NUM, B_RECALCLIGHT, "X ",
2598                                 xpos+edgsp, y1, mpref/3, buth, 
2599                                 U.light[cur_light].vec, -1.0, 1.0, 100, 2, "");
2600                         uiDefButF(block, NUM, B_RECALCLIGHT, "Y ",
2601                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2602                                 U.light[cur_light].vec+1, -1.0, 1.0, 100, 2, "");
2603                         uiDefButF(block, NUM, B_RECALCLIGHT, "Z ",
2604                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2605                                 U.light[cur_light].vec+2, -1.0, 1.0, 100, 2, "");
2606                 }
2607
2608 /*
2609                 uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
2610                         (xpos+edgsp),y2,lpref,buth,
2611                         &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
2612
2613                 uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
2614                         (xpos+edgsp), y1, lpref,buth,
2615                         &U.console_out, 0, 0, 0, 0, "Select console output method");
2616
2617                 uiDefButS(block, NUM, B_CONSOLENUMLINES, "Lines:",
2618                         (xpos+edgsp+lpref+midsp),y1,spref,buth,
2619                         &U.console_buffer, 1.0, 4000.0, 0, 0, "Maximum number of internal console lines");
2620 */
2621
2622 #ifdef _WIN32
2623                 uiDefBut(block, LABEL,0,"Win Codecs:",
2624                         (xpos+edgsp+(1*midsp)+(1*mpref)),y3label,mpref,buth,
2625                         0, 0, 0, 0, 0, "");
2626
2627                 uiDefButBitS(block, TOG, USER_ALLWINCODECS, 0, "Enable all codecs",
2628                         (xpos+edgsp+(1*mpref)+(1*midsp)),y2,mpref,buth,
2629                         &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
2630 #endif
2631
2632                 uiDefBut(block, LABEL,0,"Keyboard:",
2633                         (xpos+edgsp+(3*midsp)+(3*mpref)),y3label,mpref,buth,
2634                         0, 0, 0, 0, 0, "");
2635
2636                 uiDefButBitS(block, TOG, USER_NO_CAPSLOCK, B_U_CAPSLOCK, "Disable Caps Lock",
2637                         (xpos+edgsp+(3*midsp)+(3*mpref)),y1,mpref,buth,
2638                         &(U.flag), 0, 0, 0, 0,
2639                         "Disables the Caps Lock key when entering text");
2640
2641                 uiDefButBitS(block, TOG, USER_NONUMPAD, 0, "Emulate Numpad",
2642                         (xpos+edgsp+(3*midsp)+(3*mpref)),y2,mpref,buth,
2643                         &(U.flag), 0, 0, 0, 0,
2644                         "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
2645
2646
2647                 uiDefBut(block, LABEL,0,"System:",
2648                         (xpos+edgsp+(4*midsp)+(4*mpref)),y3label,mpref,buth,
2649                         0, 0, 0, 0, 0, "");
2650
2651                 uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Sound",
2652                         (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
2653                         &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
2654
2655                 uiDefButBitS(block, TOG, USER_FILTERFILEEXTS, 0, "Filter File Extensions",
2656                         (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
2657                         &(U.uiflag), 0, 0, 0, 0, "Display only files with extensions in the image select window");
2658
2659
2660                 uiDefBut(block, LABEL,0,"OpenGL:",
2661                         (xpos+edgsp+(5*midsp)+(5*mpref)),y3label,mpref,buth,
2662                         0, 0, 0, 0, 0, "");
2663
2664                 uiDefButBitI(block, TOGN, USER_DISABLE_MIPMAP, B_MIPMAPCHANGED, "Mipmaps",
2665                         (xpos+edgsp+(5*mpref)+(5*midsp)),y2,mpref,buth,
2666                         &(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
2667
2668                 uiDefButBitI(block, TOG, USER_VERTEX_ARRAYS, 0, "Vertex Arrays",
2669                         (xpos+edgsp+(5*mpref)+(5*midsp)),y1,mpref,buth,
2670                         &(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
2671
2672                 uiDefBut(block, LABEL,0,"Audio mixing buffer:",
2673                         (xpos+edgsp+(2*midsp)+(2*mpref)),y3label,mpref,buth,
2674                         0, 0, 0, 0, 0, "");
2675                 uiBlockBeginAlign(block);
2676                 uiDefButI(block, ROW, 0, "256",
2677                         (xpos+edgsp+(2*midsp)+(2*mpref)),y2,(mpref/4),buth,
2678                         &U.mixbufsize, 2.0, 256.0, 0, 0, "Set audio mixing buffer size to 256 samples");
2679                 uiDefButI(block, ROW, 0, "512",
2680                         (xpos+edgsp+(2*midsp)+(2*mpref)+(mpref/4)),y2,(mpref/4),buth,
2681                         &U.mixbufsize, 2.0, 512.0, 0, 0, "Set audio mixing buffer size to 512 samples");        
2682                 uiDefButI(block, ROW, 0, "1024",
2683                         (xpos+edgsp+(2*midsp)+(2*mpref)+(2*mpref/4)),y2,(mpref/4),buth,
2684                         &U.mixbufsize, 2.0, 1024.0, 0, 0, "Set audio mixing buffer size to 1024 samples");              
2685                 uiDefButI(block, ROW, 0, "2048",
2686                         (xpos+edgsp+(2*midsp)+(2*mpref)+(3*mpref/4)),y2,(mpref/4),buth,
2687                         &U.mixbufsize, 2.0, 2048.0, 0, 0, "Set audio mixing buffer size to 2048 samples");                      
2688                 uiBlockEndAlign(block);
2689
2690         } else if(U.userpref == 5) { /* file paths */
2691
2692                 /* yafray: (temporary) path button for yafray xml export, now with fileselect */
2693                 uiDefBut(block, TEX, 0, "YFexport: ",
2694                         (xpos+edgsp), y2+buth+rspace, lpref-smfileselbut, buth,
2695                         U.yfexportdir, 1.0, 63.0, 0, 0,
2696                         "The default directory for yafray xml export (must exist!)");
2697                 uiDefIconBut(block, BUT, B_YAFRAYDIRFILESEL, ICON_FILESEL,
2698                         (xpos+edgsp+lpref-smfileselbut), y2+buth+rspace, smfileselbut, buth,
2699                         0, 0, 0, 0, 0, "Select the default yafray export directory");
2700
2701                 uiDefBut(block, TEX, 0, "Fonts: ",
2702                         (xpos+edgsp),y2,(lpref-smfileselbut),buth,
2703                         U.fontdir, 1.0, 63.0, 0, 0,
2704                         "The default directory to search for loading fonts");
2705                 uiDefIconBut(block, BUT, B_FONTDIRFILESEL, ICON_FILESEL,
2706                         (xpos+edgsp+lpref-smfileselbut),y2,smfileselbut,buth,
2707                         0, 0, 0, 0, 0, "Select the default font directory");
2708
2709                 uiDefBut(block, TEX, 0, "Textures: ",
2710                         (xpos+edgsp+lpref+midsp),y2,(lpref-smfileselbut),buth,
2711                         U.textudir, 1.0, 63.0, 0, 0, "The default directory to search for textures");
2712                 uiDefIconBut(block, BUT, B_TEXTUDIRFILESEL, ICON_FILESEL,
2713                         (xpos+edgsp+(2*lpref)+midsp-smfileselbut),y2,smfileselbut,buth,
2714                         0, 0, 0, 0, 0, "Select the default texture location");
2715
2716
2717                 uiDefBut(block, TEX, 0, "Tex Plugins: ",
2718                         (xpos+edgsp+(2*lpref)+(2*midsp)),y2,(lpref-smfileselbut),buth,
2719                         U.plugtexdir, 1.0, 63.0, 0, 0, "The default directory to search for texture plugins");
2720                 uiDefIconBut(block, BUT, B_PLUGTEXDIRFILESEL, ICON_FILESEL,
2721                         (xpos+edgsp+(3*lpref)+(2*midsp)-smfileselbut),y2,smfileselbut,buth,
2722                         0, 0, 0, 0, 0, "Select the default texture plugin location");
2723
2724                 uiDefBut(block, TEX, 0, "Seq Plugins: ",
2725                         (xpos+edgsp+(3*lpref)+(3*midsp)),y2,(lpref-smfileselbut),buth,
2726                         U.plugseqdir, 1.0, 63.0, 0, 0, "The default directory to search for sequence plugins");
2727                 uiDefIconBut(block, BUT, B_PLUGSEQDIRFILESEL, ICON_FILESEL,
2728                         (xpos+edgsp+(4*lpref)+(3*midsp)-smfileselbut),y2,smfileselbut,buth,
2729                         0, 0, 0, 0, 0, "Select the default sequence plugin location");
2730
2731
2732                 uiDefBut(block, TEX, 0, "Render: ",
2733                         (xpos+edgsp),y1,(lpref-smfileselbut),buth,
2734                         U.renderdir, 1.0, 63.0, 0, 0, "The default directory for rendering output");
2735                 uiDefIconBut(block, BUT, B_RENDERDIRFILESEL, ICON_FILESEL,
2736                         (xpos+edgsp+lpref-smfileselbut),y1,smfileselbut,buth,
2737                         0, 0, 0, 0, 0, "Select the default render output location");
2738
2739                 uiDefBut(block, TEX, 0, "Python: ",
2740                         (xpos+edgsp+lpref+midsp),y1,(lpref-2*smfileselbut),buth,
2741                         U.pythondir, 1.0, 63.0, 0, 0, "The default directory to search for Python scripts");
2742                 uiDefIconBut(block, BUT, B_PYMENUEVAL, ICON_SCRIPT,
2743                         (xpos+edgsp+(2*lpref)+midsp-2*smfileselbut),y1,smfileselbut,buth,
2744                         0, 0, 0, 0, 0, "Re-evaluate scripts registration in menus");
2745                 uiDefIconBut(block, BUT, B_PYTHONDIRFILESEL, ICON_FILESEL,
2746                         (xpos+edgsp+(2*lpref)+midsp-smfileselbut),y1,smfileselbut,buth,
2747                         0, 0, 0, 0, 0, "Select the default Python script location");
2748
2749
2750                 uiDefBut(block, TEX, 0, "Sounds: ",
2751                         (xpos+edgsp+(2*lpref)+(2*midsp)),y1,(lpref-smfileselbut),buth,
2752                         U.sounddir, 1.0, 63.0, 0, 0, "The default directory to search for sounds");
2753                 uiDefIconBut(block, BUT, B_SOUNDDIRFILESEL, ICON_FILESEL,
2754                         (xpos+edgsp+(3*lpref)+(2*midsp)-smfileselbut),y1,smfileselbut,buth,
2755                         0, 0, 0, 0, 0, "Select the default sound location");
2756
2757                 uiDefBut(block, TEX, 0, "Temp: ",
2758                          (xpos+edgsp+(3*lpref)+(3*midsp)),y1,(lpref-smfileselbut),buth,
2759                          U.tempdir, 1.0, 63.0, 0, 0, "The directory for storing temporary save files");
2760                 uiDefIconBut(block, BUT, B_TEMPDIRFILESEL, ICON_FILESEL,
2761                         (xpos+edgsp+(4*lpref)+(3*midsp)-smfileselbut),y1,smfileselbut,buth,
2762                         0, 0, 0, 0, 0, "Select the default temporary save file location");
2763
2764         }
2765
2766         uiDrawBlock(block);
2767         
2768         myortho2(-0.375, (float)(sa->winx)-0.375, -0.375, (float)(sa->winy)-0.375);
2769         draw_area_emboss(sa);
2770         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2771         sa->win_swap= WIN_BACK_OK;
2772         
2773 }
2774
2775
2776 void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2777 {
2778         unsigned short event= evt->event;
2779         short val= evt->val;
2780         
2781         if(val) {
2782                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2783
2784                 switch(event) {
2785                 case UI_BUT_EVENT:
2786                         if(val==B_ADD_THEME) {
2787                                 bTheme *btheme, *new;
2788                                 
2789                                 btheme= U.themes.first;
2790                                 new= MEM_callocN(sizeof(bTheme), "theme");
2791                                 memcpy(new, btheme, sizeof(bTheme));
2792                                 BLI_addhead(&U.themes, new);
2793                                 strcpy(new->name, "New User Theme");
2794                                 addqueue(sa->win, REDRAW, 1);
2795                         }
2796                         else if(val==B_DEL_THEME) {
2797                                 bTheme *btheme= U.themes.first;
2798                                 BLI_remlink(&U.themes, btheme);
2799                                 MEM_freeN(btheme);
2800                                 BIF_SetTheme(sa); // prevent usage of old theme in calls        
2801                                 addqueue(sa->win, REDRAW, 1);
2802                         }
2803                         else if(val==B_NAME_THEME) {
2804                                 bTheme *btheme= U.themes.first;