Added baking for softbodies.
[blender.git] / source / blender / src / space.c
index f014942aca86ec9515d179b0f5e475b86d21d6be..dadfbf0f0b23bb3997434082b2ed84f4590926ca 100644 (file)
 #include <config.h>
 #endif
 
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
 #include "MEM_guardedalloc.h"
 
 #ifdef INTERNATIONAL
 
 #include "BLO_readfile.h" /* for BLO_blendhandle_close */
 
+#include "PIL_time.h"
+
 #include "BPY_extern.h"
 
 #include "mydevice.h"
 #include "blendef.h"
 #include "datatoc.h"
 
+#include "BIF_transform.h"
+
+#include "BKE_depsgraph.h"
+
 #include "TPT_DependKludge.h"
 #ifdef NAN_TPT
 #include "BSE_trans_types.h"
@@ -526,7 +528,7 @@ static void align_view_to_selected(View3D *v3d)
        }
 }
 
-void select_children(Object *ob, int recursive)
+static void select_children(Object *ob, int recursive)
 {
        Base *base;
 
@@ -538,7 +540,7 @@ void select_children(Object *ob, int recursive)
                }
 }
 
-void select_parent(void)       /* Makes parent active and de-selected OBACT */
+static void select_parent(void)        /* Makes parent active and de-selected OBACT */
 {
        Base *base, *startbase, *basact=NULL, *oldbasact;
        
@@ -551,16 +553,19 @@ void select_parent(void)  /* Makes parent active and de-selected OBACT */
        while(base) {
                if(base->object==BASACT->object->parent) { basact=base; break; }
                base=base->next;
-               if(base==0) base= FIRSTBASE;
+               if(base==NULL) base= FIRSTBASE;
                if(base==startbase) break;
        }
-       oldbasact = BASACT;
-       BASACT = basact;
-       basact->flag |= SELECT;         
-       
-       basact->object->flag= basact->flag;
-       
-       set_active_base(basact);
+       /* can be NULL if parent in other scene */
+       if(basact) {
+               oldbasact = BASACT;
+               BASACT = basact;
+               basact->flag |= SELECT;         
+               
+               basact->object->flag= basact->flag;
+               
+               set_active_base(basact);
+       }
 }
 
 
@@ -632,8 +637,12 @@ void BIF_undo_push(char *str)
                        undo_push_mesh(str);
                else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
                        undo_push_curve(str);
+               else if (G.obedit->type==OB_FONT)
+                       undo_push_font(str);
                else if (G.obedit->type==OB_MBALL)
                        undo_push_mball(str);
