converted more mixed tab/space indentations to tabs. only whitespace changes.
[blender.git] / source / blender / editors / transform / transform.c
index df0d43f..c710312 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/editors/transform/transform.c
+ *  \ingroup edtransform
+ */
+
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
 #include <float.h>
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #ifndef WIN32
 #include <unistd.h>
 #else
 
 #include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
-#include "DNA_action_types.h"  /* for some special action-editor settings */
 #include "DNA_constraint_types.h"
-#include "DNA_ipo_types.h"             /* some silly ipo flag  */
-#include "DNA_listBase.h"
 #include "DNA_meshdata_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_object_types.h"
 #include "DNA_scene_types.h"           /* PET modes                    */
-#include "DNA_screen_types.h"  /* area dimensions              */
-#include "DNA_texture_types.h"
-#include "DNA_userdef_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_space_types.h"
-#include "DNA_windowmanager_types.h"
 
 #include "RNA_access.h"
 
-//#include "BIF_editview.h"            /* arrows_move_cursor   */
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
-//#include "BIF_mywindow.h"
-//#include "BIF_resources.h"
-//#include "BIF_screen.h"
-//#include "BIF_space.h"                       /* undo                                 */
-//#include "BIF_toets.h"                       /* persptoetsen                 */
-//#include "BIF_mywindow.h"            /* warp_pointer                 */
-//#include "BIF_toolbox.h"                     /* notice                               */
-//#include "BIF_editmesh.h"
-//#include "BIF_editsima.h"
-//#include "BIF_editparticle.h"
-
-#include "BKE_action.h"
+
 #include "BKE_nla.h"
-//#include "BKE_bad_level_calls.h"/* popmenu and error */
 #include "BKE_bmesh.h"
 #include "BKE_context.h"
 #include "BKE_constraint.h"
 #include "BKE_global.h"
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
-#include "BKE_utildefines.h"
-#include "BKE_context.h"
 #include "BKE_unit.h"
 
-//#include "BSE_view.h"
-
 #include "ED_image.h"
 #include "ED_keyframing.h"
 #include "ED_screen.h"
 #include "ED_space_api.h"
 #include "ED_markers.h"
-#include "ED_util.h"
 #include "ED_view3d.h"
 #include "ED_mesh.h"
 
 
 #include "BLI_math.h"
 #include "BLI_blenlib.h"
+#include "BLI_utildefines.h"
 #include "BLI_editVert.h"
 #include "BLI_ghash.h"
 #include "BLI_linklist.h"
 
-#include "PIL_time.h"                  /* sleep                                */
-
 #include "UI_resources.h"
 
 //#include "blendef.h"
 #include "transform.h"
 
 void drawTransformApply(const struct bContext *C, struct ARegion *ar, void *arg);
+int doEdgeSlide(TransInfo *t, float perc);
 
 /* ************************** SPACE DEPENDANT CODE **************************** */
 
@@ -219,17 +191,33 @@ void projectIntView(TransInfo *t, float *vec, int *adr)
 
                UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
        }
-       else if(ELEM3(t->spacetype, SPACE_IPO, SPACE_NLA, SPACE_ACTION)) {
+       else if(t->spacetype == SPACE_ACTION) {
+               SpaceAction *sact = t->sa->spacedata.first;
                int out[2] = {0, 0};
 
-               UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
+               if (sact->flag & SACTION_DRAWTIME) {
+                       //vec[0] = vec[0]/((t->scene->r.frs_sec / t->scene->r.frs_sec_base));
+
+                       UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
+               } 
+               else {
+                       UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
+               }
+
+               adr[0]= out[0];
+               adr[1]= out[1];
+       }
+       else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
+               int out[2] = {0, 0};
+
+               UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
                adr[0]= out[0];
                adr[1]= out[1];
        }
        else if(t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */
                int out[2] = {0, 0};
 
-               UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
+               UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
                adr[0]= out[0];
                adr[1]= out[1];
        }
@@ -259,9 +247,8 @@ void projectFloatView(TransInfo *t, float *vec, float *adr)
 
 void applyAspectRatio(TransInfo *t, float *vec)
 {
-       SpaceImage *sima= t->sa->spacedata.first;
-
        if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
+               SpaceImage *sima= t->sa->spacedata.first;
                float aspx, aspy;
 
                if((sima->flag & SI_COORDFLOATS)==0) {
@@ -280,9 +267,8 @@ void applyAspectRatio(TransInfo *t, float *vec)
 
 void removeAspectRatio(TransInfo *t, float *vec)
 {
-       SpaceImage *sima= t->sa->spacedata.first;
-
        if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
+               SpaceImage *sima= t->sa->spacedata.first;
                float aspx, aspy;
 
                if((sima->flag & SI_COORDFLOATS)==0) {
@@ -304,7 +290,10 @@ static void viewRedrawForce(const bContext *C, TransInfo *t)
        if (t->spacetype == SPACE_VIEW3D)
        {
                /* Do we need more refined tags? */
-               WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
+               if(t->flag & T_POSE)
+                       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
+               else
+                       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
                
                /* for realtime animation record - send notifiers recognised by animation editors */
                // XXX: is this notifier a lame duck?
@@ -314,14 +303,14 @@ static void viewRedrawForce(const bContext *C, TransInfo *t)
        }
        else if (t->spacetype == SPACE_ACTION) {
                //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
-               WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
+               WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
        }
        else if (t->spacetype == SPACE_IPO) {
                //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
-               WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
+               WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
        }
        else if (t->spacetype == SPACE_NLA) {
-               WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_EDIT, NULL);
+               WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_EDITED, NULL);
        }
        else if(t->spacetype == SPACE_NODE)
        {
@@ -340,14 +329,18 @@ static void viewRedrawForce(const bContext *C, TransInfo *t)
        }
 }
 
-static void viewRedrawPost(TransInfo *t)
+static void viewRedrawPost(bContext *C, TransInfo *t)
 {
        ED_area_headerprint(t->sa, NULL);
        
        if(t->spacetype == SPACE_VIEW3D) {
                /* if autokeying is enabled, send notifiers that keyframes were added */
                if (IS_AUTOKEY_ON(t->scene))
-                       WM_main_add_notifier(NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
+                       WM_main_add_notifier(NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
+               
+               /* XXX temp, first hack to get auto-render in compositor work (ton) */
+               WM_event_add_notifier(C, NC_SCENE|ND_TRANSFORM_DONE, CTX_data_scene(C));
+
        }
        
 #if 0 // TRANSFORM_FIX_ME
@@ -374,7 +367,7 @@ static void viewRedrawPost(TransInfo *t)
 
 /* ************************** TRANSFORMATIONS **************************** */
 
-void BIF_selectOrientation() {
+void BIF_selectOrientation(void) {
 #if 0 // TRANSFORM_FIX_ME
        short val;
        char *str_menu = BIF_menustringTransformOrientation("Orientation");
@@ -387,7 +380,7 @@ void BIF_selectOrientation() {
 #endif
 }
 
-static void view_editmove(unsigned short event)
+static void view_editmove(unsigned short UNUSED(event))
 {
 #if 0 // TRANSFORM_FIX_ME
        int refresh = 0;
@@ -482,6 +475,10 @@ static void view_editmove(unsigned short event)
 #define TFM_MODAL_REMOVE_SNAP  17
 /*     18 and 19 used by numinput, defined in transform.h
  * */
+#define TFM_MODAL_PROPSIZE_UP  20
+#define TFM_MODAL_PROPSIZE_DOWN        21
+#define TFM_MODAL_AUTOIK_LEN_INC 22
+#define TFM_MODAL_AUTOIK_LEN_DEC 23
 
 /* called in transform_ops.c, on each regeneration of keymaps */
 wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf)
@@ -506,6 +503,10 @@ wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf)
        {TFM_MODAL_REMOVE_SNAP, "REMOVE_SNAP", 0, "Remove Last Snap Point", ""},
        {NUM_MODAL_INCREMENT_UP, "INCREMENT_UP", 0, "Numinput Increment Up", ""},
        {NUM_MODAL_INCREMENT_DOWN, "INCREMENT_DOWN", 0, "Numinput Increment Down", ""},
+       {TFM_MODAL_PROPSIZE_UP, "PROPORTIONAL_SIZE_UP", 0, "Increase Proportional Influence", ""},
+       {TFM_MODAL_PROPSIZE_DOWN, "PROPORTIONAL_SIZE_DOWN", 0, "Decrease Poportional Influence", ""},
+       {TFM_MODAL_AUTOIK_LEN_INC, "AUTOIK_CHAIN_LEN_UP", 0, "Increase Max AutoIK Chain Length", ""},
+       {TFM_MODAL_AUTOIK_LEN_DEC, "AUTOIK_CHAIN_LEN_DOWN", 0, "Decrease Max AutoIK Chain Length", ""},
        {0, NULL, 0, NULL, NULL}};
        
        wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Transform Modal Map");
@@ -529,20 +530,30 @@ wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf)
 
        WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_INV_ON);
        WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_INV_OFF);
+
+       WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_INV_ON);
+       WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_INV_OFF);
        
        WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, 0, 0, TFM_MODAL_ADD_SNAP);
        WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, KM_ALT, 0, TFM_MODAL_REMOVE_SNAP);
 
