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