+               else if (G.obedit->type==OB_LATTICE)
+                       undo_push_lattice(str);
        }
        else {
                if(U.uiflag & USER_GLOBALUNDO) 
@@ -644,22 +653,16 @@ void BIF_undo_push(char *str)
 void BIF_undo(void)
 {      
        if(G.obedit) {
-               if(G.obedit->type==OB_MESH)
+               if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
                        undo_editmode_step(1);
-               else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
-                       undo_editmode_step(1);
-               else if (G.obedit->type==OB_MBALL)
-                       undo_editmode_step(1);
-                       
        }
        else {
-               if (G.f & G_FACESELECT)
-                       ;
-               else if(G.f & G_WEIGHTPAINT)
+               if(G.f & G_WEIGHTPAINT)
                        wpaint_undo();
                else if(G.f & G_VERTEXPAINT)
                        vpaint_undo();
                else {
+                       /* now also in faceselect mode */
                        if(U.uiflag & USER_GLOBALUNDO) BKE_undo_step(1);
                }
        }
@@ -668,22 +671,16 @@ void BIF_undo(void)
 void BIF_redo(void)
 {
        if(G.obedit) {
-               if(G.obedit->type==OB_MESH)
+               if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
                        undo_editmode_step(-1);
-               else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
-                       undo_editmode_step(-1);
-               else if (G.obedit->type==OB_MBALL)
-                       undo_editmode_step(-1);
-       
        }
        else {
-               if (G.f & G_FACESELECT)
-                       ;
-               else if(G.f & G_WEIGHTPAINT)
+               if(G.f & G_WEIGHTPAINT)
                        wpaint_undo();
                else if(G.f & G_VERTEXPAINT)
                        vpaint_undo();
                else {
+                       /* includes faceselect now */
                        if(U.uiflag & USER_GLOBALUNDO) BKE_undo_step(-1);
                }
        }
@@ -692,24 +689,24 @@ void BIF_redo(void)
 void BIF_undo_menu(void)
 {
        if(G.obedit) {
-               if(G.obedit->type==OB_MESH)
-                       undo_editmode_menu();
-               else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
-                       undo_editmode_menu();
-               else if (G.obedit->type==OB_MBALL)
+               if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
                        undo_editmode_menu();
-               
                allqueue(REDRAWALL, 0);
        }
        else {
-               if (G.f & G_FACESELECT)
-                       ;
-               else if(G.f & G_WEIGHTPAINT)
+               if(G.f & G_WEIGHTPAINT)
                        ;
                else if(G.f & G_VERTEXPAINT)
                        ;
                else {
-                       if(U.uiflag & USER_GLOBALUNDO) BKE_undo_menu();
+                       if(U.uiflag & USER_GLOBALUNDO) {
+                               char *menu= BKE_undo_menu_string();
+                               if(menu) {
+                                       short event= pupmenu_col(menu, 20);
+                                       MEM_freeN(menu);
+                                       if(event>0) BKE_undo_number(event);
+                               }
+                       }
                }
        }
 }
@@ -721,7 +718,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        unsigned short event= evt->event;
        short val= evt->val;
        char ascii= evt->ascii;
-       View3D *v3d= curarea->spacedata.first;
+       View3D *v3d= sa->spacedata.first;
        Object *ob;
        float *curs;
        int doredraw= 0, pupval;
@@ -735,13 +732,13 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                
                if(event==UI_BUT_EVENT) do_butspace(val); // temporal, view3d deserves own queue?
                
+               /* we consider manupilator a button, defaulting to leftmouse */
+               if(event==LEFTMOUSE) if(BIF_do_manipulator(sa)) return;
+               
                /* swap mouse buttons based on user preference */
                if (U.flag & USER_LMOUSESELECT) {
-                       if (evt->event == LEFTMOUSE) {
-                               event = RIGHTMOUSE;
-                       } else if (evt->event == RIGHTMOUSE) {
-                               event = LEFTMOUSE;
-                       }
+                       if (event==LEFTMOUSE) event = RIGHTMOUSE;
+                       else if (event==RIGHTMOUSE) event = LEFTMOUSE;
                }
                
                /* TEXTEDITING?? */
@@ -1059,6 +1056,34 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                do_layer_buttons(11); break;
                        case ACCENTGRAVEKEY:
                                do_layer_buttons(-1); break;
+                       
+                       case SPACEKEY:
+                               if(G.qual == LR_CTRLKEY) {
+                                       val= pupmenu("Manipulator%t|Enable/Disable|Translate|Rotate|Scale|Combo");
+                                       if(val>0) {
+                                               if(val==1) v3d->twflag ^= V3D_USE_MANIPULATOR;
+                                               else {
+                                                       if(val==2) v3d->twtype= V3D_MANIP_TRANSLATE;
+                                                       else if(val==3) v3d->twtype= V3D_MANIP_ROTATE;
+                                                       else if(val==4) v3d->twtype= V3D_MANIP_SCALE;
+                                                       else if(val==5) v3d->twtype= V3D_MANIP_TRANSLATE|V3D_MANIP_ROTATE|V3D_MANIP_SCALE;
+                                                       v3d->twflag |= V3D_USE_MANIPULATOR;
+                                               }
+                                               doredraw= 1;
+                                       }
+                               }
+                               else if(G.qual == LR_ALTKEY) {
+                                       val= pupmenu("Manipulator Orientation%t|Global|Local|Normal");
+                                       if(val>0) {
+                                               if(val==1) v3d->twmode= V3D_MANIP_GLOBAL;
+                                               else if(val==2) v3d->twmode= V3D_MANIP_LOCAL;
+                                               else if(val==3) v3d->twmode= V3D_MANIP_NORMAL;
+                                               v3d->twflag |= V3D_USE_MANIPULATOR;
+                                               doredraw= 1;
+                                       }
+                               }
+
+                               break;
                                
                        case AKEY:
                                if(G.qual & LR_CTRLKEY) apply_object(); // also with shift!
@@ -1185,7 +1210,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                else if (G.qual==LR_SHIFTKEY) {
                                        if (G.obedit && G.obedit->type==OB_MESH) {
-                                               transform('e');
+                                               Transform(TFM_CREASE, CTX_EDGE);
                                        }
                                }
                                break;
@@ -1217,10 +1242,18 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                else if(G.qual & LR_ALTKEY) rem_selected_from_group(); */
                                if((G.qual==LR_SHIFTKEY))
                                        select_group_menu();
-                               else if(G.qual==LR_ALTKEY)
-                                       clear_object('g');
-                               else if((G.qual==0))
-                                       transform('g');
+                               else if(G.qual==LR_ALTKEY) {
+                                       if(okee("Clear location")) {
+                                               clear_object('g');
+                                       }
+                               }
+                               else if(G.qual== (LR_CTRLKEY|LR_ALTKEY)) {
+                                       v3d->twtype= V3D_MANIP_TRANSLATE;
+                                       doredraw= 1;
+                               }
+                               else if((G.qual==0)) {
+                                       Transform(TFM_TRANSLATION, CTX_NONE);
+                               }
                                break;
                        case HKEY:
                                if(G.obedit) {
@@ -1263,6 +1296,14 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        else if(G.obedit->type==OB_LATTICE) {
                                                if(G.qual==LR_CTRLKEY) add_hook();
                                        }
+                                       else if(G.obedit->type==OB_MBALL) {
+                                               if(G.qual==LR_ALTKEY)
+                                                       reveal_mball();
+                                               else if((G.qual==LR_SHIFTKEY))
+                                                       hide_mball(1);
+                                               else if((G.qual==0)) 
+                                                       hide_mball(0);
+                                       }
                                }
                                else if(G.f & G_FACESELECT)
                                        hide_tface();
@@ -1342,14 +1383,22 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                selectconnected_posearmature();
                                }
                                else {
-                                       if((G.qual==LR_SHIFTKEY))
-                                               selectlinks_menu();
-                                       else if(G.qual==LR_CTRLKEY)
-                                               make_links_menu();
-                                       else if(G.f & G_FACESELECT)
-                                               select_linked_tfaces();
-                                       else if((G.qual==0))
-                                               make_local();
+                                       if(G.f & G_FACESELECT) {
+                                               if((G.qual==0))
+                                                       select_linked_tfaces(0);
+                                               else if((G.qual==LR_SHIFTKEY))
+                                                       select_linked_tfaces(1);
+                                               else if(G.qual==LR_CTRLKEY)
+                                                       select_linked_tfaces(2);
+                                       }
+                                       else {
+                                               if((G.qual==0))
+                                                       make_local();
+                                               else if((G.qual==LR_SHIFTKEY))
+                                                       selectlinks_menu();
+                                               else if(G.qual==LR_CTRLKEY)
+                                                       make_links_menu();
+                                       }
                                }
                                break;
                        case MKEY:
@@ -1363,7 +1412,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        else if((G.qual==0) || (G.qual==LR_CTRLKEY)) {
                                                mirrormenu();
                                        }
-                                       if(G.qual & (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY)) {
+                                       if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
                                                if(G.obedit->type==OB_MESH) select_non_manifold();
                                        }
                                }
@@ -1411,11 +1460,10 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case OKEY:
                                ob= OBACT;
-                               if(G.obedit) {
-                                       extern int prop_mode;
-
+                               if (G.obedit) {
                                        if (G.qual==LR_SHIFTKEY) {
-                                               prop_mode= !prop_mode;
+                                               extern int prop_mode;
+                                               prop_mode = (prop_mode+1)%6;
                                                allqueue(REDRAWHEADERS, 0);
                                        }
                                        else if((G.qual==0)) {
@@ -1428,11 +1476,14 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                flip_subdivison(ob, -1);
                                        }
                                }
-                               else if(G.qual==LR_ALTKEY) clear_object('o');
+                               else if(G.qual==LR_ALTKEY) {
+                                       if(okee("Clear origin")) {
+                                               clear_object('o');
+                                       }
+                               }
                                break;
 
                        case PKEY:
-                               
                                if(G.obedit) {
                                        if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
                                                make_parent();
@@ -1440,9 +1491,13 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                separatemenu();
                                        else if ((G.qual==0) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
                                                separate_nurb();
+                                       else if (G.qual==LR_SHIFTKEY)
+                                               Transform(TFM_PUSHPULL, CTX_NONE);
                                }
                                else if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
                                        make_parent();
+                               else if(G.qual==LR_SHIFTKEY)
+                                       Transform(TFM_PUSHPULL, CTX_NONE);
                                else if(G.qual==LR_ALTKEY)
                                        clear_parent();
                                else if((G.qual==0)) {
@@ -1452,8 +1507,15 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        case RKEY:
                                if((G.obedit==0) && (G.f & G_FACESELECT) && (G.qual==0))
                                        rotate_uv_tface();
-                               else if(G.qual==LR_ALTKEY)
-                                       clear_object('r');
+                               else if(G.qual==LR_ALTKEY) {
+                                       if(okee("Clear rotation")) {
+                                               clear_object('r');
+                                       }
+                               } 
+                               else if(G.qual== (LR_CTRLKEY|LR_ALTKEY)) {
+                                       v3d->twtype= V3D_MANIP_ROTATE;
+                                       doredraw= 1;
+                               }
                                else if (G.obedit) {
                                        if((G.qual==LR_SHIFTKEY)) {
                                                if ELEM(G.obedit->type,  OB_CURVE, OB_SURF)                                     
@@ -1465,30 +1527,51 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                if (G.obedit->type==OB_MESH)
                                                        loopoperations(LOOP_CUT);
                                        }
-                                       else if((G.qual==0))
-                                               transform('r');
+                                       else if((G.qual==0)) {
+                                               Transform(TFM_ROTATION, CTX_NONE);
+                                       }
+                               }
+                               else if((G.qual==0)) {
+                                       Transform(TFM_ROTATION, CTX_NONE);
                                }
-                               else if((G.qual==0))
-                                       transform('r');
                                break;
                        case SKEY:
-                               if(G.obedit) {
+                               if(G.qual== (LR_CTRLKEY|LR_ALTKEY)) {
+                                       v3d->twtype= V3D_MANIP_SCALE;
+                                       doredraw= 1;
+                               }
+                               else if(G.obedit) {
                                        if(G.qual==LR_ALTKEY)
-                                               transform('N'); /* scale along normal */
+                                               Transform(TFM_SHRINKFATTEN, CTX_NONE);
                                        else if(G.qual==LR_CTRLKEY)
-                                               transform('S');
+                                               Transform(TFM_SHEAR, CTX_NONE);
+                                       else if(G.qual==(LR_CTRLKEY|LR_ALTKEY))
+                                               Transform(TFM_SHEAR, CTX_NONE);
                                        else if(G.qual==LR_SHIFTKEY)
                                                snapmenu();
-                                       else if((G.qual==0))
-                                               transform('s');
+                                       else if(G.qual==0) {
+                                               Transform(TFM_RESIZE, CTX_NONE);
+                                       }
+                                       else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)){
+                                               Transform(TFM_TOSPHERE, CTX_NONE);
+                                       }
+                                       
                                }
                                else if(G.qual==LR_ALTKEY) {
-                                       clear_object('s');
+                                       if(okee("Clear size")) {
+                                               clear_object('s');
+                                       }
                                }
-                               else if((G.qual==LR_SHIFTKEY))
+                               else if(G.qual==LR_SHIFTKEY) {
                                        snapmenu();
-                               else if((G.qual==0))
-                                       transform('s');
+                               }
+                               else if((G.qual==0)) {
+                                       Transform(TFM_RESIZE, CTX_NONE);
+                               }
+                               else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
+                                       Transform(TFM_TOSPHERE, CTX_NONE);
+                               else if(G.qual==(LR_CTRLKEY|LR_ALTKEY))
+                                       Transform(TFM_SHEAR, CTX_NONE);
                                break;
                        case TKEY:
                                if(G.obedit){
@@ -1498,10 +1581,14 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                countall();
                                                makeDispList(G.obedit);
                                        }
-                                       else if((G.qual==LR_ALTKEY) && G.obedit->type==OB_CURVE)
-                                               clear_tilt();
-                                       else if((G.qual==0))
-                                               transform('t');
+                                       if (G.obedit->type==OB_CURVE) {
+                                               if (G.qual==LR_ALTKEY) {
+                                                       clear_tilt();
+                                               }
+                                               else if (G.qual==0) {
+                                                       Transform(TFM_TILT, CTX_NONE);
+                                               }
+                                       }
                                }
                                else if(G.qual==LR_CTRLKEY) {
                                        make_track();
@@ -1521,13 +1608,11 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        }
                                        else if(G.obedit->type==OB_ARMATURE)
                                                remake_editArmature();
-                                       else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
+                                       else if ELEM4(G.obedit->type, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE) {
                                                if(G.qual==0) BIF_undo(); else BIF_redo();
                                        }
-                                       else if(G.obedit->type==OB_LATTICE)
-                                               remake_editLatt();
                                }
-                               else if((G.qual==0)){
+                               else if((G.qual==0)) {
                                        if (G.f & G_FACESELECT)
                                                uv_autocalc_tface();
                                        else if(G.f & G_WEIGHTPAINT)
@@ -1567,7 +1652,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case WKEY:
                                if((G.qual==LR_SHIFTKEY)) {
-                                       transform('w');
+                                       Transform(TFM_WARP, CTX_NONE);
                                }
                                else if(G.qual==LR_ALTKEY) {
                                        /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
@@ -1612,6 +1697,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                } else if(G.qual==0) {
                                        G.vd->around= V3D_CENTRE;
                                }
+                               handle_view3d_around();
+                               
                                scrarea_queue_headredraw(curarea);
                                break;
                                
@@ -1621,6 +1708,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }       else if(G.qual==0) {
                                        G.vd->around= V3D_CURSOR;
                                }
+                               handle_view3d_around();
+                               
                                scrarea_queue_headredraw(curarea);
                                break;
                        
@@ -1641,7 +1730,18 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                if(G.qual==0) {
                                        ob= OBACT;
                                        if(ob) {
-                                               obmat_to_viewmat(ob);
+                                               if ((G.obedit) && (G.obedit->type == OB_MESH)) {
+                                                       editmesh_align_view_to_selected(G.vd, 2);
+                                               } 
+                                               else if (G.f & G_FACESELECT) {
+                                                       if(ob->type==OB_MESH) {
+                                                               Mesh *me= ob->data;
+                                                               faceselect_align_view_to_selected(G.vd, me, 2);
+                                                       }
+                                               }
+                                               else
+                                                       obmat_to_viewmat(ob);
+                                               
                                                if(G.vd->persp==2) G.vd->persp= 1;
                                                scrarea_queue_winredraw(curarea);
                                        }
@@ -1772,10 +1872,10 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 
                /* swap mouse buttons based on user preference */
                if (U.flag & USER_LMOUSESELECT) {
-                       if (evt->event == LEFTMOUSE) {
+                       if (event == LEFTMOUSE) {
                                event = RIGHTMOUSE;
                                mousebut = L_MOUSE;
-                       } else if (evt->event == RIGHTMOUSE) {
+                       } else if (event == RIGHTMOUSE) {
                                event = LEFTMOUSE;
                                mousebut = R_MOUSE;
                        }
@@ -1806,8 +1906,9 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        if( cfra!=CFRA ) {
                                                CFRA= cfra;
                                                update_for_newframe();
-                                               force_draw_all();/* To make constraint sliders redraw */
+                                               force_draw_all(0); /* To make constraint sliders redraw */
                                        }
+                                       else PIL_sleep_ms(30);
                                
                                } while(get_mbut() & mousebut);
                        }
@@ -1857,7 +1958,9 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                if(in_ipo_buttons()) {
                                        swap_visible_editipo();
                                }
-                               else swap_selectall_editipo();
+                               else {
+                                       swap_selectall_editipo();
+                               }
                                allspace (REMAKEIPO, 0);
                                allqueue (REDRAWNLA, 0);
                                allqueue (REDRAWACTION, 0);
@@ -1970,7 +2073,8 @@ void space_mipmap_button_function(int event) {
        allqueue(REDRAWVIEW3D, 0);
 }
 
-void space_sound_button_function(int event)
+#if 0
+static void space_sound_button_function(int event)
 {
        int a;
        SYS_SystemHandle syshandle;
@@ -1981,6 +2085,7 @@ void space_sound_button_function(int event)
                SYS_WriteCommandLineInt(syshandle, "noaudio", a);
        }
 }
+#endif
 
 #define B_ADD_THEME    3301
 #define B_DEL_THEME    3302
@@ -1998,7 +2103,7 @@ static short th_curcol= TH_BACK;
 static char *th_curcol_ptr= NULL;
 static char th_curcol_arr[4]={0, 0, 0, 255};
 
-void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
+static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
 {
        bTheme *btheme, *bt;
        int spacetype= 0;
@@ -2052,7 +2157,7 @@ void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        /* main choices pup */
        uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|%l|3D View %x2|%l|Ipo Curve Editor %x3|Action Editor %x4|"
                "NLA Editor %x5|%l|UV/Image Editor %x6|Video Sequence Editor %x7|Audio Timeline %x8|Text Editor %x9|%l|User Preferences %x10|"
-               "OOPS Schematic %x11|Buttons Window %x12|%l|File Browser %x13|Image Browser %x14",
+               "Outliner %x11|Buttons Window %x12|%l|File Browser %x13|Image Browser %x14",
                                                                                                        255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
        if(curmain==1) spacetype= 0;
        else if(curmain==2) spacetype= SPACE_VIEW3D;
@@ -2139,8 +2244,13 @@ void drawinfospace(ScrArea *sa, void *spacedata)
        glClearColor(col[0], col[1], col[2], 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
 
-       fac= ((float)curarea->winx)/1280.0f;
-       myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
+       if(curarea->winx<=1280.0) {
+               fac= ((float)curarea->winx)/1280.0f;
+               myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
+       }
+       else {
+               myortho2(0.0, (float)curarea->winx, 0.0, (float)curarea->winy);
+       }
        
        sprintf(naam, "infowin %d", curarea->win);
        block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->win);
@@ -2361,11 +2471,15 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                                (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
                                0, 0, 0, 0, 0, "");
                }
-
-               uiDefButBitS(block, TOG, USER_TWOBUTTONMOUSE, 0, "Emulate 3 Button Mouse",
+               
+               /* illegal combo... */
+               if (U.flag & USER_LMOUSESELECT) 
+                       U.flag &= ~USER_TWOBUTTONMOUSE;
+               
+               uiDefButBitS(block, TOG, USER_TWOBUTTONMOUSE, B_DRAWINFO, "Emulate 3 Button Mouse",
                        (xpos+edgsp+(3*mpref)+(4*midsp)),y3,mpref,buth,
                        &(U.flag), 0, 0, 0, 0,
-                       "Emulates a middle mouse button with Alt LeftMouse");
+                       "Emulates Middle Mouse with Alt+LeftMouse (doesnt work with Left Mouse Select option)");
                
                        
                uiDefBut(block, LABEL,0,"Middle Mouse Button:",
@@ -2393,6 +2507,22 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        "The number of lines scrolled at a time with the mouse wheel"); 
 
 
+               uiDefBut(block, LABEL,0,"3D Transform Widget:",
+                                (xpos+(2*edgsp)+(5*mpref)+(5*midsp)),y6label,mpref,buth,
+                                0, 0, 0, 0, 0, "");
+               uiBlockBeginAlign(block);
+               uiDefButS(block, NUM, B_REDRCURW3D, "Size:",
+                                        (xpos+edgsp+(5*mpref)+(6*midsp)),y5,(mpref/2),buth,
+                                        &(U.tw_size), 2, 40, 0, 0, "Size of widget as percentage of window size");
+               uiDefButS(block, NUM, B_REDRCURW3D, "Handle:",
+                                        (xpos+edgsp+(5*mpref)+(6*midsp)+(mpref/2)),y5,(mpref/2),buth,
+                                        &(U.tw_handlesize), 2, 40, 0, 0, "Size of widget handles as percentage of widget radius");
+               uiDefButS(block, NUM, B_REDRCURW3D, "Hotspot:",
+                                 (xpos+edgsp+(5*mpref)+(6*midsp)),y4,(mpref),buth,
+                                 &(U.tw_hotspot), 4, 40, 0, 0, "Hotspot in pixels for clicking widget handles");
+               
+               uiBlockEndAlign(block);
+               
        } else if (U.userpref == 1) { /* edit methods */
 
 
@@ -2474,25 +2604,29 @@ void drawinfospace(ScrArea *sa, void *spacedata)
        } else if(U.userpref == 2) { /* language & colors */
 
 #ifdef INTERNATIONAL
-               char curfont[320];
-
-               sprintf(curfont, "Interface Font: ");
-               strcat(curfont,U.fontname);
-
                uiDefButBitS(block, TOG, USER_DOTRANSLATE, B_DOLANGUIFONT, "International Fonts",
                        xpos,y2,mpref,buth,
                        &(U.transopts), 0, 0, 0, 0, "Activate international interface");
 
                if(U.transopts & USER_DOTRANSLATE) {
+                       char curfont[320];
+                       
+                       sprintf(curfont, "Interface Font: ");
+                       if(U.fontname[0]) strcat(curfont, U.fontname);
+                       else strcat(curfont, "Built-in");
+                       
                        uiDefBut(block, LABEL,0,curfont,
-                               (xpos+edgsp+mpref+midsp),y2,mpref,buth,
+                               (xpos),y3,4*mpref,buth,
                                0, 0, 0, 0, 0, "");
 
                        uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
                                xpos,y1,mpref,buth,
                                0, 0, 0, 0, 0, "Select a new font for the interface");
 
-
+                       uiDefButI(block, BUT, B_RESTOREFONT, "Restore to default",
+                                         (xpos+edgsp+mpref+midsp),y2,mpref,buth,
+                                         &U.fontsize, 0, 0, 0, 0, "Restores to using the default included antialised font");
+                       
                        uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
                                (xpos+edgsp+mpref+midsp),y1,mpref,buth,
                                &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
@@ -2524,12 +2658,10 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                                (xpos+edgsp+(2.2*mpref)+(3*midsp)),y2,mpref+(0.5*mpref)+3,buth,
                                &U.language, 0, 0, 0, 0, "Select interface language");
                                
-                       /* uiDefButBitS(block, TOG, USER_TR_TEXTEDIT, B_SETTRANSBUTS, "FTF All windows",
-                               (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
+                       uiDefButBitS(block, TOG, USER_USETEXTUREFONT, B_USETEXTUREFONT, "Use Textured Fonts",
+                               (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
                                &(U.transopts), 0, 0, 0, 0,
-                               "Use FTF drawing for fileselect and textwindow "
-                               "(under construction)");
-                       */
+                               "Use Textured Fonts");
                }
 
 /* end of INTERNATIONAL */
