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