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