Orange; stuff for the animation department!
[blender.git] / source / blender / src / space.c
index f2bf392f956d43f0e64b984dee7e30997dbd51d5..b2b091f572b2f52dc17270768d29a15e85ed0bf1 100644 (file)
@@ -54,6 +54,7 @@
 #include "BLI_linklist.h"
 
 #include "DNA_action_types.h"
+#include "DNA_armature_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_image_types.h"
 #include "DNA_ipo_types.h"
 
 #include "BKE_blender.h"
 #include "BKE_curve.h"
+#include "BKE_depsgraph.h"
 #include "BKE_displist.h"
 #include "BKE_global.h"
 #include "BKE_ipo.h"
 #include "BKE_main.h"
+#include "BKE_node.h"
 #include "BKE_scene.h"
 #include "BKE_utildefines.h"
 
@@ -85,8 +88,9 @@
 #include "BIF_drawtext.h"
 #include "BIF_drawscript.h"
 #include "BIF_editarmature.h"
+#include "BIF_editconstraint.h"
 #include "BIF_editfont.h"
-#include "BIF_editika.h"
+#include "BIF_editgroup.h"
 #include "BIF_editkey.h"
 #include "BIF_editlattice.h"
 #include "BIF_editmesh.h"
 #include "BIF_meshtools.h"
 #include "BIF_mywindow.h"
 #include "BIF_oops.h"
+#include "BIF_poseobject.h"
 #include "BIF_outliner.h"
 #include "BIF_resources.h"
 #include "BIF_screen.h"
 #include "BDR_editface.h"
 #include "BDR_drawmesh.h"
 #include "BDR_drawobject.h"
+#include "BDR_imagepaint.h"
 #include "BDR_unwrapper.h"
 
 #include "BLO_readfile.h" /* for BLO_blendhandle_close */
 
 #include "BIF_transform.h"
 
-#include "TPT_DependKludge.h"
-#ifdef NAN_TPT
+#include "BKE_depsgraph.h"
+
 #include "BSE_trans_types.h"
 #include "IMG_Api.h"
-#endif /* NAN_TPT */
 
 #include "SYS_System.h" /* for the user def menu ... should move elsewhere. */
 
-extern void StartKetsjiShell(ScrArea *area, char* startscenename, struct Main* maggie, int always_use_expand_framing);
+
+extern void StartKetsjiShell(ScrArea *area, char* startscenename, struct Main* maggie, struct SpaceIpo* sipo,int always_use_expand_framing);
 
 /**
  * When the mipmap setting changes, we want to redraw the view right
@@ -354,6 +360,11 @@ void space_set_commmandline_options(void) {
 
                a= (G.fileflags & G_FILE_ENABLE_ALL_FRAMES);
                SYS_WriteCommandLineInt(syshandle, "fixedtime", a);
+
+               a= (G.fileflags & G_FILE_GAME_TO_IPO);
+               SYS_WriteCommandLineInt(syshandle, "game2ipo", a);
+
+
        }
 }
 
@@ -395,7 +406,9 @@ static LinkNode *save_and_reset_all_scene_cfra(void)
        
        for (sc= G.main->scene.first; sc; sc= sc->id.next) {
                BLI_linklist_prepend(&storelist, (void*) (long) sc->r.cfra);
-               sc->r.cfra= 1;
+
+               //why is this reset to 1 ?
+               //sc->r.cfra= 1;
 
                set_scene_bg(sc);
        }
@@ -468,7 +481,7 @@ void start_game(void)
        space_set_commmandline_options();
 
        SaveState();
-       StartKetsjiShell(curarea, startscene->id.name+2, G.main, 1);
+       StartKetsjiShell(curarea, startscene->id.name+2, G.main,G.sipo, 1);
        RestoreState();
 
        /* Restart BPY - unload the game engine modules. */
@@ -479,7 +492,7 @@ void start_game(void)
        restore_all_scene_cfra(scene_cfra_store);
        set_scene_bg(startscene);
        
-       if (G.flags & G_FLAGS_AUTOPLAY)
+       if (G.flags & G_FILE_AUTOPLAY)
                exit_usiblender();
 
                /* groups could have changed ipo */
@@ -566,31 +579,10 @@ static void select_parent(void)   /* Makes parent active and de-selected OBACT */
        }
 }
 