-       WM_modalkeymap_add_item(keymap, UPARROWKEY, KM_PRESS, 0, 0, NUM_MODAL_INCREMENT_UP);
-       WM_modalkeymap_add_item(keymap, DOWNARROWKEY, KM_PRESS, 0, 0, NUM_MODAL_INCREMENT_DOWN);
-
+       WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
+       WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
+       WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
+       WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
+       
+       WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_INC);
+       WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_DEC);
+       WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_INC);
+       WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_DEC);
+       
        return keymap;
 }
 
 
 int transformEvent(TransInfo *t, wmEvent *event)
 {
-       float mati[3][3] = {{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
+       float mati[3][3]= MAT3_UNITY;
        char cmode = constraintModeToChar(t);
        int handled = 1;
 
@@ -556,10 +567,12 @@ int transformEvent(TransInfo *t, wmEvent *event)
                t->mval[0] = event->x - t->ar->winrct.xmin;
                t->mval[1] = event->y - t->ar->winrct.ymin;
 
-               t->redraw |= TREDRAW_SOFT;
+               // t->redraw |= TREDRAW_SOFT; /* Use this for soft redraw. Might cause flicker in object mode */
+               t->redraw |= TREDRAW_HARD;
+
 
                if (t->state == TRANS_STARTING) {
-                   t->state = TRANS_RUNNING;
+                       t->state = TRANS_RUNNING;
                }
 
                applyMouseInput(t, &t->mouse, t->mval, t->values);
@@ -586,20 +599,22 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                break;
                        case TFM_MODAL_ROTATE:
                                /* only switch when... */
-                               if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
-                                       
-                                       resetTransRestrictions(t);
-                                       
-                                       if (t->mode == TFM_ROTATION) {
-                                               restoreTransObjects(t);
-                                               initTrackball(t);
-                                       }
-                                       else {
-                                               restoreTransObjects(t);
-                                               initRotation(t);
+                               if(!(t->options & CTX_TEXTURE)) {
+                                       if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
+                                               
+                                               resetTransRestrictions(t);
+                                               
+                                               if (t->mode == TFM_ROTATION) {
+                                                       restoreTransObjects(t);
+                                                       initTrackball(t);
+                                               }
+                                               else {
+                                                       restoreTransObjects(t);
+                                                       initRotation(t);
+                                               }
+                                               initSnapping(t, NULL); // need to reinit after mode change
+                                               t->redraw |= TREDRAW_HARD;
                                        }
-                                       initSnapping(t, NULL); // need to reinit after mode change
-                                       t->redraw |= TREDRAW_HARD;
                                }
                                break;
                        case TFM_MODAL_RESIZE:
@@ -715,13 +730,39 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                removeSnapPoint(t);
                                t->redraw |= TREDRAW_HARD;
                                break;
+                       case TFM_MODAL_PROPSIZE_UP:
+                               if(t->flag & T_PROP_EDIT) {
+                                       t->prop_size*= 1.1f;
+                                       if(t->spacetype==SPACE_VIEW3D && t->persp != RV3D_ORTHO)
+                                               t->prop_size= MIN2(t->prop_size, ((View3D *)t->view)->far);
+                                       calculatePropRatio(t);
+                               }
+                               t->redraw |= TREDRAW_HARD;
+                               break;
+                       case TFM_MODAL_PROPSIZE_DOWN:
+                               if (t->flag & T_PROP_EDIT) {
+                                       t->prop_size*= 0.90909090f;
+                                       calculatePropRatio(t);
+                               }
+                               t->redraw |= TREDRAW_HARD;
+                               break;
+                       case TFM_MODAL_AUTOIK_LEN_INC:
+                               if (t->flag & T_AUTOIK)
+                                       transform_autoik_update(t, 1);
+                               t->redraw |= TREDRAW_HARD;
+                               break;
+                       case TFM_MODAL_AUTOIK_LEN_DEC:
+                               if (t->flag & T_AUTOIK) 
+                                       transform_autoik_update(t, -1);
+                               t->redraw |= TREDRAW_HARD;
+                               break;
                        default:
                                handled = 0;
                                break;
                }
 
                // Modal numinput events
-               t->redraw |= handleNumInput(&(t->num), event, t->snap[1]);
+               t->redraw |= handleNumInput(&(t->num), event);
        }
        /* else do non-mapped events */
        else if (event->val==KM_PRESS) {
@@ -813,20 +854,22 @@ int transformEvent(TransInfo *t, wmEvent *event)
                        break;
                case RKEY:
                        /* only switch when... */
-                       if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
+                       if(!(t->options & CTX_TEXTURE)) {
+                               if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
 
-                               resetTransRestrictions(t);
+                                       resetTransRestrictions(t);
 
-                               if (t->mode == TFM_ROTATION) {
-                                       restoreTransObjects(t);
-                                       initTrackball(t);
-                               }
-                               else {
-                                       restoreTransObjects(t);
-                                       initRotation(t);
+                                       if (t->mode == TFM_ROTATION) {
+                                               restoreTransObjects(t);
+                                               initTrackball(t);
+                                       }
+                                       else {
+                                               restoreTransObjects(t);
+                                               initRotation(t);
+                                       }
+                                       initSnapping(t, NULL); // need to reinit after mode change
+                                       t->redraw |= TREDRAW_HARD;
                                }
-                               initSnapping(t, NULL); // need to reinit after mode change
-                               t->redraw |= TREDRAW_HARD;
                        }
                        break;
                case CKEY:
@@ -930,6 +973,8 @@ int transformEvent(TransInfo *t, wmEvent *event)
                case PADPLUSKEY:
                        if(event->alt && t->flag & T_PROP_EDIT) {
                                t->prop_size *= 1.1f;
+                               if(t->spacetype==SPACE_VIEW3D && t->persp != RV3D_ORTHO)
+                                       t->prop_size= MIN2(t->prop_size, ((View3D *)t->view)->far);
                                calculatePropRatio(t);
                        }
                        t->redraw= 1;
@@ -939,10 +984,6 @@ int transformEvent(TransInfo *t, wmEvent *event)
                        if (t->flag & T_AUTOIK) {
                                transform_autoik_update(t, 1);
                        }
-                       else if(t->flag & T_PROP_EDIT) {
-                               t->prop_size*= 1.1f;
-                               calculatePropRatio(t);
-                       }
                        else view_editmove(event->type);
                        t->redraw= 1;
                        break;
@@ -958,10 +999,6 @@ int transformEvent(TransInfo *t, wmEvent *event)
                        if (t->flag & T_AUTOIK) {
                                transform_autoik_update(t, -1);
                        }
-                       else if (t->flag & T_PROP_EDIT) {
-                               t->prop_size*= 0.90909090f;
-                               calculatePropRatio(t);
-                       }
                        else view_editmove(event->type);
                        t->redraw= 1;
                        break;
@@ -974,7 +1011,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                }
 
                // Numerical input events
-               t->redraw |= handleNumInput(&(t->num), event, t->snap[1]);
+               t->redraw |= handleNumInput(&(t->num), event);
 
                // NDof input events
                switch(handleNDofInput(&(t->ndof), event))
@@ -1016,7 +1053,6 @@ int transformEvent(TransInfo *t, wmEvent *event)
                // Snapping events
                t->redraw |= handleSnapping(t, event);
 
-               //arrows_move_cursor(event->type);
        }
        else if (event->val==KM_RELEASE) {
                switch (event->type){
@@ -1045,10 +1081,13 @@ int transformEvent(TransInfo *t, wmEvent *event)
                }
 
                /* confirm transform if launch key is released after mouse move */
-               /* XXX Keyrepeat bug in Xorg fucks this up, will test when fixed */
-               if (event->type == LEFTMOUSE /*t->launch_event*/ && t->state != TRANS_STARTING)
+               if (t->flag & T_RELEASE_CONFIRM)
                {
-                       t->state = TRANS_CONFIRM;
+                       /* XXX Keyrepeat bug in Xorg fucks this up, will test when fixed */
+                       if (event->type == t->launch_event && (t->launch_event == LEFTMOUSE || t->launch_event == RIGHTMOUSE))
+                       {
+                               t->state = TRANS_CONFIRM;
+                       }
                }
        }
 
@@ -1186,14 +1225,26 @@ static void drawArc(float size, float angle_start, float angle_end, int segments
        glEnd();
 }
 
-static void drawHelpline(bContext *C, int x, int y, void *customdata)
+static int helpline_poll(bContext *C)
+{
+       ARegion *ar= CTX_wm_region(C);
+       
+       if(ar && ar->regiontype==RGN_TYPE_WINDOW)
+               return 1;
+       return 0;
+}
+
+static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
 {
        TransInfo *t = (TransInfo*)customdata;
 
        if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR))
        {
                float vecrot[3], cent[2];
-               int mval[2] = {x, y};
+               int mval[2];
+
+               mval[0]= x;
+               mval[1]= y;
 
                VECCOPY(vecrot, t->center);
                if(t->flag & T_EDIT) {
@@ -1221,7 +1272,7 @@ static void drawHelpline(bContext *C, int x, int y, void *customdata)
                                glEnd();
 
                                glTranslatef(mval[0], mval[1], 0);
-                               glRotatef(-180 / M_PI * atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1]), 0, 0, 1);
+                               glRotatef(-RAD2DEGF(atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1])), 0, 0, 1);
 
                                setlinestyle(0);
                                glLineWidth(3.0);
@@ -1255,8 +1306,8 @@ static void drawHelpline(bContext *C, int x, int y, void *customdata)
                                        float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
                                        float angle = atan2f(dy, dx);
                                        float dist = sqrtf(dx*dx + dy*dy);
-                                       float delta_angle = MIN2(15 / dist, M_PI/4);
-                                       float spacing_angle = MIN2(5 / dist, M_PI/12);
+                                       float delta_angle = MIN2(15.0f / dist, (float)M_PI/4.0f);
+                                       float spacing_angle = MIN2(5.0f / dist, (float)M_PI/12.0f);
                                        UI_ThemeColor(TH_WIRE);
 
                                        setlinestyle(3);
@@ -1275,14 +1326,14 @@ static void drawHelpline(bContext *C, int x, int y, void *customdata)
                                        glPushMatrix();
 
                                        glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
-                                       glRotatef(180 / M_PI * (angle - delta_angle), 0, 0, 1);
+                                       glRotatef(RAD2DEGF(angle - delta_angle), 0, 0, 1);
 
                                        drawArrowHead(DOWN, 5);
 
                                        glPopMatrix();
 
                                        glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
-                                       glRotatef(180 / M_PI * (angle + delta_angle), 0, 0, 1);
+                                       glRotatef(RAD2DEGF(angle + delta_angle), 0, 0, 1);
 
                                        drawArrowHead(UP, 5);
 
@@ -1291,20 +1342,20 @@ static void drawHelpline(bContext *C, int x, int y, void *customdata)
                                }
                                case HLP_TRACKBALL:
                                {
-                                       char col[3], col2[3];
+                                       unsigned char col[3], col2[3];
                                        UI_GetThemeColor3ubv(TH_GRID, col);
 
                                        glTranslatef(mval[0], mval[1], 0);
 
                                        glLineWidth(3.0);
 
-                                       UI_make_axis_color(col, col2, 'x');
+                                       UI_make_axis_color(col, col2, 'X');
                                        glColor3ubv((GLubyte *)col2);
 
                                        drawArrow(RIGHT, 5, 10, 5);
                                        drawArrow(LEFT, 5, 10, 5);
 
-                                       UI_make_axis_color(col, col2, 'y');
+                                       UI_make_axis_color(col, col2, 'Y');
                                        glColor3ubv((GLubyte *)col2);
 
                                        drawArrow(UP, 5, 10, 5);
@@ -1318,21 +1369,23 @@ static void drawHelpline(bContext *C, int x, int y, void *customdata)
        }
 }
 
-void drawTransformView(const struct bContext *C, struct ARegion *ar, void *arg)
+static void drawTransformView(const struct bContext *C, struct ARegion *UNUSED(ar), void *arg)
 {
        TransInfo *t = arg;
 
-       drawConstraint(C, t);
+       drawConstraint(t);
        drawPropCircle(C, t);
        drawSnapping(C, t);
 }
 
-void drawTransformPixel(const struct bContext *C, struct ARegion *ar, void *arg)
+#if 0
+static void drawTransformPixel(const struct bContext *UNUSED(C), struct ARegion *UNUSED(ar), void *UNUSED(arg))
 {
 //     TransInfo *t = arg;
 //
 //     drawHelpline(C, t->mval[0], t->mval[1], t);
 }
+#endif
 
 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
 {
@@ -1352,17 +1405,17 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
                }
        }
 
-       /* XXX convert stupid flag to enum */
+       /* convert flag to enum */
        switch(t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
        {
        case (T_PROP_EDIT|T_PROP_CONNECTED):
-               proportional = 2;
+               proportional = PROP_EDIT_CONNECTED;
                break;
        case T_PROP_EDIT:
-               proportional = 1;
+               proportional = PROP_EDIT_ON;
                break;
        default:
-               proportional = 0;
+               proportional = PROP_EDIT_OFF;
        }
 
        // If modal, save settings back in scene if not set as operator argument
@@ -1370,14 +1423,17 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
 
                /* save settings if not set in operator */
                if (RNA_struct_find_property(op->ptr, "proportional") && !RNA_property_is_set(op->ptr, "proportional")) {
-                       ts->proportional = proportional;
+                       if (t->obedit)
+                               ts->proportional = proportional;
+                       else
+                               ts->proportional_objects = (proportional != PROP_EDIT_OFF);
                }
 
                if (RNA_struct_find_property(op->ptr, "proportional_size") && !RNA_property_is_set(op->ptr, "proportional_size")) {
                        ts->proportional_size = t->prop_size;
                }
                        
-               if (RNA_struct_find_property(op->ptr, "proportional_editing_falloff") && !RNA_property_is_set(op->ptr, "proportional_editing_falloff")) {
+               if (RNA_struct_find_property(op->ptr, "proportional_edit_falloff") && !RNA_property_is_set(op->ptr, "proportional_edit_falloff")) {
                        ts->prop_mode = t->prop_mode;
                }
                
@@ -1400,7 +1456,7 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
        if (RNA_struct_find_property(op->ptr, "proportional"))
        {
                RNA_enum_set(op->ptr, "proportional", proportional);
-               RNA_enum_set(op->ptr, "proportional_editing_falloff", t->prop_mode);
+               RNA_enum_set(op->ptr, "proportional_edit_falloff", t->prop_mode);
                RNA_float_set(op->ptr, "proportional_size", t->prop_size);
        }
 
@@ -1442,20 +1498,43 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
        }
 }
 