@@ -2660,9 +2792,9 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+edgsp+(4*midsp)+(4*mpref)),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
 
-               uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Sound",
+               uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Game Sound",
                        (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
-                       &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
+                       &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played in games");
 
                uiDefButBitS(block, TOG, USER_FILTERFILEEXTS, 0, "Filter File Extensions",
                        (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
@@ -2779,7 +2911,15 @@ void drawinfospace(ScrArea *sa, void *spacedata)
        
        myortho2(-0.375, (float)(sa->winx)-0.375, -0.375, (float)(sa->winy)-0.375);
        draw_area_emboss(sa);
-       myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
+
+       /* restore buttons transform */
+       if(curarea->winx<=1280.0) {
+               fac= ((float)curarea->winx)/1280.0f;
+               myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
+       }
+       else {
+               myortho2(0.0, (float)curarea->winx, 0.0, (float)curarea->winy);
+       }
        sa->win_swap= WIN_BACK_OK;
        
 }
@@ -3097,10 +3237,10 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                
                /* swap mouse buttons based on user preference */
                if (U.flag & USER_LMOUSESELECT) {
-                       if (evt->event == LEFTMOUSE) {
+                       if (event == LEFTMOUSE) {
                                event = RIGHTMOUSE;
                                mousebut = L_MOUSE;
-                       } else if (evt->event == RIGHTMOUSE) {
+                       } else if (event == RIGHTMOUSE) {
                                event = LEFTMOUSE;
                                mousebut = R_MOUSE;
                        }
@@ -3128,9 +3268,10 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                first= 0;
                                
                                                CFRA= cfra;
-                                               force_draw();
+                                               force_draw(0);
                                                update_for_newframe();  /* for audio scrubbing */                                               
                                        }
+                                       else PIL_sleep_ms(30);
                                
                                } while(get_mbut() & mousebut);
                                
@@ -3163,10 +3304,12 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                else if((G.qual==LR_SHIFTKEY)) {
                                        insert_gap(25, CFRA);
+                                       BIF_undo_push("Insert gaps Sequencer");
                                        allqueue(REDRAWSEQ, 0);
                                }
                                else if(G.qual==LR_ALTKEY) {
                                        insert_gap(250, CFRA);
+                                       BIF_undo_push("Insert gaps Sequencer");
                                        allqueue(REDRAWSEQ, 0);
                                }
                        }
@@ -3243,7 +3386,7 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                case GKEY:
                        if(sseq->mainb) break;
                        if((G.qual==0))
-                               transform_seq('g');
+                               transform_seq('g', 0);
                        break;
                case MKEY:
                        if(G.qual==LR_ALTKEY)
@@ -3374,7 +3517,7 @@ static void init_actionspace(ScrArea *sa)
        
 }
 
