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