+/* note: caller needs to free 't' on a 0 return */
 int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int mode)
 {
        int options = 0;
 
+       t->context = C;
+
        /* added initialize, for external calls to set stuff in TransInfo, like undo string */
 
        t->state = TRANS_STARTING;
 
+       if(RNA_struct_find_property(op->ptr, "texture_space"))
+               if(RNA_boolean_get(op->ptr, "texture_space"))
+                       options |= CTX_TEXTURE;
+       
        t->options = options;
 
        t->mode = mode;
 
        t->launch_event = event ? event->type : -1;
 
+       if (t->launch_event == EVT_TWEAK_R)
+       {
+               t->launch_event = RIGHTMOUSE;
+       }
+       else if (t->launch_event == EVT_TWEAK_L)
+       {
+               t->launch_event = LEFTMOUSE;
+       }
+
+       // XXX Remove this when wm_operator_call_internal doesn't use window->eventstate (which can have type = 0)
+       // For manipulator only, so assume LEFTMOUSE
+       if (t->launch_event == 0)
+       {
+               t->launch_event = LEFTMOUSE;
+       }
+
        if (!initTransInfo(C, t, op, event))                                    // internal data, mouse, vectors
        {
                return 0;
@@ -1469,7 +1548,7 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int
                t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);
                t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
                //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
-               t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), NULL, drawHelpline, t);
+               t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
        }
        else if(t->spacetype == SPACE_IMAGE) {
                unit_m3(t->spacemtx);
@@ -1486,6 +1565,28 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int
                return 0;
        }
 
+       /* Stupid code to have Ctrl-Click on manipulator work ok */
+       if(event)
+       {
+               wmKeyMap *keymap = WM_keymap_active(CTX_wm_manager(C), op->type->modalkeymap);
+               wmKeyMapItem *kmi;
+
+               for (kmi = keymap->items.first; kmi; kmi = kmi->next)
+               {
+                       if (kmi->propvalue == TFM_MODAL_SNAP_INV_ON && kmi->val == KM_PRESS)
+                       {
+                               if ((ELEM(kmi->type, LEFTCTRLKEY, RIGHTCTRLKEY) && event->ctrl) ||
+                                       (ELEM(kmi->type, LEFTSHIFTKEY, RIGHTSHIFTKEY) && event->shift) ||
+                                       (ELEM(kmi->type, LEFTALTKEY, RIGHTALTKEY) && event->alt) ||
+                                       (kmi->type == OSKEY && event->oskey)) {
+                                       t->modifiers |= MOD_SNAP_INVERT;
+                               }
+                               break;
+                       }
+               }
+
+       }
+
        initSnapping(t, op); // Initialize snapping data AFTER mode flags
 
        /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
@@ -1562,6 +1663,16 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int
        case TFM_TIME_SCALE:
                initTimeScale(t);
                break;
+       case TFM_TIME_DUPLICATE:
+               /* same as TFM_TIME_EXTEND, but we need the mode info for later 
+                * so that duplicate-culling will work properly
+                */
+               if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
+                       initTranslation(t);
+               else
+                       initTimeTranslate(t);
+               t->mode = mode;
+               break;
        case TFM_TIME_EXTEND:
                /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
                 * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
@@ -1593,10 +1704,17 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int
                break;
        }
 
+       if(t->state == TRANS_CANCEL)
+       {
+               postTrans(C, t);
+               return 0;
+       }
+
+
        /* overwrite initial values if operator supplied a non-null vector */
        if (RNA_property_is_set(op->ptr, "value"))
        {
-               float values[4];
+               float values[4]= {0}; /* incase value isn't length 4, avoid uninitialized memory  */
                RNA_float_get_array(op->ptr, "value", values);
                QUATCOPY(t->values, values);
                QUATCOPY(t->auto_values, values);
@@ -1608,6 +1726,7 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int
        {
                RNA_float_get_array(op->ptr, "axis", t->axis);
                normalize_v3(t->axis);
+               copy_v3_v3(t->axis_orig, t->axis);
        }
 
        /* Constraint init from operator */
@@ -1635,11 +1754,15 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int
                }
        }
 
+       t->context = NULL;
+
        return 1;
 }
 
-void transformApply(const bContext *C, TransInfo *t)
+void transformApply(bContext *C, TransInfo *t)
 {
+       t->context = C;
+
        if ((t->redraw & TREDRAW_HARD) || (t->draw_handle_apply == NULL && (t->redraw & TREDRAW_SOFT)))
        {
                selectConstraint(t);
@@ -1664,15 +1787,17 @@ void transformApply(const bContext *C, TransInfo *t)
                //do_screenhandlers(G.curscreen);
                t->redraw |= TREDRAW_HARD;
        }
+
+       t->context = NULL;
 }
 
-void drawTransformApply(const struct bContext *C, struct ARegion *ar, void *arg)
+void drawTransformApply(const bContext *C, struct ARegion *UNUSED(ar), void *arg)
 {
        TransInfo *t = arg;
 
        if (t->redraw & TREDRAW_SOFT) {
                t->redraw |= TREDRAW_HARD;
-               transformApply(C, t);
+               transformApply((bContext *)C, t);
        }
 }
 
@@ -1680,11 +1805,17 @@ int transformEnd(bContext *C, TransInfo *t)
 {
        int exit_code = OPERATOR_RUNNING_MODAL;
 
+       t->context = C;
+
        if (t->state != TRANS_STARTING && t->state != TRANS_RUNNING)
        {
                /* handle restoring objects */
                if(t->state == TRANS_CANCEL)
                {
+                       /* exception, edge slide transformed UVs too */
+                       if(t->mode==TFM_EDGE_SLIDE)
+                               doEdgeSlide(t, 0.0f);
+                       
                        exit_code = OPERATOR_CANCELLED;
                        restoreTransObjects(t); // calls recalcData()
                }
@@ -1700,7 +1831,7 @@ int transformEnd(bContext *C, TransInfo *t)
                postTrans(C, t);
 
                /* send events out for redraws */
-               viewRedrawPost(t);
+               viewRedrawPost(C, t);
 
                /*  Undo as last, certainly after special_trans_update! */
 
@@ -1716,6 +1847,8 @@ int transformEnd(bContext *C, TransInfo *t)
                viewRedrawForce(C, t);
        }
 
+       t->context = NULL;
+
        return exit_code;
 }
 
