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