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