-void free_actionspace(SpaceAction *saction)
+static void free_actionspace(SpaceAction *saction)
 {
        /* don't free saction itself */
        
@@ -3545,10 +3688,10 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        
        /* swap mouse buttons based on user preference */
        if (U.flag & USER_LMOUSESELECT) {
-               if (evt->event == LEFTMOUSE) {
+               if (event == LEFTMOUSE) {
                        event = RIGHTMOUSE;
                        mousebut = R_MOUSE;
-               } else if (evt->event == RIGHTMOUSE) {
+               } else if (event == RIGHTMOUSE) {
                        event = LEFTMOUSE;
                        mousebut = L_MOUSE;
                }
@@ -3586,11 +3729,11 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                        /* Make OpenGL aware of a changed texture */
                                                        free_realtime_image(sima->image);
                                                        /* Redraw this view and the 3D view */
-                                                       force_draw_plus(SPACE_VIEW3D);
+                                                       force_draw_plus(SPACE_VIEW3D, 0);
                                                }
                                                else {
                                                        /* Redraw only this view */
-                                                       force_draw();
+                                                       force_draw(0);
                                                }
                                                xy_prev[0] = xy_curr[0];
                                                xy_prev[1] = xy_curr[1];
@@ -3602,7 +3745,7 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        /* Make OpenGL aware of a changed texture */
                                        free_realtime_image(sima->image);
                                        /* Redraw this view and the 3D view */
-                                       force_draw_plus(SPACE_VIEW3D);
+                                       force_draw_plus(SPACE_VIEW3D, 1);
                                }
                                IMG_BrushDispose(brush);
                                IMG_CanvasDispose(canvas);
@@ -3622,9 +3765,6 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                if(G.qual & LR_SHIFTKEY) mouseco_to_curtile();
                                else gesture();
                                break;
-                       case MIDDLEMOUSE:
-                               image_viewmove();
-                               break;
                        case RIGHTMOUSE:
                                if(G.f & G_FACESELECT)
                                        mouse_select_sima();
@@ -3650,12 +3790,12 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        toggle_uv_select('f');
                                break;
                        case EKEY :
-                               if (okee("LSCM unwrap"))
+                               if(okee("LSCM Unwrap"))
                                        unwrap_lscm();
                                break;
                        case GKEY:
                                if((G.qual==0))
-                                       transform_tface_uv('g');
+                                       transform_tface_uv('g', 0);
                                break;
                        case HKEY:
                                if(G.qual==LR_ALTKEY)
@@ -3666,8 +3806,12 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        hide_tface_uv(0);
                                break;
                        case LKEY:
-                               if((G.qual==0))
-                                       select_linked_tface_uv();
+                               if(G.qual==0)
+                                       select_linked_tface_uv(0);
+                               else if(G.qual==LR_SHIFTKEY)
+                                       select_linked_tface_uv(1);
+                               else if(G.qual==LR_CTRLKEY)
+                                       select_linked_tface_uv(2);
                                else if(G.qual==LR_ALTKEY)
                                        unlink_selection();
                                break;
@@ -3699,11 +3843,11 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case RKEY:
                                if((G.qual==0))
-                                       transform_tface_uv('r');
+                                       transform_tface_uv('r', 0);
                                break;
                        case SKEY:
                                if((G.qual==0))
-                                       transform_tface_uv('s');
+                                       transform_tface_uv('s', 0);
                                break;
                        case VKEY:
                                if((G.qual==0))
@@ -3712,7 +3856,11 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        stitch_uv_tface(1);
                                break;
                        case WKEY:
-                               transform_tface_uv('w');
+                               weld_align_menu_tface_uv();
+                               break;
+                       case PADPERIOD:
+                               if(G.qual==0)
+                                       image_viewcentre();
                                break;
                }
        }       
