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