Orange; stuff for the animation department!
[blender.git] / source / blender / src / space.c
index 72636f38ed14b417783a2d5d6297aa22f7f6fcfd..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"
@@ -75,6 +76,7 @@
 #include "BKE_global.h"
 #include "BKE_ipo.h"
 #include "BKE_main.h"
+#include "BKE_node.h"
 #include "BKE_scene.h"
 #include "BKE_utildefines.h"
 
@@ -86,7 +88,9 @@
 #include "BIF_drawtext.h"
 #include "BIF_drawscript.h"
 #include "BIF_editarmature.h"
+#include "BIF_editconstraint.h"
 #include "BIF_editfont.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 "BKE_depsgraph.h"
 
-#include "TPT_DependKludge.h"
-#ifdef NAN_TPT
 #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
@@ -356,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);
+
+
        }
 }
 
@@ -397,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);
        }
@@ -470,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. */
@@ -481,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 */
@@ -568,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) {
@@ -607,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) {
@@ -633,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)
@@ -663,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();
+                       }
                }
        }
 }
@@ -683,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();
+                       }
                }
        }
 }
@@ -717,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() */
        
@@ -927,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)
@@ -942,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 */
@@ -1006,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);
@@ -1016,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);
@@ -1026,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:
@@ -1080,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;
@@ -1110,12 +1132,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                else if(G.obedit->type==OB_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();
@@ -1130,18 +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==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();
@@ -1167,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) {
@@ -1195,7 +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();
+                                                       extrude_armature(0);
                                        }
                                }
                                else if (G.qual==LR_CTRLKEY) {
@@ -1207,6 +1235,9 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                initTransform(TFM_CREASE, CTX_EDGE);
                                                Transform();
                                        }
+                                       else if (G.obedit && G.obedit->type==OB_ARMATURE) {
+                                               extrude_armature(1);
+                                       }
                                }
                                break;
                        case FKEY:
@@ -1220,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');
@@ -1300,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)
@@ -1313,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)
@@ -1371,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) {
@@ -1395,7 +1454,9 @@ 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();
@@ -1413,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:
@@ -1452,7 +1516,6 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                
                                break;
                        case OKEY:
-                               ob= OBACT;
                                if (G.obedit) {
                                        if (G.qual==LR_SHIFTKEY) {
                                                G.scene->prop_mode = (G.scene->prop_mode+1)%6;
@@ -1551,8 +1614,9 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                else if(G.obedit) {
                                        
                                        if(G.qual==LR_ALTKEY) {
-                                               if(G.obedit->type==OB_ARMATURE)
+                                               if(G.obedit->type==OB_ARMATURE) {
                                                        initTransform(TFM_BONESIZE, CTX_NONE);
+                                               }
                                                else
                                                        initTransform(TFM_SHRINKFATTEN, CTX_NONE);
                                                Transform();
@@ -1564,16 +1628,37 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        else if(G.qual==LR_SHIFTKEY)
                                                snapmenu();
                                        else if(G.qual==0) {
-                                               initTransform(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)){
                                                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');
                                        }
@@ -1596,8 +1681,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                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();
                                                DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
@@ -1613,10 +1698,12 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        }
                                }
                                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();
@@ -1646,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);
@@ -1659,7 +1745,10 @@ 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);
                                                        DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
                                                        allqueue(REDRAWVIEW3D, 0);
@@ -1751,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);
@@ -1928,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);
@@ -2007,7 +2095,7 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        break;
                case HKEY:
                        if(G.qual==LR_ALTKEY)
-                               sethandles_ipo(4);              // tsk tsk ton!
+                               sethandles_ipo(HD_AUTO_ANIM);
                        if(G.qual==LR_SHIFTKEY)
                                sethandles_ipo(HD_AUTO);
                        else if(G.qual==0)
@@ -2049,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;
                }
        }
@@ -2112,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;
@@ -2181,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|Timeline %x15|Audio Window %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;
@@ -2199,6 +2273,7 @@ static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        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 */
@@ -2231,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, "");
@@ -2264,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);
@@ -2377,13 +2452,17 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        &(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:",
@@ -2478,7 +2557,7 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                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,
-                       "Allow the view to tumble freely when orbiting with the Middle Mouse Button");
+                       "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,
@@ -2560,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 */
 
 
@@ -2586,27 +2675,32 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                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)");
 
                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",
                        (xpos+(2*edgsp)+(2*mpref)+midsp),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
+
                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");
@@ -2679,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");
 
@@ -2706,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");
 
-                       uiDefButI(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");
                                
@@ -2752,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");
                        
@@ -2802,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");
 
@@ -3135,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:
@@ -3220,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;
@@ -3248,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 ********************** */
@@ -3356,6 +3500,7 @@ 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 {
@@ -3381,7 +3526,8 @@ 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))
@@ -3451,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();
@@ -3697,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();
@@ -3801,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)
@@ -3823,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)
@@ -3854,31 +3948,40 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case OKEY:
                                if (G.qual==LR_SHIFTKEY) {
-                                       G.scene->prop_mode= !G.scene->prop_mode;
+                                       G.scene->prop_mode = (G.scene->prop_mode+1)%6;
+                                       allqueue(REDRAWHEADERS, 0);
                                }
                                else if((G.qual==0)) {
                                        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();
@@ -3979,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:
@@ -4062,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)) {
@@ -4334,6 +4445,47 @@ static void init_timespace(ScrArea *sa)
        
 }
 
+/* ******************** 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 ********************** */
 
@@ -4401,6 +4553,8 @@ void newspace(ScrArea *sa, int type)
                                        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;
@@ -4454,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;
@@ -4471,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);
@@ -4494,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);
@@ -4505,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) {
@@ -4525,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;
@@ -4544,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;
        }
@@ -4569,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;
                        }
@@ -4639,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;
                                        }
                                }
@@ -4779,6 +4945,12 @@ void allqueue(unsigned short event, short val)
                                        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);
@@ -4842,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;
        }
@@ -4861,16 +5024,18 @@ 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);
@@ -4909,8 +5074,6 @@ void force_draw_all(int header)
        /* redraws all */
        ScrArea *tempsa, *sa;
 
-       drawscreen();
-
        tempsa= curarea;
        sa= G.curscreen->areabase.first;
        while(sa) {
@@ -5095,3 +5258,15 @@ SpaceType *spacetime_get_type(void)
        
        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;
+}