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