@@ -1788,7 +1921,7 @@ static void protectedAxisAngleBits(short protectflag, float axis[3], float *angl
                eulO_to_axis_angle( axis, angle,eul, EULER_ORDER_DEFAULT);
                
                /* when converting to axis-angle, we need a special exception for the case when there is no axis */
-               if (IS_EQ(axis[0], axis[1]) && IS_EQ(axis[1], axis[2])) {
+               if (IS_EQF(axis[0], axis[1]) && IS_EQF(axis[1], axis[2])) {
                        /* for now, rotate around y-axis then (so that it simply becomes the roll) */
                        axis[1]= 1.0f;
                }
@@ -1815,23 +1948,29 @@ static void protectedQuaternionBits(short protectflag, float *quat, float *oldqu
        }
        else {
                /* quaternions get limited with euler... (compatability mode) */
-               float eul[3], oldeul[3], quat1[4];
-               
-               QUATCOPY(quat1, quat);
-               quat_to_eul( eul,quat);
-               quat_to_eul( oldeul,oldquat);
-               
+               float eul[3], oldeul[3], nquat[4], noldquat[4];
+               float qlen;
+
+               qlen= normalize_qt_qt(nquat, quat);
+               normalize_qt_qt(noldquat, oldquat);
+
+               quat_to_eul(eul, nquat);
+               quat_to_eul(oldeul, noldquat);
+
                if (protectflag & OB_LOCK_ROTX)
                        eul[0]= oldeul[0];
                if (protectflag & OB_LOCK_ROTY)
                        eul[1]= oldeul[1];
                if (protectflag & OB_LOCK_ROTZ)
                        eul[2]= oldeul[2];
-               
+
                eul_to_quat( quat,eul);
+
+               /* restore original quat size */
+               mul_qt_fl(quat, qlen);
                
                /* quaternions flip w sign to accumulate rotations correctly */
-               if ( (quat1[0]<0.0f && quat[0]>0.0f) || (quat1[0]>0.0f && quat[0]<0.0f) ) {
+               if ( (nquat[0]<0.0f && quat[0]>0.0f) || (nquat[0]>0.0f && quat[0]<0.0f) ) {
                        mul_qt_fl(quat, -1.0f);
                }
        }
@@ -1839,18 +1978,17 @@ static void protectedQuaternionBits(short protectflag, float *quat, float *oldqu
 
 /* ******************* TRANSFORM LIMITS ********************** */
 
-static void constraintTransLim(TransInfo *t, TransData *td)
+static void constraintTransLim(TransInfo *UNUSED(t), TransData *td)
 {
        if (td->con) {
                bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
-               bConstraintOb cob;
+               bConstraintOb cob= {NULL};
                bConstraint *con;
                
                /* Make a temporary bConstraintOb for using these limit constraints
                 *      - they only care that cob->matrix is correctly set ;-)
                 *      - current space should be local
                 */
-               memset(&cob, 0, sizeof(bConstraintOb));
                unit_m4(cob.matrix);
                VECCOPY(cob.matrix[3], td->loc);
                
@@ -1897,39 +2035,42 @@ static void constraintTransLim(TransInfo *t, TransData *td)
        }
 }
 
-static void constraintRotLim(TransInfo *t, TransData *td)
+static void constraintob_from_transdata(bConstraintOb *cob, TransData *td)
 {
-       if (td->con) {
-               bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
-               bConstraintOb cob;
-               bConstraint *con;
-
-               /* Make a temporary bConstraintOb for using these limit constraints
-                *      - they only care that cob->matrix is correctly set ;-)
-                *      - current space should be local
-                */
-               memset(&cob, 0, sizeof(bConstraintOb));
-               if (td->rotOrder == ROT_MODE_QUAT) {
+       /* Make a temporary bConstraintOb for use by limit constraints
+        *      - they only care that cob->matrix is correctly set ;-)
+        *      - current space should be local
+        */
+       memset(cob, 0, sizeof(bConstraintOb));
+       if (td->ext)
+       {
+               if (td->ext->rotOrder == ROT_MODE_QUAT) {
                        /* quats */
-                       if (td->ext)
-                               quat_to_mat4( cob.matrix,td->ext->quat);
-                       else
-                               return;
+                       /* objects and bones do normalization first too, otherwise
+                          we don't necessarily end up with a rotation matrix, and
+                          then conversion back to quat gives a different result */
+                       float quat[4];
+                       normalize_qt_qt(quat, td->ext->quat);
+                       quat_to_mat4(cob->matrix, quat);
                }
-               else if (td->rotOrder == ROT_MODE_AXISANGLE) {
+               else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
                        /* axis angle */
-                       if (td->ext)
-                               axis_angle_to_mat4( cob.matrix,&td->ext->quat[1], td->ext->quat[0]);
-                       else
-                               return;
+                       axis_angle_to_mat4(cob->matrix, &td->ext->quat[1], td->ext->quat[0]);
                }
                else {
                        /* eulers */
-                       if (td->ext)
-                               eulO_to_mat4( cob.matrix,td->ext->rot, td->rotOrder);
-                       else
-                               return;
+                       eulO_to_mat4(cob->matrix, td->ext->rot, td->ext->rotOrder);
                }
+       }
+}
+
+static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
+{
+       if (td->con) {
+               bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
+               bConstraintOb cob;
+               bConstraint *con;
+               int dolimit = 0;
                
                /* Evaluate valid constraints */
                for (con= td->con; con; con= con->next) {
@@ -1945,6 +2086,16 @@ static void constraintRotLim(TransInfo *t, TransData *td)
                                /* only use it if it's tagged for this purpose */
                                if ((data->flag2 & LIMIT_TRANSFORM)==0)
                                        continue;
+
+                               /* skip incompatable spacetypes */
+                               if (!ELEM(con->ownspace, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL))
+                                       continue;
+
+                               /* only do conversion if necessary, to preserve quats and eulers */
+                               if(!dolimit) {
+                                       constraintob_from_transdata(&cob, td);
+                                       dolimit= 1;
+                               }
                                
                                /* do space conversions */
                                if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
@@ -1952,10 +2103,6 @@ static void constraintRotLim(TransInfo *t, TransData *td)
                                        copy_m4_m4(tmat, cob.matrix);
                                        mul_m4_m3m4(cob.matrix, td->mtx, tmat);
                                }
-                               else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
-                                       /* skip... incompatable spacetype */
-                                       continue;
-                               }
                                
                                /* do constraint */
                                cti->evaluate_constraint(con, &cob, NULL);
@@ -1969,18 +2116,20 @@ static void constraintRotLim(TransInfo *t, TransData *td)
                        }
                }
                
-               /* copy results from cob->matrix */
-               if (td->rotOrder == ROT_MODE_QUAT) {
-                       /* quats */
-                       mat4_to_quat( td->ext->quat,cob.matrix);
-               }
-               else if (td->rotOrder == ROT_MODE_AXISANGLE) {
-                       /* axis angle */
-                       mat4_to_axis_angle( &td->ext->quat[1], &td->ext->quat[0],cob.matrix);
-               }
-               else {
-                       /* eulers */
-                       mat4_to_eulO( td->ext->rot, td->rotOrder,cob.matrix);
+               if(dolimit) {
+                       /* copy results from cob->matrix */
+                       if (td->ext->rotOrder == ROT_MODE_QUAT) {
+                               /* quats */
+                               mat4_to_quat( td->ext->quat,cob.matrix);
+                       }
+                       else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
+                               /* axis angle */
+                               mat4_to_axis_angle( &td->ext->quat[1], &td->ext->quat[0],cob.matrix);
+                       }
+                       else {
+                               /* eulers */
+                               mat4_to_eulO( td->ext->rot, td->ext->rotOrder,cob.matrix);
+                       }
                }
        }
 }
@@ -1989,14 +2138,13 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
 {
        if (td->con && td->ext) {
                bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
-               bConstraintOb cob;
+               bConstraintOb cob= {NULL};
                bConstraint *con;
                
                /* Make a temporary bConstraintOb for using these limit constraints
                 *      - they only care that cob->matrix is correctly set ;-)
                 *      - current space should be local
                 */
-               memset(&cob, 0, sizeof(bConstraintOb));
                if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
                        /* scale val and reset size */
                        return; // TODO: fix this case
@@ -2064,6 +2212,16 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
 
 /* ************************** WARP *************************** */
 
+static void postInputWarp(TransInfo *t, float values[3])
+{
+       mul_v3_fl(values, (float)(M_PI * 2));
+
+       if (t->customData) /* non-null value indicates reversed input */
+       {
+               negate_v3(values);
+       }
+}
+
 void initWarp(TransInfo *t)
 {
        float max[3], min[3];
@@ -2073,36 +2231,37 @@ void initWarp(TransInfo *t)
        t->transform = Warp;
        t->handleEvent = handleEventWarp;
        
+       setInputPostFct(&t->mouse, postInputWarp);
        initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
        
        t->idx_max = 0;
        t->num.idx_max = 0;
        t->snap[0] = 0.0f;
-       t->snap[1] = 5.0f;
-       t->snap[2] = 1.0f;
+       t->snap[1] = 5.0f / 180.0f * (float)M_PI;
+       t->snap[2] = 1.0f / 180.0f * (float)M_PI;
        
+       t->num.increment = 1.0f;
+
        t->flag |= T_NO_CONSTRAINT;
        
        /* we need min/max in view space */
        for(i = 0; i < t->total; i++) {
                float center[3];
-               VECCOPY(center, t->data[i].center);
+               copy_v3_v3(center, t->data[i].center);
                mul_m3_v3(t->data[i].mtx, center);
                mul_m4_v3(t->viewmat, center);
-               sub_v3_v3v3(center, center, t->viewmat[3]);
+               sub_v3_v3(center, t->viewmat[3]);
                if (i)
-                       minmax_v3_v3v3(min, max, center);
+                       minmax_v3v3_v3(min, max, center);
                else {
-                       VECCOPY(max, center);
-                       VECCOPY(min, center);
+                       copy_v3_v3(max, center);
+                       copy_v3_v3(min, center);
                }
        }
-       
-       t->center[0]= (min[0]+max[0])/2.0f;
-       t->center[1]= (min[1]+max[1])/2.0f;
-       t->center[2]= (min[2]+max[2])/2.0f;
 
-       if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
+       mid_v3_v3v3(t->center, min, max);
+
+       if (max[0] == min[0]) max[0] += 0.1f; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
        t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
 }
 
@@ -2113,10 +2272,10 @@ int handleEventWarp(TransInfo *t, wmEvent *event)
        if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
        {
                // Use customData pointer to signal warp direction
-               if      (t->customData == 0)
+               if      (t->customData == NULL)
                        t->customData = (void*)1;
                else
-                       t->customData = 0;
+                       t->customData = NULL;
                
                status = 1;
        }
@@ -2124,7 +2283,7 @@ int handleEventWarp(TransInfo *t, wmEvent *event)
        return status;
 }
 
-int Warp(TransInfo *t, short mval[2])
+int Warp(TransInfo *t, short UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
@@ -2145,20 +2304,15 @@ int Warp(TransInfo *t, short mval[2])
        VECCOPY(cursor, curs);
        VECCOPY(gcursor, cursor);
        if (t->flag & T_EDIT) {
-               sub_v3_v3v3(cursor, cursor, t->obedit->obmat[3]);
-               sub_v3_v3v3(gcursor, gcursor, t->obedit->obmat[3]);
+               sub_v3_v3(cursor, t->obedit->obmat[3]);
+               sub_v3_v3(gcursor, t->obedit->obmat[3]);
                mul_m3_v3(t->data->smtx, gcursor);
        }
        mul_m4_v3(t->viewmat, cursor);
-       sub_v3_v3v3(cursor, cursor, t->viewmat[3]);
+       sub_v3_v3(cursor, t->viewmat[3]);
        
-       /* amount of degrees for warp */
-       circumfac = 360.0f * t->values[0];
-       
-       if (t->customData) /* non-null value indicates reversed input */
-       {
-               circumfac *= -1;
-       }
+       /* amount of radians for warp */
+       circumfac = t->values[0];
        
        snapGrid(t, &circumfac);
        applyNumInput(&t->num, &circumfac);
@@ -2170,13 +2324,17 @@ int Warp(TransInfo *t, short mval[2])
                outputNumInput(&(t->num), c);
                
                sprintf(str, "Warp: %s", c);
+
+               circumfac = DEG2RADF(circumfac);
        }
        else {
                /* default header print */
-               sprintf(str, "Warp: %.3f", circumfac);
+               sprintf(str, "Warp: %.3f", RAD2DEGF(circumfac));
        }
        
-       circumfac*= (float)(-M_PI/360.0);
+       t->values[0] = circumfac;
+
+       circumfac /= 2; /* only need 180 on each side to make 360 */
        
        for(i = 0; i < t->total; i++, td++) {
                float loc[3];
@@ -2190,7 +2348,7 @@ int Warp(TransInfo *t, short mval[2])
                VECCOPY(vec, td->iloc);
                mul_m3_v3(td->mtx, vec);
                mul_m4_v3(t->viewmat, vec);
-               sub_v3_v3v3(vec, vec, t->viewmat[3]);
+               sub_v3_v3(vec, t->viewmat[3]);
                
                dist= vec[0]-cursor[0];
                
@@ -2206,10 +2364,10 @@ int Warp(TransInfo *t, short mval[2])
                loc[2]= vec[2];
                
                mul_m4_v3(t->viewinv, loc);
-               sub_v3_v3v3(loc, loc, t->viewinv[3]);
+               sub_v3_v3(loc, t->viewinv[3]);
                mul_m3_v3(td->smtx, loc);
                
-               sub_v3_v3v3(loc, loc, td->iloc);
+               sub_v3_v3(loc, td->iloc);
                mul_v3_fl(loc, td->factor);
                add_v3_v3v3(td->loc, td->iloc, loc);
        }
@@ -2223,12 +2381,18 @@ int Warp(TransInfo *t, short mval[2])
 
 /* ************************** SHEAR *************************** */
 
+static void postInputShear(TransInfo *UNUSED(t), float values[3])
+{
+       mul_v3_fl(values, 0.05f);
+}
+
 void initShear(TransInfo *t)
 {
        t->mode = TFM_SHEAR;
        t->transform = Shear;
        t->handleEvent = handleEventShear;
        
+       setInputPostFct(&t->mouse, postInputShear);
        initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
        
        t->idx_max = 0;
@@ -2237,6 +2401,8 @@ void initShear(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
        
+       t->num.increment = 0.1f;
+
        t->flag |= T_NO_CONSTRAINT;
 }
 
@@ -2247,7 +2413,7 @@ int handleEventShear(TransInfo *t, wmEvent *event)
        if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
        {
                // Use customData pointer to signal Shear direction
-               if      (t->customData == 0)
+               if      (t->customData == NULL)
                {
                        initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
                        t->customData = (void*)1;
@@ -2255,7 +2421,7 @@ int handleEventShear(TransInfo *t, wmEvent *event)
                else
                {
                        initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
-                       t->customData = 0;
+                       t->customData = NULL;
                }
                
                status = 1;
@@ -2265,7 +2431,7 @@ int handleEventShear(TransInfo *t, wmEvent *event)
 }
 
 
-int Shear(TransInfo *t, short mval[2])
+int Shear(TransInfo *t, short UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float vec[3];
@@ -2277,7 +2443,7 @@ int Shear(TransInfo *t, short mval[2])
        copy_m3_m4(persmat, t->viewmat);
        invert_m3_m3(persinv, persmat);
        
-       value = 0.05f * t->values[0];
+       value = t->values[0];
        
        snapGrid(t, &value);
        
@@ -2299,7 +2465,7 @@ int Shear(TransInfo *t, short mval[2])
        unit_m3(smat);
        
        // Custom data signals shear direction
-       if (t->customData == 0)
+       if (t->customData == NULL)
                smat[1][0] = value;
        else
                smat[0][1] = value;
@@ -2326,8 +2492,8 @@ int Shear(TransInfo *t, short mval[2])
                
                mul_m3_v3(tmat, vec);
                
-               add_v3_v3v3(vec, vec, t->center);
-               sub_v3_v3v3(vec, vec, td->center);
+               add_v3_v3(vec, t->center);
+               sub_v3_v3(vec, td->center);
                
                mul_v3_fl(vec, td->factor);
                
@@ -2363,10 +2529,13 @@ void initResize(TransInfo *t)
        t->snap[0] = 0.0f;
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
+
+       t->num.increment = t->snap[1];
 }
 
 static void headerResize(TransInfo *t, float vec[3], char *str) {
        char tvec[60];
+       char *spos= str;
        if (hasNumInput(&t->num)) {
                outputNumInput(&(t->num), tvec);
        }
@@ -2379,21 +2548,27 @@ static void headerResize(TransInfo *t, float vec[3], char *str) {
        if (t->con.mode & CON_APPLY) {
                switch(t->num.idx_max) {
                case 0:
-                       sprintf(str, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
+                       spos += sprintf(spos, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
                        break;
                case 1:
-                       sprintf(str, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
+                       spos += sprintf(spos, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
                        break;
                case 2:
-                       sprintf(str, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
+                       spos += sprintf(spos, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
                }
        }
        else {
                if (t->flag & T_2D_EDIT)
-                       sprintf(str, "Scale X: %s   Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
+                       spos += sprintf(spos, "Scale X: %s   Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
                else
-                       sprintf(str, "Scale X: %s   Y: %s  Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
+                       spos += sprintf(spos, "Scale X: %s   Y: %s  Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
+       }
+       
+       if (t->flag & (T_PROP_EDIT|T_PROP_CONNECTED)) {
+               spos += sprintf(spos, " Proportional size: %.2f", t->prop_size);
        }
+
+       (void)spos;
 }
 
 #define SIGN(a)                (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
@@ -2476,16 +2651,16 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
                if ((t->flag & T_V3D_ALIGN)==0) {       // align mode doesn't resize objects itself
                        if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
                                /* scale val and reset size */
-                               *td->val = td->ival * (1 + (fsize[0] - 1) * td->factor);
+                                *td->val = td->ival * (1 + (fsize[0] - 1) * td->factor);
                                
                                td->ext->size[0] = td->ext->isize[0];
                                td->ext->size[1] = td->ext->isize[1];
                                td->ext->size[2] = td->ext->isize[2];
-                       }
+                        }
                        else {
                                /* Reset val if SINGLESIZE but using a constraint */
                                if (td->flag & TD_SINGLESIZE)
-                                       *td->val = td->ival;
+                                        *td->val = td->ival;
                                
                                td->ext->size[0] = td->ext->isize[0] * (1 + (fsize[0] - 1) * td->factor);
                                td->ext->size[1] = td->ext->isize[1] * (1 + (fsize[1] - 1) * td->factor);
@@ -2504,11 +2679,11 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
        
        mul_m3_v3(tmat, vec);
        
-       add_v3_v3v3(vec, vec, center);
+       add_v3_v3(vec, center);
        if (t->flag & T_POINTS)
-               sub_v3_v3v3(vec, vec, td->iloc);
+               sub_v3_v3(vec, td->iloc);
        else
-               sub_v3_v3v3(vec, vec, td->center);
+               sub_v3_v3(vec, td->center);
        
        mul_v3_fl(vec, td->factor);
        
@@ -2614,6 +2789,8 @@ void initToSphere(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
        
+       t->num.increment = t->snap[1];
+
        t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
        t->flag |= T_NO_CONSTRAINT;
        
@@ -2625,7 +2802,7 @@ void initToSphere(TransInfo *t)
        t->val /= (float)t->total;
 }
 
-int ToSphere(TransInfo *t, short mval[2])
+int ToSphere(TransInfo *t, short UNUSED(mval[2]))
 {
        float vec[3];
        float ratio, radius;
@@ -2644,6 +2821,8 @@ int ToSphere(TransInfo *t, short mval[2])
        else if (ratio > 1)
                ratio = 1.0f;
        
+       t->values[0] = ratio;
+
        /* header print for NumInput */
        if (hasNumInput(&t->num)) {
                char c[20];
@@ -2688,11 +2867,19 @@ int ToSphere(TransInfo *t, short mval[2])
 /* ************************** ROTATION *************************** */
 
 
+static void postInputRotation(TransInfo *t, float values[3])
+{
+       if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
+               t->con.applyRot(t, NULL, t->axis, values);
+       }
+}
+
 void initRotation(TransInfo *t)
 {
        t->mode = TFM_ROTATION;
        t->transform = Rotation;
        
+       setInputPostFct(&t->mouse, postInputRotation);
        initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
        
        t->ndof.axis = 16;
@@ -2705,12 +2892,15 @@ void initRotation(TransInfo *t)
        t->snap[1] = (float)((5.0/180)*M_PI);
        t->snap[2] = t->snap[1] * 0.2f;
        
+       t->num.increment = 1.0f;
+
        if (t->flag & T_2D_EDIT)
                t->flag |= T_NO_CONSTRAINT;
 
-       VECCOPY(t->axis, t->viewinv[2]);
-       mul_v3_fl(t->axis, -1.0f);
+       negate_v3_v3(t->axis, t->viewinv[2]);
        normalize_v3(t->axis);
+
+       copy_v3_v3(t->axis_orig, t->axis);
 }
 
 static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short around) {
@@ -2745,7 +2935,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                
                
                if(td->flag & TD_USEQUAT) {
-                       mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
+                       mul_serie_m3(fmat, td->mtx, mat, td->smtx, NULL, NULL, NULL, NULL, NULL);
                        mat3_to_quat( quat,fmat);       // Actual transform
                        
                        if(td->ext->quat){
@@ -2783,14 +2973,24 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                        mul_m3_v3(mat, vec);            // Applying rotation
                        mul_m3_v3(imtx, vec);   // To Local space
                        
-                       add_v3_v3v3(vec, vec, center);
+                       add_v3_v3(vec, center);
                        /* vec now is the location where the object has to be */
                        
                        sub_v3_v3v3(vec, vec, td->center); // Translation needed from the initial location
                        
-                       mul_m3_v3(pmtx, vec);   // To Global space
-                       mul_m3_v3(td->smtx, vec);// To Pose space
-                       
+                       /* special exception, see TD_PBONE_LOCAL_MTX definition comments */
+                       if(td->flag & TD_PBONE_LOCAL_MTX_P) {
+                               /* do nothing */
+                       }
+                       else if (td->flag & TD_PBONE_LOCAL_MTX_C) {
+                               mul_m3_v3(pmtx, vec);   // To Global space
+                               mul_m3_v3(td->ext->l_smtx, vec);// To Pose space (Local Location)
+                       }
+                       else {
+                               mul_m3_v3(pmtx, vec);   // To Global space
+                               mul_m3_v3(td->smtx, vec);// To Pose space
+                       }
+
                        protectedTransBits(td->protectflag, vec);
                        
                        add_v3_v3v3(td->loc, td->iloc, vec);
@@ -2801,8 +3001,8 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                /* rotation */
                if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
                        /* euler or quaternion/axis-angle? */
-                       if (td->rotOrder == ROT_MODE_QUAT) {
-                               mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
+                       if (td->ext->rotOrder == ROT_MODE_QUAT) {
+                               mul_serie_m3(fmat, td->mtx, mat, td->smtx, NULL, NULL, NULL, NULL, NULL);
                                
                                mat3_to_quat( quat,fmat);       // Actual transform
                                
@@ -2811,13 +3011,13 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                                protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
                                
                        }
-                       else if (td->rotOrder == ROT_MODE_AXISANGLE) {
+                       else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
                                /* calculate effect based on quats */
                                float iquat[4], tquat[4];
                                
                                axis_angle_to_quat(iquat, td->ext->irotAxis, td->ext->irotAngle);
                                
-                               mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
+                               mul_serie_m3(fmat, td->mtx, mat, td->smtx, NULL, NULL, NULL, NULL, NULL);
                                mat3_to_quat( quat,fmat);       // Actual transform
                                mul_qt_qtqt(tquat, quat, iquat);
                                
@@ -2834,12 +3034,12 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                                
                                /* calculate the total rotatation in eulers */
                                VECCOPY(eul, td->ext->irot);
-                               eulO_to_mat3( eulmat,eul, td->rotOrder);
+                               eulO_to_mat3( eulmat,eul, td->ext->rotOrder);
                                
                                /* mat = transform, obmat = bone rotation */
                                mul_m3_m3m3(fmat, smat, eulmat);
                                
-                               mat3_to_compatible_eulO( eul, td->ext->rot, td->rotOrder,fmat);
+                               mat3_to_compatible_eulO( eul, td->ext->rot, td->ext->rotOrder,fmat);
                                
                                /* and apply (to end result only) */
                                protectedRotateBits(td->protectflag, eul, td->ext->irot);
@@ -2855,9 +3055,9 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                        /* translation */
                        sub_v3_v3v3(vec, td->center, center);
                        mul_m3_v3(mat, vec);
-                       add_v3_v3v3(vec, vec, center);
+                       add_v3_v3(vec, center);
                        /* vec now is the location where the object has to be */
-                       sub_v3_v3v3(vec, vec, td->center);
+                       sub_v3_v3(vec, td->center);
                        mul_m3_v3(td->smtx, vec);
                        
                        protectedTransBits(td->protectflag, vec);
@@ -2871,25 +3071,25 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                /* rotation */
                if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
                        /* euler or quaternion? */
-                   if ((td->rotOrder == ROT_MODE_QUAT) || (td->flag & TD_USEQUAT)) {
-                               mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
+                          if ((td->ext->rotOrder == ROT_MODE_QUAT) || (td->flag & TD_USEQUAT)) {
+                               mul_serie_m3(fmat, td->mtx, mat, td->smtx, NULL, NULL, NULL, NULL, NULL);
                                mat3_to_quat( quat,fmat);       // Actual transform
                                
                                mul_qt_qtqt(td->ext->quat, quat, td->ext->iquat);
                                /* this function works on end result */
                                protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
                        }
-                       else if (td->rotOrder == ROT_MODE_AXISANGLE) {
+                       else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
                                /* calculate effect based on quats */
                                float iquat[4], tquat[4];
                                
                                axis_angle_to_quat(iquat, td->ext->irotAxis, td->ext->irotAngle);
                                
-                               mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
+                               mul_serie_m3(fmat, td->mtx, mat, td->smtx, NULL, NULL, NULL, NULL, NULL);
                                mat3_to_quat( quat,fmat);       // Actual transform
                                mul_qt_qtqt(tquat, quat, iquat);
                                
-                               quat_to_axis_angle( td->ext->rotAxis, td->ext->rotAngle,quat); 
+                               quat_to_axis_angle( td->ext->rotAxis, td->ext->rotAngle,tquat); 
                                
                                /* this function works on end result */
                                protectedAxisAngleBits(td->protectflag, td->ext->rotAxis, td->ext->rotAngle, td->ext->irotAxis, td->ext->irotAngle);
@@ -2902,11 +3102,11 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                                
                                /* calculate the total rotatation in eulers */
                                add_v3_v3v3(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
-                               eulO_to_mat3( obmat,eul, td->rotOrder);
+                               eulO_to_mat3( obmat,eul, td->ext->rotOrder);
                                /* mat = transform, obmat = object rotation */
                                mul_m3_m3m3(fmat, smat, obmat);
                                
-                               mat3_to_compatible_eulO( eul, td->ext->rot, td->rotOrder,fmat);
+                               mat3_to_compatible_eulO( eul, td->ext->rot, td->ext->rotOrder,fmat);
                                
                                /* correct back for delta rot */
                                sub_v3_v3v3(eul, eul, td->ext->drot);
@@ -2949,14 +3149,12 @@ static void applyRotation(TransInfo *t, float angle, float axis[3])
        }
 }
 
-int Rotation(TransInfo *t, short mval[2])
+int Rotation(TransInfo *t, short UNUSED(mval[2]))
 {
-       char str[64];
+       char str[128];
        
        float final;
-       
-       float mat[3][3];
-       
+
        final = t->values[0];
        
        applyNDofInput(&t->ndof, &final);
@@ -2964,12 +3162,10 @@ int Rotation(TransInfo *t, short mval[2])
        snapGrid(t, &final);
        
        if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
-               t->con.applyRot(t, NULL, t->axis, &final);
+               t->con.applyRot(t, NULL, t->axis, NULL);
        } else {
                /* reset axis if constraint is not set */
-               VECCOPY(t->axis, t->viewinv[2]);
-               mul_v3_fl(t->axis, -1.0f);
-               normalize_v3(t->axis);
+               copy_v3_v3(t->axis, t->axis_orig);
        }
        
        applySnapping(t, &final);
@@ -2982,25 +3178,18 @@ int Rotation(TransInfo *t, short mval[2])
                outputNumInput(&(t->num), c);
                
                sprintf(str, "Rot: %s %s %s", &c[0], t->con.text, t->proptext);
-               
+
                /* Clamp between -180 and 180 */
-               while (final >= 180.0)
-                       final -= 360.0;
-               
-               while (final <= -180.0)
-                       final += 360.0;
-               
-               final *= (float)(M_PI / 180.0);
+               final= angle_wrap_rad(DEG2RADF(final));
        }
        else {
-               sprintf(str, "Rot: %.2f%s %s", 180.0*final/M_PI, t->con.text, t->proptext);
+               sprintf(str, "Rot: %.2f%s %s", RAD2DEGF(final), t->con.text, t->proptext);
        }
        
-       vec_rot_to_mat3( mat, t->axis, final);
+       if (t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
+               sprintf(str, "%s Proportional size: %.2f", str, t->prop_size);
        
-       // TRANSFORM_FIX_ME
-//     t->values[0] = final;           // used in manipulator
-//     copy_m3_m3(t->mat, mat);        // used in manipulator
+       t->values[0] = final;
        
        applyRotation(t, final, t->axis);
        
@@ -3032,6 +3221,8 @@ void initTrackball(TransInfo *t)
        t->snap[1] = (float)((5.0/180)*M_PI);
        t->snap[2] = t->snap[1] * 0.2f;
 
+       t->num.increment = 1.0f;
+
        t->flag |= T_NO_CONSTRAINT;
 }
 
@@ -3064,7 +3255,7 @@ static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float a
        }
 }
 
-int Trackball(TransInfo *t, short mval[2])
+int Trackball(TransInfo *t, short UNUSED(mval[2]))
 {
        char str[128];
        float axis1[3], axis2[3];
@@ -3092,11 +3283,11 @@ int Trackball(TransInfo *t, short mval[2])
 
                sprintf(str, "Trackball: %s %s %s", &c[0], &c[20], t->proptext);
 
-               phi[0] *= (float)(M_PI / 180.0);
-               phi[1] *= (float)(M_PI / 180.0);
+               phi[0] = DEG2RADF(phi[0]);
+               phi[1] = DEG2RADF(phi[1]);
        }
        else {
-               sprintf(str, "Trackball: %.2f %.2f %s", 180.0*phi[0]/M_PI, 180.0*phi[1]/M_PI, t->proptext);
+               sprintf(str, "Trackball: %.2f %.2f %s", RAD2DEGF(phi[0]), RAD2DEGF(phi[1]), t->proptext);
        }
 
        vec_rot_to_mat3( smat,axis1, phi[0]);
@@ -3149,6 +3340,8 @@ void initTranslation(TransInfo *t)
                t->snap[0] = 0.0f;
                t->snap[1] = t->snap[2] = 1.0f;
        }
+
+       t->num.increment = t->snap[1];
 }
 
 static void headerTranslation(TransInfo *t, float vec[3], char *str) {
@@ -3168,7 +3361,7 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) {
                applyAspectRatio(t, dvec);
 
                dist = len_v3(vec);
-               if(t->scene->unit.system) {
+               if(!(t->flag & T_2D_EDIT) && t->scene->unit.system) {
                        int i, do_split= t->scene->unit.flag & USER_UNIT_OPT_SPLIT ? 1:0;
 
                        for(i=0; i<3; i++)
@@ -3181,9 +3374,9 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) {
                }
        }
 
-       if(t->scene->unit.system)
+       if(!(t->flag & T_2D_EDIT) && t->scene->unit.system)
                bUnit_AsString(distvec, sizeof(distvec), dist*t->scene->unit.scale_length, 4, t->scene->unit.system, B_UNIT_LENGTH, t->scene->unit.flag & USER_UNIT_OPT_SPLIT, 0);
-       else if( dist > 1e10 || dist < -1e10 )  /* prevent string buffer overflow */
+       else if( dist > 1e10f || dist < -1e10f )        /* prevent string buffer overflow */
                sprintf(distvec, "%.4e", dist);
        else
                sprintf(distvec, "%.4f", dist);
@@ -3217,6 +3410,9 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) {
                else
                        sprintf(str, "Dx: %s   Dy: %s  Dz: %s (%s)%s %s  %s", &tvec[0], &tvec[20], &tvec[40], distvec, t->con.text, t->proptext, &autoik[0]);
        }
+       
+       if (t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
+               sprintf(str, "%s Proportional size: %.2f", str, t->prop_size);
 }
 
 static void applyTranslation(TransInfo *t, float vec[3]) {
@@ -3281,13 +3477,16 @@ static void applyTranslation(TransInfo *t, float vec[3]) {
 }
 
 /* uses t->vec to store actual translation in */
-int Translation(TransInfo *t, short mval[2])
+int Translation(TransInfo *t, short UNUSED(mval[2]))
 {
        char str[250];
 
        if (t->con.mode & CON_APPLY) {
                float pvec[3] = {0.0f, 0.0f, 0.0f};
                float tvec[3];
+               if (hasNumInput(&t->num)) {
+                       removeAspectRatio(t, t->values);
+               }
                applySnapping(t, t->values);
                t->con.applyVec(t, NULL, t->values, tvec, pvec);
                VECCOPY(t->values, tvec);
@@ -3297,11 +3496,9 @@ int Translation(TransInfo *t, short mval[2])
                applyNDofInput(&t->ndof, t->values);
                snapGrid(t, t->values);
                applyNumInput(&t->num, t->values);
-               if (hasNumInput(&t->num))
-               {
+               if (hasNumInput(&t->num)) {
                        removeAspectRatio(t, t->values);
                }
-
                applySnapping(t, t->values);
                headerTranslation(t, t->values, str);
        }
@@ -3339,13 +3536,15 @@ void initShrinkFatten(TransInfo *t)
                t->snap[1] = 1.0f;
                t->snap[2] = t->snap[1] * 0.1f;
 
+               t->num.increment = t->snap[1];
+
                t->flag |= T_NO_CONSTRAINT;
        }
 }
 
 
 
-int ShrinkFatten(TransInfo *t, short mval[2])
+int ShrinkFatten(TransInfo *t, short UNUSED(mval[2]))
 {
        float vec[3];
        float distance;
@@ -3413,12 +3612,14 @@ void initTilt(TransInfo *t)
        t->snap[1] = (float)((5.0/180)*M_PI);
        t->snap[2] = t->snap[1] * 0.2f;
 
-       t->flag |= T_NO_CONSTRAINT;
+       t->num.increment = t->snap[1];
+
+       t->flag |= T_NO_CONSTRAINT|T_NO_PROJECT;
 }
 
 
 
-int Tilt(TransInfo *t, short mval[2])
+int Tilt(TransInfo *t, short UNUSED(mval[2]))
 {
        TransData *td = t->data;
        int i;
@@ -3441,10 +3642,10 @@ int Tilt(TransInfo *t, short mval[2])
 
                sprintf(str, "Tilt: %s %s", &c[0], t->proptext);
 
-               final *= (float)(M_PI / 180.0);
+               final = DEG2RADF(final);
        }
        else {
-               sprintf(str, "Tilt: %.2f %s", 180.0*final/M_PI, t->proptext);
+               sprintf(str, "Tilt: %.2f %s", RAD2DEGF(final), t->proptext);
        }
 
        for(i = 0 ; i < t->total; i++, td++) {
@@ -3482,13 +3683,15 @@ void initCurveShrinkFatten(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
 
+       t->num.increment = t->snap[1];
+
        t->flag |= T_NO_ZERO;
        t->num.flag |= NUM_NO_ZERO;
 
        t->flag |= T_NO_CONSTRAINT;
 }
 
-int CurveShrinkFatten(TransInfo *t, short mval[2])
+int CurveShrinkFatten(TransInfo *t, short UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float ratio;
@@ -3551,10 +3754,12 @@ void initPushPull(TransInfo *t)
        t->snap[0] = 0.0f;
        t->snap[1] = 1.0f;
        t->snap[2] = t->snap[1] * 0.1f;
+
+       t->num.increment = t->snap[1];
 }
 
 
-int PushPull(TransInfo *t, short mval[2])
+int PushPull(TransInfo *t, short UNUSED(mval[2]))
 {
        float vec[3], axis[3];
        float distance;
@@ -3600,7 +3805,7 @@ int PushPull(TransInfo *t, short mval[2])
                        if (isLockConstraint(t)) {
                                float dvec[3];
                                project_v3_v3v3(dvec, vec, axis);
-                               sub_v3_v3v3(vec, vec, dvec);
+                               sub_v3_v3(vec, dvec);
                        }
                        else {
                                project_v3_v3v3(vec, vec, axis);
@@ -3639,6 +3844,8 @@ void initBevel(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
 
+       t->num.increment = t->snap[1];
+
        /* DON'T KNOW WHY THIS IS NEEDED */
        if (G.editBMesh->imval[0] == 0 && G.editBMesh->imval[1] == 0) {
                /* save the initial mouse co */
@@ -3685,12 +3892,12 @@ int handleEventBevel(TransInfo *t, wmEvent *event)
        return 0;
 }
 
-int Bevel(TransInfo *t, short mval[2])
+int Bevel(TransInfo *t, short UNUSED(mval[2]))
 {
        float distance,d;
        int i;
        char str[128];
-       char *mode;
+       const char *mode;
        TransData *td = t->data;
 
        mode = (G.editBMesh->options & BME_BEVEL_VERT) ? "verts only" : "normal";
@@ -3748,10 +3955,12 @@ void initBevelWeight(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
 
-       t->flag |= T_NO_CONSTRAINT;
+       t->num.increment = t->snap[1];
+
+       t->flag |= T_NO_CONSTRAINT|T_NO_PROJECT;
 }
 
-int BevelWeight(TransInfo *t, short mval[2])
+int BevelWeight(TransInfo *t, short UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float weight;
@@ -3819,10 +4028,12 @@ void initCrease(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
 
-       t->flag |= T_NO_CONSTRAINT;
+       t->num.increment = t->snap[1];
+
+       t->flag |= T_NO_CONSTRAINT|T_NO_PROJECT;
 }
 
-int Crease(TransInfo *t, short mval[2])
+int Crease(TransInfo *t, short UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float crease;
@@ -3890,9 +4101,12 @@ void initBoneSize(TransInfo *t)
        t->idx_max = 2;
        t->num.idx_max = 2;
        t->num.flag |= NUM_NULL_ONE;
+       t->num.flag |= NUM_AFFECT_ALL;
        t->snap[0] = 0.0f;
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
+
+       t->num.increment = t->snap[1];
 }
 
 static void headerBoneSize(TransInfo *t, float vec[3], char *str) {
@@ -4009,10 +4223,12 @@ void initBoneEnvelope(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
        
-       t->flag |= T_NO_CONSTRAINT;
+       t->num.increment = t->snap[1];
+
+       t->flag |= T_NO_CONSTRAINT|T_NO_PROJECT;
 }
 
-int BoneEnvelope(TransInfo *t, short mval[2])
+int BoneEnvelope(TransInfo *t, short UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float ratio;
@@ -4079,7 +4295,7 @@ static int createSlideVerts(TransInfo *t)
        int  uvlay_tot= CustomData_number_of_layers(&em->fdata, CD_MTFACE);
        int uvlay_idx;
        TransDataSlideUv *slideuvs=NULL, *suv=NULL, *suv_last=NULL;
-       RegionView3D *v3d = t->ar->regiondata;
+       RegionView3D *v3d = t->ar ? t->ar->regiondata : NULL; /* background mode support */
        float projectMat[4][4];
        float start[3] = {0.0f, 0.0f, 0.0f}, end[3] = {0.0f, 0.0f, 0.0f};
        float vec[3];
@@ -4114,6 +4330,7 @@ static int createSlideVerts(TransInfo *t)
                        efa->e1->f1++;
                        if(efa->e1->f1 > 2) {
                                //BKE_report(op->reports, RPT_ERROR, "3+ face edge");
+                               MEM_freeN(sld);
                                return 0;
                        }
                }
@@ -4122,6 +4339,7 @@ static int createSlideVerts(TransInfo *t)
                        efa->e2->f1++;
                        if(efa->e2->f1 > 2) {
                                //BKE_report(op->reports, RPT_ERROR, "3+ face edge");
+                               MEM_freeN(sld);
                                return 0;
                        }
                }
@@ -4130,6 +4348,7 @@ static int createSlideVerts(TransInfo *t)
                        efa->e3->f1++;
                        if(efa->e3->f1 > 2) {
                                //BKE_report(op->reports, RPT_ERROR, "3+ face edge");
+                               MEM_freeN(sld);
                                return 0;
                        }
                }
@@ -4138,13 +4357,15 @@ static int createSlideVerts(TransInfo *t)
                        efa->e4->f1++;
                        if(efa->e4->f1 > 2) {
                                //BKE_report(op->reports, RPT_ERROR, "3+ face edge");
+                               MEM_freeN(sld);
                                return 0;
                        }
                }
                // Make sure loop is not 2 edges of same face
                if(ct > 1) {
                   //BKE_report(op->reports, RPT_ERROR, "Loop crosses itself");
-                  return 0;
+                       MEM_freeN(sld);
+                       return 0;
                }
        }
 
@@ -4156,6 +4377,7 @@ static int createSlideVerts(TransInfo *t)
        // Test for multiple segments
        if(vertsel > numsel+1) {
                //BKE_report(op->reports, RPT_ERROR, "Please choose a single edge loop");
+               MEM_freeN(sld);
                return 0;
        }
 
@@ -4192,6 +4414,7 @@ static int createSlideVerts(TransInfo *t)
                if(timesthrough >= numsel*2) {
                        BLI_linklist_free(edgelist,NULL);
                        //BKE_report(op->reports, RPT_ERROR, "Could not order loop");
+                       MEM_freeN(sld);
                        return 0;
                }
        }
@@ -4231,7 +4454,7 @@ static int createSlideVerts(TransInfo *t)
 
        // populate the SlideVerts
 
-       vertgh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
+       vertgh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "createSlideVerts gh");
        look = vertlist;
        while(look) {
                i=0;
@@ -4262,11 +4485,11 @@ static int createSlideVerts(TransInfo *t)
                        for(eed=em->edges.first;eed;eed=eed->next) {
                                if(editedge_containsVert(eed, ev)) {
                                        if(!(eed->f & SELECT)) {
-                                                if(!tempsv->up) {
-                                                        tempsv->up = eed;
-                                                } else if (!(tempsv->down)) {
-                                                        tempsv->down = eed;
-                                                }
+                                               if(!tempsv->up) {
+                                                       tempsv->up = eed;
+                                               } else if (!(tempsv->down)) {
+                                                       tempsv->down = eed;
+                                               }
                                        }
                                }
                        }
@@ -4278,33 +4501,33 @@ static int createSlideVerts(TransInfo *t)
                                        for(efa = em->faces.first;efa;efa=efa->next) {
                                                if(editface_containsEdge(efa, eed)) {
                                                        if(editedge_containsVert(efa->e1, ev) && efa->e1 != eed) {
-                                                                if(!tempsv->up) {
-                                                                        tempsv->up = efa->e1;
-                                                                } else if (!(tempsv->down)) {
-                                                                        tempsv->down = efa->e1;
-                                                                }
+                                                               if(!tempsv->up) {
+                                                                       tempsv->up = efa->e1;
+                                                               } else if (!(tempsv->down)) {
+                                                                       tempsv->down = efa->e1;
+                                                               }
                                                        }
                                                        if(editedge_containsVert(efa->e2, ev) && efa->e2 != eed) {
-                                                                if(!tempsv->up) {
-                                                                        tempsv->up = efa->e2;
-                                                                } else if (!(tempsv->down)) {
-                                                                        tempsv->down = efa->e2;
-                                                                }
+                                                               if(!tempsv->up) {
+                                                                       tempsv->up = efa->e2;
+                                                               } else if (!(tempsv->down)) {
+                                                                       tempsv->down = efa->e2;
+                                                               }
                                                        }
                                                        if(editedge_containsVert(efa->e3, ev) && efa->e3 != eed) {
-                                                                if(!tempsv->up) {
-                                                                        tempsv->up = efa->e3;
-                                                                } else if (!(tempsv->down)) {
-                                                                        tempsv->down = efa->e3;
-                                                                }
+                                                               if(!tempsv->up) {
+                                                                       tempsv->up = efa->e3;
+                                                               } else if (!(tempsv->down)) {
+                                                                       tempsv->down = efa->e3;
+                                                               }
                                                        }
                                                        if(efa->e4) {
                                                                if(editedge_containsVert(efa->e4, ev) && efa->e4 != eed) {
-                                                                        if(!tempsv->up) {
-                                                                                tempsv->up = efa->e4;
-                                                                        } else if (!(tempsv->down)) {
-                                                                                tempsv->down = efa->e4;
-                                                                        }
+                                                                       if(!tempsv->up) {
+                                                                               tempsv->up = efa->e4;
+                                                                       } else if (!(tempsv->down)) {
+                                                                               tempsv->down = efa->e4;
+                                                                       }
                                                                }
                                                        }
 
@@ -4324,7 +4547,7 @@ static int createSlideVerts(TransInfo *t)
                look = look->next;
        }
 
-       // make sure the UPs nad DOWNs are 'faceloops'
+       // make sure the UPs and DOWNs are 'faceloops'
        // Also find the nearest slidevert to the cursor
 
        look = vertlist;
@@ -4341,7 +4564,7 @@ static int createSlideVerts(TransInfo *t)
                        return 0;
                }
 
-               if(me->drawflag & ME_DRAW_EDGELEN) {
+               if(me->drawflag & ME_DRAWEXTRA_EDGELEN) {
                        if(!(tempsv->up->f & SELECT)) {
                                tempsv->up->f |= SELECT;
                                tempsv->up->f2 |= 16;
@@ -4363,7 +4586,7 @@ static int createSlideVerts(TransInfo *t)
                        sv = BLI_ghash_lookup(vertgh, ev);
 
                        if(sv) {
-                               float co[3], co2[3], vec[3];
+                               float co[3], co2[3], tvec[3];
 
                                ev = (EditVert*)look->link;
 
@@ -4380,12 +4603,12 @@ static int createSlideVerts(TransInfo *t)
                                }
 
                                if (ev == tempsv->up->v1) {
-                                       sub_v3_v3v3(vec, co, co2);
+                                       sub_v3_v3v3(tvec, co, co2);
                                } else {
-                                       sub_v3_v3v3(vec, co2, co);
+                                       sub_v3_v3v3(tvec, co2, co);
                                }
 
-                               add_v3_v3v3(start, start, vec);
+                               add_v3_v3(start, tvec);
 
                                if (v3d) {
                                        view3d_project_float(t->ar, tempsv->down->v1->co, co, projectMat);
@@ -4393,12 +4616,12 @@ static int createSlideVerts(TransInfo *t)
                                }
 
                                if (ev == tempsv->down->v1) {
-                                       sub_v3_v3v3(vec, co2, co);
+                                       sub_v3_v3v3(tvec, co2, co);
                                } else {
-                                       sub_v3_v3v3(vec, co, co2);
+                                       sub_v3_v3v3(tvec, co, co2);
                                }
 
-                               add_v3_v3v3(end, end, vec);
+                               add_v3_v3(end, tvec);
 
                                totvec += 1.0f;
                                nearest = (EditVert*)look->link;
@@ -4410,13 +4633,32 @@ static int createSlideVerts(TransInfo *t)
                look = look->next;
        }
 
-       add_v3_v3v3(start, start, end);
-       mul_v3_fl(start, 0.5*(1.0/totvec));
+       add_v3_v3(start, end);
+       mul_v3_fl(start, 0.5f*(1.0f/totvec));
        VECCOPY(vec, start);
        start[0] = t->mval[0];
        start[1] = t->mval[1];
        add_v3_v3v3(end, start, vec);
-       
+
+
+       /* Ensure minimum screen distance, when looking top down on edge loops */
+#define EDGE_SLIDE_MIN 30
+       if (len_squared_v2v2(start, end) < (EDGE_SLIDE_MIN * EDGE_SLIDE_MIN)) {
+               if(ABS(start[0]-end[0]) + ABS(start[1]-end[1]) < 4.0f) {
+                       /* even more exceptional case, points are ontop of eachother */
+                       end[0]= start[0];
+                       end[1]= start[1] + EDGE_SLIDE_MIN;
+               }
+               else {
+                       sub_v2_v2(end, start);
+                       normalize_v2(end);
+                       mul_v2_fl(end, EDGE_SLIDE_MIN);
+                       add_v2_v2(end, start);
+               }
+       }
+#undef EDGE_SLIDE_MIN
+
+
        sld->start[0] = (short) start[0];
        sld->start[1] = (short) start[1];
        sld->end[0] = (short) end[0];
@@ -4432,7 +4674,7 @@ static int createSlideVerts(TransInfo *t)
 
                for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) {
 
-                       uvarray[uvlay_idx] = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
+                       uvarray[uvlay_idx] = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "createSlideVerts2 gh");
 
                        for(ev=em->verts.first;ev;ev=ev->next) {
                                ev->tmp.l = 0;
@@ -4461,7 +4703,7 @@ static int createSlideVerts(TransInfo *t)
                                                        uv_new = tf->uv[k];
 
                                                        if (ev->tmp.l) {
-                                                               if (fabs(suv->origuv[0]-uv_new[0]) > 0.0001 || fabs(suv->origuv[1]-uv_new[1])) {
+                                                               if (fabs(suv->origuv[0]-uv_new[0]) > 0.0001f || fabs(suv->origuv[1]-uv_new[1]) > 0.0001f) {
                                                                        ev->tmp.l = -1; /* Tag as invalid */
                                                                        BLI_linklist_free(suv->fuv_list,NULL);
                                                                        suv->fuv_list = NULL;
@@ -4533,8 +4775,23 @@ void freeSlideVerts(TransInfo *t)
 {
        TransDataSlideUv *suv;
        SlideData *sld = t->customData;
+       Mesh *me = t->obedit->data;
        int uvlay_idx;
 
+       if(me->drawflag & ME_DRAWEXTRA_EDGELEN) {
+               TransDataSlideVert *tempsv;
+               LinkNode *look = sld->vertlist;
+               GHash *vertgh = sld->vhash;
+               while(look) {
+                       tempsv  = BLI_ghash_lookup(vertgh,(EditVert*)look->link);
+                       if(tempsv != NULL) {
+                               tempsv->up->f &= !SELECT;
+                               tempsv->down->f &= !SELECT;
+                       }
+                       look = look->next;
+               }
+       }
+
        //BLI_ghash_free(edgesgh, freeGHash, NULL);
        BLI_ghash_free(sld->vhash, NULL, (GHashValFreeFP)MEM_freeN);
        BLI_linklist_free(sld->vertlist, NULL);
@@ -4568,7 +4825,11 @@ void initEdgeSlide(TransInfo *t)
        t->mode = TFM_EDGE_SLIDE;
        t->transform = EdgeSlide;
        
-       createSlideVerts(t);
+       if(!createSlideVerts(t)) {
+               t->state= TRANS_CANCEL;
+               return;
+       }
+       
        sld = t->customData;
 
        if (!sld)
@@ -4586,7 +4847,9 @@ void initEdgeSlide(TransInfo *t)
        t->snap[1] = (float)((5.0/180)*M_PI);
        t->snap[2] = t->snap[1] * 0.2f;
 
-       t->flag |= T_NO_CONSTRAINT;
+       t->num.increment = t->snap[1];
+
+       t->flag |= T_NO_CONSTRAINT|T_NO_PROJECT;
 }
 
 int doEdgeSlide(TransInfo *t, float perc)
@@ -4599,18 +4862,16 @@ int doEdgeSlide(TransInfo *t, float perc)
        LinkNode *vertlist=sld->vertlist, *look;
        GHash *vertgh = sld->vhash;
        TransDataSlideVert *tempsv;
-       float len = 0.0f;
+       float len;
        int prop=1, flip=0;
        /* UV correction vars */
        GHash **uvarray= sld->uvhash;
        int  uvlay_tot= CustomData_number_of_layers(&em->fdata, CD_MTFACE);
        int uvlay_idx;
-       TransDataSlideUv *suv=sld->slideuv;
+       TransDataSlideUv *suv;
        float uv_tmp[2];
        LinkNode *fuv_link;
 
-       len = 0.0f;
-
        tempsv = BLI_ghash_lookup(vertgh,nearest);
 
        centerVert = editedge_getSharedVert(tempsv->up, tempsv->down);
@@ -4652,12 +4913,13 @@ int doEdgeSlide(TransInfo *t, float perc)
                //Non prop code
                look = vertlist;
                while(look) {
-                       float newlen;
+                       float newlen, edgelen;
                        ev = look->link;
                        tempsv = BLI_ghash_lookup(vertgh,ev);
-                       newlen = (len / len_v3v3(editedge_getOtherVert(tempsv->up,ev)->co,editedge_getOtherVert(tempsv->down,ev)->co));
-                       if(newlen > 1.0) {newlen = 1.0;}
-                       if(newlen < 0.0) {newlen = 0.0;}
+                       edgelen = len_v3v3(editedge_getOtherVert(tempsv->up,ev)->co,editedge_getOtherVert(tempsv->down,ev)->co);
+                       newlen = (edgelen != 0.0f)? (len / edgelen): 0.0f;
+                       if(newlen > 1.0f) {newlen = 1.0;}
+                       if(newlen < 0.0f) {newlen = 0.0;}
                        if(flip == 0) {
                                interp_v3_v3v3(ev->co, editedge_getOtherVert(tempsv->down,ev)->co, editedge_getOtherVert(tempsv->up,ev)->co, fabs(newlen));
                                if (uvlay_tot) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) {
@@ -4700,7 +4962,7 @@ int doEdgeSlide(TransInfo *t, float perc)
        return 1;
 }
 
-int EdgeSlide(TransInfo *t, short mval[2])
+int EdgeSlide(TransInfo *t, short UNUSED(mval[2]))
 {
        char str[50];
        float final;
@@ -4754,10 +5016,12 @@ void initBoneRoll(TransInfo *t)
        t->snap[1] = (float)((5.0/180)*M_PI);
        t->snap[2] = t->snap[1] * 0.2f;
 
-       t->flag |= T_NO_CONSTRAINT;
+       t->num.increment = 1.0f;
+
+       t->flag |= T_NO_CONSTRAINT|T_NO_PROJECT;
 }
 
-int BoneRoll(TransInfo *t, short mval[2])
+int BoneRoll(TransInfo *t, short UNUSED(mval[2]))
 {
        TransData *td = t->data;
        int i;
@@ -4778,10 +5042,10 @@ int BoneRoll(TransInfo *t, short mval[2])
 
                sprintf(str, "Roll: %s", &c[0]);
 
-               final *= (float)(M_PI / 180.0);
+               final = DEG2RADF(final);
        }
        else {
-               sprintf(str, "Roll: %.2f", 180.0*final/M_PI);
+               sprintf(str, "Roll: %.2f", RAD2DEGF(final));
        }
 
        /* set roll values */
@@ -4814,6 +5078,8 @@ void initBakeTime(TransInfo *t)
        t->snap[0] = 0.0f;
        t->snap[1] = 1.0f;
        t->snap[2] = t->snap[1] * 0.1f;
+
+       t->num.increment = t->snap[1];
 }
 
 int BakeTime(TransInfo *t, short mval[2])
@@ -4891,7 +5157,7 @@ void initMirror(TransInfo *t)
        }
 }
 
-int Mirror(TransInfo *t, short mval[2])
+int Mirror(TransInfo *t, short UNUSED(mval[2]))
 {
        TransData *td;
        float size[3], mat[3][3];
@@ -4968,7 +5234,7 @@ void initAlign(TransInfo *t)
        initMouseInputMode(t, &t->mouse, INPUT_NONE);
 }
 
-int Align(TransInfo *t, short mval[2])
+int Align(TransInfo *t, short UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float center[3];
@@ -5031,6 +5297,8 @@ void initSeqSlide(TransInfo *t)
        t->snap[0] = 0.0f;
        t->snap[1] = floor(t->scene->r.frs_sec / t->scene->r.frs_sec_base);
        t->snap[2] = 10.0f;
+
+       t->num.increment = t->snap[1];
 }
 
 static void headerSeqSlide(TransInfo *t, float val[2], char *str)
@@ -5069,7 +5337,7 @@ static void applySeqSlide(TransInfo *t, float val[2]) {
        }
 }
 
-int SeqSlide(TransInfo *t, short mval[2])
+int SeqSlide(TransInfo *t, short UNUSED(mval[2]))
 {
        char str[200];
 
@@ -5085,8 +5353,8 @@ int SeqSlide(TransInfo *t, short mval[2])
                applyNumInput(&t->num, t->values);
        }
 
-       t->values[0] = floor(t->values[0] + 0.5);
-       t->values[1] = floor(t->values[1] + 0.5);
+       t->values[0] = floor(t->values[0] + 0.5f);
+       t->values[1] = floor(t->values[1] + 0.5f);
 
        headerSeqSlide(t, t->values, str);
        applySeqSlide(t, t->values);
@@ -5180,27 +5448,27 @@ static short getAnimEdit_DrawTime(TransInfo *t)
 /* This function is used by Animation Editor specific transform functions to do
  * the Snap Keyframe to Nearest Frame/Marker
  */
-static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, AnimData *adt, short autosnap)
+static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, TransData2D *td2d, AnimData *adt, short autosnap)
 {
        /* snap key to nearest frame? */
        if (autosnap == SACTSNAP_FRAME) {
                const Scene *scene= t->scene;
-               const short doTime= getAnimEdit_DrawTime(t);
+               const short doTime= 0; //getAnimEdit_DrawTime(t); // NOTE: this works, but may be confusing behaviour given the option's label, hence disabled
                const double secf= FPS;
                double val;
-
+               
                /* convert frame to nla-action time (if needed) */
                if (adt)
                        val= BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_MAP);
                else
                        val= *(td->val);
-
+               
                /* do the snapping to nearest frame/second */
                if (doTime)
                        val= (float)( floor((val/secf) + 0.5f) * secf );
                else
                        val= (float)( floor(val+0.5f) );
-
+               
                /* convert frame out of nla-action time */
                if (adt)
                        *(td->val)= BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP);
@@ -5210,29 +5478,45 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, AnimData *adt, sho
        /* snap key to nearest marker? */
        else if (autosnap == SACTSNAP_MARKER) {
                float val;
-
+               
                /* convert frame to nla-action time (if needed) */
                if (adt)
                        val= BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_MAP);
                else
                        val= *(td->val);
-
+               
                /* snap to nearest marker */
                // TODO: need some more careful checks for where data comes from
                val= (float)ED_markers_find_nearest_marker_time(&t->scene->markers, val);
-
+               
                /* convert frame out of nla-action time */
                if (adt)
                        *(td->val)= BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP);
                else
                        *(td->val)= val;
        }
+       
+       /* if the handles are to be moved too (as side-effect of keyframes moving, to keep the general effect) 
+        * offset them by the same amount so that the general angles are maintained (i.e. won't change while 
+        * handles are free-to-roam and keyframes are snap-locked)
+        */
+       if ((td->flag & TD_MOVEHANDLE1) && td2d->h1) {
+               td2d->h1[0] = td2d->ih1[0] + *td->val - td->ival;
+       }
+       if ((td->flag & TD_MOVEHANDLE2) && td2d->h2) {
+               td2d->h2[0] = td2d->ih2[0] + *td->val - td->ival;
+       }
 }
 
 /* ----------------- Translation ----------------------- */
 
 void initTimeTranslate(TransInfo *t)
 {
+       /* this tool is only really available in the Action Editor... */
+       if (t->spacetype != SPACE_ACTION) {
+               t->state = TRANS_CANCEL;
+       }
+
        t->mode = TFM_TIME_TRANSLATE;
        t->transform = TimeTranslate;
 
@@ -5246,6 +5530,8 @@ void initTimeTranslate(TransInfo *t)
        /* initialise snap like for everything else */
        t->snap[0] = 0.0f;
        t->snap[1] = t->snap[2] = 1.0f;
+
+       t->num.increment = t->snap[1];
 }
 
 static void headerTimeTranslate(TransInfo *t, char *str)
@@ -5284,9 +5570,10 @@ static void headerTimeTranslate(TransInfo *t, char *str)
        sprintf(str, "DeltaX: %s", &tvec[0]);
 }
 
-static void applyTimeTranslate(TransInfo *t, float sval)
+static void applyTimeTranslate(TransInfo *t, float UNUSED(sval))
 {
        TransData *td = t->data;
+       TransData2D *td2d = t->data2d;
        Scene *scene = t->scene;
        int i;
 
@@ -5295,16 +5582,18 @@ static void applyTimeTranslate(TransInfo *t, float sval)
 
        const short autosnap= getAnimEdit_SnapMode(t);
 
-       float deltax, val;
+       float deltax, val, valprev;
 
        /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */
-       for (i = 0 ; i < t->total; i++, td++) {
+       for (i = 0 ; i < t->total; i++, td++, td2d++) {
                /* it is assumed that td->extra is a pointer to the AnimData,
                 * whose active action is where this keyframe comes from
                 * (this is only valid when not in NLA)
                 */
                AnimData *adt= (t->spacetype != SPACE_NLA) ? td->extra : NULL;
 
+               valprev = *td->val;
+
                /* check if any need to apply nla-mapping */
                if (adt && t->spacetype != SPACE_SEQ) {
                        deltax = t->values[0];
@@ -5334,7 +5623,7 @@ static void applyTimeTranslate(TransInfo *t, float sval)
                }
 
                /* apply nearest snapping */
-               doAnimEdit_SnapFrame(t, td, adt, autosnap);
+               doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap);
        }
 }
 
@@ -5376,8 +5665,11 @@ void initTimeSlide(TransInfo *t)
 
                /* set flag for drawing stuff */
                saction->flag |= SACTION_MOVING;
+       } else {
+               t->state = TRANS_CANCEL;
        }
 
+
        t->mode = TFM_TIME_SLIDE;
        t->transform = TimeSlide;
        t->flag |= T_FREE_CUSTOMDATA;
@@ -5392,6 +5684,8 @@ void initTimeSlide(TransInfo *t)
        /* initialise snap like for everything else */
        t->snap[0] = 0.0f;
        t->snap[1] = t->snap[2] = 1.0f;
+
+       t->num.increment = t->snap[1];
 }
 
 static void headerTimeSlide(TransInfo *t, float sval, char *str)
@@ -5476,12 +5770,13 @@ int TimeSlide(TransInfo *t, short mval[2])
        UI_view2d_region_to_view(v2d, t->imval[0], t->imval[0], &sval[0], &sval[1]);
 
        /* t->values[0] stores cval[0], which is the current mouse-pointer location (in frames) */
+       // XXX Need to be able to repeat this
        t->values[0] = cval[0];
 
        /* handle numeric-input stuff */
        t->vec[0] = 2.0f*(cval[0]-sval[0]) / (maxx-minx);
        applyNumInput(&t->num, &t->vec[0]);
-       t->values[0] = (maxx-minx) * t->vec[0] / 2.0 + sval[0];
+       t->values[0] = (maxx-minx) * t->vec[0] / 2.0f + sval[0];
 
        headerTimeSlide(t, sval[0], str);
        applyTimeSlide(t, sval[0]);
@@ -5499,6 +5794,13 @@ void initTimeScale(TransInfo *t)
 {
        int center[2];
 
+       /* this tool is only really available in the Action Editor
+        * AND NLA Editor (for strip scaling)
+        */
+       if (ELEM(t->spacetype, SPACE_ACTION, SPACE_NLA) == 0) {
+               t->state = TRANS_CANCEL;
+       }
+
        t->mode = TFM_TIME_SCALE;
        t->transform = TimeScale;
 
@@ -5524,6 +5826,8 @@ void initTimeScale(TransInfo *t)
        /* initialise snap like for everything else */
        t->snap[0] = 0.0f;
        t->snap[1] = t->snap[2] = 1.0f;
+
+       t->num.increment = t->snap[1];
 }
 
 static void headerTimeScale(TransInfo *t, char *str) {
@@ -5540,6 +5844,7 @@ static void headerTimeScale(TransInfo *t, char *str) {
 static void applyTimeScale(TransInfo *t) {
        Scene *scene = t->scene;
        TransData *td = t->data;
+       TransData2D *td2d = t->data2d;
        int i;
 
        const short autosnap= getAnimEdit_SnapMode(t);
@@ -5547,7 +5852,7 @@ static void applyTimeScale(TransInfo *t) {
        const double secf= FPS;
 
 
-       for (i = 0 ; i < t->total; i++, td++) {
+       for (i = 0 ; i < t->total; i++, td++, td2d++) {
                /* it is assumed that td->extra is a pointer to the AnimData,
                 * whose active action is where this keyframe comes from
                 * (this is only valid when not in NLA)
@@ -5573,11 +5878,11 @@ static void applyTimeScale(TransInfo *t) {
                *(td->val) += startx;
 
                /* apply nearest snapping */
-               doAnimEdit_SnapFrame(t, td, adt, autosnap);
+               doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap);
        }
 }
 
-int TimeScale(TransInfo *t, short mval[2])
+int TimeScale(TransInfo *t, short UNUSED(mval[2]))
 {
        char str[200];
        
@@ -5598,21 +5903,21 @@ int TimeScale(TransInfo *t, short mval[2])
 
 /* ************************************ */
 
-void BIF_TransformSetUndo(char *str)
+void BIF_TransformSetUndo(char *UNUSED(str))
 {
        // TRANSFORM_FIX_ME
        //Trans.undostr= str;
 }
 
 
-void NDofTransform()
-{
 #if 0 // TRANSFORM_FIX_ME
-    float fval[7];
-    float maxval = 50.0f; // also serves as threshold
-    int axis = -1;
-    int mode = 0;
-    int i;
+static void NDofTransform(void)
+{
+       float fval[7];
+       float maxval = 50.0f; // also serves as threshold
+       int axis = -1;
+       int mode = 0;
+       int i;
 
        getndof(fval);
 
@@ -5652,5 +5957,5 @@ void NDofTransform()
                initTransform(mode, CTX_NDOF);
                Transform();
        }
-#endif
 }
+#endif