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