Add theme colour for "Draw Normals"
[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                                                 if(U.uiflag & USER_GLOBALUNDO) BIF_undo_step(1);
1443                                                 else single_user();
1444                                         }
1445                                 }
1446                                 else if(G.qual==LR_SHIFTKEY)
1447                                         if(U.uiflag & USER_GLOBALUNDO) BIF_undo_step(-1);
1448                                         
1449                                 break;
1450                         case VKEY:
1451                                 ob= OBACT;
1452                                 if((G.qual==LR_SHIFTKEY)) {
1453                                         if ((G.obedit) && G.obedit->type==OB_MESH) {
1454                                                 align_view_to_selected(v3d);
1455                                         }
1456                                         else if (G.f & G_FACESELECT) {
1457                                                 align_view_to_selected(v3d);
1458                                         }
1459                                 }
1460                                 else if(G.qual==LR_ALTKEY)
1461                                         image_aspect();
1462                                 else if (G.qual==0){
1463                                         if(G.obedit) {
1464                                                 if(G.obedit->type==OB_CURVE) {
1465                                                         undo_push_curve("Handle change");
1466                                                         sethandlesNurb(2);
1467                                                         makeDispList(G.obedit);
1468                                                         allqueue(REDRAWVIEW3D, 0);
1469                                                 }
1470                                         }
1471                                         else if(ob && ob->type == OB_MESH) 
1472                                                 set_vpaint();
1473                                 }
1474                                 break;
1475                         case WKEY:
1476                                 if((G.qual==LR_SHIFTKEY)) {
1477                                         transform('w');
1478                                 }
1479                                 else if(G.qual==LR_ALTKEY) {
1480                                         /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
1481                                 }
1482                                 else if(G.qual==LR_CTRLKEY) {
1483                                         if(G.obedit) {
1484                                                 if ELEM(G.obedit->type,  OB_CURVE, OB_SURF) {
1485                                                         switchdirectionNurb2();
1486                                                 }
1487                                         }
1488                                 }
1489                                 else if((G.qual==0))
1490                                         special_editmenu();
1491                                 
1492                                 break;
1493                         case XKEY:
1494                         case DELKEY:
1495                                 if(G.qual==0)
1496                                         delete_context_selected();
1497                                 break;
1498                         case YKEY:
1499                                 if((G.qual==0) && (G.obedit)) {
1500                                         if(G.obedit->type==OB_MESH) split_mesh();
1501                                 }
1502                                 break;
1503                         case ZKEY:
1504                                 toggle_shading();
1505                                 
1506                                 scrarea_queue_headredraw(curarea);
1507                                 scrarea_queue_winredraw(curarea);
1508                                 break;
1509                                 
1510                         
1511                         case HOMEKEY:
1512                                 if(G.qual==0)
1513                                         view3d_home(0);
1514                                 break;
1515                         case COMMAKEY:
1516                                 if(G.qual==LR_CTRLKEY) {
1517                                         G.vd->around= V3D_CENTROID;
1518                                 } else if(G.qual==LR_SHIFTKEY) {
1519                                         G.vd->around= V3D_CENTROID;
1520                                 } else if(G.qual==0) {
1521                                         G.vd->around= V3D_CENTRE;
1522                                 }
1523                                 scrarea_queue_headredraw(curarea);
1524                                 break;
1525                                 
1526                         case PERIODKEY:
1527                                 if(G.qual==LR_CTRLKEY) {
1528                                         G.vd->around= V3D_LOCAL;
1529                                 }       else if(G.qual==0) {
1530                                         G.vd->around= V3D_CURSOR;
1531                                 }
1532                                 scrarea_queue_headredraw(curarea);
1533                                 break;
1534                         
1535                         case PADSLASHKEY:
1536                                 if(G.qual==0) {
1537                                         if(G.vd->localview) {
1538                                                 G.vd->localview= 0;
1539                                                 endlocalview(curarea);
1540                                         }
1541                                         else {
1542                                                 G.vd->localview= 1;
1543                                                 initlocalview();
1544                                         }
1545                                         scrarea_queue_headredraw(curarea);
1546                                 }
1547                                 break;
1548                         case PADASTERKEY:       /* '*' */
1549                                 if(G.qual==0) {
1550                                         ob= OBACT;
1551                                         if(ob) {
1552                                                 obmat_to_viewmat(ob);
1553                                                 if(G.vd->persp==2) G.vd->persp= 1;
1554                                                 scrarea_queue_winredraw(curarea);
1555                                         }
1556                                 }
1557                                 break;
1558                         case PADPERIOD: /* '.' */
1559                                 if(G.qual==0)
1560                                         centreview();
1561                                 break;
1562                         
1563                         case PAGEUPKEY:
1564                                 if(G.qual==LR_CTRLKEY)
1565                                         movekey_obipo(1);
1566                                 else if((G.qual==0))
1567                                         nextkey_obipo(1);       /* in editipo.c */
1568                                 break;
1569
1570                         case PAGEDOWNKEY:
1571                                 if(G.qual==LR_CTRLKEY)
1572                                         movekey_obipo(-1);
1573                                 else if((G.qual==0))
1574                                         nextkey_obipo(-1);
1575                                 break;
1576                                 
1577                         case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
1578                         case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
1579                         case PADENTER:
1580                                 persptoetsen(event);
1581                                 doredraw= 1;
1582                                 break;
1583                         case PADMINUS:
1584                                 if ( (G.qual==LR_CTRLKEY)
1585                                          && (G.obedit) && (G.obedit->type==OB_MESH) )
1586                                         select_less();
1587                                 else {
1588                                         persptoetsen(event);
1589                                         doredraw= 1;
1590                                 }
1591                                 break;
1592
1593                         case PADPLUSKEY:
1594                                 if ( (G.qual==LR_CTRLKEY)
1595                                          && (G.obedit) && (G.obedit->type==OB_MESH) )
1596                                         select_more();
1597                                 else {
1598                                         persptoetsen(event);
1599                                         doredraw= 1;
1600                                 }
1601                                 break;
1602
1603                         case ESCKEY:
1604                                 if(G.qual==0) {
1605                                         if (G.vd->flag & V3D_DISPIMAGE) {
1606                                                 G.vd->flag &= ~V3D_DISPIMAGE;
1607                                                 doredraw= 1;
1608                                         }
1609                                 }
1610                                 break;
1611                         }
1612                 }
1613         }
1614         
1615         if(doredraw) {
1616                 scrarea_queue_winredraw(curarea);
1617                 scrarea_queue_headredraw(curarea);
1618         }
1619 }
1620
1621 void initview3d(ScrArea *sa)
1622 {
1623         View3D *vd;
1624         
1625         vd= MEM_callocN(sizeof(View3D), "initview3d");
1626         BLI_addhead(&sa->spacedata, vd);        /* addhead! not addtail */
1627
1628         vd->spacetype= SPACE_VIEW3D;
1629         vd->blockscale= 0.7;
1630         vd->viewquat[0]= 1.0;
1631         vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0;
1632         vd->persp= 1;
1633         vd->drawtype= OB_WIRE;
1634         vd->view= 7;
1635         vd->dist= 10.0;
1636         vd->lens= 35.0f;
1637         vd->near= 0.01f;
1638         vd->far= 500.0f;
1639         vd->grid= 1.0f;
1640         vd->gridlines= 16;
1641         vd->lay= vd->layact= 1;
1642         if(G.scene) {
1643                 vd->lay= vd->layact= G.scene->lay;
1644                 vd->camera= G.scene->camera;
1645         }
1646         vd->scenelock= 1;
1647         vd->gridflag |= V3D_SHOW_X;
1648         vd->gridflag |= V3D_SHOW_Y;
1649         vd->gridflag |= V3D_SHOW_FLOOR;
1650         vd->gridflag &= ~V3D_SHOW_Z;
1651 }
1652
1653
1654 /* ******************** SPACE: IPO ********************** */
1655
1656 static void changeview2dspace(ScrArea *sa, void *spacedata)
1657 {
1658         if(G.v2d==0) return;
1659
1660         test_view2d(G.v2d, curarea->winx, curarea->winy);
1661         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
1662 }
1663
1664 void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
1665 {
1666         extern void do_ipobuts(unsigned short event);   // drawipo.c
1667         unsigned short event= evt->event;
1668         short val= evt->val;
1669         SpaceIpo *sipo= curarea->spacedata.first;
1670         View2D *v2d= &sipo->v2d;
1671         float dx, dy;
1672         int cfra, doredraw= 0;
1673         short mval[2];
1674         short mousebut = L_MOUSE;
1675         
1676         if(sa->win==0) return;
1677
1678         if(val) {
1679                 if( uiDoBlocks(&sa->uiblocks, event)!=UI_NOTHING ) event= 0;
1680
1681                 /* swap mouse buttons based on user preference */
1682                 if (U.flag & USER_LMOUSESELECT) {
1683                         if (evt->event == LEFTMOUSE) {
1684                                 event = RIGHTMOUSE;
1685                                 mousebut = L_MOUSE;
1686                         } else if (evt->event == RIGHTMOUSE) {
1687                                 event = LEFTMOUSE;
1688                                 mousebut = R_MOUSE;
1689                         }
1690                 }
1691
1692                 switch(event) {
1693                 case UI_BUT_EVENT:
1694                         /* note: bad bad code, will be cleaned! is because event queues are all shattered */
1695                         if(val>0 && val < 65) do_ipowin_buts(val-1);
1696                         else do_ipobuts(val);
1697                         break;
1698                         
1699                 case LEFTMOUSE:
1700                         if( in_ipo_buttons() ) {
1701                                 do_ipo_selectbuttons();
1702                                 doredraw= 1;
1703                         }                       
1704                         else if(G.qual & LR_CTRLKEY) add_vert_ipo();
1705                         else {
1706                                 do {
1707                                         getmouseco_areawin(mval);
1708                                         areamouseco_to_ipoco(v2d, mval, &dx, &dy);
1709                                         
1710                                         cfra= (int)dx;
1711                                         if(cfra< 1) cfra= 1;
1712                                         
1713                                         if( cfra!=CFRA ) {
1714                                                 CFRA= cfra;
1715                                                 update_for_newframe();
1716                                                 force_draw_plus(SPACE_VIEW3D);
1717                                                 force_draw_plus(SPACE_ACTION);
1718                                                 force_draw_plus(SPACE_BUTS);    /* To make constraint sliders redraw */
1719                                         }
1720                                 
1721                                 } while(get_mbut() & mousebut);
1722                         }
1723                         break;
1724                 case RIGHTMOUSE:
1725                         mouse_select_ipo();
1726                         allqueue (REDRAWACTION, 0);
1727                         allqueue(REDRAWNLA, 0);
1728                         break;
1729                 case MIDDLEMOUSE:
1730                         if(in_ipo_buttons()) {
1731                                 scroll_ipobuts();
1732                         }
1733                         else view2dmove(event); /* in drawipo.c */
1734                         break;
1735                 case WHEELUPMOUSE:
1736                 case WHEELDOWNMOUSE:
1737                         view2dmove(event);      /* in drawipo.c */
1738                         break;
1739                 case PADPLUSKEY:
1740                         view2d_zoom(v2d, 0.1154, sa->winx, sa->winy);
1741                         doredraw= 1;
1742                         break;
1743                 case PADMINUS:
1744                         view2d_zoom(v2d, -0.15, sa->winx, sa->winy);
1745                         doredraw= 1;
1746                         break;
1747                 case PAGEUPKEY:
1748                         if(G.qual==LR_CTRLKEY)
1749                                 movekey_ipo(1);
1750                         else if((G.qual==0))
1751                                 nextkey_ipo(1);
1752                         break;
1753                 case PAGEDOWNKEY:
1754                         if(G.qual==LR_CTRLKEY)
1755                                 movekey_ipo(-1);
1756                         else if((G.qual==0))
1757                                 nextkey_ipo(-1);
1758                         break;
1759                 case HOMEKEY:
1760                         if((G.qual==0))
1761                                 do_ipo_buttons(B_IPOHOME);
1762                         break;
1763                         
1764                 case AKEY:
1765                         if((G.qual==0)) {
1766                                 if(in_ipo_buttons()) {
1767                                         swap_visible_editipo();
1768                                 }
1769                                 else swap_selectall_editipo();
1770                                 allspace (REMAKEIPO, 0);
1771                                 allqueue (REDRAWNLA, 0);
1772                                 allqueue (REDRAWACTION, 0);
1773                         }
1774                         break;
1775                 case BKEY:
1776                         if((G.qual==0))
1777                                 borderselect_ipo();
1778                         break;
1779                 case CKEY:
1780                         if((G.qual==0))
1781                                 move_to_frame();
1782                         break;
1783                 case DKEY:
1784                         if((G.qual==LR_SHIFTKEY))
1785                                 add_duplicate_editipo();
1786                         break;
1787                 case GKEY:
1788                         if((G.qual==0))
1789                                 transform_ipo('g');
1790                         break;
1791                 case HKEY:
1792                         if((G.qual==LR_SHIFTKEY))
1793                                 sethandles_ipo(HD_AUTO);
1794                         else if((G.qual==0))
1795                                 sethandles_ipo(HD_ALIGN);
1796                         break;
1797                 case JKEY:
1798                         if((G.qual==0))
1799                                 join_ipo_menu();
1800                         break;
1801                 case KKEY:
1802                         if((G.qual==0)) {
1803                                 ipo_toggle_showkey();
1804                                 scrarea_queue_headredraw(curarea);
1805                                 allqueue(REDRAWVIEW3D, 0);
1806                                 doredraw= 1;
1807                         }
1808                         break;
1809                 case NKEY:
1810                         toggle_blockhandler(sa, IPO_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
1811                         doredraw= 1;
1812                         break;
1813                 case RKEY:
1814                         if((G.qual==0))
1815                                 ipo_record();
1816                         break;
1817                 case SKEY:
1818                         if((G.qual==LR_SHIFTKEY)) {             
1819                                 ipo_snap_menu();
1820                         } else if((G.qual==0))
1821                                 transform_ipo('s');
1822                         break;
1823                 case TKEY:
1824                         if((G.qual==0))
1825                                 set_ipotype();
1826                         break;
1827                 case VKEY:
1828                         if((G.qual==0))
1829                                 sethandles_ipo(HD_VECT);
1830                         break;
1831                 case XKEY:
1832                 case DELKEY:
1833                         if((G.qual==LR_SHIFTKEY))
1834                                 delete_key();
1835                         else if((G.qual==0))
1836                                 del_ipo();
1837                         break;
1838                 }
1839         }
1840
1841         if(doredraw) scrarea_queue_winredraw(sa);
1842 }
1843
1844 void initipo(ScrArea *sa)
1845 {
1846         SpaceIpo *sipo;
1847         
1848         sipo= MEM_callocN(sizeof(SpaceIpo), "initipo");
1849         BLI_addhead(&sa->spacedata, sipo);
1850
1851         sipo->spacetype= SPACE_IPO;
1852         sipo->blockscale= 0.7;
1853         
1854         /* sipo space loopt van (0,-?) tot (??,?) */
1855         sipo->v2d.tot.xmin= 0.0;
1856         sipo->v2d.tot.ymin= -10.0;
1857         sipo->v2d.tot.xmax= G.scene->r.efra;
1858         sipo->v2d.tot.ymax= 10.0;
1859
1860         sipo->v2d.cur= sipo->v2d.tot;
1861
1862         sipo->v2d.min[0]= 0.01f;
1863         sipo->v2d.min[1]= 0.01f;
1864
1865         sipo->v2d.max[0]= 15000.0f;
1866         sipo->v2d.max[1]= 10000.0f;
1867         
1868         sipo->v2d.scroll= L_SCROLL+B_SCROLL;
1869         sipo->v2d.keeptot= 0;
1870
1871         sipo->blocktype= ID_OB;
1872 }
1873
1874 /* ******************** SPACE: INFO ********************** */
1875
1876 void space_mipmap_button_function(int event) {
1877         set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
1878
1879         allqueue(REDRAWVIEW3D, 0);
1880 }
1881
1882 void space_sound_button_function(int event)
1883 {
1884         int a;
1885         SYS_SystemHandle syshandle;
1886
1887         if ((syshandle = SYS_GetSystem()))
1888         {
1889                 a = (U.gameflags & USER_DISABLE_SOUND);
1890                 SYS_WriteCommandLineInt(syshandle, "noaudio", a);
1891         }
1892 }
1893
1894 #define B_ADD_THEME     3301
1895 #define B_DEL_THEME     3302
1896 #define B_NAME_THEME    3303
1897 #define B_THEMECOL              3304
1898 #define B_UPDATE_THEME  3305
1899 #define B_CHANGE_THEME  3306
1900 #define B_THEME_COPY    3307
1901 #define B_THEME_PASTE   3308
1902
1903 #define B_RECALCLIGHT   3310
1904
1905 // needed for event; choose new 'curmain' resets it...
1906 static short th_curcol= TH_BACK;
1907 static char *th_curcol_ptr= NULL;
1908 static char th_curcol_arr[4]={0, 0, 0, 255};
1909
1910 void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
1911 {
1912         bTheme *btheme, *bt;
1913         int spacetype= 0;
1914         static short cur=1, curmain=2;
1915         short a, tot=0, isbuiltin= 0;
1916         char string[21*32], *strp, *col;
1917         
1918         y3= y2+23;      // exception!
1919         
1920         /* count total, max 16! */
1921         for(bt= U.themes.first; bt; bt= bt->next) tot++;
1922         
1923         /* if cur not is 1; move that to front of list */
1924         if(cur!=1) {
1925                 a= 1;
1926                 for(bt= U.themes.first; bt; bt= bt->next, a++) {
1927                         if(a==cur) {
1928                                 BLI_remlink(&U.themes, bt);
1929                                 BLI_addhead(&U.themes, bt);
1930                                 allqueue(REDRAWALL, 0);
1931                                 cur= 1;
1932                                 break;
1933                         }
1934                 }
1935         }
1936         
1937         /* the current theme */
1938         btheme= U.themes.first;
1939         if(strcmp(btheme->name, "Default")==0) isbuiltin= 1;
1940
1941         /* construct popup script */
1942         string[0]= 0;
1943         for(bt= U.themes.first; bt; bt= bt->next) {
1944                 strcat(string, bt->name);
1945                 if(btheme->next) strcat(string, "   |");
1946         }
1947         uiDefButS(block, MENU, B_UPDATE_THEME, string,                  45,y3,200,20, &cur, 0, 0, 0, 0, "Current theme");
1948         
1949         /* add / delete / name */
1950
1951         if(tot<16)
1952                 uiDefBut(block, BUT, B_ADD_THEME, "Add",        45,y2,200,20, NULL, 0, 0, 0, 0, "Makes new copy of this theme");
1953         if(tot>1 && isbuiltin==0)
1954                 uiDefBut(block, BUT, B_DEL_THEME, "Delete", 45,y1,200,20, NULL, 0, 0, 0, 0, "Delete theme");
1955
1956         if(isbuiltin) return;
1957         
1958         /* name */
1959         uiDefBut(block, TEX, B_NAME_THEME, "",                  255,y3,200,20, btheme->name, 1.0, 30.0, 0, 0, "Rename theme");
1960
1961         /* main choices pup */
1962         uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|%l|3D View %x2|%l|Ipo Curve Editor %x3|Action Editor %x4|"
1963                 "NLA Editor %x5|%l|UV/Image Editor %x6|Video Sequence Editor %x7|Audio Timeline %x8|Text Editor %x9|%l|User Preferences %x10|"
1964                 "OOPS Schematic %x11|Buttons Window %x12|%l|File Browser %x13|Image Browser %x14",
1965                                                                                                         255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
1966         if(curmain==1) spacetype= 0;
1967         else if(curmain==2) spacetype= SPACE_VIEW3D;
1968         else if(curmain==3) spacetype= SPACE_IPO;
1969         else if(curmain==4) spacetype= SPACE_ACTION;
1970         else if(curmain==5) spacetype= SPACE_NLA;
1971         else if(curmain==6) spacetype= SPACE_IMAGE;
1972         else if(curmain==7) spacetype= SPACE_SEQ;
1973         else if(curmain==8) spacetype= SPACE_SOUND;
1974         else if(curmain==9) spacetype= SPACE_TEXT;
1975         else if(curmain==10) spacetype= SPACE_INFO;
1976         else if(curmain==11) spacetype= SPACE_OOPS;
1977         else if(curmain==12) spacetype= SPACE_BUTS;
1978         else if(curmain==13) spacetype= SPACE_FILE;
1979         else if(curmain==14) spacetype= SPACE_IMASEL;
1980         else return; // only needed while coding... when adding themes for more windows
1981         
1982         /* color choices pup */
1983         if(curmain==1) {
1984                 strp= BIF_ThemeColorsPup(0);
1985                 if(th_curcol==TH_BACK) th_curcol= TH_BUT_OUTLINE;  // switching main choices...
1986         }
1987         else strp= BIF_ThemeColorsPup(spacetype);
1988         
1989         uiDefButS(block, MENU, B_REDR, strp,                    255,y1,200,20, &th_curcol, 0, 0, 0, 0, "Current color");
1990         MEM_freeN(strp);
1991         
1992         th_curcol_ptr= col= BIF_ThemeGetColorPtr(btheme, spacetype, th_curcol);
1993         if(col==NULL) return;
1994         
1995         /* first handle exceptions, special single values, row selection, etc */
1996         if(th_curcol==TH_VERTEX_SIZE) {
1997                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Vertex size ", 465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
1998         }
1999         else if(th_curcol==TH_BUT_DRAWTYPE) {
2000                 uiBlockBeginAlign(block);
2001                 uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal",        465,y3,100,20,  col, 2.0, 0.0, 0, 0, "");
2002                 uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 565,y3,100,20,  col, 2.0, 1.0, 0, 0, "");
2003                 uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded",        465,y2,100,20,  col, 2.0, 2.0, 0, 0, "");
2004                 uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool",       565,y2,100,20,  col, 2.0, 3.0, 0, 0, "");
2005                 uiBlockEndAlign(block);
2006         }
2007         else {
2008                 uiBlockBeginAlign(block);
2009                 if ELEM3(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT) {
2010                         uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
2011                 }
2012                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
2013                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"G ",   465,y2,200,20,  col+1, 0.0, 255.0, B_THEMECOL, 0, "");
2014                 uiDefButC(block, NUMSLI, B_UPDATE_THEME,"B ",   465,y1,200,20,  col+2, 0.0, 255.0, B_THEMECOL, 0, "");
2015                 uiBlockEndAlign(block);
2016
2017                 uiDefButC(block, COL, B_UPDATE_THEME, "",               675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
2018                                 
2019                 /* copy paste */
2020                 uiBlockBeginAlign(block);
2021                 uiDefBut(block, BUT, B_THEME_COPY, "Copy Color",        755,y2,120,20, NULL, 0, 0, 0, 0, "Stores current color in buffer");
2022                 uiDefBut(block, BUT, B_THEME_PASTE, "Paste Color",      755,y1,120,20, NULL, 0, 0, 0, 0, "Pastes buffer color");
2023                 uiBlockEndAlign(block);
2024                 
2025                 uiDefButC(block, COL, 0, "",                            885,y1,50,y2-y1+20, th_curcol_arr, 0, 0, 0, 0, "");
2026                 
2027         }
2028 }
2029
2030
2031 void drawinfospace(ScrArea *sa, void *spacedata)
2032 {
2033         uiBlock *block;
2034         static short cur_light=0, cur_light_var=0;
2035         float fac, col[3];
2036         short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y5, y6;
2037         short y2label, y3label, y4label, y5label, y6label;
2038         short spref, mpref, lpref, smfileselbut;
2039         short edgsp, midsp;
2040         char naam[32];
2041
2042         if(curarea->win==0) return;
2043
2044         BIF_GetThemeColor3fv(TH_BACK, col);
2045         glClearColor(col[0], col[1], col[2], 0.0);
2046         glClear(GL_COLOR_BUFFER_BIT);
2047
2048         fac= ((float)curarea->winx)/1280.0f;
2049         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2050         
2051         sprintf(naam, "infowin %d", curarea->win);
2052         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->win);
2053
2054
2055         /* Vars for nice grid alignment */ 
2056         dx= (1280-90)/7;        /* spacing for use in equally dividing 'tab' row */
2057
2058         xpos = 45;              /* left padding */
2059         ypos = 50;              /* bottom padding for buttons */
2060         ypostab = 10;           /* bottom padding for 'tab' row */
2061
2062         buth = 20;              /* standard button height */
2063
2064         spref = 90;     /* standard size for small preferences button */
2065         mpref = 189;    /* standard size for medium preferences button */
2066         lpref = 288;    /* standard size for large preferences button */
2067         smfileselbut = buth;    /* standard size for fileselect button (square) */
2068
2069         edgsp = 3;              /* space from edge of end 'tab' to edge of end button */
2070         midsp = 9;              /* horizontal space between buttons */
2071
2072         rspace = 3;             /* default space between rows */
2073
2074         y1 = ypos;              /* grid alignment for each row of buttons */
2075         y2 = ypos+buth+rspace;
2076         y3 = ypos+2*(buth+rspace);
2077         y4 = ypos+3*(buth+rspace);
2078         y5 = ypos+4*(buth+rspace);
2079         y6 = ypos+5*(buth+rspace);
2080
2081
2082         y2label = y2-2;         /* adjustments to offset the labels down to align better */
2083         y3label = y3-2;
2084         y4label = y4-2;
2085         y5label = y5-2;
2086         y6label = y6-2;
2087
2088
2089         /* set the colour to blue and draw the main 'tab' controls */
2090
2091         uiBlockSetCol(block, TH_BUT_SETTING1);
2092         uiBlockBeginAlign(block);
2093         
2094         uiDefButS(block, ROW,B_USERPREF,"View & Controls",
2095                 xpos,ypostab,(short)dx,buth,
2096                 &U.userpref,1.0,0.0, 0, 0,"");
2097                 
2098         uiDefButS(block, ROW,B_USERPREF,"Edit Methods",
2099                 (short)(xpos+dx),ypostab,(short)dx,buth,
2100                 &U.userpref,1.0,1.0, 0, 0,"");
2101
2102         uiDefButS(block, ROW,B_USERPREF,"Language & Font",
2103                 (short)(xpos+2*dx),ypostab,(short)dx,buth,
2104                 &U.userpref,1.0,2.0, 0, 0,"");
2105
2106         uiDefButS(block, ROW,B_USERPREF,"Themes",
2107                 (short)(xpos+3*dx),ypostab,(short)dx,buth,
2108                 &U.userpref,1.0,6.0, 0, 0,"");
2109
2110         uiDefButS(block, ROW,B_USERPREF,"Auto Save",
2111                 (short)(xpos+4*dx),ypostab,(short)dx,buth,
2112                 &U.userpref,1.0,3.0, 0, 0,"");
2113
2114         uiDefButS(block, ROW,B_USERPREF,"System & OpenGL",
2115                 (short)(xpos+5*dx),ypostab,(short)dx,buth,
2116                 &U.userpref,1.0,4.0, 0, 0,"");
2117                 
2118         uiDefButS(block, ROW,B_USERPREF,"File Paths",
2119                 (short)(xpos+6*dx),ypostab,(short)dx,buth,
2120                 &U.userpref,1.0,5.0, 0, 0,"");
2121
2122         uiBlockSetCol(block, TH_AUTO);
2123         uiBlockEndAlign(block);
2124         /* end 'tab' controls */
2125
2126         /* line 2: left x co-ord, top y co-ord, width, height */
2127
2128         if(U.userpref == 6) {
2129                 info_user_themebuts(block, y1, y2, y3);
2130         }
2131         else if (U.userpref == 0) { /* view & controls */
2132
2133                 uiDefBut(block, LABEL,0,"Display:",
2134                         xpos,y6label,spref,buth,
2135                         0, 0, 0, 0, 0, "");     
2136                 uiDefButBitS(block, TOG, USER_TOOLTIPS, 0, "ToolTips",
2137                         (xpos+edgsp),y5,spref,buth,
2138                         &(U.flag), 0, 0, 0, 0,
2139                         "Display tooltips (help tags) over buttons");
2140                 uiDefButBitS(block, TOG, USER_DRAWVIEWINFO, B_DRAWINFO, "Object Info",
2141                         (xpos+edgsp),y4,spref,buth,
2142                         &(U.uiflag), 0, 0, 0, 0,
2143                         "Display active object name and frame number in the 3D View");
2144                 uiDefButBitS(block, TOG, USER_SCENEGLOBAL, 0, "Global Scene",
2145                         (xpos+edgsp),y3,spref,buth,
2146                         &(U.flag), 0, 0, 0, 0,
2147                         "Forces the current Scene to be displayed in all Screens");
2148 #ifndef __APPLE__       
2149                 uiDefButS(block, TOG|BIT|0, 0, "Large Cursors",
2150                         (xpos+edgsp),y2,spref,buth,
2151                         &(U.curssize), 0, 0, 0, 0,
2152                         "Use large mouse cursors when available");
2153 #else 
2154                 U.curssize=0; /*Small Cursor always for OS X for now */
2155 #endif
2156
2157                 uiDefBut(block, LABEL,0,"Menus:",
2158                         (xpos+(2*edgsp)+spref),y6label,spref,buth,
2159                         0, 0, 0, 0, 0, "");
2160                 uiDefButBitS(block, TOG, USER_MENUOPENAUTO, 0, "Open on Mouse Over",
2161                         (xpos+edgsp+spref+midsp),y5,mpref,buth,
2162                         &(U.uiflag), 0, 0, 0, 0,
2163                         "Open menu buttons and pulldowns automatically when the mouse is hovering");
2164                 uiDefButS(block, NUM, 0, "Top Level:",
2165                         (xpos+edgsp+spref+midsp),y4,spref+edgsp,buth,
2166                         &(U.menuthreshold1), 1, 40, 0, 0,
2167                         "Time delay in 1/10 seconds before automatically opening top level menus");
2168                 uiDefButS(block, NUM, 0, "Sublevels:",
2169                         (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y4,spref+edgsp,buth,
2170                         &(U.menuthreshold2), 1, 40, 0, 0,
2171                         "Time delay in 1/10 seconds before automatically opening menu sublevels");
2172
2173                 uiDefBut(block, LABEL,0,"Toolbox click-hold delay:",
2174                         (xpos+(2*edgsp)+spref),y3label,mpref,buth,
2175                         0, 0, 0, 0, 0, "");
2176                 uiDefButS(block, NUM, 0, "LMB:",
2177                         (xpos+edgsp+spref+midsp),y2,spref+edgsp,buth,
2178                         &(U.tb_leftmouse), 2, 40, 0, 0,
2179                         "Time in 1/10 seconds to hold the Left Mouse Button before opening the toolbox");
2180                 uiDefButS(block, NUM, 0, "RMB:",
2181                         (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y2,spref+edgsp,buth,
2182                         &(U.tb_rightmouse), 2, 40, 0, 0,
2183                         "Time in 1/10 seconds to hold the Right Mouse Button before opening the toolbox");      
2184                 uiDefButBitS(block, TOG, USER_PANELPINNED, 0, "Pin Floating Panels",
2185                         (xpos+edgsp+spref+midsp),y1,mpref,buth,
2186                         &(U.uiflag), 0, 0, 0, 0,
2187                         "Make floating panels invoked by a hotkey (eg. N Key) open at the previous location");
2188                 
2189                 
2190                 uiDefBut(block, LABEL,0,"Snap to grid:",
2191                         (xpos+(2*edgsp)+spref+midsp+mpref),y6label,mpref,buth,
2192                         0, 0, 0, 0, 0, "");
2193                 uiDefButBitS(block, TOG, USER_AUTOGRABGRID, 0, "Grab/Move",
2194                         (xpos+edgsp+mpref+spref+(2*midsp)),y5,spref,buth,
2195                         &(U.flag), 0, 0, 0, 0,
2196                         "Snap objects and sub-objects to grid units when moving");
2197                 uiDefButBitS(block, TOG, USER_AUTOROTGRID, 0, "Rotate",
2198                         (xpos+edgsp+mpref+spref+(2*midsp)),y4,spref,buth,
2199                         &(U.flag), 0, 0, 0, 0,
2200                         "Snap objects and sub-objects to grid units when rotating");
2201                 uiDefButBitS(block, TOG, USER_AUTOSIZEGRID, 0, "Scale",
2202                         (xpos+edgsp+mpref+spref+(2*midsp)),y3,spref,buth,
2203                         &(U.flag), 0, 0, 0, 0,
2204                         "Snap objects and sub-objects to grid units when scaling");
2205                 
2206                 uiDefButBitS(block, TOG, USER_LOCKAROUND, B_DRAWINFO, "Global Pivot",
2207                         (xpos+edgsp+mpref+spref+(2*midsp)),y1,spref,buth,
2208                         &(U.uiflag), 0, 0, 0, 0,
2209                         "Lock the same rotation/scaling pivot in all 3D Views");        
2210                 
2211                 uiDefBut(block, LABEL,0,"View zoom:",
2212                         (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y6label,mpref,buth,
2213                         0, 0, 0, 0, 0, "");
2214                 uiBlockBeginAlign(block);
2215                 uiDefButS(block, ROW, 0, "Continue",
2216                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y5,(mpref/3),buth,
2217                         &(U.viewzoom), 40, USER_ZOOM_CONT, 0, 0,
2218                         "Old style zoom, continues while moving mouse up or down");
2219                 uiDefButS(block, ROW, 0, "Dolly",
2220                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/3)),y5,(mpref/3),buth,
2221                         &(U.viewzoom), 40, USER_ZOOM_DOLLY, 0, 0,
2222                         "Zooms in and out based on vertical mouse movement.");
2223                 uiDefButS(block, ROW, 0, "Scale",
2224                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(2*mpref/3)),y5,(mpref/3),buth,
2225                         &(U.viewzoom), 40, USER_ZOOM_SCALE, 0, 0,
2226                         "Zooms in and out like scaling the view, mouse movements relative to center.");
2227                 uiBlockEndAlign(block);
2228                 
2229                 uiDefBut(block, LABEL,0,"View rotation:",
2230                         (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y4label,mpref,buth,
2231                         0, 0, 0, 0, 0, "");
2232                 uiBlockBeginAlign(block);
2233                 uiDefButBitS(block, TOG, USER_TRACKBALL, B_DRAWINFO, "Trackball",
2234                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y3,(mpref/2),buth,
2235                         &(U.flag), 0, 0, 0, 0,
2236                         "Allow the view to tumble freely when orbiting with the Middle Mouse Button");
2237                 uiDefButBitS(block, TOGN, USER_TRACKBALL, B_DRAWINFO, "Turntable",
2238                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/2)),y3,(mpref/2),buth,
2239                         &(U.flag), 0, 0, 0, 0,
2240                         "Keep the Global Z axis pointing upwards when orbiting the view with the Middle Mouse Button");
2241                 uiBlockEndAlign(block);
2242                 
2243                 uiDefButBitS(block, TOG, USER_AUTOPERSP, B_DRAWINFO, "Auto Perspective",
2244                         (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y1,spref,buth,
2245                         &(U.uiflag), 0, 0, 0, 0,
2246                         "Automatically switch between orthographic and perspective when changing from top/front/side views");
2247
2248                 uiDefBut(block, LABEL,0,"Select with:",
2249                         (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y6label,mpref,buth,
2250                         0, 0, 0, 0, 0, "");
2251                 uiBlockBeginAlign(block);
2252                 uiDefButBitS(block, TOG, USER_LMOUSESELECT, B_DRAWINFO, "Left Mouse",
2253                         (xpos+edgsp+(3*mpref)+(4*midsp)),y5,(mpref/2),buth,
2254                         &(U.flag), 0, 0, 0, 0, "Use the Left Mouse Button for selection");
2255                 uiDefButBitS(block, TOGN, USER_LMOUSESELECT, B_DRAWINFO, "Right Mouse",
2256                         (xpos+edgsp+(3*mpref)+(4*midsp)+(mpref/2)),y5,(mpref/2),buth,
2257                         &(U.flag), 0, 0, 0, 0, "Use the Right Mouse Button for selection");
2258                 uiBlockEndAlign(block);
2259                 
2260                 
2261                 if(U.flag & USER_LMOUSESELECT) {
2262                         uiDefBut(block, LABEL,0,"Cursor with: Right Mouse",
2263                                 (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
2264                                 0, 0, 0, 0, 0, "");
2265                 } else {
2266                         uiDefBut(block, LABEL,0,"Cursor with: Left Mouse",
2267                                 (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
2268                                 0, 0, 0, 0, 0, "");
2269                 }
2270
2271                 uiDefButBitS(block, TOG, USER_TWOBUTTONMOUSE, 0, "Emulate 3 Button Mouse",
2272                         (xpos+edgsp+(3*mpref)+(4*midsp)),y3,mpref,buth,
2273                         &(U.flag), 0, 0, 0, 0,
2274                         "Emulates a middle mouse button with Alt LeftMouse");
2275                 
2276                         
2277                 uiDefBut(block, LABEL,0,"Middle Mouse Button:",
2278                         (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y6label,mpref,buth,
2279                         0, 0, 0, 0, 0, "");
2280                 uiBlockBeginAlign(block);
2281                 uiDefButBitS(block, TOGN, USER_VIEWMOVE, B_DRAWINFO, "Rotate View",
2282                         (xpos+edgsp+(4*mpref)+(5*midsp)),y5,(mpref/2),buth,
2283                         &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
2284                 uiDefButBitS(block, TOG, USER_VIEWMOVE, B_DRAWINFO, "Pan View",
2285                         (xpos+edgsp+(4*mpref)+(5*midsp)+(mpref/2)),y5,(mpref/2),buth,
2286                         &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
2287                 uiBlockEndAlign(block);
2288                         
2289                 uiDefBut(block, LABEL,0,"Mouse Wheel:",
2290                         (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y4label,mpref,buth,
2291                         0, 0, 0, 0, 0, "");
2292                 uiDefButBitS(block, TOG, USER_WHEELZOOMDIR, 0, "Invert Zoom",
2293                         (xpos+edgsp+(4*mpref)+(5*midsp)),y3,spref,buth,
2294                         &(U.uiflag), 0, 0, 0, 0,
2295                         "Swap the Mouse Wheel zoom direction");
2296                 uiDefButI(block, NUM, 0, "Scroll Lines:",
2297                         (xpos+edgsp+(4*mpref)+(6*midsp)+spref-edgsp),y3,spref+edgsp,buth,
2298                         &U.wheellinescroll, 0.0, 32.0, 0, 0,
2299                         "The number of lines scrolled at a time with the mouse wheel"); 
2300
2301
2302         } else if (U.userpref == 1) { /* edit methods */
2303
2304
2305                 uiDefBut(block, LABEL,0,"Material linked to:",
2306                         xpos,y3label,mpref,buth,
2307                         0, 0, 0, 0, 0, "");
2308                 uiBlockBeginAlign(block);
2309                 uiDefButBitS(block, TOGN, USER_MAT_ON_OB, B_DRAWINFO, "ObData",
2310                         (xpos+edgsp),y2,(mpref/2),buth,
2311                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
2312                 uiDefButBitS(block, TOG, USER_MAT_ON_OB, B_DRAWINFO, "Object",
2313                         (xpos+edgsp+(mpref/2)),y2,(mpref/2),buth,
2314                         &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
2315                 uiBlockEndAlign(block);
2316
2317
2318                 uiDefBut(block, LABEL,0,"Editmode undo:",
2319                         (xpos+(2*edgsp)+mpref),y3label, mpref,buth,
2320                         0, 0, 0, 0, 0, "");
2321                 uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps:",
2322                         (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2323                         &(U.undosteps), 2, 64, 0, 0, "Number of undo steps available in Edit Mode (smaller values conserve memory)");
2324
2325                 uiDefButBitS(block, TOG, USER_GLOBALUNDO, B_DRAWINFO, "Global undo",
2326                         (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2327                         &(U.uiflag), 2, 64, 0, 0, "");
2328
2329
2330                 uiDefBut(block, LABEL,0,"Auto keyframe on:",
2331                         (xpos+(2*edgsp)+(2*mpref)+midsp),y3label,mpref,buth,
2332                         0, 0, 0, 0, 0, "");
2333                 uiDefButBitS(block, TOG, USER_KEYINSERTACT, 0, "Action",
2334                         (xpos+edgsp+(2*mpref)+(2*midsp)),y2,(spref+edgsp),buth,
2335                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Action Ipo curve");
2336                 uiDefButBitS(block, TOG, USER_KEYINSERTOBJ, 0, "Object",
2337                         (xpos+edgsp+(2*mpref)+(3*midsp)+spref-edgsp),y2,(spref+edgsp),buth,
2338                         &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Object Ipo curve");
2339
2340
2341                 uiDefBut(block, LABEL,0,"Duplicate with object:",
2342                         (xpos+(2*edgsp)+(3*midsp)+(3*mpref)+spref),y3label,mpref,buth,
2343                         0, 0, 0, 0, 0, "");
2344
2345                 uiDefButBitS(block, TOG, USER_DUP_MESH, 0, "Mesh",
2346                         (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y2,(spref+edgsp),buth,
2347                         &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
2348                 uiDefButBitS(block, TOG, USER_DUP_ARM, 0, "Armature",
2349                         (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y1,(spref+edgsp),buth,
2350                         &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
2351
2352                 uiDefButBitS(block, TOG, USER_DUP_SURF, 0, "Surface",
2353                         (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y2,(spref+edgsp),buth,
2354                         &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
2355                 uiDefButBitS(block, TOG, USER_DUP_LAMP, 0, "Lamp",
2356                         (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y1,(spref+edgsp),buth,
2357                         &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
2358
2359                 uiDefButBitS(block, TOG, USER_DUP_CURVE, 0, "Curve",
2360                         (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y2,(spref+edgsp),buth,
2361                         &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
2362                 uiDefButBitS(block, TOG, USER_DUP_MAT, 0, "Material",
2363                         (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y1,(spref+edgsp),buth,
2364                         &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
2365
2366                 uiDefButBitS(block, TOG, USER_DUP_FONT, 0, "Text",
2367                         (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y2,(spref+edgsp),buth,
2368                         &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
2369                 uiDefButBitS(block, TOG, USER_DUP_TEX, 0, "Texture",
2370                         (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y1,(spref+edgsp),buth,
2371                         &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
2372
2373                 uiDefButBitS(block, TOG, USER_DUP_MBALL, 0, "Metaball",
2374                         (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y2,(spref+edgsp),buth,
2375                         &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
2376                 uiDefButBitS(block, TOG, USER_DUP_IPO, 0, "Ipo",
2377                         (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y1,(spref+edgsp),buth,
2378                         &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
2379         
2380         } else if(U.userpref == 2) { /* language & colors */
2381
2382 #ifdef INTERNATIONAL
2383                 char curfont[320];
2384
2385                 sprintf(curfont, "Interface Font: ");
2386                 strcat(curfont,U.fontname);
2387
2388                 uiDefButBitS(block, TOG, USER_DOTRANSLATE, B_DOLANGUIFONT, "International Fonts",
2389                         xpos,y2,mpref,buth,
2390                         &(U.transopts), 0, 0, 0, 0, "Activate international interface");
2391
2392                 if(U.transopts & USER_DOTRANSLATE) {
2393                         uiDefBut(block, LABEL,0,curfont,
2394                                 (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2395                                 0, 0, 0, 0, 0, "");
2396
2397                         uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
2398                                 xpos,y1,mpref,buth,
2399                                 0, 0, 0, 0, 0, "Select a new font for the interface");
2400
2401
2402                         uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
2403                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2404                                 &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
2405
2406 /*
2407                         uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
2408                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2409                                 &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
2410
2411
2412                         uiDefBut(block, LABEL,0,"Translate:",
2413                                 (xpos+edgsp+(2.1*mpref)+(2*midsp)),y3label,mpref,buth,
2414                                 0, 0, 0, 0, 0, "");
2415 */
2416
2417                         uiDefButBitS(block, TOG, USER_TR_TOOLTIPS, B_SETTRANSBUTS, "Tooltips",
2418                                 (xpos+edgsp+(2.2*mpref)+(3*midsp)),y1,spref,buth,
2419                                 &(U.transopts), 0, 0, 0, 0, "Translate tooltips");
2420
2421                         uiDefButBitS(block, TOG, USER_TR_BUTTONS, B_SETTRANSBUTS, "Buttons",
2422                                 (xpos+edgsp+(2.2*mpref)+(4*midsp)+spref),y1,spref,buth,
2423                                 &(U.transopts), 0, 0, 0, 0, "Translate button labels");
2424
2425                         uiDefButBitS(block, TOG, USER_TR_MENUS, B_SETTRANSBUTS, "Toolbox",
2426                                 (xpos+edgsp+(2.2*mpref)+(5*midsp)+(2*spref)),y1,spref,buth,
2427                                 &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
2428
2429                         uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
2430                                 (xpos+edgsp+(2.2*mpref)+(3*midsp)),y2,mpref+(0.5*mpref)+3,buth,
2431                                 &U.language, 0, 0, 0, 0, "Select interface language");
2432                                 
2433                         /* uiDefButBitS(block, TOG, USER_TR_TEXTEDIT, B_SETTRANSBUTS, "FTF All windows",
2434                                 (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
2435                                 &(U.transopts), 0, 0, 0, 0,
2436                                 "Use FTF drawing for fileselect and textwindow "
2437                                 "(under construction)");
2438                         */
2439                 }
2440
2441 /* end of INTERNATIONAL */
2442 #endif
2443
2444         } else if(U.userpref == 3) { /* auto save */
2445
2446
2447                 uiDefButS(block, NUM, 0, "Save Versions:",
2448                         (xpos+edgsp),y3,mpref,buth,
2449                         &U.versions, 0.0, 32.0, 0, 0,
2450                         "The number of old versions to maintain in the current directory, when manually saving");
2451
2452                 uiDefButBitS(block, TOG, USER_AUTOSAVE, B_RESETAUTOSAVE, "Auto Save Temp Files",
2453                         (xpos+edgsp+mpref+midsp),y3,mpref,buth,
2454                         &(U.flag), 0, 0, 0, 0,
2455                         "Enables automatic saving of temporary files");
2456
2457                 if(U.flag & USER_AUTOSAVE) {
2458
2459                         uiDefButI(block, NUM, B_RESETAUTOSAVE, "Minutes:",
2460                                 (xpos+edgsp+mpref+midsp),y2,mpref,buth,
2461                                 &(U.savetime), 1.0, 60.0, 0, 0,
2462                                 "The time (in minutes) to wait between automatic temporary saves");
2463
2464                         uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
2465                                 (xpos+edgsp+mpref+midsp),y1,mpref,buth,
2466                                 0, 0, 0, 0, 0,"Open the most recently saved temporary file");
2467                 }
2468
2469         } else if (U.userpref == 4) { /* system & opengl */
2470                 uiDefBut(block, LABEL,0,"Solid OpenGL light:",
2471                         xpos+edgsp, y3label, mpref, buth,
2472                         0, 0, 0, 0, 0, "");
2473                 
2474                 uiDefButS(block, MENU, B_REDR, "Light1 %x0|Light2 %x1|Light3 %x2",
2475                         xpos+edgsp, y2, 2*mpref/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
2476                 uiBlockSetCol(block, TH_BUT_SETTING1);
2477                 uiDefButI(block, TOG|BIT|0, B_RECALCLIGHT, "On",
2478                         xpos+edgsp+2*mpref/6, y2, mpref/6, buth, 
2479                         &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "");
2480                         
2481                 uiBlockSetCol(block, TH_AUTO);
2482                 uiDefButS(block, ROW, B_REDR, "Vec",
2483                         xpos+edgsp+3*mpref/6, y2, mpref/6, buth, 
2484                         &cur_light_var, 123.0, 0.0, 0, 0, "");
2485                 uiDefButS(block, ROW, B_REDR, "Col",
2486                         xpos+edgsp+4*mpref/6, y2, mpref/6, buth, 
2487                         &cur_light_var, 123.0, 1.0, 0, 0, "");
2488                 uiDefButS(block, ROW, B_REDR, "Spec",
2489                         xpos+edgsp+5*mpref/6, y2, mpref/6, buth, 
2490                         &cur_light_var, 123.0, 2.0, 0, 0, "");
2491
2492                 if(cur_light_var==1) {
2493                         uiDefButF(block, NUM, B_RECALCLIGHT, "R ",
2494                                 xpos+edgsp, y1, mpref/3, buth, 
2495                                 U.light[cur_light].col, 0.0, 1.0, 100, 2, "");
2496                         uiDefButF(block, NUM, B_RECALCLIGHT, "G ",
2497                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2498                                 U.light[cur_light].col+1, 0.0, 1.0, 100, 2, "");
2499                         uiDefButF(block, NUM, B_RECALCLIGHT, "B ",
2500                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2501                                 U.light[cur_light].col+2, 0.0, 1.0, 100, 2, "");
2502                 }
2503                 else if(cur_light_var==2) {
2504                         uiDefButF(block, NUM, B_RECALCLIGHT, "sR ",
2505                                 xpos+edgsp, y1, mpref/3, buth, 
2506                                 U.light[cur_light].spec, 0.0, 1.0, 100, 2, "");
2507                         uiDefButF(block, NUM, B_RECALCLIGHT, "sG ",
2508                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2509                                 U.light[cur_light].spec+1, 0.0, 1.0, 100, 2, "");
2510                         uiDefButF(block, NUM, B_RECALCLIGHT, "sB ",
2511                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2512                                 U.light[cur_light].spec+2, 0.0, 1.0, 100, 2, "");
2513                 }
2514                 else if(cur_light_var==0) {
2515                         uiDefButF(block, NUM, B_RECALCLIGHT, "X ",
2516                                 xpos+edgsp, y1, mpref/3, buth, 
2517                                 U.light[cur_light].vec, -1.0, 1.0, 100, 2, "");
2518                         uiDefButF(block, NUM, B_RECALCLIGHT, "Y ",
2519                                 xpos+edgsp+mpref/3, y1, mpref/3, buth, 
2520                                 U.light[cur_light].vec+1, -1.0, 1.0, 100, 2, "");
2521                         uiDefButF(block, NUM, B_RECALCLIGHT, "Z ",
2522                                 xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
2523                                 U.light[cur_light].vec+2, -1.0, 1.0, 100, 2, "");
2524                 }
2525
2526 /*
2527                 uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
2528                         (xpos+edgsp),y2,lpref,buth,
2529                         &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
2530
2531                 uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
2532                         (xpos+edgsp), y1, lpref,buth,
2533                         &U.console_out, 0, 0, 0, 0, "Select console output method");
2534
2535                 uiDefButS(block, NUM, B_CONSOLENUMLINES, "Lines:",
2536                         (xpos+edgsp+lpref+midsp),y1,spref,buth,
2537                         &U.console_buffer, 1.0, 4000.0, 0, 0, "Maximum number of internal console lines");
2538 */
2539
2540 #ifdef _WIN32
2541                 uiDefBut(block, LABEL,0,"Win Codecs:",
2542                         (xpos+edgsp+(1*midsp)+(1*mpref)),y3label,mpref,buth,
2543                         0, 0, 0, 0, 0, "");
2544
2545                 uiDefButBitS(block, TOG, USER_ALLWINCODECS, 0, "Enable all codecs",
2546                         (xpos+edgsp+(1*mpref)+(1*midsp)),y2,mpref,buth,
2547                         &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
2548 #endif
2549
2550                 uiDefBut(block, LABEL,0,"Keyboard:",
2551                         (xpos+edgsp+(3*midsp)+(3*mpref)),y3label,mpref,buth,
2552                         0, 0, 0, 0, 0, "");
2553
2554                 uiDefButBitS(block, TOG, USER_NO_CAPSLOCK, B_U_CAPSLOCK, "Disable Caps Lock",
2555                         (xpos+edgsp+(3*midsp)+(3*mpref)),y1,mpref,buth,
2556                         &(U.flag), 0, 0, 0, 0,
2557                         "Disables the Caps Lock key when entering text");
2558
2559                 uiDefButBitS(block, TOG, USER_NONUMPAD, 0, "Emulate Numpad",
2560                         (xpos+edgsp+(3*midsp)+(3*mpref)),y2,mpref,buth,
2561                         &(U.flag), 0, 0, 0, 0,
2562                         "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
2563
2564
2565                 uiDefBut(block, LABEL,0,"System:",
2566                         (xpos+edgsp+(4*midsp)+(4*mpref)),y3label,mpref,buth,
2567                         0, 0, 0, 0, 0, "");
2568
2569                 uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Sound",
2570                         (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
2571                         &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
2572
2573                 uiDefButBitS(block, TOG, USER_FILTERFILEEXTS, 0, "Filter File Extensions",
2574                         (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
2575                         &(U.uiflag), 0, 0, 0, 0, "Display only files with extensions in the image select window");
2576
2577
2578                 uiDefBut(block, LABEL,0,"OpenGL:",
2579                         (xpos+edgsp+(5*midsp)+(5*mpref)),y3label,mpref,buth,
2580                         0, 0, 0, 0, 0, "");
2581
2582                 uiDefButBitI(block, TOGN, USER_DISABLE_MIPMAP, B_MIPMAPCHANGED, "Mipmaps",
2583                         (xpos+edgsp+(5*mpref)+(5*midsp)),y2,mpref,buth,
2584                         &(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
2585
2586                 uiDefButBitI(block, TOG, USER_VERTEX_ARRAYS, 0, "Vertex Arrays",
2587                         (xpos+edgsp+(5*mpref)+(5*midsp)),y1,mpref,buth,
2588                         &(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
2589
2590                 uiDefBut(block, LABEL,0,"Audio mixing buffer:",
2591                         (xpos+edgsp+(2*midsp)+(2*mpref)),y3label,mpref,buth,
2592                         0, 0, 0, 0, 0, "");
2593                 uiBlockBeginAlign(block);
2594                 uiDefButI(block, ROW, 0, "256",
2595                         (xpos+edgsp+(2*midsp)+(2*mpref)),y2,(mpref/4),buth,
2596                         &U.mixbufsize, 2.0, 256.0, 0, 0, "Set audio mixing buffer size to 256 samples");
2597                 uiDefButI(block, ROW, 0, "512",
2598                         (xpos+edgsp+(2*midsp)+(2*mpref)+(mpref/4)),y2,(mpref/4),buth,
2599                         &U.mixbufsize, 2.0, 512.0, 0, 0, "Set audio mixing buffer size to 512 samples");        
2600                 uiDefButI(block, ROW, 0, "1024",
2601                         (xpos+edgsp+(2*midsp)+(2*mpref)+(2*mpref/4)),y2,(mpref/4),buth,
2602                         &U.mixbufsize, 2.0, 1024.0, 0, 0, "Set audio mixing buffer size to 1024 samples");              
2603                 uiDefButI(block, ROW, 0, "2048",
2604                         (xpos+edgsp+(2*midsp)+(2*mpref)+(3*mpref/4)),y2,(mpref/4),buth,
2605                         &U.mixbufsize, 2.0, 2048.0, 0, 0, "Set audio mixing buffer size to 2048 samples");                      
2606                 uiBlockEndAlign(block);
2607
2608         } else if(U.userpref == 5) { /* file paths */
2609
2610                 /* yafray: (temporary) path button for yafray xml export, now with fileselect */
2611                 uiDefBut(block, TEX, 0, "YFexport: ",
2612                         (xpos+edgsp), y2+buth+rspace, lpref-smfileselbut, buth,
2613                         U.yfexportdir, 1.0, 63.0, 0, 0,
2614                         "The default directory for yafray xml export (must exist!)");
2615                 uiDefIconBut(block, BUT, B_YAFRAYDIRFILESEL, ICON_FILESEL,
2616                         (xpos+edgsp+lpref-smfileselbut), y2+buth+rspace, smfileselbut, buth,
2617                         0, 0, 0, 0, 0, "Select the default yafray export directory");
2618
2619                 uiDefBut(block, TEX, 0, "Fonts: ",
2620                         (xpos+edgsp),y2,(lpref-smfileselbut),buth,
2621                         U.fontdir, 1.0, 63.0, 0, 0,
2622                         "The default directory to search for loading fonts");
2623                 uiDefIconBut(block, BUT, B_FONTDIRFILESEL, ICON_FILESEL,
2624                         (xpos+edgsp+lpref-smfileselbut),y2,smfileselbut,buth,
2625                         0, 0, 0, 0, 0, "Select the default font directory");
2626
2627                 uiDefBut(block, TEX, 0, "Textures: ",
2628                         (xpos+edgsp+lpref+midsp),y2,(lpref-smfileselbut),buth,
2629                         U.textudir, 1.0, 63.0, 0, 0, "The default directory to search for textures");
2630                 uiDefIconBut(block, BUT, B_TEXTUDIRFILESEL, ICON_FILESEL,
2631                         (xpos+edgsp+(2*lpref)+midsp-smfileselbut),y2,smfileselbut,buth,
2632                         0, 0, 0, 0, 0, "Select the default texture location");
2633
2634
2635                 uiDefBut(block, TEX, 0, "Tex Plugins: ",
2636                         (xpos+edgsp+(2*lpref)+(2*midsp)),y2,(lpref-smfileselbut),buth,
2637                         U.plugtexdir, 1.0, 63.0, 0, 0, "The default directory to search for texture plugins");
2638                 uiDefIconBut(block, BUT, B_PLUGTEXDIRFILESEL, ICON_FILESEL,
2639                         (xpos+edgsp+(3*lpref)+(2*midsp)-smfileselbut),y2,smfileselbut,buth,
2640                         0, 0, 0, 0, 0, "Select the default texture plugin location");
2641
2642                 uiDefBut(block, TEX, 0, "Seq Plugins: ",
2643                         (xpos+edgsp+(3*lpref)+(3*midsp)),y2,(lpref-smfileselbut),buth,
2644                         U.plugseqdir, 1.0, 63.0, 0, 0, "The default directory to search for sequence plugins");
2645                 uiDefIconBut(block, BUT, B_PLUGSEQDIRFILESEL, ICON_FILESEL,
2646                         (xpos+edgsp+(4*lpref)+(3*midsp)-smfileselbut),y2,smfileselbut,buth,
2647                         0, 0, 0, 0, 0, "Select the default sequence plugin location");
2648
2649
2650                 uiDefBut(block, TEX, 0, "Render: ",
2651                         (xpos+edgsp),y1,(lpref-smfileselbut),buth,
2652                         U.renderdir, 1.0, 63.0, 0, 0, "The default directory for rendering output");
2653                 uiDefIconBut(block, BUT, B_RENDERDIRFILESEL, ICON_FILESEL,
2654                         (xpos+edgsp+lpref-smfileselbut),y1,smfileselbut,buth,
2655                         0, 0, 0, 0, 0, "Select the default render output location");
2656
2657                 uiDefBut(block, TEX, 0, "Python: ",
2658                         (xpos+edgsp+lpref+midsp),y1,(lpref-2*smfileselbut),buth,
2659                         U.pythondir, 1.0, 63.0, 0, 0, "The default directory to search for Python scripts");
2660                 uiDefIconBut(block, BUT, B_PYMENUEVAL, ICON_SCRIPT,
2661                         (xpos+edgsp+(2*lpref)+midsp-2*smfileselbut),y1,smfileselbut,buth,
2662                         0, 0, 0, 0, 0, "Re-evaluate scripts registration in menus");
2663                 uiDefIconBut(block, BUT, B_PYTHONDIRFILESEL, ICON_FILESEL,
2664                         (xpos+edgsp+(2*lpref)+midsp-smfileselbut),y1,smfileselbut,buth,
2665                         0, 0, 0, 0, 0, "Select the default Python script location");
2666
2667
2668                 uiDefBut(block, TEX, 0, "Sounds: ",
2669                         (xpos+edgsp+(2*lpref)+(2*midsp)),y1,(lpref-smfileselbut),buth,
2670                         U.sounddir, 1.0, 63.0, 0, 0, "The default directory to search for sounds");
2671                 uiDefIconBut(block, BUT, B_SOUNDDIRFILESEL, ICON_FILESEL,
2672                         (xpos+edgsp+(3*lpref)+(2*midsp)-smfileselbut),y1,smfileselbut,buth,
2673                         0, 0, 0, 0, 0, "Select the default sound location");
2674
2675                 uiDefBut(block, TEX, 0, "Temp: ",
2676                          (xpos+edgsp+(3*lpref)+(3*midsp)),y1,(lpref-smfileselbut),buth,
2677                          U.tempdir, 1.0, 63.0, 0, 0, "The directory for storing temporary save files");
2678                 uiDefIconBut(block, BUT, B_TEMPDIRFILESEL, ICON_FILESEL,
2679                         (xpos+edgsp+(4*lpref)+(3*midsp)-smfileselbut),y1,smfileselbut,buth,
2680                         0, 0, 0, 0, 0, "Select the default temporary save file location");
2681
2682         }
2683
2684         uiDrawBlock(block);
2685         
2686         myortho2(-0.375, (float)(sa->winx)-0.375, -0.375, (float)(sa->winy)-0.375);
2687         draw_area_emboss(sa);
2688         myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
2689         sa->win_swap= WIN_BACK_OK;
2690         
2691 }
2692
2693
2694 void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
2695 {
2696         unsigned short event= evt->event;
2697         short val= evt->val;
2698         
2699         if(val) {
2700                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
2701
2702                 switch(event) {
2703                 case UI_BUT_EVENT:
2704                         if(val==B_ADD_THEME) {
2705                                 bTheme *btheme, *new;
2706                                 
2707                                 btheme= U.themes.first;
2708                                 new= MEM_callocN(sizeof(bTheme), "theme");
2709                                 memcpy(new, btheme, sizeof(bTheme));
2710                                 BLI_addhead(&U.themes, new);
2711                                 strcpy(new->name, "New User Theme");
2712                                 addqueue(sa->win, REDRAW, 1);
2713                         }
2714                         else if(val==B_DEL_THEME) {
2715                                 bTheme *btheme= U.themes.first;
2716                                 BLI_remlink(&U.themes, btheme);
2717                                 MEM_freeN(btheme);
2718                                 BIF_SetTheme(sa); // prevent usage of old theme in calls        
2719                                 addqueue(sa->win, REDRAW, 1);
2720                         }
2721                         else if(val==B_NAME_THEME) {
2722                                 bTheme *btheme= U.themes.first;
2723                                 if(strcmp(btheme->name, "Default")==0) {
2724                                         strcpy(btheme->name, "New User Theme");
2725                                         addqueue(sa->win, REDRAW, 1);
2726                                 }
2727                         }
2728                         else if(val==B_UPDATE_THEME) {
2729                                 allqueue(REDRAWALL, 0);
2730                         }
2731                         else if(val==B_CHANGE_THEME) {
2732                                 th_curcol= TH_BACK;     // backdrop color is always there...
2733                                 addqueue(sa->win, REDRAW, 1);
2734                         }
2735                         else if(val==B_THEME_COPY) {
2736                                 if(th_curcol_ptr) {
2737                                         th_curcol_arr[0]= th_curcol_ptr[0];
2738                                         th_curcol_arr[1]= th_curcol_ptr[1];
2739                                         th_curcol_arr[2]= th_curcol_ptr[2];
2740                                         th_curcol_arr[3]= th_curcol_ptr[3];
2741                                         addqueue(sa->win, REDRAW, 1);
2742                                 }
2743                         }
2744                         else if(val==B_THEME_PASTE) {
2745                                 if(th_curcol_ptr) {
2746                                         th_curcol_ptr[0]= th_curcol_arr[0];
2747                                         th_curcol_ptr[1]= th_curcol_arr[1];
2748                                         th_curcol_ptr[2]= th_curcol_arr[2];
2749                                         th_curcol_ptr[3]= th_curcol_arr[3];
2750                                         allqueue(REDRAWALL, 0);
2751                                 }
2752                         }
2753                         else if(val==B_RECALCLIGHT) {
2754                                 if(U.light[0].flag==0 && U.light[1].flag==0 && U.light[2].flag==0)
2755                                         U.light[0].flag= 1;
2756                                 
2757                                 default_gl_light();
2758                                 addqueue(sa->win, REDRAW, 1);
2759                                 allqueue(REDRAWVIEW3D, 0);
2760                         }
2761                         else do_global_buttons(val);
2762                         
2763                         break;  
2764                 }
2765         }
2766 }
2767
2768 void init_infospace(ScrArea *sa)
2769 {
2770         SpaceInfo *sinfo;
2771         
2772         sinfo= MEM_callocN(sizeof(SpaceInfo), "initinfo");
2773         BLI_addhead(&sa->spacedata, sinfo);
2774
2775         sinfo->spacetype=SPACE_INFO;
2776 }
2777
2778 /* ******************** SPACE: BUTS ********************** */
2779
2780 extern void drawbutspace(ScrArea *sa, void *spacedata); /* buttons.c */
2781
2782 static void changebutspace(ScrArea *sa, void *spacedata)
2783 {
2784         if(G.v2d==0) return;
2785         
2786         test_view2d(G.v2d, curarea->winx, curarea->winy);
2787         myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ym