@@ -3729,13 +3877,13 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                do_imagebuts(val);      // drawimage.c
                break;
        case MIDDLEMOUSE:
-               image_viewmove();
+               if((G.qual==LR_CTRLKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
+                       image_viewmove(1);
+               else
+                       image_viewmove(0);
                break;
-       case WHEELUPMOUSE:
-       case WHEELDOWNMOUSE:
-       case PADPLUSKEY:
-       case PADMINUS:
-               image_viewzoom(event);
+       case WHEELUPMOUSE: case WHEELDOWNMOUSE: case PADPLUSKEY: case PADMINUS:
+               image_viewzoom(event, 0);
                scrarea_queue_winredraw(curarea);
                break;
        case HOMEKEY:
@@ -3806,14 +3954,14 @@ static void winqreadoopsspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        view2dmove(event);      /* in drawipo.c */
                        break;
                case RIGHTMOUSE:
-                       outliner_select(sa);
+                       // outliner_select(sa);
                        break;
                        
                case AKEY:
-                       outliner_toggle_selected(sa);
+                       outliner_toggle_visible(sa);
                        break;
                case WKEY:
-                       outliner_operation_menu(sa);
+                       // outliner_operation_menu(sa);
                        break;
                        
                case HOMEKEY:
@@ -3845,13 +3993,10 @@ static void winqreadoopsspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        else {  
                /* swap mouse buttons based on user preference */
                if (U.flag & USER_LMOUSESELECT) {
-                       if (evt->event == LEFTMOUSE) {
-                               event = RIGHTMOUSE;
-                       } else if (evt->event == RIGHTMOUSE) {
-                               event = LEFTMOUSE;
-                       }
+                       if (event==LEFTMOUSE) event = RIGHTMOUSE;
+                       else if (event==RIGHTMOUSE) event = LEFTMOUSE;
                }
-       
+               
                switch(event) {
                case LEFTMOUSE:
                        gesture();
@@ -3905,7 +4050,7 @@ static void winqreadoopsspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        break;
                case GKEY:
                        if((G.qual==0))
-                               transform_oops('g');
+                               transform_oops('g', 0);
                        break;
                case LKEY:
                        if((G.qual==LR_SHIFTKEY))
@@ -3923,7 +4068,7 @@ static void winqreadoopsspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        shuffle_oops();
                                }
                        } else if((G.qual==0)) {
-                               transform_oops('s');
+                               transform_oops('s', 0);
                        }
                        break;
                case PKEY:
@@ -3972,7 +4117,7 @@ void init_v2d_oops(ScrArea *sa, SpaceOops *soops)
        
        if(soops->type==SO_OUTLINER) {
                /* outliner space is window size */
-               calc_scrollrcts(v2d, sa->winx, sa->winy);
+               calc_scrollrcts(sa, v2d, sa->winx, sa->winy);
                
                v2d->tot.xmax= 0.0;
                v2d->tot.ymax= 0.0;
@@ -4199,6 +4344,8 @@ void freespacelist(ListBase *lb)
                        SpaceFile *sfile= (SpaceFile*) sl;
                        if(sfile->libfiledata)  
                                BLO_blendhandle_close(sfile->libfiledata);
+                       if(sfile->filelist)
+                               freefilelist(sfile);
                }
                else if(sl->spacetype==SPACE_BUTS) {
                        SpaceButs *buts= (SpaceButs*) sl;
@@ -4336,6 +4483,16 @@ void allqueue(unsigned short event, short val)
 
        sa= G.curscreen->areabase.first;
        while(sa) {
+//#ifdef NAN_DEP_GRAPH
+               /* dependency check.maybe not final pos */
+               if (sa->spacetype==SPACE_VIEW3D) {
+                       if (G.scene->dagisvalid == 0) {
+//                             fprintf(stderr,"building dag \n");
+                               G.scene->theDag = build_dag(G.scene, DAG_RL_ALL_BUT_DATA_MASK);
+                               G.scene->dagisvalid = 1;
+                       }
+               }
+//#endif
                if(event==REDRAWALL) {
                        scrarea_queue_winredraw(sa);
                        scrarea_queue_headredraw(sa);
@@ -4578,15 +4735,16 @@ void allspace(unsigned short event, short val)
        }
 }
 
-
-void force_draw()
+/* if header==1, then draw header for curarea too. Excepption for headerprint()... */
+void force_draw(int header)
 {
        /* draws alle areas that something identical to curarea */
        extern int afterqtest(short win, unsigned short evt);   //editscreen.c
        ScrArea *tempsa, *sa;
 
        scrarea_do_windraw(curarea);
-       
+       if(header) scrarea_do_headdraw(curarea);
+               
        tempsa= curarea;
        sa= G.curscreen->areabase.first;
        while(sa) {
@@ -4595,19 +4753,13 @@ void force_draw()
                                if( ((View3D *)sa->spacedata.first)->lay & ((View3D *)tempsa->spacedata.first)->lay) {
                                        areawinset(sa->win);
                                        scrarea_do_windraw(sa);
+                                       scrarea_do_headdraw(sa);
                                }
                        }
-                       else if(sa->spacetype==SPACE_IPO) {
-                               areawinset(sa->win);
-                               scrarea_do_windraw(sa);
-                       }
-                       else if(sa->spacetype==SPACE_SEQ) {
-                               areawinset(sa->win);
-                               scrarea_do_windraw(sa);
-                       }
-                       else if(sa->spacetype==SPACE_ACTION) {
+                       else {
                                areawinset(sa->win);
                                scrarea_do_windraw(sa);
+                               scrarea_do_headdraw(sa);
                        }
                }
                sa= sa->next;
@@ -4632,13 +4784,14 @@ void force_draw()
        
 }
 
-void force_draw_plus(int type)
+/* if header==1, then draw header for curarea too. Excepption for headerprint()... */
+void force_draw_plus(int type, int header)
 {
        /* draws all areas that show something like curarea AND areas of 'type' */
        ScrArea *tempsa, *sa;
 
        scrarea_do_windraw(curarea); 
-       scrarea_do_headdraw(curarea);
+       if(header) scrarea_do_headdraw(curarea);
 
        tempsa= curarea;
        sa= G.curscreen->areabase.first;
@@ -4657,7 +4810,8 @@ void force_draw_plus(int type)
        screen_swapbuffers();
 }
 
-void force_draw_all(void)
+/* if header==1, then draw header for curarea too. Excepption for headerprint()... */
+void force_draw_all(int header)
 {
        /* redraws all */
        ScrArea *tempsa, *sa;
@@ -4669,7 +4823,7 @@ void force_draw_all(void)
        while(sa) {
                if(sa->headwin) {
                        scrarea_do_headdraw(sa);
-                       scrarea_do_headchange(sa);
+                       if(sa!=curarea || header) scrarea_do_headchange(sa);
                }
                if(sa->win) {
                        scrarea_do_windraw(sa);