-
-void select_group_menu(void)
-{
-       char *str;
-       short nr;
-
-       /* make menu string */
-       
-       str= MEM_mallocN(160, "groupmenu");
-       strcpy(str, "Select Grouped%t|Children%x1|"
-                   "Immediate Children%x2|Parent%x3|"
-                   "Objects on Shared Layers%x4");
-
-       /* here we go */
-       
-       nr= pupmenu(str);
-       MEM_freeN(str);
-       
-       select_group(nr);
-}
-
-void select_group(short nr)
+void select_grouped(short nr)
 {
        Base *base;
-
+       
        if(nr==4) {
                base= FIRSTBASE;
                while(base) {
@@ -605,12 +597,34 @@ void select_group(short nr)
        else if(nr==1) select_children(OBACT, 1);
        else if(nr==3) select_parent();
        
+       countall();
        allqueue(REDRAWVIEW3D, 0);
        allqueue(REDRAWBUTSOBJECT, 0);
        allspace(REMAKEIPO, 0);
        allqueue(REDRAWIPO, 0);
 }
 
+static void select_grouped_menu(void)
+{
+       char *str;
+       short nr;
+
+       /* make menu string */
+       
+       str= MEM_mallocN(160, "groupmenu");
+       strcpy(str, "Select Grouped%t|Children%x1|"
+                   "Immediate Children%x2|Parent%x3|"
+                   "Objects on Shared Layers%x4");
+
+       /* here we go */
+       
+       nr= pupmenu(str);
+       MEM_freeN(str);
+       
+       select_grouped(nr);
+}
+
+
 static unsigned short convert_for_nonumpad(unsigned short event)
 {
        if (event>=ZEROKEY && event<=NINEKEY) {
@@ -631,6 +645,8 @@ static unsigned short convert_for_nonumpad(unsigned short event)
 void BIF_undo_push(char *str)
 {
        if(G.obedit) {
+               if (U.undosteps == 0) return;
+
                if(G.obedit->type==OB_MESH)
                        undo_push_mesh(str);
                else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
@@ -641,6 +657,8 @@ void BIF_undo_push(char *str)
                        undo_push_mball(str);
                else if (G.obedit->type==OB_LATTICE)
                        undo_push_lattice(str);
+               else if (G.obedit->type==OB_ARMATURE)
+                       undo_push_armature(str);
        }
        else {
                if(U.uiflag & USER_GLOBALUNDO) 
@@ -651,7 +669,7 @@ void BIF_undo_push(char *str)
 void BIF_undo(void)
 {      
        if(G.obedit) {
-               if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
+               if ELEM7(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE)
                        undo_editmode_step(1);
        }
        else {
@@ -659,9 +677,14 @@ void BIF_undo(void)
                        wpaint_undo();
                else if(G.f & G_VERTEXPAINT)
                        vpaint_undo();
+               else if(G.f & G_TEXTUREPAINT); /* no texture paint undo yet */
+               else if(curarea->spacetype==SPACE_IMAGE && (G.sima->flag & SI_DRAWTOOL));
                else {
                        /* now also in faceselect mode */
-                       if(U.uiflag & USER_GLOBALUNDO) BKE_undo_step(1);
+                       if(U.uiflag & USER_GLOBALUNDO) {
+                               BKE_undo_step(1);
+                               sound_initialize_sounds();
+                       }
                }
        }
 }
@@ -669,7 +692,7 @@ void BIF_undo(void)
 void BIF_redo(void)
 {
        if(G.obedit) {
-               if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
+               if ELEM7(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE)
                        undo_editmode_step(-1);
        }
        else {
@@ -679,7 +702,10 @@ void BIF_redo(void)
                        vpaint_undo();
                else {
                        /* includes faceselect now */
-                       if(U.uiflag & USER_GLOBALUNDO) BKE_undo_step(-1);
+                       if(U.uiflag & USER_GLOBALUNDO) {
+                               BKE_undo_step(-1);
+                               sound_initialize_sounds();
+                       }
                }
        }
 }
@@ -687,7 +713,7 @@ void BIF_redo(void)
 void BIF_undo_menu(void)
 {
        if(G.obedit) {
-               if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
+               if ELEM7(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE)
                        undo_editmode_menu();
                allqueue(REDRAWALL, 0);
        }
@@ -713,13 +739,13 @@ void BIF_undo_menu(void)
 
 static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
-       unsigned short event= evt->event;
-       short val= evt->val;
-       char ascii= evt->ascii;
        View3D *v3d= sa->spacedata.first;
-       Object *ob;
+       Object *ob= OBACT;      // do not change!
        float *curs;
        int doredraw= 0, pupval;
+       unsigned short event= evt->event;
+       short val= evt->val;
+       char ascii= evt->ascii;
        
        if(curarea->win==0) return;     /* when it comes from sa->headqread() */
        
@@ -730,7 +756,7 @@ 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 */
+               /* we consider manipulator a button, defaulting to leftmouse */
                if(event==LEFTMOUSE) if(BIF_do_manipulator(sa)) return;
                
                /* swap mouse buttons based on user preference */
@@ -738,7 +764,12 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        if (event==LEFTMOUSE) event = RIGHTMOUSE;
                        else if (event==RIGHTMOUSE) event = LEFTMOUSE;
                }
-               
+
+               /* run any view3d event handler script links */
+               if (event && sa->scriptlink.totscript)
+                       if (BPY_do_spacehandlers(sa, event, SPACEHANDLER_VIEW3D_EVENT))
+                               return; /* return if event was processed (swallowed) by handler(s) */
+
                /* TEXTEDITING?? */
                if((G.obedit) && G.obedit->type==OB_FONT) {
                        switch(event) {
@@ -918,14 +949,10 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        else if(G.obedit->type==OB_ARMATURE)
                                                mouse_armature();
                                }
-                               else if((G.obedit) && (G.qual == (LR_CTRLKEY|LR_ALTKEY)))
+                               else if((G.obedit && G.obedit->type==OB_MESH) && (G.qual == (LR_CTRLKEY|LR_ALTKEY)))
                                        mouse_mesh();   // loop select for 1 mousebutton dudes
-                               else if((G.obedit) && (G.qual == (LR_CTRLKEY|LR_ALTKEY|LR_SHIFTKEY)))
+                               else if((G.obedit && G.obedit->type==OB_MESH) && (G.qual == (LR_CTRLKEY|LR_ALTKEY|LR_SHIFTKEY)))
                                        mouse_mesh();   // loop select for 1 mousebutton dudes
-                               else if(G.obpose) { 
-                                       if (G.obpose->type==OB_ARMATURE)
-                                               mousepose_armature();
-                               }
                                else if(G.qual==LR_CTRLKEY)
                                        mouse_select(); // also allow in editmode, for vertex parenting
                                else if(G.f & G_FACESELECT)
@@ -933,7 +960,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                else if( G.f & (G_VERTEXPAINT|G_TEXTUREPAINT))
                                        sample_vpaint();
                                else
-                                       mouse_select();
+                                       mouse_select(); // does poses too
                                break;
                        case WHEELUPMOUSE:
                                /* Regular:   Zoom in */
@@ -997,7 +1024,6 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        
                        case ONEKEY:
-                               ob= OBACT;
                                if(G.qual==LR_CTRLKEY) {
                                        if(ob && ob->type == OB_MESH) {
                                                flip_subdivison(ob, 1);
@@ -1007,7 +1033,6 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                                
                        case TWOKEY:
-                               ob= OBACT;
                                if(G.qual==LR_CTRLKEY) {
                                        if(ob && ob->type == OB_MESH) {
                                                flip_subdivison(ob, 2);
@@ -1017,27 +1042,39 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                                
                        case THREEKEY:
-                               ob= OBACT;
                                if(G.qual==LR_CTRLKEY) {
                                        if(ob && ob->type == OB_MESH) {
                                                flip_subdivison(ob, 3);
                                        }
                                }
+                               else if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
+                                       if ( (G.obedit) && (G.obedit->type==OB_MESH) )
+                                               select_faces_by_numverts(3);
+                               }
                                else do_layer_buttons(2); 
                                break;
                                
                        case FOURKEY:
-                               ob= OBACT;
                                if(G.qual==LR_CTRLKEY) {
                                        if(ob && ob->type == OB_MESH) {
                                                flip_subdivison(ob, 4);
                                        }
                                }
+                               else if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
+                                       if ( (G.obedit) && (G.obedit->type==OB_MESH) )
+                                               select_faces_by_numverts(4);
+                               }
                                else do_layer_buttons(3); 
                                break;
                                
                        case FIVEKEY:
-                               do_layer_buttons(4); break;
+                               if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
+                                       if ( (G.obedit) && (G.obedit->type==OB_MESH) )
+                                               select_faces_by_numverts(5);
+                               }
+                               else do_layer_buttons(4);
+                               break;
+
                        case SIXKEY:
                                do_layer_buttons(5); break;
                        case SEVENKEY:
@@ -1071,14 +1108,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        }
                                }
                                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;
-                                       }
+                                       BIF_selectOrientation();
+                                       doredraw= 1;
                                }
 
                                break;
@@ -1099,14 +1130,10 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                else if(G.obedit->type==OB_LATTICE)
                                                        deselectall_Latt();
                                                else if(G.obedit->type==OB_ARMATURE)
-                                                       deselectall_armature();
+                                                       deselectall_armature(1);        // 1 == toggle
                                        }
-                                       else if (G.obpose){
-                                               switch (G.obpose->type){
-                                               case OB_ARMATURE:
-                                                       deselectall_posearmature(1);
-                                                       break;
-                                               }
+                                       else if (ob && (ob->flag & OB_POSEMODE)){
+                                               deselectall_posearmature(ob, 1);
                                        }
                                        else {
                                                if(G.f & G_FACESELECT) deselectall_tface();
@@ -1121,26 +1148,28 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                break;
                        case BKEY:
-                               if((G.qual==LR_SHIFTKEY))
+                               if(G.qual==LR_ALTKEY)
+                                       view3d_edit_clipping(v3d);
+                               else if(G.qual==LR_SHIFTKEY)
                                        set_render_border();
-                               else if((G.qual==LR_ALTKEY)){
-                                       if(G.obedit && G.obedit->type==OB_MESH) {
-                                               /* Loop Select Operations */
-                                               /*   Vertexloop */
-                                               /*   Faceloop   */                                              
-                                               vertex_loop_select(); 
-                                       }
-                               }
-                               else if((G.qual==0))
+                               else if(G.qual==0)
                                        borderselect();
                                break;
                        case CKEY:
                                if(G.qual==LR_CTRLKEY) {
-                                       copy_attr_menu();
+                                       if(ob && (ob->flag & OB_POSEMODE))
+                                               pose_copy_menu();       /* poseobject.c */
+                                       else
+                                               copy_attr_menu();
                                }
                                else if(G.qual==LR_ALTKEY) {
-                                       convertmenu();  /* editobject.c */
+                                       if(ob && (ob->flag & OB_POSEMODE))
+                                               pose_clear_constraints();       /* poseobject.c */
+                                       else
+                                               convertmenu();  /* editobject.c */
                                }
+                               else if(G.qual==(LR_ALTKEY|LR_CTRLKEY)) 
+                                       add_constraint(0);      /* editconstraint.c, generic for objects and posemode */
                                else if((G.qual==LR_SHIFTKEY)) {
                                        view3d_home(1);
                                        curs= give_cursor();
@@ -1149,7 +1178,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                else if((G.obedit) && ELEM(G.obedit->type, OB_CURVE, OB_SURF) ) {
                                        makecyclicNurb();
-                                       makeDispList(G.obedit);
+                                       DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
                                        allqueue(REDRAWVIEW3D, 0);
                                }
                                else if((G.qual==0)){
@@ -1166,9 +1195,9 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        duplicate_context_selected();
                                }
                                else if(G.qual==LR_ALTKEY) {
-                                       if(G.obpose)
+                                       if(ob && (ob->flag & OB_POSEMODE))
                                                error ("Duplicate not possible in posemode.");
-                                       else if((G.obedit==0))
+                                       else if((G.obedit==NULL))
                                                adduplicate(0);
                                }
                                else if(G.qual==LR_CTRLKEY) {
@@ -1194,12 +1223,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                else if(G.obedit->type==OB_SURF)
                                                        extrude_nurb();
                                                else if(G.obedit->type==OB_ARMATURE)
-                                                       extrude_armature();
-                                       }
-                                       else {
-                                               ob= OBACT;
-                                               if(ob && ob->type==OB_IKA) if(okee("extrude IKA"))
-                                                       extrude_ika(ob, 1);
+                                                       extrude_armature(0);
                                        }
                                }
                                else if (G.qual==LR_CTRLKEY) {
@@ -1208,7 +1232,11 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                else if (G.qual==LR_SHIFTKEY) {
                                        if (G.obedit && G.obedit->type==OB_MESH) {
-                                               Transform(TFM_CREASE, CTX_EDGE);
+                                               initTransform(TFM_CREASE, CTX_EDGE);
+                                               Transform();
+                                       }
+                                       else if (G.obedit && G.obedit->type==OB_ARMATURE) {
+                                               extrude_armature(1);
                                        }
                                }
                                break;
@@ -1223,23 +1251,33 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                        edge_flip();
                                                else if (G.qual==0)
                                                        addedgeface_mesh();
+                                               else if ( G.qual == 
+                                                        (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
+                                                       select_linked_flat_faces();
+                                               }
+
                                        }
                                        else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addsegment_nurb();
                                }
                                else if(G.qual==LR_CTRLKEY)
                                        sort_faces();
-                               else if((G.qual==LR_SHIFTKEY))
-                                       fly();
+                               else if((G.qual==LR_SHIFTKEY)) {
+                                       if(ob && (ob->flag & OB_POSEMODE))
+                                          pose_activate_flipped_bone();
+                                       else if(G.f & G_WEIGHTPAINT)
+                                               pose_activate_flipped_bone();
+                                       else
+                                               fly();
+                               }
                                else {
-                                               set_faceselect();
-                                       }
+                                       set_faceselect();
+                               }
                                
                                break;
                        case GKEY:
-                               /* RMGRP if(G.qual & LR_CTRLKEY) add_selected_to_group();
-                               else if(G.qual & LR_ALTKEY) rem_selected_from_group(); */
-                               if((G.qual==LR_SHIFTKEY))
-                                       select_group_menu();
+                               if(G.qual & LR_CTRLKEY) group_operation_with_menu();
+                               else if((G.qual==LR_SHIFTKEY))
+                                       select_grouped_menu();
                                else if(G.qual==LR_ALTKEY) {
                                        if(okee("Clear location")) {
                                                clear_object('g');
@@ -1250,7 +1288,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        doredraw= 1;
                                }
                                else if((G.qual==0)) {
-                                       Transform(TFM_TRANSLATION, CTX_NONE);
+                                       initTransform(TFM_TRANSLATION, CTX_NONE);
+                                       Transform();
                                }
                                break;
                        case HKEY:
@@ -1286,7 +1325,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                        else if((G.qual==0))
                                                                sethandlesNurb(3);
                                                        
-                                                       makeDispList(G.obedit);
+                                                       DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
                                                        BIF_undo_push("Handle change");
                                                        allqueue(REDRAWVIEW3D, 0);
                                                }
@@ -1302,10 +1341,18 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                else if((G.qual==0)) 
                                                        hide_mball(0);
                                        }
+                                       else if(G.obedit->type==OB_ARMATURE) {
+                                               if (G.qual==0)
+                                                       hide_selected_armature_bones();
+                                               else if (G.qual==LR_SHIFTKEY)
+                                                       hide_unselected_armature_bones();
+                                               else if (G.qual==LR_ALTKEY)
+                                                       show_all_armature_bones();
+                                       }
                                }
                                else if(G.f & G_FACESELECT)
                                        hide_tface();
-                               else if(G.obpose) {
+                               else if(ob && (ob->flag & OB_POSEMODE)) {
                                        if (G.qual==0)
                                                hide_selected_pose_bones();
                                        else if (G.qual==LR_SHIFTKEY)
@@ -1315,11 +1362,22 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                break;
                        case IKEY:
+                               if(G.obedit);
+                               else if(G.qual==LR_CTRLKEY) {
+                                       if(ob && ob->type==OB_ARMATURE) 
+                                               if(ob->flag & OB_POSEMODE) 
+                                                       pose_add_IK();
+                               }
+                               else if(G.qual==LR_ALTKEY) {
+                                       if(ob && ob->type==OB_ARMATURE) 
+                                               if(ob->flag & OB_POSEMODE) 
+                                                       pose_clear_IK();
+                               }
                                break;
                                
                        case JKEY:
                                if(G.qual==LR_CTRLKEY) {
-                                       if( (ob= OBACT) ) {
+                                       if( ob ) {
                                                if(ob->type == OB_MESH)
                                                        join_mesh();
                                                else if(ob->type == OB_CURVE)
@@ -1359,9 +1417,6 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                else
                                                        select_select_keys();
                                        }
-                                       else if(G.qual==LR_CTRLKEY)
-                                               make_skeleton();
-/*                                     else if(G.qual & LR_ALTKEY) delete_skeleton(); */
                                        else if (G.qual==0)
                                                set_ob_ipoflags();
                                }
@@ -1376,9 +1431,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
                                                selectconnected_nurb();
                                }
-                               else if(G.obpose) {
-                                       if(G.obpose->type==OB_ARMATURE)
-                                               selectconnected_posearmature();
+                               else if(ob && (ob->flag & OB_POSEMODE)) {
+                                       selectconnected_posearmature();
                                }
                                else {
                                        if(G.f & G_FACESELECT) {
@@ -1400,11 +1454,13 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                break;
                        case MKEY:
-                               if(G.obedit){
+                               if((G.obedit==0) && (G.f & G_FACESELECT) && (G.qual==0))
+                                       mirror_uv_tface();
+                               else if(G.obedit){
                                        if(G.qual==LR_ALTKEY) {
                                                if(G.obedit->type==OB_MESH) {
                                                        mergemenu();
-                                                       makeDispList(G.obedit);
+                                                       DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
                                                }
                                        }
                                        else if((G.qual==0) || (G.qual==LR_CTRLKEY)) {
@@ -1418,7 +1474,10 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        mirrormenu();
                                }
                                else if(G.qual==0) {
-                                    movetolayer();
+                                       if(ob && (ob->flag & OB_POSEMODE))
+                                               pose_movetolayer();
+                                       else
+                                               movetolayer();
                                }
                                break;
                        case NKEY:
@@ -1457,15 +1516,18 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                
                                break;
                        case OKEY:
-                               ob= OBACT;
                                if (G.obedit) {
                                        if (G.qual==LR_SHIFTKEY) {
-                                               extern int prop_mode;
-                                               prop_mode = (prop_mode+1)%6;
+                                               G.scene->prop_mode = (G.scene->prop_mode+1)%6;
+                                               allqueue(REDRAWHEADERS, 0);
+                                       }
+                                       else if((G.qual==LR_ALTKEY)) {
+                                               if(G.scene->proportional==2) G.scene->proportional= 1;
+                                               else G.scene->proportional= 2;
                                                allqueue(REDRAWHEADERS, 0);
                                        }
                                        else if((G.qual==0)) {
-                                               G.f ^= G_PROPORTIONAL;
+                                               G.scene->proportional= !G.scene->proportional;
                                                allqueue(REDRAWHEADERS, 0);
                                        }
                                }
@@ -1483,19 +1545,29 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 
                        case PKEY:
                                if(G.obedit) {
-                                       if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
-                                               make_parent();
+                                       if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
+                                               if(G.obedit->type==OB_ARMATURE)
+                                                       make_bone_parent();
+                                               else
+                                                       make_parent();
+                                       }
+                                       else if(G.qual==LR_ALTKEY && G.obedit->type==OB_ARMATURE)
+                                               clear_bone_parent();
                                        else if((G.qual==0) && G.obedit->type==OB_MESH)
                                                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_SHIFTKEY) {
+                                               initTransform(TFM_PUSHPULL, CTX_NONE);
+                                               Transform();
+                                       }
                                }
                                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_SHIFTKEY) {
+                                       initTransform(TFM_PUSHPULL, CTX_NONE);
+                                       Transform();
+                               }
                                else if(G.qual==LR_ALTKEY)
                                        clear_parent();
                                else if((G.qual==0)) {
@@ -1518,19 +1590,20 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        if((G.qual==LR_SHIFTKEY)) {
                                                if ELEM(G.obedit->type,  OB_CURVE, OB_SURF)                                     
                                                        selectrow_nurb();
-                                               else if (G.obedit->type==OB_MESH)
-                                                       loopoperations(LOOP_SELECT);
                                        }
                                        else if(G.qual==LR_CTRLKEY) {
                                                if (G.obedit->type==OB_MESH)
-                                                       loopoperations(LOOP_CUT);
+                                                       CutEdgeloop(1);
+                                                       BIF_undo_push("Cut Edgeloop");
                                        }
                                        else if((G.qual==0)) {
-                                               Transform(TFM_ROTATION, CTX_NONE);
+                                               initTransform(TFM_ROTATION, CTX_NONE);
+                                               Transform();
                                        }
                                }
                                else if((G.qual==0)) {
-                                       Transform(TFM_ROTATION, CTX_NONE);
+                                       initTransform(TFM_ROTATION, CTX_NONE);
+                                       Transform();
                                }
                                break;
                        case SKEY:
@@ -1539,23 +1612,53 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        doredraw= 1;
                                }
                                else if(G.obedit) {
-                                       if(G.qual==LR_ALTKEY)
-                                               Transform(TFM_SHRINKFATTEN, CTX_NONE);
-                                       else if(G.qual==LR_CTRLKEY)
-                                               Transform(TFM_SHEAR, CTX_NONE);
-                                       else if(G.qual==(LR_CTRLKEY|LR_ALTKEY))
-                                               Transform(TFM_SHEAR, CTX_NONE);
+                                       
+                                       if(G.qual==LR_ALTKEY) {
+                                               if(G.obedit->type==OB_ARMATURE) {
+                                                       initTransform(TFM_BONESIZE, CTX_NONE);
+                                               }
+                                               else
+                                                       initTransform(TFM_SHRINKFATTEN, CTX_NONE);
+                                               Transform();
+                                       }
+                                       else if(G.qual==LR_CTRLKEY) {
+                                               initTransform(TFM_SHEAR, CTX_NONE);
+                                               Transform();
+                                       }
                                        else if(G.qual==LR_SHIFTKEY)
                                                snapmenu();
                                        else if(G.qual==0) {
-                                               Transform(TFM_RESIZE, CTX_NONE);
+                                               if(G.obedit->type==OB_ARMATURE) {
+                                                       bArmature *arm= G.obedit->data;
+                                                       if(arm->drawtype==ARM_ENVELOPE)
+                                                               initTransform(TFM_BONE_ENVELOPE, CTX_NONE);
+                                                       else
+                                                               initTransform(TFM_RESIZE, CTX_NONE);
+                                               }
+                                               else
+                                                       initTransform(TFM_RESIZE, CTX_NONE);
+                                               Transform();
                                        }
                                        else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)){
-                                               Transform(TFM_TOSPHERE, CTX_NONE);
+                                               initTransform(TFM_TOSPHERE, CTX_NONE);
+                                               Transform();
+                                       }
+                                       if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
+                                               if(G.obedit->type==OB_MESH) select_sharp_edges();
                                        }
-                                       
                                }
                                else if(G.qual==LR_ALTKEY) {
+                                       if(G.f & G_WEIGHTPAINT)
+                                               ob= ob->parent;
+                                       if(ob && (ob->flag & OB_POSEMODE)) {
+                                               bArmature *arm= ob->data;
+                                               if( ELEM(arm->drawtype, ARM_B_BONE, ARM_ENVELOPE)) {
+                                                       initTransform(TFM_BONESIZE, CTX_NONE);
+                                                       Transform();
+                                                       break;
+                                               }
+                                       }
+                                       
                                        if(okee("Clear size")) {
                                                clear_object('s');
                                        }
@@ -1564,35 +1667,43 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        snapmenu();
                                }
                                else if((G.qual==0)) {
-                                       Transform(TFM_RESIZE, CTX_NONE);
+                                       initTransform(TFM_RESIZE, CTX_NONE);
+                                       Transform();
+                               }
+                               else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
+                                       initTransform(TFM_TOSPHERE, CTX_NONE);
+                                       Transform();
+                               }
+                               else if(G.qual==(LR_CTRLKEY|LR_ALTKEY|LR_SHIFTKEY)) {
+                                       initTransform(TFM_SHEAR, CTX_NONE);
+                                       Transform();
                                }
-                               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){
-                                       if((G.qual==LR_CTRLKEY) && G.obedit->type==OB_MESH) {
-                                               convert_to_triface(0);
+                                       if((G.qual & LR_CTRLKEY) && G.obedit->type==OB_MESH) {
+                                               convert_to_triface(G.qual & LR_SHIFTKEY);
                                                allqueue(REDRAWVIEW3D, 0);
                                                countall();
-                                               makeDispList(G.obedit);
+                                               DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
                                        }
                                        if (G.obedit->type==OB_CURVE) {
                                                if (G.qual==LR_ALTKEY) {
                                                        clear_tilt();
                                                }
                                                else if (G.qual==0) {
-                                                       Transform(TFM_TILT, CTX_NONE);
+                                                       initTransform(TFM_TILT, CTX_NONE);
+                                                       Transform();
                                                }
                                        }
                                }
                                else if(G.qual==LR_CTRLKEY) {
-                                       make_track();
+                                       if(ob && (ob->flag & OB_POSEMODE));
+                                       else make_track();
                                }
                                else if(G.qual==LR_ALTKEY) {
-                                       clear_track();
+                                       if(ob && (ob->flag & OB_POSEMODE));
+                                       else clear_track();
                                }
                                else if((G.qual==0)){
                                        texspace_edit();
@@ -1604,9 +1715,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        if(G.obedit->type==OB_MESH) {
                                                if(G.qual==0) BIF_undo(); else BIF_redo();
                                        }
-                                       else if(G.obedit->type==OB_ARMATURE)
-                                               remake_editArmature();
-                                       else if ELEM4(G.obedit->type, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE) {
+                                       else if ELEM5(G.obedit->type, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE) {
                                                if(G.qual==0) BIF_undo(); else BIF_redo();
                                        }
                                }
@@ -1624,7 +1733,6 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        
                                break;
                        case VKEY:
-                               ob= OBACT;
                                if((G.qual==LR_SHIFTKEY)) {
                                        if ((G.obedit) && G.obedit->type==OB_MESH) {
                                                align_view_to_selected(v3d);
@@ -1637,9 +1745,12 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        image_aspect();
                                else if (G.qual==0){
                                        if(G.obedit) {
-                                               if(G.obedit->type==OB_CURVE) {
+                                               if(G.obedit->type==OB_MESH) {
+                                                       mesh_rip();
+                                               }
+                                               else if(G.obedit->type==OB_CURVE) {
                                                        sethandlesNurb(2);
-                                                       makeDispList(G.obedit);
+                                                       DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
                                                        allqueue(REDRAWVIEW3D, 0);
                                                        BIF_undo_push("Handle change");
                                                }
@@ -1650,7 +1761,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case WKEY:
                                if((G.qual==LR_SHIFTKEY)) {
-                                       Transform(TFM_WARP, CTX_NONE);
+                                       initTransform(TFM_WARP, CTX_NONE);
+                                       Transform();
                                }
                                else if(G.qual==LR_ALTKEY) {
                                        /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
@@ -1698,6 +1810,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                handle_view3d_around();
                                
                                scrarea_queue_headredraw(curarea);
+                               scrarea_queue_winredraw(curarea);
                                break;
                                
                        case PERIODKEY:
@@ -1709,6 +1822,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                handle_view3d_around();
                                
                                scrarea_queue_headredraw(curarea);
+                               scrarea_queue_winredraw(curarea);
                                break;
                        
                        case PADSLASHKEY:
@@ -1726,7 +1840,6 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case PADASTERKEY:       /* '*' */
                                if(G.qual==0) {
-                                       ob= OBACT;
                                        if(ob) {
                                                if ((G.obedit) && (G.obedit->type == OB_MESH)) {
                                                        editmesh_align_view_to_selected(G.vd, 2);
@@ -1816,9 +1929,9 @@ static void initview3d(ScrArea *sa)
        BLI_addhead(&sa->spacedata, vd);        /* addhead! not addtail */
 
        vd->spacetype= SPACE_VIEW3D;
-       vd->blockscale= 0.7;
-       vd->viewquat[0]= 1.0;
-       vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0;
+       vd->blockscale= 0.7f;
+       vd->viewquat[0]= 1.0f;
+       vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0f;
        vd->persp= 1;
        vd->drawtype= OB_WIRE;
        vd->view= 7;
@@ -1903,7 +2016,7 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        
                                        if( cfra!=CFRA ) {
                                                CFRA= cfra;
-                                               update_for_newframe();
+                                               update_for_newframe_nodraw(1);  /* 1 = nosound */
                                                force_draw_all(0); /* To make constraint sliders redraw */
                                        }
                                        else PIL_sleep_ms(30);
@@ -1927,11 +2040,11 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        view2dmove(event);      /* in drawipo.c */
                        break;
                case PADPLUSKEY:
-                       view2d_zoom(v2d, 0.1154, sa->winx, sa->winy);
+                       view2d_zoom(v2d, 0.1154f, sa->winx, sa->winy);
                        doredraw= 1;
                        break;
                case PADMINUS:
-                       view2d_zoom(v2d, -0.15, sa->winx, sa->winy);
+                       view2d_zoom(v2d, -0.15f, sa->winx, sa->winy);
                        doredraw= 1;
                        break;
                case PAGEUPKEY:
@@ -1981,9 +2094,11 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                transform_ipo('g');
                        break;
                case HKEY:
-                       if((G.qual==LR_SHIFTKEY))
+                       if(G.qual==LR_ALTKEY)
+                               sethandles_ipo(HD_AUTO_ANIM);
+                       if(G.qual==LR_SHIFTKEY)
                                sethandles_ipo(HD_AUTO);
-                       else if((G.qual==0))
+                       else if(G.qual==0)
                                sethandles_ipo(HD_ALIGN);
                        break;
                case JKEY:
@@ -2022,10 +2137,7 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        break;
                case XKEY:
                case DELKEY:
-                       if((G.qual==LR_SHIFTKEY))
-                               delete_key();
-                       else if((G.qual==0))
-                               del_ipo();
+                       del_ipo();
                        break;
                }
        }
@@ -2041,7 +2153,7 @@ void initipo(ScrArea *sa)
        BLI_addhead(&sa->spacedata, sipo);
 
        sipo->spacetype= SPACE_IPO;
-       sipo->blockscale= 0.7;
+       sipo->blockscale= 0.7f;
        
        /* sipo space loopt van (0,-?) tot (??,?) */
        sipo->v2d.tot.xmin= 0.0;
@@ -2085,17 +2197,6 @@ static void space_sound_button_function(int event)
 }
 #endif
 
-#define B_ADD_THEME    3301
-#define B_DEL_THEME    3302
-#define B_NAME_THEME   3303
-#define B_THEMECOL             3304
-#define B_UPDATE_THEME         3305
-#define B_CHANGE_THEME         3306
-#define B_THEME_COPY   3307
-#define B_THEME_PASTE  3308
-
-#define B_RECALCLIGHT  3310
-
 // needed for event; choose new 'curmain' resets it...
 static short th_curcol= TH_BACK;
 static char *th_curcol_ptr= NULL;
@@ -2154,7 +2255,7 @@ static 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|"
+               "NLA Editor %x5|%l|UV/Image Editor %x6|Video Sequence Editor %x7|Node Editor %x16|Timeline %x15|Audio Window %x8|Text Editor %x9|%l|User Preferences %x10|"
                "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;
@@ -2171,6 +2272,8 @@ static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        else if(curmain==12) spacetype= SPACE_BUTS;
        else if(curmain==13) spacetype= SPACE_FILE;
        else if(curmain==14) spacetype= SPACE_IMASEL;
+       else if(curmain==15) spacetype= SPACE_TIME;
+       else if(curmain==16) spacetype= SPACE_NODE;
        else return; // only needed while coding... when adding themes for more windows
        
        /* color choices pup */
@@ -2203,7 +2306,7 @@ static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        }
        else {
                uiBlockBeginAlign(block);
-               if ELEM6(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT, TH_MENU_BACK, TH_MENU_HILITE, TH_MENU_ITEM) {
+               if ELEM7(th_curcol, TH_PANEL, TH_LAMP, TH_FACE, TH_FACE_SELECT, TH_MENU_BACK, TH_MENU_HILITE, TH_MENU_ITEM) {
                        uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
                }
                uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
@@ -2236,7 +2339,7 @@ void drawinfospace(ScrArea *sa, void *spacedata)
        short edgsp, midsp;
        char naam[32];
 
-       if(curarea->win==0) return;
+       if(curarea->win==0 || curarea->winy<2) return;
 
        BIF_GetThemeColor3fv(TH_BACK, col);
        glClearColor(col[0], col[1], col[2], 0.0);
@@ -2244,10 +2347,10 @@ void drawinfospace(ScrArea *sa, void *spacedata)
 
        if(curarea->winx<=1280.0) {
                fac= ((float)curarea->winx)/1280.0f;
-               myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
+               myortho2(0.375f, 1280.375f, 0.375f, curarea->winy/fac + 0.375f);
        }
        else {
-               myortho2(0.0, (float)curarea->winx, 0.0, (float)curarea->winy);
+               myortho2(0.375f, (float)curarea->winx + 0.375f, 0.375f, (float)curarea->winy + 0.375f);
        }
        
        sprintf(naam, "infowin %d", curarea->win);
@@ -2335,31 +2438,38 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                uiDefBut(block, LABEL,0,"Display:",
                        xpos,y6label,spref,buth,
                        0, 0, 0, 0, 0, "");     
-               uiDefButBitS(block, TOG, USER_TOOLTIPS, 0, "ToolTips",
+               uiBlockBeginAlign(block);
+               uiDefButBitI(block, TOG, USER_TOOLTIPS, 0, "ToolTips",
                        (xpos+edgsp),y5,spref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Display tooltips (help tags) over buttons");
-               uiDefButBitS(block, TOG, USER_DRAWVIEWINFO, B_DRAWINFO, "Object Info",
+               uiDefButBitI(block, TOG, USER_DRAWVIEWINFO, B_DRAWINFO, "Object Info",
                        (xpos+edgsp),y4,spref,buth,
                        &(U.uiflag), 0, 0, 0, 0,
                        "Display active object name and frame number in the 3D View");
-               uiDefButBitS(block, TOG, USER_SCENEGLOBAL, 0, "Global Scene",
+               uiDefButBitI(block, TOG, USER_SCENEGLOBAL, 0, "Global Scene",
                        (xpos+edgsp),y3,spref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Forces the current Scene to be displayed in all Screens");
 #ifndef __APPLE__      
-               uiDefButS(block, TOG|BIT|0, 0, "Large Cursors",
+               uiDefButBitS(block, TOG, 1, 0, "Large Cursors",
                        (xpos+edgsp),y2,spref,buth,
                        &(U.curssize), 0, 0, 0, 0,
                        "Use large mouse cursors when available");
 #else 
                U.curssize=0; /*Small Cursor always for OS X for now */
 #endif
+               uiDefButBitI(block, TOG, USER_PLAINMENUS, B_PLAINMENUS, "Plain menus",
+                       (xpos+edgsp),y1,spref,buth,
+                       &(U.uiflag), 0, 0, 0, 0,
+                       "Use column layout for toolbox and do not flip contents in any menu");
+               uiBlockEndAlign(block);
 
                uiDefBut(block, LABEL,0,"Menus:",
                        (xpos+(2*edgsp)+spref),y6label,spref,buth,
                        0, 0, 0, 0, 0, "");
-               uiDefButBitS(block, TOG, USER_MENUOPENAUTO, 0, "Open on Mouse Over",
+               uiBlockBeginAlign(block);
+               uiDefButBitI(block, TOG, USER_MENUOPENAUTO, 0, "Open on Mouse Over",
                        (xpos+edgsp+spref+midsp),y5,mpref,buth,
                        &(U.uiflag), 0, 0, 0, 0,
                        "Open menu buttons and pulldowns automatically when the mouse is hovering");
@@ -2371,10 +2481,12 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y4,spref+edgsp,buth,
                        &(U.menuthreshold2), 1, 40, 0, 0,
                        "Time delay in 1/10 seconds before automatically opening menu sublevels");
+               uiBlockEndAlign(block);
 
                uiDefBut(block, LABEL,0,"Toolbox click-hold delay:",
                        (xpos+(2*edgsp)+spref),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
+               uiBlockBeginAlign(block);
                uiDefButS(block, NUM, 0, "LMB:",
                        (xpos+edgsp+spref+midsp),y2,spref+edgsp,buth,
                        &(U.tb_leftmouse), 2, 40, 0, 0,
@@ -2383,37 +2495,41 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y2,spref+edgsp,buth,
                        &(U.tb_rightmouse), 2, 40, 0, 0,
                        "Time in 1/10 seconds to hold the Right Mouse Button before opening the toolbox");      
-               uiDefButBitS(block, TOG, USER_PANELPINNED, 0, "Pin Floating Panels",
-                       (xpos+edgsp+spref+midsp),y1,mpref,buth,
+               uiBlockEndAlign(block);
+
+               uiDefButBitI(block, TOG, USER_PANELPINNED, 0, "Pin Floating Panels",
+                       (xpos+edgsp+spref+midsp),y1,(mpref/2),buth,
                        &(U.uiflag), 0, 0, 0, 0,
                        "Make floating panels invoked by a hotkey (eg. N Key) open at the previous location");
                
+               uiDefButBitI(block, TOG, USER_LOCKAROUND, B_DRAWINFO, "Global Pivot",
+                       (xpos+edgsp+spref+midsp+(mpref/2)),y1,(mpref/2),buth,
+                       &(U.uiflag), 0, 0, 0, 0,
+                       "Lock the same rotation/scaling pivot in all 3D Views");        
                
                uiDefBut(block, LABEL,0,"Snap to grid:",
                        (xpos+(2*edgsp)+spref+midsp+mpref),y6label,mpref,buth,
                        0, 0, 0, 0, 0, "");
-               uiDefButBitS(block, TOG, USER_AUTOGRABGRID, 0, "Grab/Move",
+               uiBlockBeginAlign(block);
+               uiDefButBitI(block, TOG, USER_AUTOGRABGRID, 0, "Grab/Move",
                        (xpos+edgsp+mpref+spref+(2*midsp)),y5,spref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Snap objects and sub-objects to grid units when moving");
-               uiDefButBitS(block, TOG, USER_AUTOROTGRID, 0, "Rotate",
+               uiDefButBitI(block, TOG, USER_AUTOROTGRID, 0, "Rotate",
                        (xpos+edgsp+mpref+spref+(2*midsp)),y4,spref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Snap objects and sub-objects to grid units when rotating");
-               uiDefButBitS(block, TOG, USER_AUTOSIZEGRID, 0, "Scale",
+               uiDefButBitI(block, TOG, USER_AUTOSIZEGRID, 0, "Scale",
                        (xpos+edgsp+mpref+spref+(2*midsp)),y3,spref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Snap objects and sub-objects to grid units when scaling");
-               
-               uiDefButBitS(block, TOG, USER_LOCKAROUND, B_DRAWINFO, "Global Pivot",
-                       (xpos+edgsp+mpref+spref+(2*midsp)),y1,spref,buth,
-                       &(U.uiflag), 0, 0, 0, 0,
-                       "Lock the same rotation/scaling pivot in all 3D Views");        
+               uiBlockEndAlign(block);
                
                uiDefBut(block, LABEL,0,"View zoom:",
                        (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y6label,mpref,buth,
                        0, 0, 0, 0, 0, "");
                uiBlockBeginAlign(block);
+               uiBlockSetCol(block, TH_BUT_SETTING1);  /* mutually exclusive toggles, start color */
                uiDefButS(block, ROW, 0, "Continue",
                        (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y5,(mpref/3),buth,
                        &(U.viewzoom), 40, USER_ZOOM_CONT, 0, 0,
@@ -2426,37 +2542,45 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(2*mpref/3)),y5,(mpref/3),buth,
                        &(U.viewzoom), 40, USER_ZOOM_SCALE, 0, 0,
                        "Zooms in and out like scaling the view, mouse movements relative to center.");
+               uiBlockSetCol(block, TH_AUTO);                  /* end color */
                uiBlockEndAlign(block);
                
                uiDefBut(block, LABEL,0,"View rotation:",
                        (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y4label,mpref,buth,
                        0, 0, 0, 0, 0, "");
                uiBlockBeginAlign(block);
-               uiDefButBitS(block, TOG, USER_TRACKBALL, B_DRAWINFO, "Trackball",
+               uiBlockSetCol(block, TH_BUT_SETTING1);  /* mutually exclusive toggles, start color */
+               uiDefButBitI(block, TOG, USER_TRACKBALL, B_DRAWINFO, "Trackball",
                        (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y3,(mpref/2),buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Allow the view to tumble freely when orbiting with the Middle Mouse Button");
-               uiDefButBitS(block, TOGN, USER_TRACKBALL, B_DRAWINFO, "Turntable",
+               uiDefButBitI(block, TOGN, USER_TRACKBALL, B_DRAWINFO, "Turntable",
                        (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/2)),y3,(mpref/2),buth,
                        &(U.flag), 0, 0, 0, 0,
-                       "Keep the Global Z axis pointing upwards when orbiting the view with the Middle Mouse Button");
-               uiBlockEndAlign(block);
-               
-               uiDefButBitS(block, TOG, USER_AUTOPERSP, B_DRAWINFO, "Auto Perspective",
-                       (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y1,spref,buth,
+                       "Use fixed up axis for orbiting with Middle Mouse Button");
+               uiBlockSetCol(block, TH_AUTO);                  /* end color */
+               uiDefButBitI(block, TOG, USER_AUTOPERSP, B_DRAWINFO, "Auto Perspective",
+                       (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y2,(mpref/2),buth,
                        &(U.uiflag), 0, 0, 0, 0,
                        "Automatically switch between orthographic and perspective when changing from top/front/side views");
+               uiDefButBitI(block, TOG, USER_ORBIT_SELECTION, B_DRAWINFO, "Around Active",
+                       (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/2)),y2,(mpref/2),buth,
+                       &(U.uiflag), 0, 0, 0, 0,
+                       "Keep the active object in place when orbiting the views (Object Mode)");
+               uiBlockEndAlign(block);
 
                uiDefBut(block, LABEL,0,"Select with:",
                        (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y6label,mpref,buth,
                        0, 0, 0, 0, 0, "");
                uiBlockBeginAlign(block);
-               uiDefButBitS(block, TOG, USER_LMOUSESELECT, B_DRAWINFO, "Left Mouse",
+               uiBlockSetCol(block, TH_BUT_SETTING1);  /* mutually exclusive toggles, start color */
+               uiDefButBitI(block, TOG, USER_LMOUSESELECT, B_DRAWINFO, "Left Mouse",
                        (xpos+edgsp+(3*mpref)+(4*midsp)),y5,(mpref/2),buth,
                        &(U.flag), 0, 0, 0, 0, "Use the Left Mouse Button for selection");
-               uiDefButBitS(block, TOGN, USER_LMOUSESELECT, B_DRAWINFO, "Right Mouse",
+               uiDefButBitI(block, TOGN, USER_LMOUSESELECT, B_DRAWINFO, "Right Mouse",
                        (xpos+edgsp+(3*mpref)+(4*midsp)+(mpref/2)),y5,(mpref/2),buth,
                        &(U.flag), 0, 0, 0, 0, "Use the Right Mouse Button for selection");
+               uiBlockSetCol(block, TH_AUTO);                  /* end color */
                uiBlockEndAlign(block);
                
                
@@ -2474,7 +2598,7 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                if (U.flag & USER_LMOUSESELECT) 
                        U.flag &= ~USER_TWOBUTTONMOUSE;
                
-               uiDefButBitS(block, TOG, USER_TWOBUTTONMOUSE, B_DRAWINFO, "Emulate 3 Button Mouse",
+               uiDefButBitI(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 Middle Mouse with Alt+LeftMouse (doesnt work with Left Mouse Select option)");
@@ -2484,18 +2608,21 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y6label,mpref,buth,
                        0, 0, 0, 0, 0, "");
                uiBlockBeginAlign(block);
-               uiDefButBitS(block, TOGN, USER_VIEWMOVE, B_DRAWINFO, "Rotate View",
+               uiBlockSetCol(block, TH_BUT_SETTING1);  /* mutually exclusive toggles, start color */
+               uiDefButBitI(block, TOGN, USER_VIEWMOVE, B_DRAWINFO, "Rotate View",
                        (xpos+edgsp+(4*mpref)+(5*midsp)),y5,(mpref/2),buth,
                        &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
-               uiDefButBitS(block, TOG, USER_VIEWMOVE, B_DRAWINFO, "Pan View",
+               uiDefButBitI(block, TOG, USER_VIEWMOVE, B_DRAWINFO, "Pan View",
                        (xpos+edgsp+(4*mpref)+(5*midsp)+(mpref/2)),y5,(mpref/2),buth,
                        &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
+               uiBlockSetCol(block, TH_AUTO);                  /* end color */
                uiBlockEndAlign(block);
                        
                uiDefBut(block, LABEL,0,"Mouse Wheel:",
                        (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y4label,mpref,buth,
                        0, 0, 0, 0, 0, "");
-               uiDefButBitS(block, TOG, USER_WHEELZOOMDIR, 0, "Invert Zoom",
+               uiBlockBeginAlign(block);
+               uiDefButBitI(block, TOG, USER_WHEELZOOMDIR, 0, "Invert Zoom",
                        (xpos+edgsp+(4*mpref)+(5*midsp)),y3,spref,buth,
                        &(U.uiflag), 0, 0, 0, 0,
                        "Swap the Mouse Wheel zoom direction");
@@ -2503,6 +2630,7 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+edgsp+(4*mpref)+(6*midsp)+spref-edgsp),y3,spref+edgsp,buth,
                        &U.wheellinescroll, 0.0, 32.0, 0, 0,
                        "The number of lines scrolled at a time with the mouse wheel"); 
+               uiBlockEndAlign(block);
 
 
                uiDefBut(block, LABEL,0,"3D Transform Widget:",
@@ -2511,16 +2639,26 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                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");
+                                        &(U.tw_size), 2, 40, 0, 0, "Diameter of widget, in 10 pixel units");
                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);
                
+               
+               uiDefBut(block, LABEL,0,"Object center diameter",
+                                (xpos+(2*edgsp)+(5*mpref)+(5*midsp)),y3label,mpref,buth,
+                                0, 0, 0, 0, 0, "");
+               uiBlockBeginAlign(block);
+               uiDefButS(block, NUM, B_REDRCURW3D, "Size",
+                                 (xpos+(2*edgsp)+(5*mpref)+(5*midsp)),y2,mpref,buth,
+                                 &(U.obcenter_dia), 4, 10, 0, 0,
+                                 "Diameter in Pixels for Object/Lamp center drawing");
+               
+               
        } else if (U.userpref == 1) { /* edit methods */
 
 
@@ -2528,76 +2666,86 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        xpos,y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
                uiBlockBeginAlign(block);
-               uiDefButBitS(block, TOGN, USER_MAT_ON_OB, B_DRAWINFO, "ObData",
+               uiDefButBitI(block, TOGN, USER_MAT_ON_OB, B_DRAWINFO, "ObData",
                        (xpos+edgsp),y2,(mpref/2),buth,
                        &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
-               uiDefButBitS(block, TOG, USER_MAT_ON_OB, B_DRAWINFO, "Object",
+               uiDefButBitI(block, TOG, USER_MAT_ON_OB, B_DRAWINFO, "Object",
                        (xpos+edgsp+(mpref/2)),y2,(mpref/2),buth,
                        &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
                uiBlockEndAlign(block);
 
 
-               uiDefBut(block, LABEL,0,"Editmode undo:",
+               uiDefBut(block, LABEL,0,"Undo:",
                        (xpos+(2*edgsp)+mpref),y3label, mpref,buth,
                        0, 0, 0, 0, 0, "");
+               uiBlockBeginAlign(block);
                uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps:",
                        (xpos+edgsp+mpref+midsp),y2,mpref,buth,
-                       &(U.undosteps), 2, 64, 0, 0, "Number of undo steps available in Edit Mode (smaller values conserve memory)");
+                       &(U.undosteps), 0, 64, 0, 0, "Number of undo steps available (smaller values conserve memory)");
 
-               uiDefButBitS(block, TOG, USER_GLOBALUNDO, B_DRAWINFO, "Global undo",
+               uiDefButBitI(block, TOG, USER_GLOBALUNDO, B_DRAWINFO, "Global undo",
                        (xpos+edgsp+mpref+midsp),y1,mpref,buth,
-                       &(U.uiflag), 2, 64, 0, 0, "");
+                       &(U.uiflag), 2, 64, 0, 0, "Global undo works by keeping a full copy of the file itself in memory, so takes extra memory");
+               uiBlockEndAlign(block);
 
 
-               uiDefBut(block, LABEL,0,"Auto keyframe on:",
+               uiDefBut(block, LABEL,0,"Auto keyframe",
                        (xpos+(2*edgsp)+(2*mpref)+midsp),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
-               uiDefButBitS(block, TOG, USER_KEYINSERTACT, 0, "Action",
-                       (xpos+edgsp+(2*mpref)+(2*midsp)),y2,(spref+edgsp),buth,
-                       &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Action Ipo curve");
-               uiDefButBitS(block, TOG, USER_KEYINSERTOBJ, 0, "Object",
-                       (xpos+edgsp+(2*mpref)+(3*midsp)+spref-edgsp),y2,(spref+edgsp),buth,
-                       &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Object Ipo curve");
+
+               uiDefButBitI(block, TOG, G_RECORDKEYS, REDRAWTIME, "Action and Object", 
+                                       (xpos+edgsp+(2*mpref)+(2*midsp)),y2,mpref, buth,
+                                        &(G.flags), 0, 0, 0, 0, "Automatic keyframe insertion in Object and Action Ipo curves");
+
+               uiDefButBitI(block, TOG, USER_KEYINSERTAVAI, REDRAWTIME, "Available", 
+                       (xpos+edgsp+(2*mpref)+(2*midsp)),y1,mpref, buth,
+                       &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in available curves");
+
+//             uiDefButBitS(block, TOG, USER_KEYINSERTACT, 0, "Action",
+//                     (xpos+edgsp+(2*mpref)+(2*midsp)),y2,(spref+edgsp),buth,
+//                     &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Action Ipo curve");
+//             uiDefButBitS(block, TOG, USER_KEYINSERTOBJ, 0, "Object",
+//                     (xpos+edgsp+(2*mpref)+(3*midsp)+spref-edgsp),y2,(spref+edgsp),buth,
+//                     &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Object Ipo curve");
 
 
                uiDefBut(block, LABEL,0,"Duplicate with object:",
                        (xpos+(2*edgsp)+(3*midsp)+(3*mpref)+spref),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
 
-               uiDefButBitS(block, TOG, USER_DUP_MESH, 0, "Mesh",
+               uiBlockBeginAlign(block);
+               uiDefButBitI(block, TOG, USER_DUP_MESH, 0, "Mesh",
                        (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y2,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
-               uiDefButBitS(block, TOG, USER_DUP_ARM, 0, "Armature",
-                       (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y1,(spref+edgsp),buth,
-                       &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
-
-               uiDefButBitS(block, TOG, USER_DUP_SURF, 0, "Surface",
+               uiDefButBitI(block, TOG, USER_DUP_SURF, 0, "Surface",
                        (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y2,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
-               uiDefButBitS(block, TOG, USER_DUP_LAMP, 0, "Lamp",
-                       (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y1,(spref+edgsp),buth,
-                       &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
-
-               uiDefButBitS(block, TOG, USER_DUP_CURVE, 0, "Curve",
+               uiDefButBitI(block, TOG, USER_DUP_CURVE, 0, "Curve",
                        (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y2,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
-               uiDefButBitS(block, TOG, USER_DUP_MAT, 0, "Material",
-                       (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y1,(spref+edgsp),buth,
-                       &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
-
-               uiDefButBitS(block, TOG, USER_DUP_FONT, 0, "Text",
+               uiDefButBitI(block, TOG, USER_DUP_FONT, 0, "Text",
                        (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y2,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
-               uiDefButBitS(block, TOG, USER_DUP_TEX, 0, "Texture",
-                       (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y1,(spref+edgsp),buth,
-                       &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
-
-               uiDefButBitS(block, TOG, USER_DUP_MBALL, 0, "Metaball",
+               uiDefButBitI(block, TOG, USER_DUP_MBALL, 0, "Metaball",
                        (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y2,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
-               uiDefButBitS(block, TOG, USER_DUP_IPO, 0, "Ipo",
+
+               uiDefButBitI(block, TOG, USER_DUP_ARM, 0, "Armature",
+                       (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y1,(spref+edgsp),buth,
+                       &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
+               uiDefButBitI(block, TOG, USER_DUP_LAMP, 0, "Lamp",
+                       (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y1,(spref+edgsp),buth,
+                       &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
+               uiDefButBitI(block, TOG, USER_DUP_MAT, 0, "Material",
+                       (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y1,(spref+edgsp),buth,
+                       &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
+               uiDefButBitI(block, TOG, USER_DUP_TEX, 0, "Texture",
+                       (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y1,(spref+edgsp),buth,
+                       &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
+               uiDefButBitI(block, TOG, USER_DUP_IPO, 0, "Ipo",
                        (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y1,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
+               uiBlockEndAlign(block);
        
        } else if(U.userpref == 2) { /* language & colors */
 
@@ -2625,12 +2773,12 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                                          (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(),
+                       uiDefButI(block, MENU, B_SETFONTSIZE, fontsize_pup(),
                                (xpos+edgsp+mpref+midsp),y1,mpref,buth,
                                &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
 
 /*
-                       uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
+                       uiDefButS(block, MENU, B_SETENCODING, encoding_pup(),
                                (xpos+edgsp+mpref+midsp),y1,mpref,buth,
                                &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
 
@@ -2652,7 +2800,7 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                                (xpos+edgsp+(2.2*mpref)+(5*midsp)+(2*spref)),y1,spref,buth,
                                &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
 
-                       uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
+                       uiDefButI(block, MENU, B_SETLANGUAGE, language_pup(),
                                (xpos+edgsp+(2.2*mpref)+(3*midsp)),y2,mpref+(0.5*mpref)+3,buth,
                                &U.language, 0, 0, 0, 0, "Select interface language");
                                
@@ -2673,7 +2821,7 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        &U.versions, 0.0, 32.0, 0, 0,
                        "The number of old versions to maintain in the current directory, when manually saving");
 
-               uiDefButBitS(block, TOG, USER_AUTOSAVE, B_RESETAUTOSAVE, "Auto Save Temp Files",
+               uiDefButBitI(block, TOG, USER_AUTOSAVE, B_RESETAUTOSAVE, "Auto Save Temp Files",
                        (xpos+edgsp+mpref+midsp),y3,mpref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Enables automatic saving of temporary files");
@@ -2698,7 +2846,7 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                uiDefButS(block, MENU, B_REDR, "Light1 %x0|Light2 %x1|Light3 %x2",
                        xpos+edgsp, y2, 2*mpref/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
                uiBlockSetCol(block, TH_BUT_SETTING1);
-               uiDefButI(block, TOG|BIT|0, B_RECALCLIGHT, "On",
+               uiDefButBitI(block, TOG, 1, B_RECALCLIGHT, "On",
                        xpos+edgsp+2*mpref/6, y2, mpref/6, buth, 
                        &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "Enable this OpenGL light in Solid draw mode");
                        
@@ -2748,11 +2896,11 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                }
 
 /*
-               uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
+               uiDefButBitS(block, TOG, USER_EVTTOCONSOLE, 0, "Log Events to Console",
                        (xpos+edgsp),y2,lpref,buth,
                        &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
 
-               uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
+               uiDefButS(block, MENU, B_CONSOLEOUT, consolemethod_pup(),
                        (xpos+edgsp), y1, lpref,buth,
                        &U.console_out, 0, 0, 0, 0, "Select console output method");
 
@@ -2766,7 +2914,7 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+edgsp+(1*midsp)+(1*mpref)),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
 
-               uiDefButBitS(block, TOG, USER_ALLWINCODECS, 0, "Enable all codecs",
+               uiDefButBitI(block, TOG, USER_ALLWINCODECS, 0, "Enable all codecs",
                        (xpos+edgsp+(1*mpref)+(1*midsp)),y2,mpref,buth,
                        &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
 #endif
@@ -2775,42 +2923,52 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+edgsp+(3*midsp)+(3*mpref)),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
 
-               uiDefButBitS(block, TOG, USER_NO_CAPSLOCK, B_U_CAPSLOCK, "Disable Caps Lock",
+               uiDefButBitI(block, TOG, USER_NO_CAPSLOCK, B_U_CAPSLOCK, "Disable Caps Lock",
                        (xpos+edgsp+(3*midsp)+(3*mpref)),y1,mpref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Disables the Caps Lock key when entering text");
 
-               uiDefButBitS(block, TOG, USER_NONUMPAD, 0, "Emulate Numpad",
+               uiDefButBitI(block, TOG, USER_NONUMPAD, 0, "Emulate Numpad",
                        (xpos+edgsp+(3*midsp)+(3*mpref)),y2,mpref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
 
 
                uiDefBut(block, LABEL,0,"System:",
-                       (xpos+edgsp+(4*midsp)+(4*mpref)),y3label,mpref,buth,
+                       (xpos+edgsp+(4*midsp)+(4*mpref)),y4label,mpref,buth,
                        0, 0, 0, 0, 0, "");
 
                uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Game Sound",
-                       (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
+                       (xpos+edgsp+(4*mpref)+(4*midsp)),y3,mpref,buth,
                        &(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,
+               uiDefButBitI(block, TOG, USER_FILTERFILEEXTS, 0, "Filter File Extensions",
+                       (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
                        &(U.uiflag), 0, 0, 0, 0, "Display only files with extensions in the image select window");
 
+               uiDefButBitI(block, TOG, USER_HIDE_DOT, 0, "Hide dot file/datablock",
+                       (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
+                       &(U.uiflag), 0, 0, 0, 0, "Hide files/datablocks that start with a dot(.*)");
+
 
                uiDefBut(block, LABEL,0,"OpenGL:",
-                       (xpos+edgsp+(5*midsp)+(5*mpref)),y3label,mpref,buth,
+                       (xpos+edgsp+(5*midsp)+(5*mpref)),y5label,mpref,buth,
                        0, 0, 0, 0, 0, "");
-
                uiDefButBitI(block, TOGN, USER_DISABLE_MIPMAP, B_MIPMAPCHANGED, "Mipmaps",
-                       (xpos+edgsp+(5*mpref)+(5*midsp)),y2,mpref,buth,
+                       (xpos+edgsp+(5*mpref)+(5*midsp)),y4,mpref,buth,
                        &(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
-
                uiDefButBitI(block, TOG, USER_VERTEX_ARRAYS, 0, "Vertex Arrays",
-                       (xpos+edgsp+(5*mpref)+(5*midsp)),y1,mpref,buth,
+                       (xpos+edgsp+(5*mpref)+(5*midsp)),y3,mpref,buth,
                        &(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
 
+               uiDefButI(block, NUM, 0, "Time Out ",
+                       (xpos+edgsp+(5*mpref)+(5*midsp)), y2, mpref, buth, 
+                       &U.textimeout, 0.0, 3600.0, 30, 2, "Time since last access of a GL texture in seconds after which it is freed. (Set to 0 to keep textures allocated)");
+               uiDefButI(block, NUM, 0, "Collect Rate ",
+                       (xpos+edgsp+(5*mpref)+(5*midsp)), y1, mpref, buth, 
+                       &U.texcollectrate, 1.0, 3600.0, 30, 2, "Number of seconds between each run of the GL texture garbage collector.");
+
+
                uiDefBut(block, LABEL,0,"Audio mixing buffer:",
                        (xpos+edgsp+(2*midsp)+(2*mpref)),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
@@ -2933,7 +3091,8 @@ static void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 
                switch(event) {
                case UI_BUT_EVENT:
-                       if(val==B_ADD_THEME) {
+                       if(val==REDRAWTIME) allqueue(REDRAWTIME, 0);
+                       else if(val==B_ADD_THEME) {
                                bTheme *btheme, *new;
                                
                                btheme= U.themes.first;
@@ -3070,7 +3229,7 @@ static void winqreadbutspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        scrarea_queue_winredraw(curarea);
                        break;
                case RENDERPREVIEW:
-                       BIF_previewrender(sbuts);
+                       BIF_previewrender_buts(sbuts);
                        break;
                
                case HOMEKEY:
@@ -3137,9 +3296,9 @@ void set_rects_butspace(SpaceButs *buts)
 void test_butspace(void)
 {
        ScrArea *area= curarea;
-       int blocksmin= uiBlocksGetYMin(&area->uiblocks)-10.0;
+       int blocksmin= uiBlocksGetYMin(&area->uiblocks)-10.0f;
        
-       G.buts->v2d.tot.ymin= MIN2(0.0, blocksmin-10.0);
+       G.buts->v2d.tot.ymin= MIN2(0.0f, blocksmin-10.0f);
 }
 
 static void init_butspace(ScrArea *sa)
@@ -3155,12 +3314,15 @@ static void init_butspace(ScrArea *sa)
        /* set_rects only does defaults, so after reading a file the cur has not changed */
        set_rects_butspace(buts);
        buts->v2d.cur= buts->v2d.tot;
+
+       buts->ri = NULL;
 }
 
 void extern_set_butspace(int fkey)
 {
        ScrArea *sa;
        SpaceButs *sbuts;
+       Object *ob= OBACT;
        
        /* when a f-key pressed: 'closest' button window is initialized */
        if(curarea->spacetype==SPACE_BUTS) sa= curarea;
@@ -3183,32 +3345,79 @@ void extern_set_butspace(int fkey)
                sbuts->mainb= CONTEXT_LOGIC;
        }
        else if(fkey==F5KEY) {
-               sbuts->mainb= CONTEXT_SHADING;
-               if(OBACT) {
-                       if(OBACT->type==OB_CAMERA) 
+               /* if it's already in shading context, cycle between tabs with the same key */
+               if (sbuts->oldkeypress == F5KEY) {
+
+                       if (sbuts->tab[CONTEXT_SHADING]==TAB_SHADING_LAMP)
+                               sbuts->tab[CONTEXT_SHADING]=TAB_SHADING_MAT;
+                       else if (sbuts->tab[CONTEXT_SHADING]==TAB_SHADING_MAT)
+                               sbuts->tab[CONTEXT_SHADING]=TAB_SHADING_TEX;
+                       else if (sbuts->tab[CONTEXT_SHADING]==1) {
+                               sbuts->tab[CONTEXT_SHADING]=TAB_SHADING_RAD;
+                       }
+                       else if (sbuts->tab[CONTEXT_SHADING]==TAB_SHADING_RAD)
+                               sbuts->tab[CONTEXT_SHADING]=TAB_SHADING_WORLD;
+                       else if (sbuts->tab[CONTEXT_SHADING]==TAB_SHADING_WORLD)
+                               sbuts->tab[CONTEXT_SHADING]=TAB_SHADING_LAMP;
+               }
+               /* if we're coming in from texture buttons, 
+               or from outside the shading context, just go to the 'default' */
+               else if (ob && ((sbuts->mainb!= CONTEXT_SHADING) || (sbuts->oldkeypress == F6KEY)) ) {
+                       sbuts->mainb= CONTEXT_SHADING;
+                       
+                       if(ob->type==OB_CAMERA) 
                                sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_WORLD;
-                       else if(OBACT->type==OB_LAMP) 
+                       else if(ob->type==OB_LAMP) 
                                sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_LAMP;
                        else  
                                sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
                }
-               else sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
+               else {
+                       sbuts->mainb= CONTEXT_SHADING;
+                       sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
+               }
+               BIF_preview_changed(ID_TE);
        }
        else if(fkey==F6KEY) {
                sbuts->mainb= CONTEXT_SHADING;
                sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_TEX;
+               BIF_preview_changed(ID_TE);
+       }
+       else if(fkey==F7KEY) {
+               /* if it's already in object context, cycle between tabs with the same key */
+               if (sbuts->oldkeypress == F7KEY) {
+
+                       if (sbuts->tab[CONTEXT_OBJECT]==TAB_OBJECT_OBJECT)
+                               sbuts->tab[CONTEXT_OBJECT]=TAB_OBJECT_PHYSICS;
+                       else if (sbuts->tab[CONTEXT_OBJECT]==TAB_OBJECT_PHYSICS)
+                               sbuts->tab[CONTEXT_OBJECT]=TAB_OBJECT_OBJECT;
+               }
+               else sbuts->mainb= CONTEXT_OBJECT;
+               
        }
-       else if(fkey==F7KEY) sbuts->mainb= CONTEXT_OBJECT;
        else if(fkey==F8KEY) {
                sbuts->mainb= CONTEXT_SHADING;
                sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_WORLD;
        }
        else if(fkey==F9KEY) sbuts->mainb= CONTEXT_EDITING;
-       else if(fkey==F10KEY) sbuts->mainb= CONTEXT_SCENE;
+       else if(fkey==F10KEY) {
+               /* if it's already in scene context, cycle between tabs with the same key */
+               if (sbuts->oldkeypress == F10KEY) {
+
+                       if (sbuts->tab[CONTEXT_SCENE]==TAB_SCENE_RENDER)
+                               sbuts->tab[CONTEXT_SCENE]=TAB_SCENE_ANIM;
+                       else if (sbuts->tab[CONTEXT_SCENE]==TAB_SCENE_ANIM)
+                               sbuts->tab[CONTEXT_SCENE]=TAB_SCENE_SOUND;
+                       else if (sbuts->tab[CONTEXT_SCENE]==TAB_SCENE_SOUND)
+                               sbuts->tab[CONTEXT_SCENE]=TAB_SCENE_RENDER;
+               }
+               else sbuts->mainb= CONTEXT_SCENE;
+       }
+
+       sbuts->oldkeypress = fkey;
 
        scrarea_queue_headredraw(sa);
        scrarea_queue_winredraw(sa);
-       BIF_preview_changed(sbuts);
 }
 
 /* ******************** SPACE: SEQUENCE ********************** */
@@ -3291,11 +3500,12 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                case PADPLUSKEY:
                        if(sseq->mainb) {
                                sseq->zoom++;
+                               if(sseq->zoom==-1) sseq->zoom= 1;
                                if(sseq->zoom>8) sseq->zoom= 8;
                        }
                        else {
                                if((G.qual==0)) {
-                                       dx= 0.1154*(v2d->cur.xmax-v2d->cur.xmin);
+                                       dx= 0.1154f*(v2d->cur.xmax-v2d->cur.xmin);
                                        v2d->cur.xmin+= dx;
                                        v2d->cur.xmax-= dx;
                                        test_view2d(G.v2d, curarea->winx, curarea->winy);
@@ -3316,13 +3526,14 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                case PADMINUS:
                        if(sseq->mainb) {
                                sseq->zoom--;
-                               if(sseq->zoom<1) sseq->zoom= 1;
+                               if(sseq->zoom==0) sseq->zoom= -2;
+                               if(sseq->zoom<-8) sseq->zoom= -8;
                        }
                        else {
                                if((G.qual==LR_SHIFTKEY))
                                        no_gaps();
                                else if((G.qual==0)) {
-                                       dx= 0.15*(v2d->cur.xmax-v2d->cur.xmin);
+                                       dx= 0.15f*(v2d->cur.xmax-v2d->cur.xmin);
                                        v2d->cur.xmin-= dx;
                                        v2d->cur.xmax+= dx;
                                        test_view2d(G.v2d, curarea->winx, curarea->winy);
@@ -3386,6 +3597,11 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        if((G.qual==0))
                                transform_seq('g', 0);
                        break;
+               case KKEY:
+                       if((G.qual==0)) { /* Cut at current frame */
+                               if(okee("Cut strips")) seq_cut(CFRA);
+                       }
+                       break;
                case MKEY:
                        if(G.qual==LR_ALTKEY)
                                un_meta();
@@ -3543,40 +3759,6 @@ static void init_filespace(ScrArea *sa)
        sfile->spacetype= SPACE_FILE;
 }
 
-static void init_textspace(ScrArea *sa)
-{
-       SpaceText *st;
-       
-       st= MEM_callocN(sizeof(SpaceText), "inittextspace");
-       BLI_addhead(&sa->spacedata, st);
-
-       st->spacetype= SPACE_TEXT;      
-       st->blockscale= 0.7;
-       st->text= NULL;
-       st->flags= 0;
-       
-       st->font_id= 5;
-       st->lheight= 12;
-       st->showlinenrs= 0;
-       st->tabnumber = 4;
-       st->currtab_set = 0;
-       
-       st->top= 0;
-}
-
-static void init_scriptspace(ScrArea *sa)
-{
-       SpaceScript *sc;
-
-       sc = MEM_callocN(sizeof(SpaceScript), "initscriptspace");
-       BLI_addhead(&sa->spacedata, sc);
-
-       sc->spacetype = SPACE_SCRIPT;
-       sc->blockscale= 0.7;
-       sc->script = NULL;
-       sc->flags = 0;
-}
-
 static void init_imaselspace(ScrArea *sa)
 {
        SpaceImaSel *simasel;
@@ -3666,98 +3848,38 @@ void free_soundspace(SpaceSound *ssound)
 
 static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
-       unsigned short event= evt->event;
+       unsigned short event= evt->event, origevent= evt->event;
        short val= evt->val;
        SpaceImage *sima= curarea->spacedata.first;
-       View2D *v2d= &sima->v2d;
-#ifdef NAN_TPT
-       IMG_BrushPtr brush;
-       IMG_CanvasPtr canvas;
-       int rowBytes;
-       short xy_prev[2], xy_curr[2];
-       float uv_prev[2], uv_curr[2];
-       extern VPaint Gvp;
-#endif /* NAN_TPT */
-       short mousebut = L_MOUSE;
        
        if(val==0) return;
 
        if(uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
        
-       /* swap mouse buttons based on user preference */
        if (U.flag & USER_LMOUSESELECT) {
                if (event == LEFTMOUSE) {
                        event = RIGHTMOUSE;
-                       mousebut = R_MOUSE;
                } else if (event == RIGHTMOUSE) {
                        event = LEFTMOUSE;
-                       mousebut = L_MOUSE;
                }
        }
-       
+
        if (sima->flag & SI_DRAWTOOL) {
-#ifdef NAN_TPT
-               /* Draw tool is active */
                switch(event) {
+                       case CKEY: 
+                               add_blockhandler(curarea, IMAGE_HANDLER_PAINT, UI_PNL_UNSTOW);
+                               scrarea_queue_winredraw(curarea);
+                               break;
                        case LEFTMOUSE:
-                               /* Paranoia checks */
-                               if (!sima) break;
-                               if (!sima->image) break;
-                               if (!sima->image->ibuf) break;
-                               if (sima->image->packedfile) {
-                                       error("Painting in packed images not supported");
-                                       break;
-                               }
-                       
-                               brush = IMG_BrushCreate(Gvp.size, Gvp.size, Gvp.r, Gvp.g, Gvp.b, Gvp.a);
-                               /* skipx is not set most of the times. Make a guess. */
-                               rowBytes = sima->image->ibuf->skipx ? sima->image->ibuf->skipx : sima->image->ibuf->x * 4;
-                               canvas = IMG_CanvasCreateFromPtr(sima->image->ibuf->rect, sima->image->ibuf->x, sima->image->ibuf->y, rowBytes);
-
-                               getmouseco_areawin(xy_prev);
-                               while (get_mbut() & mousebut) {
-                                       getmouseco_areawin(xy_curr);
-                                       /* Check if mouse position changed */
-                                       if ((xy_prev[0] != xy_curr[0]) || (xy_prev[1] != xy_curr[1])) {
-                                               /* Convert mouse coordinates to u,v and draw */
-                                               areamouseco_to_ipoco(v2d, xy_prev, &uv_prev[0], &uv_prev[1]);
-                                               areamouseco_to_ipoco(v2d, xy_curr, &uv_curr[0], &uv_curr[1]);
-                                               IMG_CanvasDrawLineUV(canvas, brush, uv_prev[0], uv_prev[1], uv_curr[0], uv_curr[1]);
-                                               if (G.sima->lock) {
-                                                       /* Make OpenGL aware of a changed texture */
-                                                       free_realtime_image(sima->image);
-                                                       /* Redraw this view and the 3D view */
-                                                       force_draw_plus(SPACE_VIEW3D, 0);
-                                               }
-                                               else {
-                                                       /* Redraw only this view */
-                                                       force_draw(0);
-                                               }
-                                               xy_prev[0] = xy_curr[0];
-                                               xy_prev[1] = xy_curr[1];
-                                       }
-                               }
-                               /* Set the dirty bit in the image so that it is clear that it has been modified. */
-                               sima->image->ibuf->userflags |= IB_BITMAPDIRTY;
-                               if (!G.sima->lock) {
-                                       /* Make OpenGL aware of a changed texture */
-                                       free_realtime_image(sima->image);
-                                       /* Redraw this view and the 3D view */
-                                       force_draw_plus(SPACE_VIEW3D, 1);
-                               }
-                               IMG_BrushDispose(brush);
-                               IMG_CanvasDispose(canvas);
-                               allqueue(REDRAWHEADERS, 0);
+                               imagepaint_paint(origevent==LEFTMOUSE? L_MOUSE: R_MOUSE);
                                break;
                        case RIGHTMOUSE:
-                               sample_vpaint();
+                               imagepaint_pick(origevent==LEFTMOUSE? L_MOUSE: R_MOUSE);
                                break;
                }
-#endif /* NAN_TPT */
        }
        else {
                /* Draw tool is inactive */
-
                switch(event) {
                        case LEFTMOUSE:
                                if(G.qual & LR_SHIFTKEY) mouseco_to_curtile();
@@ -3770,12 +3892,13 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        sample_vpaint();
                                break;
                        case AKEY:
-                               if((G.qual==0))
-                                       select_swap_tface_uv();
+                               select_swap_tface_uv();
                                break;
                        case BKEY:
-                               if((G.qual==0))
-                                       borderselect_sima();
+                               if(G.qual==LR_SHIFTKEY)
+                                       borderselect_sima(UV_SELECT_PINNED);
+                               else if((G.qual==0))
+                                       borderselect_sima(UV_SELECT_ALL);
                                break;
                        case CKEY:
                                if(G.qual==LR_CTRLKEY)
@@ -3792,8 +3915,10 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        unwrap_lscm();
                                break;
                        case GKEY:
-                               if((G.qual==0))
-                                       transform_tface_uv('g', 0);
+                               if((G.qual==0) && is_uv_tface_editing_allowed()) {
+                                       initTransform(TFM_TRANSLATION, CTX_NONE);
+                                       Transform();
+                               }
                                break;
                        case HKEY:
                                if(G.qual==LR_ALTKEY)
@@ -3823,35 +3948,40 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case OKEY:
                                if (G.qual==LR_SHIFTKEY) {
-                                       extern int prop_mode;
-                                       prop_mode= !prop_mode;
+                                       G.scene->prop_mode = (G.scene->prop_mode+1)%6;
+                                       allqueue(REDRAWHEADERS, 0);
                                }
                                else if((G.qual==0)) {
-                                       if(G.f & G_PROPORTIONAL)
-                                               G.f &= ~G_PROPORTIONAL;
-                                       else
-                                               G.f |= G_PROPORTIONAL;
+                                       G.scene->proportional= !G.scene->proportional;
                                }
                                break;
                        case PKEY:
-                               if(G.qual==LR_ALTKEY)
+                               if(G.qual==LR_SHIFTKEY)
+                                       select_pinned_tface_uv();
+                               else if(G.qual==LR_ALTKEY)
                                        pin_tface_uv(0);
                                else
                                        pin_tface_uv(1);
                                break;
                        case RKEY:
-                               if((G.qual==0))
-                                       transform_tface_uv('r', 0);
+                               if((G.qual==0) && is_uv_tface_editing_allowed()) {
+                                       initTransform(TFM_ROTATION, CTX_NONE);
+                                       Transform();
+                               }
                                break;
                        case SKEY:
-                               if((G.qual==0))
-                                       transform_tface_uv('s', 0);
+                               if((G.qual==0) && is_uv_tface_editing_allowed()) {
+                                       initTransform(TFM_RESIZE, CTX_NONE);
+                                       Transform();
+                               }
                                break;
                        case VKEY:
                                if((G.qual==0))
                                        stitch_uv_tface(0);
                                else if(G.qual==LR_SHIFTKEY)
                                        stitch_uv_tface(1);
+                               else if(G.qual==LR_CTRLKEY)
+                                       minimize_stretch_tface_uv();
                                break;
                        case WKEY:
                                weld_align_menu_tface_uv();
@@ -3952,14 +4082,17 @@ static void winqreadoopsspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        view2dmove(event);      /* in drawipo.c */
                        break;
                case RIGHTMOUSE:
-                       // outliner_select(sa);
+                       outliner_operation_menu(sa);
                        break;
                        
                case AKEY:
-                       outliner_toggle_visible(sa);
+                       if(G.qual==LR_SHIFTKEY)
+                               outliner_toggle_selected(sa);
+                       else
+                               outliner_toggle_visible(sa);
                        break;
                case WKEY:
-                       // outliner_operation_menu(sa);
+                       outliner_operation_menu(sa);
                        break;
                        
                case HOMEKEY:
@@ -4035,6 +4168,11 @@ static void winqreadoopsspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        if((G.qual==0))
                                do_oops_buttons(B_OOPSHOME);
                        break;
+               
+               case PADPERIOD:
+                       if((G.qual==0))
+                               do_oops_buttons(B_OOPSVIEWSEL);
+                       break;
                        
                case AKEY:
                        if((G.qual==0)) {
@@ -4225,12 +4363,131 @@ static void init_nlaspace(ScrArea *sa)
 extern void drawtextspace(ScrArea *sa, void *spacedata);
 extern void winqreadtextspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
 
+static void init_textspace(ScrArea *sa)
+{
+       SpaceText *st;
+       
+       st= MEM_callocN(sizeof(SpaceText), "inittextspace");
+       BLI_addhead(&sa->spacedata, st);
+       
+       st->spacetype= SPACE_TEXT;      
+       st->blockscale= 0.7;
+       st->text= NULL;
+       st->flags= 0;
+       
+       st->font_id= 5;
+       st->lheight= 12;
+       st->showlinenrs= 0;
+       st->tabnumber = 4;
+       st->currtab_set = 0;
+       
+       st->top= 0;
+}
+
+
 /* ******************** SPACE: Script ********************** */
 
 extern void drawscriptspace(ScrArea *sa, void *spacedata);
 extern void winqreadscriptspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
 
-/* ******************** SPACE: ALGEMEEN ********************** */
+static void init_scriptspace(ScrArea *sa)
+{
+       SpaceScript *sc;
+       
+       sc = MEM_callocN(sizeof(SpaceScript), "initscriptspace");
+       BLI_addhead(&sa->spacedata, sc);
+       
+       sc->spacetype = SPACE_SCRIPT;
+       sc->blockscale= 0.7;
+       sc->script = NULL;
+       sc->flags = 0;
+}
+
+
+/* ******************** SPACE: Time ********************** */
+
+extern void drawtimespace(ScrArea *sa, void *spacedata);
+extern void winqreadtimespace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
+
+static void init_timespace(ScrArea *sa)
+{
+       SpaceTime *stime;
+       
+       stime= MEM_callocN(sizeof(SpaceTime), "init timespace");
+       BLI_addhead(&sa->spacedata, stime);
+       
+       stime->spacetype= SPACE_TIME;
+       stime->blockscale= 0.7;
+       stime->redraws= TIME_ALL_3D_WIN|TIME_ALL_ANIM_WIN;
+       
+       stime->v2d.tot.xmin= -4.0;
+       stime->v2d.tot.ymin=  0.0;
+       stime->v2d.tot.xmax= (float)EFRA + 4.0;
+       stime->v2d.tot.ymax= (float)sa->winy;
+       
+       stime->v2d.cur= stime->v2d.tot;
+       
+       stime->v2d.min[0]= 1.0;
+       stime->v2d.min[1]= (float)sa->winy;
+       
+       stime->v2d.max[0]= 32000.0;
+       stime->v2d.max[1]= (float)sa->winy;
+       
+       stime->v2d.minzoom= 0.1f;
+       stime->v2d.maxzoom= 10.0;
+       
+       stime->v2d.scroll= 0;
+       stime->v2d.keepaspect= 0;
+       stime->v2d.keepzoom= 0;
+       stime->v2d.keeptot= 0;
+       
+       stime->flag |= TIME_DRAWFRAMES;
+       
+}
+
+/* ******************** SPACE: Time ********************** */
+
+extern void drawnodespace(ScrArea *sa, void *spacedata);
+extern void winqreadnodespace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
+
+static void init_nodespace(ScrArea *sa)
+{
+       SpaceNode *snode;
+       
+       snode= MEM_callocN(sizeof(SpaceNode), "init nodespace");
+       BLI_addhead(&sa->spacedata, snode);
+       
+       snode->spacetype= SPACE_NODE;
+       snode->blockscale= 0.7;
+       
+       snode->v2d.tot.xmin=  -10.0;
+       snode->v2d.tot.ymin=  -10.0;
+       snode->v2d.tot.xmax= (float)sa->winx + 10.0f;
+       snode->v2d.tot.ymax= (float)sa->winy + 10.0f;
+       
+       snode->v2d.cur.xmin=  0.0;
+       snode->v2d.cur.ymin=  0.0;
+       snode->v2d.cur.xmax= (float)sa->winx;
+       snode->v2d.cur.ymax= (float)sa->winy;
+       
+       snode->v2d.min[0]= 1.0;
+       snode->v2d.min[1]= 1.0;
+       
+       snode->v2d.max[0]= 32000.0f;
+       snode->v2d.max[1]= 32000.0f;
+       
+       snode->v2d.minzoom= 0.5f;
+       snode->v2d.maxzoom= 1.21f;
+       
+       snode->v2d.scroll= 0;
+       snode->v2d.keepaspect= 1;
+       snode->v2d.keepzoom= 1;
+       snode->v2d.keeptot= 0;
+}
+
+
+
+/* ******************** SPACE: GENERAL ********************** */
 
 void newspace(ScrArea *sa, int type)
 {
@@ -4294,6 +4551,10 @@ void newspace(ScrArea *sa, int type)
                                        init_soundspace(sa);
                                else if(type==SPACE_NLA)
                                        init_nlaspace(sa);
+                               else if(type==SPACE_TIME)
+                                       init_timespace(sa);
+                               else if(type==SPACE_NODE)
+                                       init_nodespace(sa);
 
                                sl= sa->spacedata.first;
                                sl->area= sa;
@@ -4347,14 +4608,17 @@ void freespacelist(ListBase *lb)
                }
                else if(sl->spacetype==SPACE_BUTS) {
                        SpaceButs *buts= (SpaceButs*) sl;
-                       if(buts->rect) MEM_freeN(buts->rect);
-                       if(G.buts==buts) G.buts= 0;
+                       if(buts->ri) { 
+                               if (buts->ri->rect) MEM_freeN(buts->ri->rect);
+                               MEM_freeN(buts->ri);
+                       }
+                       if(G.buts==buts) G.buts= NULL;
                }
                else if(sl->spacetype==SPACE_IPO) {
                        SpaceIpo *si= (SpaceIpo*) sl;
                        if(si->editipo) MEM_freeN(si->editipo);
                        free_ipokey(&si->ipokey);
-                       if(G.sipo==si) G.sipo= 0;
+                       if(G.sipo==si) G.sipo= NULL;
                }
                else if(sl->spacetype==SPACE_VIEW3D) {
                        View3D *vd= (View3D*) sl;
@@ -4364,7 +4628,8 @@ void freespacelist(ListBase *lb)
                                MEM_freeN(vd->bgpic);
                        }
                        if(vd->localvd) MEM_freeN(vd->localvd);
-                       if(G.vd==vd) G.vd= 0;
+                       if(vd->clipbb) MEM_freeN(vd->clipbb);
+                       if(G.vd==vd) G.vd= NULL;
                }
                else if(sl->spacetype==SPACE_OOPS) {
                        free_oopspace((SpaceOops *)sl);
@@ -4387,6 +4652,9 @@ void freespacelist(ListBase *lb)
                else if(sl->spacetype==SPACE_SOUND) {
                        free_soundspace((SpaceSound *)sl);
                }
+               else if(sl->spacetype==SPACE_NODE) {
+/*                     SpaceNode *snode= (SpaceNode *)sl; */
+               }
        }
 
        BLI_freelistN(lb);
@@ -4398,7 +4666,7 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
 
        duplicatelist(lb1, lb2);
        
-       /* lb1 is kopie from lb2, from lb2 we free the file list */
+       /* lb1 is copy from lb2, from lb2 we free the file list */
        
        sl= lb2->first;
        while(sl) {
@@ -4418,6 +4686,10 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
                }
                else if(sl->spacetype==SPACE_TEXT) {
                }
+               else if(sl->spacetype==SPACE_NODE) {
+                       SpaceNode *snode= (SpaceNode *)sl;
+                       snode->nodetree= NULL;
+               }
                /* __PINFAKE */
 /*             else if(sfile->spacetype==SPACE_ACTION) {
                        SpaceAction *sa= (SpaceAction *)sfile;
@@ -4437,20 +4709,21 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
 
                if(sl->spacetype==SPACE_BUTS) {
                        SpaceButs *buts= (SpaceButs *)sl;
-                       buts->rect= 0;
+                       buts->ri= NULL;
                }
                else if(sl->spacetype==SPACE_IPO) {
                        SpaceIpo *si= (SpaceIpo *)sl;
-                       si->editipo= 0;
-                       si->ipokey.first= si->ipokey.last= 0;
+                       si->editipo= NULL;
+                       si->ipokey.first= si->ipokey.last= NULL;
                }
                else if(sl->spacetype==SPACE_VIEW3D) {
                        View3D *vd= (View3D *)sl;
                        if(vd->bgpic) {
                                vd->bgpic= MEM_dupallocN(vd->bgpic);
-                               vd->bgpic->rect= 0;
+                               vd->bgpic->rect= NULL;
                                if(vd->bgpic->ima) vd->bgpic->ima->id.us++;
                        }
+                       vd->clipbb= MEM_dupallocN(vd->clipbb);
                }
                sl= sl->next;
        }
@@ -4462,7 +4735,7 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
                        View3D *v3d= (View3D*) sl;
                        if(v3d->localvd) {
                                restore_localviewdata(v3d);
-                               v3d->localvd= 0;
+                               v3d->localvd= NULL;
                                v3d->localview= 0;
                                v3d->lay &= 0xFFFFFF;
                        }
@@ -4481,6 +4754,7 @@ void allqueue(unsigned short event, short val)
 
        sa= G.curscreen->areabase.first;
        while(sa) {
+
                if(event==REDRAWALL) {
                        scrarea_queue_winredraw(sa);
                        scrarea_queue_headredraw(sa);
@@ -4531,7 +4805,7 @@ void allqueue(unsigned short event, short val)
                                        scrarea_queue_headredraw(sa);
                                        if(val) {
                                                si= sa->spacedata.first;
-                                               if (si->pin==0)                                                 
+                                               if (si->pin==0)                         
                                                        si->blocktype= val;
                                        }
                                }
@@ -4665,6 +4939,23 @@ void allqueue(unsigned short event, short val)
                                        scrarea_queue_winredraw(sa);
                                }
                                break;
+                       case REDRAWTIME:
+                               if(sa->spacetype==SPACE_TIME) {
+                                       scrarea_queue_headredraw(sa);
+                                       scrarea_queue_winredraw(sa);
+                               }
+                               break;
+                       case REDRAWNODE:
+                               if(sa->spacetype==SPACE_NODE) {
+                                       scrarea_queue_headredraw(sa);
+                                       scrarea_queue_winredraw(sa);
+                               }
+                               break;
+                       case REDRAWANIM:
+                               if ELEM6(sa->spacetype, SPACE_IPO, SPACE_SOUND, SPACE_TIME, SPACE_NLA, SPACE_ACTION, SPACE_SEQ) {
+                                       scrarea_queue_winredraw(sa);
+                                       if(val) scrarea_queue_headredraw(sa);
+                               }
                        }
                }
                sa= sa->next;
@@ -4682,20 +4973,6 @@ void allspace(unsigned short event, short val)
                        SpaceLink *sl= sa->spacedata.first;
                        while(sl) {
                                switch(event) {
-                               case REMAKEALLIPO:
-                                       {
-                                               Ipo *ipo;
-                                               IpoCurve *icu;
-                                               
-                                               /* Go to each ipo */
-                                               for (ipo=G.main->ipo.first; ipo; ipo=ipo->id.next){
-                                                       for (icu = ipo->curve.first; icu; icu=icu->next){
-                                                               sort_time_ipocurve(icu);
-                                                               testhandles_ipocurve(icu);
-                                                       }
-                                               }
-                                       }
-                                       break;
                                case REMAKEIPO:
                                        if(sl->spacetype==SPACE_IPO) {
                                                SpaceIpo *si= (SpaceIpo *)sl;
@@ -4726,7 +5003,7 @@ void allspace(unsigned short event, short val)
 /* 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 */
+       /* draws all areas that show something identical to curarea */
        extern int afterqtest(short win, unsigned short evt);   //editscreen.c
        ScrArea *tempsa, *sa;
 
@@ -4737,18 +5014,9 @@ void force_draw(int header)
        sa= G.curscreen->areabase.first;
        while(sa) {
                if(sa!=tempsa && sa->spacetype==tempsa->spacetype) {
-                       if(sa->spacetype==SPACE_VIEW3D) {
-                               if( ((View3D *)sa->spacedata.first)->lay & ((View3D *)tempsa->spacedata.first)->lay) {
-                                       areawinset(sa->win);
-                                       scrarea_do_windraw(sa);
-                                       scrarea_do_headdraw(sa);
-                               }
-                       }
-                       else {
-                               areawinset(sa->win);
-                               scrarea_do_windraw(sa);
-                               scrarea_do_headdraw(sa);
-                       }
+                       areawinset(sa->win);
+                       scrarea_do_windraw(sa);
+                       scrarea_do_headdraw(sa);
                }
                sa= sa->next;
        }
@@ -4756,23 +5024,25 @@ void force_draw(int header)
        screen_swapbuffers();
 
 #ifndef __APPLE__
-       /* de the afterqueuetest for backbuf draw */
-       sa= G.curscreen->areabase.first;
-       while(sa) {
-               if(sa->spacetype==SPACE_VIEW3D) {
-                       if(afterqtest(sa->win, BACKBUFDRAW)) {
-                               areawinset(sa->win);
-                               backdrawview3d(0);
+       if(tempsa->spacetype==SPACE_VIEW3D) {
+               /* de the afterqueuetest for backbuf draw */
+               sa= G.curscreen->areabase.first;
+               while(sa) {
+                       if(sa->spacetype==SPACE_VIEW3D) {
+                               if(afterqtest(sa->win, BACKBUFDRAW)) {
+                                       areawinset(sa->win);
+                                       backdrawview3d(0);
+                               }
                        }
+                       sa= sa->next;
                }
-               sa= sa->next;
        }
 #endif
        if(curarea!=tempsa) areawinset(tempsa->win);
        
 }
 
-/* if header==1, then draw header for curarea too. Excepption for headerprint()... */
+/* if header==1, then draw header for curarea too. Exception for headerprint()... */
 void force_draw_plus(int type, int header)
 {
        /* draws all areas that show something like curarea AND areas of 'type' */
@@ -4804,8 +5074,6 @@ void force_draw_all(int header)
        /* redraws all */
        ScrArea *tempsa, *sa;
 
-       drawscreen();
-
        tempsa= curarea;
        sa= G.curscreen->areabase.first;
        while(sa) {
@@ -4941,7 +5209,7 @@ SpaceType *spacesound_get_type(void)
        
        if (!st) {
                st= spacetype_new("Sound");
-               spacetype_set_winfuncs(st, drawsoundspace, NULL, winqreadsoundspace);
+               spacetype_set_winfuncs(st, drawsoundspace, changeview2dspace, winqreadsoundspace);
        }
 
        return st;
@@ -4979,3 +5247,26 @@ SpaceType *spaceview3d_get_type(void)
 
        return st;
 }
+SpaceType *spacetime_get_type(void)
+{
+       static SpaceType *st= NULL;
+       
+       if (!st) {
+               st= spacetype_new("Time");
+               spacetype_set_winfuncs(st, drawtimespace, NULL, winqreadtimespace);
+       }
+       
+       return st;
+}
+
+SpaceType *spacenode_get_type(void)
+{
+       static SpaceType *st= NULL;
+       
+       if (!st) {
+               st= spacetype_new("Node");
+               spacetype_set_winfuncs(st, drawnodespace, changeview2dspace, winqreadnodespace);
+       }
+       
+       return st;
+}