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