Fix T42444: Neg scale rotated object flips 2x axis
[blender.git] / source / blender / editors / transform / transform.c
index 87ef3d6742a0b7ced9b35eeda0ebd4059c852269..d704f62654baaaab0591de3328ef63213863be63 100644 (file)
 #include <math.h>
 #include <float.h>
 
-#ifndef WIN32
-#  include <unistd.h>
-#else
-#  include <io.h>
-#endif
-
 #include "MEM_guardedalloc.h"
 
 #include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_constraint_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
 #include "DNA_mask_types.h"
 #include "DNA_movieclip_types.h"
 #include "DNA_scene_types.h"  /* PET modes */
 #include "BLI_listbase.h"
 #include "BLI_string.h"
 #include "BLI_ghash.h"
-#include "BLI_linklist.h"
 
 #include "BKE_nla.h"
 #include "BKE_editmesh_bvh.h"
 #include "BKE_context.h"
 #include "BKE_constraint.h"
-#include "BKE_global.h"
 #include "BKE_particle.h"
-#include "BKE_pointcache.h"
 #include "BKE_unit.h"
 #include "BKE_mask.h"
+#include "BKE_report.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
@@ -81,7 +71,7 @@
 #include "ED_view3d.h"
 #include "ED_mesh.h"
 #include "ED_clip.h"
-#include "ED_mask.h"
+#include "ED_node.h"
 
 #include "WM_types.h"
 #include "WM_api.h"
@@ -97,6 +87,9 @@
 
 #include "transform.h"
 
+/* Disabling, since when you type you know what you are doing, and being able to set it to zero is handy. */
+// #define USE_NUM_NO_ZERO
+
 #define MAX_INFO_LEN 256
 
 static void drawTransformApply(const struct bContext *C, ARegion *ar, void *arg);
@@ -105,13 +98,105 @@ static int doVertSlide(TransInfo *t, float perc);
 
 static void drawEdgeSlide(const struct bContext *C, TransInfo *t);
 static void drawVertSlide(const struct bContext *C, TransInfo *t);
+static void len_v3_ensure(float v[3], const float length);
+static void postInputRotation(TransInfo *t, float values[3]);
+
+
+/* Transform Callbacks */
+static void initBend(TransInfo *t);
+static eRedrawFlag handleEventBend(TransInfo *t, const struct wmEvent *event);
+static void Bend(TransInfo *t, const int mval[2]);
+
+static void initShear(TransInfo *t);
+static eRedrawFlag handleEventShear(TransInfo *t, const struct wmEvent *event);
+static void applyShear(TransInfo *t, const int mval[2]);
+
+static void initResize(TransInfo *t);
+static void applyResize(TransInfo *t, const int mval[2]);
+
+static void initSkinResize(TransInfo *t);
+static void applySkinResize(TransInfo *t, const int mval[2]);
+
+static void initTranslation(TransInfo *t);
+static void applyTranslation(TransInfo *t, const int mval[2]);
+
+static void initToSphere(TransInfo *t);
+static void applyToSphere(TransInfo *t, const int mval[2]);
+
+static void initRotation(TransInfo *t);
+static void applyRotation(TransInfo *t, const int mval[2]);
+
+static void initShrinkFatten(TransInfo *t);
+static void applyShrinkFatten(TransInfo *t, const int mval[2]);
+
+static void initTilt(TransInfo *t);
+static void applyTilt(TransInfo *t, const int mval[2]);
+
+static void initCurveShrinkFatten(TransInfo *t);
+static void applyCurveShrinkFatten(TransInfo *t, const int mval[2]);
+
+static void initMaskShrinkFatten(TransInfo *t);
+static void applyMaskShrinkFatten(TransInfo *t, const int mval[2]);
+
+static void initTrackball(TransInfo *t);
+static void applyTrackball(TransInfo *t, const int mval[2]);
+
+static void initPushPull(TransInfo *t);
+static void applyPushPull(TransInfo *t, const int mval[2]);
+
+static void initBevelWeight(TransInfo *t);
+static void applyBevelWeight(TransInfo *t, const int mval[2]);
+
+static void initCrease(TransInfo *t);
+static void applyCrease(TransInfo *t, const int mval[2]);
+
+static void initBoneSize(TransInfo *t);
+static void applyBoneSize(TransInfo *t, const int mval[2]);
+
+static void initBoneEnvelope(TransInfo *t);
+static void applyBoneEnvelope(TransInfo *t, const int mval[2]);
+
+static void initBoneRoll(TransInfo *t);
+static void applyBoneRoll(TransInfo *t, const int mval[2]);
+
+static void initEdgeSlide(TransInfo *t);
+static eRedrawFlag handleEventEdgeSlide(TransInfo *t, const struct wmEvent *event);
+static void applyEdgeSlide(TransInfo *t, const int mval[2]);
+
+static void initVertSlide(TransInfo *t);
+static eRedrawFlag handleEventVertSlide(TransInfo *t, const struct wmEvent *event);
+static void applyVertSlide(TransInfo *t, const int mval[2]);
+
+static void initTimeTranslate(TransInfo *t);
+static void applyTimeTranslate(TransInfo *t, const int mval[2]);
+
+static void initTimeSlide(TransInfo *t);
+static void applyTimeSlide(TransInfo *t, const int mval[2]);
+
+static void initTimeScale(TransInfo *t);
+static void applyTimeScale(TransInfo *t, const int mval[2]);
+
+static void initBakeTime(TransInfo *t);
+static void applyBakeTime(TransInfo *t, const int mval[2]);
+
+static void initMirror(TransInfo *t);
+static void applyMirror(TransInfo *t, const int mval[2]);
+
+static void initAlign(TransInfo *t);
+static void applyAlign(TransInfo *t, const int mval[2]);
+
+static void initSeqSlide(TransInfo *t);
+static void applySeqSlide(TransInfo *t, const int mval[2]);
+/* end transform callbacks */
 
-static bool transdata_check_local_center(TransInfo *t)
+
+static bool transdata_check_local_center(TransInfo *t, short around)
 {
-       return ((t->around == V3D_LOCAL) && (
+       return ((around == V3D_LOCAL) && (
                    (t->flag & (T_OBJECT | T_POSE)) ||
-                   (t->obedit && ELEM4(t->obedit->type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE)) ||
-                   (t->spacetype == SPACE_IPO))
+                   (t->obedit && ELEM(t->obedit->type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE)) ||
+                   (t->spacetype == SPACE_IPO) ||
+                   (t->options & (CTX_MOVIECLIP | CTX_MASK | CTX_PAINT_CURVE)))
                );
 }
 
@@ -182,17 +267,28 @@ static void convertViewVec2D_mask(View2D *v2d, float r_vec[3], int dx, int dy)
 void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
 {
        if ((t->spacetype == SPACE_VIEW3D) && (t->ar->regiontype == RGN_TYPE_WINDOW)) {
-               const float mval_f[2] = {(float)dx, (float)dy};
-               ED_view3d_win_to_delta(t->ar, mval_f, r_vec, t->zfac);
+               if (t->options & CTX_PAINT_CURVE) {
+                       r_vec[0] = dx;
+                       r_vec[1] = dy;
+               }
+               else {
+                       const float mval_f[2] = {(float)dx, (float)dy};
+                       ED_view3d_win_to_delta(t->ar, mval_f, r_vec, t->zfac);
+               }
        }
        else if (t->spacetype == SPACE_IMAGE) {
                float aspx, aspy;
 
                if (t->options & CTX_MASK) {
-
                        convertViewVec2D_mask(t->view, r_vec, dx, dy);
                        ED_space_image_get_aspect(t->sa->spacedata.first, &aspx, &aspy);
                }
+               else if (t->options & CTX_PAINT_CURVE) {
+                       r_vec[0] = dx;
+                       r_vec[1] = dy;
+
+                       aspx = aspy = 1.0;
+               }
                else {
                        convertViewVec2D(t->view, r_vec, dx, dy);
                        ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
@@ -253,7 +349,6 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr
                SpaceImage *sima = t->sa->spacedata.first;
 
                if (t->options & CTX_MASK) {
-                       /* not working quite right, TODO (see below too) */
                        float aspx, aspy;
                        float v[2];
 
@@ -266,14 +361,15 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr
 
                        BKE_mask_coord_to_image(sima->image, &sima->iuser, v, v);
 
-                       v[0] = v[0] / aspx;
-                       v[1] = v[1] / aspy;
-
                        ED_image_point_pos__reverse(sima, t->ar, v, v);
 
                        adr[0] = v[0];
                        adr[1] = v[1];
                }
+               else if (t->options & CTX_PAINT_CURVE) {
+                       adr[0] = vec[0];
+                       adr[1] = vec[1];
+               }
                else {
                        float aspx, aspy, v[2];
 
@@ -281,7 +377,7 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr
                        v[0] = vec[0] / aspx;
                        v[1] = vec[1] / aspy;
 
-                       UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr + 1);
+                       UI_view2d_view_to_region(t->view, v[0], v[1], &adr[0], &adr[1]);
                }
        }
        else if (t->spacetype == SPACE_ACTION) {
@@ -292,12 +388,12 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr
                if (sact->flag & SACTION_DRAWTIME) {
                        //vec[0] = vec[0]/((t->scene->r.frs_sec / t->scene->r.frs_sec_base));
                        /* same as below */
-                       UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out + 1);
+                       UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &out[0], &out[1]);
                }
                else
 #endif
                {
-                       UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out + 1);
+                       UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &out[0], &out[1]);
                }
 
                adr[0] = out[0];
@@ -306,14 +402,14 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr
        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);
+               UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &out[0], &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_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out + 1);
+               UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &out[0], &out[1]);
                adr[0] = out[0];
                adr[1] = out[1];
        }
@@ -321,26 +417,30 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr
                SpaceClip *sc = t->sa->spacedata.first;
 
                if (t->options & CTX_MASK) {
-                       /* not working quite right, TODO (see above too) */
-                       float aspx, aspy;
-                       float v[2];
+                       MovieClip *clip = ED_space_clip_get_clip(sc);
 
-                       ED_space_clip_get_aspect(sc, &aspx, &aspy);
+                       if (clip) {
+                               float aspx, aspy;
+                               float v[2];
 
-                       copy_v2_v2(v, vec);
+                               ED_space_clip_get_aspect(sc, &aspx, &aspy);
 
-                       v[0] = v[0] / aspx;
-                       v[1] = v[1] / aspy;
+                               copy_v2_v2(v, vec);
 
-                       BKE_mask_coord_to_movieclip(sc->clip, &sc->user, v, v);
+                               v[0] = v[0] / aspx;
+                               v[1] = v[1] / aspy;
 
-                       v[0] = v[0] / aspx;
-                       v[1] = v[1] / aspy;
+                               BKE_mask_coord_to_movieclip(sc->clip, &sc->user, v, v);
 
-                       ED_clip_point_stable_pos__reverse(sc, t->ar, v, v);
+                               ED_clip_point_stable_pos__reverse(sc, t->ar, v, v);
 
-                       adr[0] = v[0];
-                       adr[1] = v[1];
+                               adr[0] = v[0];
+                               adr[1] = v[1];
+                       }
+                       else {
+                               adr[0] = 0;
+                               adr[1] = 0;
+                       }
                }
                else if (t->options & CTX_MOVIECLIP) {
                        float v[2], aspx, aspy;
@@ -351,14 +451,14 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr
                        v[0] /= aspx;
                        v[1] /= aspy;
 
-                       UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr + 1);
+                       UI_view2d_view_to_region(t->view, v[0], v[1], &adr[0], &adr[1]);
                }
                else {
                        BLI_assert(0);
                }
        }
        else if (t->spacetype == SPACE_NODE) {
-               UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], adr, adr + 1);
+               UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &adr[0], &adr[1]);
        }
 }
 void projectIntView(TransInfo *t, const float vec[3], int adr[2])
@@ -371,7 +471,11 @@ void projectFloatViewEx(TransInfo *t, const float vec[3], float adr[2], const eV
        switch (t->spacetype) {
                case SPACE_VIEW3D:
                {
-                       if (t->ar->regiontype == RGN_TYPE_WINDOW) {
+                       if (t->options & CTX_PAINT_CURVE) {
+                               adr[0] = vec[0];
+                               adr[1] = vec[1];
+                       }
+                       else if (t->ar->regiontype == RGN_TYPE_WINDOW) {
                                /* allow points behind the view [#33643] */
                                if (ED_view3d_project_float_global(t->ar, vec, adr, flag) != V3D_PROJ_RET_OK) {
                                        /* XXX, 2.64 and prior did this, weak! */
@@ -382,20 +486,15 @@ void projectFloatViewEx(TransInfo *t, const float vec[3], float adr[2], const eV
                        }
                        break;
                }
-               case SPACE_IMAGE:
-               case SPACE_CLIP:
-               case SPACE_IPO:
-               case SPACE_NLA:
+               default:
                {
-                       int a[2];
+                       int a[2] = {0, 0};
                        projectIntView(t, vec, a);
                        adr[0] = a[0];
                        adr[1] = a[1];
-                       return;
+                       break;
                }
        }
-
-       zero_v2(adr);
 }
 void projectFloatView(TransInfo *t, const float vec[3], float adr[2])
 {
@@ -404,7 +503,7 @@ void projectFloatView(TransInfo *t, const float vec[3], float adr[2])
 
 void applyAspectRatio(TransInfo *t, float vec[2])
 {
-       if ((t->spacetype == SPACE_IMAGE) && (t->mode == TFM_TRANSLATION)) {
+       if ((t->spacetype == SPACE_IMAGE) && (t->mode == TFM_TRANSLATION) && !(t->options & CTX_PAINT_CURVE)) {
                SpaceImage *sima = t->sa->spacedata.first;
                float aspx, aspy;
 
@@ -481,17 +580,23 @@ void removeAspectRatio(TransInfo *t, float vec[2])
 static void viewRedrawForce(const bContext *C, TransInfo *t)
 {
        if (t->spacetype == SPACE_VIEW3D) {
-               /* Do we need more refined tags? */
-               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);
+               if (t->options & CTX_PAINT_CURVE) {
+                       wmWindow *window = CTX_wm_window(C);
+                       WM_paint_cursor_tag_redraw(window, t->ar);
+               }
+               else {
+                       /* Do we need more refined tags? */
+                       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?
-               if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
-                       WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, NULL);
-               
+                       /* for realtime animation record - send notifiers recognised by animation editors */
+                       // XXX: is this notifier a lame duck?
+                       if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
+                               WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, NULL);
+
+               }
        }
        else if (t->spacetype == SPACE_ACTION) {
                //SpaceAction *saction = (SpaceAction *)t->sa->spacedata.first;
@@ -517,6 +622,10 @@ static void viewRedrawForce(const bContext *C, TransInfo *t)
 
                        WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
                }
+               else if (t->options & CTX_PAINT_CURVE) {
+                       wmWindow *window = CTX_wm_window(C);
+                       WM_paint_cursor_tag_redraw(window, t->ar);
+               }
                else {
                        // XXX how to deal with lock?
                        SpaceImage *sima = (SpaceImage *)t->sa->spacedata.first;
@@ -570,7 +679,7 @@ static void viewRedrawPost(bContext *C, TransInfo *t)
                allqueue(REDRAWIMAGE, 0);
                allqueue(REDRAWVIEW3D, 0);
        }
-       else if (ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
+       else if (ELEM(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
                allqueue(REDRAWVIEW3D, 0);
                allqueue(REDRAWACTION, 0);
                allqueue(REDRAWNLA, 0);
@@ -849,13 +958,19 @@ static void transform_event_xyz_constraint(TransInfo *t, short key_type, char cm
 
 int transformEvent(TransInfo *t, const wmEvent *event)
 {
-       float mati[3][3] = MAT3_UNITY;
        char cmode = constraintModeToChar(t);
-       int handled = 1;
-       
+       bool handled = false;
+
        t->redraw |= handleMouseInput(t, &t->mouse, event);
 
-       if (event->type == MOUSEMOVE) {
+       /* Handle modal numinput events first, if already activated. */
+       if (((event->val == KM_PRESS) || (event->type == EVT_MODAL_MAP)) &&
+           hasNumInput(&t->num) && handleNumInput(t->context, &(t->num), event))
+       {
+               t->redraw |= TREDRAW_HARD;
+               handled = true;
+       }
+       else if (event->type == MOUSEMOVE) {
                if (t->modifiers & MOD_CONSTRAINT_SELECT)
                        t->con.mode |= CON_SELECT;
 
@@ -864,7 +979,6 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                // 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;
                }
@@ -873,20 +987,22 @@ int transformEvent(TransInfo *t, const wmEvent *event)
 
                // Snapping mouse move events
                t->redraw |= handleSnapping(t, event);
+               handled = true;
        }
-
        /* handle modal keymap first */
-       if (event->type == EVT_MODAL_MAP) {
+       else if (event->type == EVT_MODAL_MAP) {
                switch (event->val) {
                        case TFM_MODAL_CANCEL:
                                t->state = TRANS_CANCEL;
+                               handled = true;
                                break;
                        case TFM_MODAL_CONFIRM:
                                t->state = TRANS_CONFIRM;
+                               handled = true;
                                break;
                        case TFM_MODAL_TRANSLATE:
                                /* only switch when... */
-                               if (ELEM5(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_EDGE_SLIDE, TFM_VERT_SLIDE)) {
+                               if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_EDGE_SLIDE, TFM_VERT_SLIDE)) {
                                        resetTransModal(t);
                                        resetTransRestrictions(t);
                                        restoreTransObjects(t);
@@ -894,10 +1010,12 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                        initSnapping(t, NULL); // need to reinit after mode change
                                        t->redraw |= TREDRAW_HARD;
                                        WM_event_add_mousemove(t->context);
+                                       handled = true;
                                }
                                else if (t->mode == TFM_SEQ_SLIDE) {
                                        t->flag ^= T_ALT_TRANSFORM;
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                else {
                                        if (t->obedit && t->obedit->type == OB_MESH) {
@@ -922,6 +1040,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                                        }
                                                        initSnapping(t, NULL); // need to reinit after mode change
                                                        t->redraw |= TREDRAW_HARD;
+                                                       handled = true;
                                                        WM_event_add_mousemove(t->context);
                                                }
                                        }
@@ -931,6 +1050,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
 
                                                        t->flag ^= T_ALT_TRANSFORM;
                                                        t->redraw |= TREDRAW_HARD;
+                                                       handled = true;
                                                }
                                        }
                                }
@@ -938,7 +1058,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                        case TFM_MODAL_ROTATE:
                                /* only switch when... */
                                if (!(t->options & CTX_TEXTURE) && !(t->options & (CTX_MOVIECLIP | CTX_MASK))) {
-                                       if (ELEM6(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION, TFM_EDGE_SLIDE, TFM_VERT_SLIDE)) {
+                                       if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION, TFM_EDGE_SLIDE, TFM_VERT_SLIDE)) {
                                                resetTransModal(t);
                                                resetTransRestrictions(t);
                                                
@@ -952,22 +1072,31 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                                }
                                                initSnapping(t, NULL); // need to reinit after mode change
                                                t->redraw |= TREDRAW_HARD;
+                                               handled = true;
                                        }
                                }
                                break;
                        case TFM_MODAL_RESIZE:
                                /* only switch when... */
-                               if (ELEM5(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL, TFM_EDGE_SLIDE, TFM_VERT_SLIDE)) {
+                               if (ELEM(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL, TFM_EDGE_SLIDE, TFM_VERT_SLIDE)) {
+
+                                       /* Scale isn't normally very useful after extrude along normals, see T39756 */
+                                       if ((t->con.mode & CON_APPLY) && (t->con.orientation == V3D_MANIP_NORMAL)) {
+                                               stopConstraint(t);
+                                       }
+
                                        resetTransModal(t);
                                        resetTransRestrictions(t);
                                        restoreTransObjects(t);
                                        initResize(t);
                                        initSnapping(t, NULL); // need to reinit after mode change
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                else if (t->mode == TFM_SHRINKFATTEN) {
                                        t->flag ^= T_ALT_TRANSFORM;
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                else if (t->mode == TFM_RESIZE) {
                                        if (t->options & CTX_MOVIECLIP) {
@@ -975,6 +1104,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
 
                                                t->flag ^= T_ALT_TRANSFORM;
                                                t->redraw |= TREDRAW_HARD;
+                                               handled = true;
                                        }
                                }
                                break;
@@ -982,56 +1112,37 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                        case TFM_MODAL_SNAP_INV_ON:
                                t->modifiers |= MOD_SNAP_INVERT;
                                t->redraw |= TREDRAW_HARD;
+                               handled = true;
                                break;
                        case TFM_MODAL_SNAP_INV_OFF:
                                t->modifiers &= ~MOD_SNAP_INVERT;
                                t->redraw |= TREDRAW_HARD;
+                               handled = true;
                                break;
                        case TFM_MODAL_SNAP_TOGGLE:
                                t->modifiers ^= MOD_SNAP;
                                t->redraw |= TREDRAW_HARD;
+                               handled = true;
                                break;
                        case TFM_MODAL_AXIS_X:
-                               if ((t->flag & T_NO_CONSTRAINT) == 0) {
-                                       if (cmode == 'X') {
-                                               stopConstraint(t);
-                                       }
-                                       else {
-                                               if (t->flag & T_2D_EDIT) {
-                                                       setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), IFACE_("along X"));
-                                               }
-                                               else {
-                                                       setUserConstraint(t, t->current_orientation, (CON_AXIS0), IFACE_("along %s X"));
-                                               }
-                                       }
+                               if (!(t->flag & T_NO_CONSTRAINT)) {
+                                       transform_event_xyz_constraint(t, XKEY, cmode);
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                break;
                        case TFM_MODAL_AXIS_Y:
                                if ((t->flag & T_NO_CONSTRAINT) == 0) {
-                                       if (cmode == 'Y') {
-                                               stopConstraint(t);
-                                       }
-                                       else {
-                                               if (t->flag & T_2D_EDIT) {
-                                                       setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), IFACE_("along Y"));
-                                               }
-                                               else {
-                                                       setUserConstraint(t, t->current_orientation, (CON_AXIS1), IFACE_("along %s Y"));
-                                               }
-                                       }
+                                       transform_event_xyz_constraint(t, YKEY, cmode);
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                break;
                        case TFM_MODAL_AXIS_Z:
-                               if ((t->flag & (T_NO_CONSTRAINT | T_2D_EDIT)) == 0) {
-                                       if (cmode == 'Z') {
-                                               stopConstraint(t);
-                                       }
-                                       else {
-                                               setUserConstraint(t, t->current_orientation, (CON_AXIS2), IFACE_("along %s Z"));
-                                       }
+                               if ((t->flag & (T_NO_CONSTRAINT)) == 0) {
+                                       transform_event_xyz_constraint(t, ZKEY, cmode);
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                break;
                        case TFM_MODAL_PLANE_X:
@@ -1043,6 +1154,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                                setUserConstraint(t, t->current_orientation, (CON_AXIS1 | CON_AXIS2), IFACE_("locking %s X"));
                                        }
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                break;
                        case TFM_MODAL_PLANE_Y:
@@ -1054,6 +1166,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                                setUserConstraint(t, t->current_orientation, (CON_AXIS0 | CON_AXIS2), IFACE_("locking %s Y"));
                                        }
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                break;
                        case TFM_MODAL_PLANE_Z:
@@ -1065,23 +1178,26 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                                setUserConstraint(t, t->current_orientation, (CON_AXIS0 | CON_AXIS1), IFACE_("locking %s Z"));
                                        }
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                break;
                        case TFM_MODAL_CONS_OFF:
                                if ((t->flag & T_NO_CONSTRAINT) == 0) {
                                        stopConstraint(t);
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                break;
                        case TFM_MODAL_ADD_SNAP:
                                addSnapPoint(t);
                                t->redraw |= TREDRAW_HARD;
+                               handled = true;
                                break;
                        case TFM_MODAL_REMOVE_SNAP:
                                removeSnapPoint(t);
                                t->redraw |= TREDRAW_HARD;
+                               handled = true;
                                break;
-                               
                        case TFM_MODAL_PROPSIZE:
                                /* MOUSEPAN usage... */
                                if (t->flag & T_PROP_EDIT) {
@@ -1090,63 +1206,69 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                        if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO)
                                                t->prop_size = min_ff(t->prop_size, ((View3D *)t->view)->far);
                                        calculatePropRatio(t);
+                                       t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
-                               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 = min_ff(t->prop_size, ((View3D *)t->view)->far);
                                        calculatePropRatio(t);
+                                       t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
-                               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;
+                                       handled = true;
                                }
-                               t->redraw |= TREDRAW_HARD;
                                break;
                        case TFM_MODAL_EDGESLIDE_UP:
                        case TFM_MODAL_EDGESLIDE_DOWN:
                                t->redraw |= TREDRAW_HARD;
+                               handled = true;
                                break;
                        case TFM_MODAL_AUTOIK_LEN_INC:
-                               if (t->flag & T_AUTOIK)
+                               if (t->flag & T_AUTOIK) {
                                        transform_autoik_update(t, 1);
-                               t->redraw |= TREDRAW_HARD;
+                                       t->redraw |= TREDRAW_HARD;
+                                       handled = true;
+                               }
                                break;
                        case TFM_MODAL_AUTOIK_LEN_DEC:
-                               if (t->flag & T_AUTOIK) 
+                               if (t->flag & T_AUTOIK) {
                                        transform_autoik_update(t, -1);
-                               t->redraw |= TREDRAW_HARD;
+                                       t->redraw |= TREDRAW_HARD;
+                                       handled = true;
+                               }
                                break;
                        default:
-                               handled = 0;
                                break;
                }
-
-               // Modal numinput events
-               t->redraw |= handleNumInput(&(t->num), event);
        }
        /* else do non-mapped events */
        else if (event->val == KM_PRESS) {
                switch (event->type) {
                        case RIGHTMOUSE:
                                t->state = TRANS_CANCEL;
+                               handled = true;
                                break;
                        /* enforce redraw of transform when modifiers are used */
                        case LEFTSHIFTKEY:
                        case RIGHTSHIFTKEY:
                                t->modifiers |= MOD_CONSTRAINT_PLANE;
                                t->redraw |= TREDRAW_HARD;
+                               handled = true;
                                break;
 
                        case SPACEKEY:
                                t->state = TRANS_CONFIRM;
+                               handled = true;
                                break;
 
                        case MIDDLEMOUSE:
@@ -1171,48 +1293,55 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                                        }
                                                        else {
                                                                /* bit hackish... but it prevents mmb select to print the orientation from menu */
+                                                               float mati[3][3];
                                                                strcpy(t->spacename, "global");
+                                                               unit_m3(mati);
                                                                initSelectConstraint(t, mati);
                                                        }
                                                        postSelectConstraint(t);
                                                }
                                        }
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                break;
                        case ESCKEY:
                                t->state = TRANS_CANCEL;
+                               handled = true;
                                break;
                        case PADENTER:
                        case RETKEY:
                                t->state = TRANS_CONFIRM;
+                               handled = true;
                                break;
                        case GKEY:
                                /* only switch when... */
-                               if (ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
+                               if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL)) {
                                        resetTransModal(t);
                                        resetTransRestrictions(t);
                                        restoreTransObjects(t);
                                        initTranslation(t);
                                        initSnapping(t, NULL); // need to reinit after mode change
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                break;
                        case SKEY:
                                /* only switch when... */
-                               if (ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
+                               if (ELEM(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL)) {
                                        resetTransModal(t);
                                        resetTransRestrictions(t);
                                        restoreTransObjects(t);
                                        initResize(t);
                                        initSnapping(t, NULL); // need to reinit after mode change
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                break;
                        case RKEY:
                                /* only switch when... */
                                if (!(t->options & CTX_TEXTURE)) {
-                                       if (ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
+                                       if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION)) {
                                                resetTransModal(t);
                                                resetTransRestrictions(t);
 
@@ -1226,31 +1355,42 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                                }
                                                initSnapping(t, NULL); // need to reinit after mode change
                                                t->redraw |= TREDRAW_HARD;
+                                               handled = true;
                                        }
                                }
                                break;
                        case CKEY:
                                if (event->alt) {
-                                       t->flag ^= T_PROP_CONNECTED;
-                                       sort_trans_data_dist(t);
-                                       calculatePropRatio(t);
-                                       t->redraw = 1;
+                                       if (!(t->options & CTX_NO_PET)) {
+                                               t->flag ^= T_PROP_CONNECTED;
+                                               sort_trans_data_dist(t);
+                                               calculatePropRatio(t);
+                                               t->redraw = TREDRAW_HARD;
+                                               handled = true;
+                                       }
                                }
                                else {
-                                       stopConstraint(t);
-                                       t->redraw |= TREDRAW_HARD;
+                                       if (!(t->flag & T_NO_CONSTRAINT)) {
+                                               stopConstraint(t);
+                                               t->redraw |= TREDRAW_HARD;
+                                               handled = true;
+                                       }
                                }
                                break;
                        case XKEY:
                        case YKEY:
                        case ZKEY:
-                               transform_event_xyz_constraint(t, event->type, cmode);
+                               if (!(t->flag & T_NO_CONSTRAINT)) {
+                                       transform_event_xyz_constraint(t, event->type, cmode);
+                                       handled = true;
+                               }
                                break;
                        case OKEY:
                                if (t->flag & T_PROP_EDIT && event->shift) {
                                        t->prop_mode = (t->prop_mode + 1) % PROP_MODE_MAX;
                                        calculatePropRatio(t);
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                break;
                        case PADPLUSKEY:
@@ -1259,8 +1399,9 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                        if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO)
                                                t->prop_size = min_ff(t->prop_size, ((View3D *)t->view)->far);
                                        calculatePropRatio(t);
+                                       t->redraw = TREDRAW_HARD;
+                                       handled = true;
                                }
-                               t->redraw = 1;
                                break;
                        case PAGEUPKEY:
                        case WHEELDOWNMOUSE:
@@ -1270,14 +1411,16 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                else {
                                        view_editmove(event->type);
                                }
-                               t->redraw = 1;
+                               t->redraw = TREDRAW_HARD;
+                               handled = true;
                                break;
                        case PADMINUS:
                                if (event->alt && t->flag & T_PROP_EDIT) {
                                        t->prop_size *= 0.90909090f;
                                        calculatePropRatio(t);
+                                       t->redraw = TREDRAW_HARD;
+                                       handled = true;
                                }
-                               t->redraw = 1;
                                break;
                        case PAGEDOWNKEY:
                        case WHEELUPMOUSE:
@@ -1287,27 +1430,23 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                else {
                                        view_editmove(event->type);
                                }
-                               t->redraw = 1;
+                               t->redraw = TREDRAW_HARD;
+                               handled = true;
                                break;
                        case LEFTALTKEY:
                        case RIGHTALTKEY:
                                if (ELEM(t->spacetype, SPACE_SEQ, SPACE_VIEW3D)) {
                                        t->flag |= T_ALT_TRANSFORM;
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
-
                                break;
                        default:
-                               handled = 0;
                                break;
                }
 
-               // Numerical input events
-               t->redraw |= handleNumInput(&(t->num), event);
-
-               // Snapping key events
+               /* Snapping key events */
                t->redraw |= handleSnapping(t, event);
-
        }
        else if (event->val == KM_RELEASE) {
                switch (event->type) {
@@ -1315,6 +1454,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                        case RIGHTSHIFTKEY:
                                t->modifiers &= ~MOD_CONSTRAINT_PLANE;
                                t->redraw |= TREDRAW_HARD;
+                               handled = true;
                                break;
 
                        case MIDDLEMOUSE:
@@ -1322,6 +1462,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                        t->modifiers &= ~MOD_CONSTRAINT_SELECT;
                                        postSelectConstraint(t);
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
                                break;
                        case LEFTALTKEY:
@@ -1329,28 +1470,38 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                if (ELEM(t->spacetype, SPACE_SEQ, SPACE_VIEW3D)) {
                                        t->flag &= ~T_ALT_TRANSFORM;
                                        t->redraw |= TREDRAW_HARD;
+                                       handled = true;
                                }
-
                                break;
                        default:
-                               handled = 0;
                                break;
                }
 
                /* confirm transform if launch key is released after mouse move */
                if (t->flag & T_RELEASE_CONFIRM) {
-                       /* XXX Keyrepeat bug in Xorg fucks this up, will test when fixed */
+                       /* XXX Keyrepeat bug in Xorg messes this up, will test when fixed */
                        if (event->type == t->launch_event && (t->launch_event == LEFTMOUSE || t->launch_event == RIGHTMOUSE)) {
                                t->state = TRANS_CONFIRM;
                        }
                }
        }
-       else
-               handled = 0;
 
-       // Per transform event, if present
-       if (t->handleEvent)
+       /* Per transform event, if present */
+       if (t->handleEvent &&
+           (!handled ||
+            /* Needed for vertex slide, see [#38756] */
+            (event->type == MOUSEMOVE)))
+       {
                t->redraw |= t->handleEvent(t, event);
+       }
+
+       /* Try to init modal numinput now, if possible. */
+       if (!(handled || t->redraw) && ((event->val == KM_PRESS) || (event->type == EVT_MODAL_MAP)) &&
+           handleNumInput(t->context, &(t->num), event))
+       {
+               t->redraw |= TREDRAW_HARD;
+               handled = true;
+       }
 
        if (handled || t->redraw) {
                return 0;
@@ -1360,10 +1511,10 @@ int transformEvent(TransInfo *t, const wmEvent *event)
        }
 }
 
-int calculateTransformCenter(bContext *C, int centerMode, float cent3d[3], int cent2d[2])
+bool calculateTransformCenter(bContext *C, int centerMode, float cent3d[3], float cent2d[2])
 {
        TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
-       int success;
+       bool success;
 
        t->state = TRANS_RUNNING;
 
@@ -1372,7 +1523,7 @@ int calculateTransformCenter(bContext *C, int centerMode, float cent3d[3], int c
 
        t->mode = TFM_DUMMY;
 
-       initTransInfo(C, t, NULL, NULL);    // internal data, mouse, vectors
+       initTransInfo(C, t, NULL, NULL);
 
        /* avoid doing connectivity lookups (when V3D_LOCAL is set) */
        t->around = V3D_CENTER;
@@ -1382,15 +1533,15 @@ int calculateTransformCenter(bContext *C, int centerMode, float cent3d[3], int c
        t->around = centerMode;             // override userdefined mode
 
        if (t->total == 0) {
-               success = FALSE;
+               success = false;
        }
        else {
-               success = TRUE;
+               success = true;
 
                calculateCenter(t);
 
                if (cent2d) {
-                       copy_v2_v2_int(cent2d, t->center2d);
+                       copy_v2_v2(cent2d, t->center2d);
                }
 
                if (cent3d) {
@@ -1400,7 +1551,7 @@ int calculateTransformCenter(bContext *C, int centerMode, float cent3d[3], int c
        }
 
 
-       /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
+       /* aftertrans does insert keyframes, and clears base flags; doesn't read transdata */
        special_aftertrans_update(C, t);
 
        postTrans(C, t);
@@ -1534,7 +1685,7 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
 
                switch (t->helpline) {
                        case HLP_SPRING:
-                               UI_ThemeColor(TH_WIRE);
+                               UI_ThemeColor(TH_VIEW_OVERLAY);
 
                                setlinestyle(3);
                                glBegin(GL_LINE_STRIP);
@@ -1552,7 +1703,7 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
                                glLineWidth(1.0);
                                break;
                        case HLP_HARROW:
-                               UI_ThemeColor(TH_WIRE);
+                               UI_ThemeColor(TH_VIEW_OVERLAY);
 
                                glTranslatef(mval[0], mval[1], 0);
 
@@ -1562,7 +1713,7 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
                                glLineWidth(1.0);
                                break;
                        case HLP_VARROW:
-                               UI_ThemeColor(TH_WIRE);
+                               UI_ThemeColor(TH_VIEW_OVERLAY);
 
                                glTranslatef(mval[0], mval[1], 0);
 
@@ -1575,10 +1726,10 @@ static void drawHelpline(bContext *UNUSED(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 dist = hypotf(dx, dy);
                                float delta_angle = min_ff(15.0f / dist, (float)M_PI / 4.0f);
                                float spacing_angle = min_ff(5.0f / dist, (float)M_PI / 12.0f);
-                               UI_ThemeColor(TH_WIRE);
+                               UI_ThemeColor(TH_VIEW_OVERLAY);
 
                                setlinestyle(3);
                                glBegin(GL_LINE_STRIP);
@@ -1662,26 +1813,28 @@ static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
 
        ED_region_visible_rect(ar, &rect);
        
-       BLF_width_and_height_default(printable, &printable_size[0], &printable_size[1]);
+       BLF_width_and_height_default(printable, BLF_DRAW_STR_DUMMY_MAX, &printable_size[0], &printable_size[1]);
        
-       xco = rect.xmax - (int)printable_size[0] - 10;
-       yco = rect.ymax - (int)printable_size[1] - 10;
+       xco = (rect.xmax - U.widget_unit) - (int)printable_size[0];
+       yco = (rect.ymax - U.widget_unit);
        
        /* warning text (to clarify meaning of overlays)
         * - original color was red to match the icon, but that clashes badly with a less nasty border
         */
        UI_ThemeColorShade(TH_TEXT_HI, -50);
 #ifdef WITH_INTERNATIONAL
-       BLF_draw_default(xco, ar->winy - 17, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
+       BLF_draw_default(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
 #else
-       BLF_draw_default_ascii(xco, ar->winy - 17, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
+       BLF_draw_default_ascii(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
 #endif
        
        /* autokey recording icon... */
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_BLEND);
        
-       xco -= (ICON_DEFAULT_WIDTH + 2);
+       xco -= U.widget_unit;
+       yco -= (int)printable_size[1] / 2;
+
        UI_icon_draw(xco, yco, ICON_REC);
        
        glDisable(GL_BLEND);
@@ -1722,7 +1875,7 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
        }
 
        if ((prop = RNA_struct_find_property(op->ptr, "value"))) {
-               float *values = (t->flag & T_AUTOVALUES) ? t->auto_values : t->values;
+               const float *values = (t->flag & T_AUTOVALUES) ? t->auto_values : t->values;
                if (RNA_property_array_check(prop)) {
                        RNA_property_float_set_array(op->ptr, prop, values);
                }
@@ -1754,7 +1907,7 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
                /* skip saving proportional edit if it was not actually used */
                if (!(t->options & CTX_NO_PET)) {
                        if ((prop = RNA_struct_find_property(op->ptr, "proportional")) &&
-                               !RNA_property_is_set(op->ptr, prop))
+                           !RNA_property_is_set(op->ptr, prop))
                        {
                                if (t->obedit)
                                        ts->proportional = proportional;
@@ -1765,13 +1918,13 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
                        }
 
                        if ((prop = RNA_struct_find_property(op->ptr, "proportional_size")) &&
-                               !RNA_property_is_set(op->ptr, prop))
+                           !RNA_property_is_set(op->ptr, prop))
                        {
                                ts->proportional_size = t->prop_size;
                        }
 
                        if ((prop = RNA_struct_find_property(op->ptr, "proportional_edit_falloff")) &&
-                               !RNA_property_is_set(op->ptr, prop))
+                           !RNA_property_is_set(op->ptr, prop))
                        {
                                ts->prop_mode = t->prop_mode;
                        }
@@ -1838,7 +1991,7 @@ 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, const wmEvent *event, int mode)
+bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event, int mode)
 {
        int options = 0;
        PropertyRNA *prop;
@@ -1874,12 +2027,9 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *even
                t->launch_event = LEFTMOUSE;
        }
 
-       if (!initTransInfo(C, t, op, event)) {  /* internal data, mouse, vectors */
-               return 0;
-       }
+       initTransInfo(C, t, op, event);
 
        if (t->spacetype == SPACE_VIEW3D) {
-               //calc_manipulator_stats(curarea);
                initTransformOrientation(C, t);
 
                t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);
@@ -1902,7 +2052,7 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *even
                unit_m3(t->spacemtx);
                /*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_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);*/
+               t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
        }
        else
                unit_m3(t->spacemtx);
@@ -1924,7 +2074,7 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *even
                 * moded are available from manipulator and doing such check could
                 * lead to keymap conflicts for other modes (see #31584)
                 */
-               if (ELEM3(mode, TFM_TRANSLATION, TFM_ROTATION, TFM_RESIZE)) {
+               if (ELEM(mode, TFM_TRANSLATION, TFM_ROTATION, TFM_RESIZE)) {
                        wmKeyMapItem *kmi;
 
                        for (kmi = t->keymap->items.first; kmi; kmi = kmi->next) {
@@ -1973,8 +2123,8 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *even
                case TFM_SHEAR:
                        initShear(t);
                        break;
-               case TFM_WARP:
-                       initWarp(t);
+               case TFM_BEND:
+                       initBend(t);
                        break;
                case TFM_SHRINKFATTEN:
                        initShrinkFatten(t);
@@ -2176,7 +2326,7 @@ int transformEnd(bContext *C, TransInfo *t)
                        exit_code = OPERATOR_FINISHED;
                }
 
-               /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */
+               /* aftertrans does insert keyframes, and clears base flags; doesn't read transdata */
                special_aftertrans_update(C, t);
 
                /* free data */
@@ -2195,7 +2345,7 @@ int transformEnd(bContext *C, TransInfo *t)
 
 /* ************************** TRANSFORM LOCKS **************************** */
 
-static void protectedTransBits(short protectflag, float *vec)
+static void protectedTransBits(short protectflag, float vec[3])
 {
        if (protectflag & OB_LOCK_LOCX)
                vec[0] = 0.0f;
@@ -2205,7 +2355,7 @@ static void protectedTransBits(short protectflag, float *vec)
                vec[2] = 0.0f;
 }
 
-static void protectedSizeBits(short protectflag, float *size)
+static void protectedSizeBits(short protectflag, float size[3])
 {
        if (protectflag & OB_LOCK_SCALEX)
                size[0] = 1.0f;
@@ -2215,7 +2365,7 @@ static void protectedSizeBits(short protectflag, float *size)
                size[2] = 1.0f;
 }
 
-static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
+static void protectedRotateBits(short protectflag, float eul[3], const float oldeul[3])
 {
        if (protectflag & OB_LOCK_ROTX)
                eul[0] = oldeul[0];
@@ -2270,7 +2420,7 @@ static void protectedAxisAngleBits(short protectflag, float axis[3], float *angl
 }
 
 /* this function only does the delta rotation */
-static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
+static void protectedQuaternionBits(short protectflag, float quat[4], const float oldquat[4])
 {
        /* check that protection flags are set */
        if ((protectflag & (OB_LOCK_ROTX | OB_LOCK_ROTY | OB_LOCK_ROTZ | OB_LOCK_ROTW)) == 0)
@@ -2324,8 +2474,8 @@ static void protectedQuaternionBits(short protectflag, float *quat, float *oldqu
 static void constraintTransLim(TransInfo *t, TransData *td)
 {
        if (td->con) {
-               bConstraintTypeInfo *ctiLoc = BKE_get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
-               bConstraintTypeInfo *ctiDist = BKE_get_constraint_typeinfo(CONSTRAINT_TYPE_DISTLIMIT);
+               bConstraintTypeInfo *ctiLoc = BKE_constraint_typeinfo_from_type(CONSTRAINT_TYPE_LOCLIMIT);
+               bConstraintTypeInfo *ctiDist = BKE_constraint_typeinfo_from_type(CONSTRAINT_TYPE_DISTLIMIT);
                
                bConstraintOb cob = {NULL};
                bConstraint *con;
@@ -2375,7 +2525,7 @@ static void constraintTransLim(TransInfo *t, TransData *td)
                                }
                                
                                /* get constraint targets if needed */
-                               BKE_get_constraint_targets_for_solving(con, &cob, &targets, ctime);
+                               BKE_constraint_targets_for_solving_get(con, &cob, &targets, ctime);
                                
                                /* do constraint */
                                cti->evaluate_constraint(con, &cob, &targets);
@@ -2427,10 +2577,10 @@ static void constraintob_from_transdata(bConstraintOb *cob, TransData *td)
 static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
 {
        if (td->con) {
-               bConstraintTypeInfo *cti = BKE_get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
+               bConstraintTypeInfo *cti = BKE_constraint_typeinfo_from_type(CONSTRAINT_TYPE_ROTLIMIT);
                bConstraintOb cob;
                bConstraint *con;
-               int do_limit = FALSE;
+               bool do_limit = false;
 
                /* Evaluate valid constraints */
                for (con = td->con; con; con = con->next) {
@@ -2451,9 +2601,9 @@ static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
                                        continue;
 
                                /* only do conversion if necessary, to preserve quats and eulers */
-                               if (do_limit == FALSE) {
+                               if (do_limit == false) {
                                        constraintob_from_transdata(&cob, td);
-                                       do_limit = TRUE;
+                                       do_limit = true;
                                }
 
                                /* do space conversions */
@@ -2494,7 +2644,7 @@ static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
 static void constraintSizeLim(TransInfo *t, TransData *td)
 {
        if (td->con && td->ext) {
-               bConstraintTypeInfo *cti = BKE_get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
+               bConstraintTypeInfo *cti = BKE_constraint_typeinfo_from_type(CONSTRAINT_TYPE_SIZELIMIT);
                bConstraintOb cob = {NULL};
                bConstraint *con;
                float size_sign[3], size_abs[3];
@@ -2574,187 +2724,226 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
        }
 }
 
-/* ************************** WARP *************************** */
 
-static void postInputWarp(TransInfo *t, float values[3])
-{
-       mul_v3_fl(values, (float)(M_PI * 2));
+/* -------------------------------------------------------------------- */
+/* Transform (Bend) */
 
-       if (t->customData) { /* non-null value indicates reversed input */
-               negate_v3(values);
-       }
-}
+/** \name Transform Bend
+ * \{ */
+
+struct BendCustomData {
+       float warp_sta[3];
+       float warp_end[3];
+
+       float warp_nor[3];
+       float warp_tan[3];
+
+       /* for applying the mouse distance */
+       float warp_init_dist;
+};
 
-void initWarp(TransInfo *t)
+static void initBend(TransInfo *t)
 {
-       float max[3], min[3];
-       int i;
+       const float mval_fl[2] = {UNPACK2(t->mval)};
+       const float *curs;
+       float tvec[3];
+       struct BendCustomData *data;
        
-       t->mode = TFM_WARP;
-       t->transform = Warp;
-       t->handleEvent = handleEventWarp;
+       t->mode = TFM_BEND;
+       t->transform = Bend;
+       t->handleEvent = handleEventBend;
        
-       setInputPostFct(&t->mouse, postInputWarp);
-       initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
+       setInputPostFct(&t->mouse, postInputRotation);
+       initMouseInputMode(t, &t->mouse, INPUT_ANGLE_SPRING);
        
-       t->idx_max = 0;
-       t->num.idx_max = 0;
+       t->idx_max = 1;
+       t->num.idx_max = 1;
        t->snap[0] = 0.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->snap[1] = DEG2RAD(5.0);
+       t->snap[2] = DEG2RAD(1.0);
+
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
+       t->num.unit_type[0] = B_UNIT_ROTATION;
+       t->num.unit_type[1] = B_UNIT_LENGTH;
 
        t->flag |= T_NO_CONSTRAINT;
-       
-       /* we need min/max in view space */
-       for (i = 0; i < t->total; i++) {
-               float center[3];
-               copy_v3_v3(center, t->data[i].center);
-               mul_m3_v3(t->data[i].mtx, center);
-               mul_m4_v3(t->viewmat, center);
-               sub_v3_v3(center, t->viewmat[3]);
-               if (i) {
-                       minmax_v3v3_v3(min, max, center);
-               }
-               else {
-                       copy_v3_v3(max, center);
-                       copy_v3_v3(min, center);
-               }
+
+       //copy_v3_v3(t->center, ED_view3d_cursor3d_get(t->scene, t->view));
+       calculateCenterCursor(t, t->center);
+
+       t->val = 0.0f;
+
+       data = MEM_callocN(sizeof(*data), __func__);
+
+       curs = ED_view3d_cursor3d_get(t->scene, t->view);
+       copy_v3_v3(data->warp_sta, curs);
+       ED_view3d_win_to_3d(t->ar, curs, mval_fl, data->warp_end);
+
+       copy_v3_v3(data->warp_nor, t->viewinv[2]);
+       if (t->flag & T_EDIT) {
+               sub_v3_v3(data->warp_sta, t->obedit->obmat[3]);
+               sub_v3_v3(data->warp_end, t->obedit->obmat[3]);
        }
+       normalize_v3(data->warp_nor);
+
+       /* tangent */
+       sub_v3_v3v3(tvec, data->warp_end, data->warp_sta);
+       cross_v3_v3v3(data->warp_tan, tvec, data->warp_nor);
+       normalize_v3(data->warp_tan);
 
-       mid_v3_v3v3(t->center, min, max);
+       data->warp_init_dist = len_v3v3(data->warp_end, data->warp_sta);
 
-       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 */
+       t->customData = data;
 }
 
-int handleEventWarp(TransInfo *t, const wmEvent *event)
+static eRedrawFlag handleEventBend(TransInfo *UNUSED(t), const wmEvent *event)
 {
-       int status = 0;
+       eRedrawFlag status = TREDRAW_NOTHING;
        
        if (event->type == MIDDLEMOUSE && event->val == KM_PRESS) {
-               // Use customData pointer to signal warp direction
-               if (t->customData == NULL)
-                       t->customData = (void *)1;
-               else
-                       t->customData = NULL;
-               
-               status = 1;
+               status = TREDRAW_HARD;
        }
        
        return status;
 }
 
-int Warp(TransInfo *t, const int UNUSED(mval[2]))
+static void Bend(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td = t->data;
-       float vec[3], circumfac, dist, phi0, co, si, cursor[3], gcursor[3];
-       const float *curs;
+       float vec[3];
+       float pivot[3];
+       float warp_end_radius[3];
        int i;
        char str[MAX_INFO_LEN];
-       
-       curs = give_cursor(t->scene, t->view);
-       /*
-        * gcursor is the one used for helpline.
-        * It has to be in the same space as the drawing loop
-        * (that means it needs to be in the object's space when in edit mode and
-        *  in global space in object mode)
-        *
-        * cursor is used for calculations.
-        * It needs to be in view space, but we need to take object's offset
-        * into account if in Edit mode.
-        */
-       copy_v3_v3(cursor, curs);
-       copy_v3_v3(gcursor, cursor);
-       if (t->flag & T_EDIT) {
-               sub_v3_v3(cursor, t->obedit->obmat[3]);
-               sub_v3_v3(gcursor, t->obedit->obmat[3]);
-               mul_m3_v3(t->data->smtx, gcursor);
+       const struct BendCustomData *data = t->customData;
+       const bool is_clamp = (t->flag & T_ALT_TRANSFORM) == 0;
+
+       union {
+               struct { float angle, scale; };
+               float vector[2];
+       } values;
+
+       /* amount of radians for bend */
+       copy_v2_v2(values.vector, t->values);
+
+#if 0
+       snapGrid(t, angle_rad);
+#else
+       /* hrmf, snapping radius is using 'angle' steps, need to convert to something else
+        * this isnt essential but nicer to give reasonable snapping values for radius */
+       if (t->tsnap.mode == SCE_SNAP_MODE_INCREMENT) {
+               const float radius_snap = 0.1f;
+               const float snap_hack = (t->snap[1] * data->warp_init_dist) / radius_snap;
+               values.scale *= snap_hack;
+               snapGridIncrement(t, values.vector);
+               values.scale /= snap_hack;
        }
-       mul_m4_v3(t->viewmat, cursor);
-       sub_v3_v3(cursor, t->viewmat[3]);
-       
-       /* amount of radians for warp */
-       circumfac = t->values[0];
-       
-       snapGrid(t, &circumfac);
-       applyNumInput(&t->num, &circumfac);
-       
+#endif
+
+       if (applyNumInput(&t->num, values.vector)) {
+               values.scale = values.scale / data->warp_init_dist;
+       }
+
        /* header print for NumInput */
        if (hasNumInput(&t->num)) {
-               char c[NUM_STR_REP_LEN];
-               
-               outputNumInput(&(t->num), c);
-               
-               BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Warp: %s"), c);
+               char c[NUM_STR_REP_LEN * 2];
 
-               circumfac = DEG2RADF(circumfac);
+               outputNumInput(&(t->num), c, &t->scene->unit);
+               
+               BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bend Angle: %s Radius: %s Alt, Clamp %s"),
+                            &c[0], &c[NUM_STR_REP_LEN],
+                            WM_bool_as_string(is_clamp));
        }
        else {
                /* default header print */
-               BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Warp: %.3f"), RAD2DEGF(circumfac));
+               BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bend Angle: %.3f Radius: %.4f, Alt, Clamp %s"),
+                            RAD2DEGF(values.angle), values.scale * data->warp_init_dist,
+                            WM_bool_as_string(is_clamp));
        }
        
-       t->values[0] = circumfac;
+       copy_v2_v2(t->values, values.vector);
 
-       circumfac /= 2; /* only need 180 on each side to make 360 */
+       values.angle *= -1.0f;
+       values.scale *= data->warp_init_dist;
        
+       /* calc 'data->warp_end' from 'data->warp_end_init' */
+       copy_v3_v3(warp_end_radius, data->warp_end);
+       dist_ensure_v3_v3fl(warp_end_radius, data->warp_sta, values.scale);
+       /* done */
+
+       /* calculate pivot */
+       copy_v3_v3(pivot, data->warp_sta);
+       if (values.angle > 0.0f) {
+               madd_v3_v3fl(pivot, data->warp_tan, -values.scale * shell_angle_to_dist((float)M_PI_2 - values.angle));
+       }
+       else {
+               madd_v3_v3fl(pivot, data->warp_tan, +values.scale * shell_angle_to_dist((float)M_PI_2 + values.angle));
+       }
+
        for (i = 0; i < t->total; i++, td++) {
-               float loc[3];
+               float mat[3][3];
+               float delta[3];
+               float fac, fac_scaled;
+
                if (td->flag & TD_NOACTION)
                        break;
                
                if (td->flag & TD_SKIP)
                        continue;
-               
-               /* translate point to center, rotate in such a way that outline==distance */
+
+               if (UNLIKELY(values.angle == 0.0f)) {
+                       copy_v3_v3(td->loc, td->iloc);
+                       continue;
+               }
+
                copy_v3_v3(vec, td->iloc);
                mul_m3_v3(td->mtx, vec);
-               mul_m4_v3(t->viewmat, vec);
-               sub_v3_v3(vec, t->viewmat[3]);
-               
-               dist = vec[0] - cursor[0];
-               
-               /* t->val is X dimension projected boundbox */
-               phi0 = (circumfac * dist / t->val);
-               
-               vec[1] = (vec[1] - cursor[1]);
-               
-               co = cosf(phi0);
-               si = sinf(phi0);
-               loc[0] = -si * vec[1] + cursor[0];
-               loc[1] = co * vec[1] + cursor[1];
-               loc[2] = vec[2];
-               
-               mul_m4_v3(t->viewinv, loc);
-               sub_v3_v3(loc, t->viewinv[3]);
-               mul_m3_v3(td->smtx, loc);
-               
-               sub_v3_v3(loc, td->iloc);
-               mul_v3_fl(loc, td->factor);
-               add_v3_v3v3(td->loc, td->iloc, loc);
+
+               fac = line_point_factor_v3(vec, data->warp_sta, warp_end_radius);
+               if (is_clamp) {
+                       CLAMP(fac, 0.0f, 1.0f);
+               }
+
+               fac_scaled = fac * td->factor;
+               axis_angle_normalized_to_mat3(mat, data->warp_nor, values.angle * fac_scaled);
+               interp_v3_v3v3(delta, data->warp_sta, warp_end_radius, fac_scaled);
+               sub_v3_v3(delta, data->warp_sta);
+
+               /* delta is subtracted, rotation adds back this offset */
+               sub_v3_v3(vec, delta);
+
+               sub_v3_v3(vec, pivot);
+               mul_m3_v3(mat, vec);
+               add_v3_v3(vec, pivot);
+
+               mul_m3_v3(td->smtx, vec);
+               copy_v3_v3(td->loc, vec);
        }
        
        recalcData(t);
        
        ED_area_headerprint(t->sa, str);
-       
-       return 1;
 }
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/* Transform (Shear) */
 
-/* ************************** SHEAR *************************** */
+/** \name Transform Shear
+ * \{ */
 
 static void postInputShear(TransInfo *UNUSED(t), float values[3])
 {
        mul_v3_fl(values, 0.05f);
 }
 
-void initShear(TransInfo *t)
+static void initShear(TransInfo *t)
 {
        t->mode = TFM_SHEAR;
-       t->transform = Shear;
+       t->transform = applyShear;
        t->handleEvent = handleEventShear;
        
        setInputPostFct(&t->mouse, postInputShear);
@@ -2765,15 +2954,17 @@ void initShear(TransInfo *t)
        t->snap[0] = 0.0f;
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
-       
-       t->num.increment = 0.1f;
+
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;  /* Don't think we have any unit here? */
 
        t->flag |= T_NO_CONSTRAINT;
 }
 
-int handleEventShear(TransInfo *t, const wmEvent *event)
+static eRedrawFlag handleEventShear(TransInfo *t, const wmEvent *event)
 {
-       int status = 0;
+       eRedrawFlag status = TREDRAW_NOTHING;
        
        if (event->type == MIDDLEMOUSE && event->val == KM_PRESS) {
                // Use customData pointer to signal Shear direction
@@ -2786,26 +2977,26 @@ int handleEventShear(TransInfo *t, const wmEvent *event)
                        t->customData = NULL;
                }
 
-               status = 1;
+               status = TREDRAW_HARD;
        }
        else if (event->type == XKEY && event->val == KM_PRESS) {
                initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
                t->customData = NULL;
                
-               status = 1;
+               status = TREDRAW_HARD;
        }
        else if (event->type == YKEY && event->val == KM_PRESS) {
                initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
                t->customData = (void *)1;
                
-               status = 1;
+               status = TREDRAW_HARD;
        }
        
        return status;
 }
 
 
-int Shear(TransInfo *t, const int UNUSED(mval[2]))
+static void applyShear(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float vec[3];
@@ -2819,7 +3010,7 @@ int Shear(TransInfo *t, const int UNUSED(mval[2]))
        
        value = t->values[0];
        
-       snapGrid(t, &value);
+       snapGridIncrement(t, &value);
        
        applyNumInput(&t->num, &value);
        
@@ -2827,7 +3018,7 @@ int Shear(TransInfo *t, const int UNUSED(mval[2]))
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
                
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
                
                BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shear: %s %s"), c, t->proptext);
        }
@@ -2879,25 +3070,35 @@ int Shear(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
        
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
 
-/* ************************** RESIZE *************************** */
 
-void initResize(TransInfo *t)
+/* -------------------------------------------------------------------- */
+/* Transform (Resize) */
+
+/** \name Transform Resize
+ * \{ */
+
+static void initResize(TransInfo *t)
 {
        t->mode = TFM_RESIZE;
-       t->transform = Resize;
+       t->transform = applyResize;
        
        initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
        
        t->flag |= T_NULL_ONE;
-       t->num.flag |= NUM_NULL_ONE;
+       t->num.val_flag[0] |= NUM_NULL_ONE;
+       t->num.val_flag[1] |= NUM_NULL_ONE;
+       t->num.val_flag[2] |= NUM_NULL_ONE;
        t->num.flag |= NUM_AFFECT_ALL;
        if (!t->obedit) {
                t->flag |= T_NO_ZERO;
-               t->num.flag |= NUM_NO_ZERO;
+#ifdef USE_NUM_NO_ZERO
+               t->num.val_flag[0] |= NUM_NO_ZERO;
+               t->num.val_flag[1] |= NUM_NO_ZERO;
+               t->num.val_flag[2] |= NUM_NO_ZERO;
+#endif
        }
        
        t->idx_max = 2;
@@ -2906,16 +3107,19 @@ void initResize(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
+       t->num.unit_type[1] = B_UNIT_NONE;
+       t->num.unit_type[2] = B_UNIT_NONE;
 }
 
-/* We assume str is MAX_INFO_LEN long. */
-static void headerResize(TransInfo *t, float vec[3], char *str)
+static void headerResize(TransInfo *t, float vec[3], char str[MAX_INFO_LEN])
 {
        char tvec[NUM_STR_REP_LEN * 3];
        size_t ofs = 0;
        if (hasNumInput(&t->num)) {
-               outputNumInput(&(t->num), tvec);
+               outputNumInput(&(t->num), tvec, &t->scene->unit);
        }
        else {
                BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", vec[0]);
@@ -2955,38 +3159,23 @@ static void headerResize(TransInfo *t, float vec[3], char *str)
        }
 }
 
-/* FLT_EPSILON is too small [#29633], 0.0000001f starts to flip */
-#define TX_FLIP_EPS 0.00001f
-BLI_INLINE int tx_sign(const float a)
-{
-       return (a < -TX_FLIP_EPS ? 1 : a > TX_FLIP_EPS ? 2 : 3);
-}
-BLI_INLINE int tx_vec_sign_flip(const float a[3], const float b[3])
-{
-       return ((tx_sign(a[0]) & tx_sign(b[0])) == 0 ||
-               (tx_sign(a[1]) & tx_sign(b[1])) == 0 ||
-               (tx_sign(a[2]) & tx_sign(b[2])) == 0);
-}
-
-/* smat is reference matrix, only scaled */
+/**
+ * \a smat is reference matrix only.
+ *
+ * \note this is a tricky area, before making changes see: T29633, T42444
+ */
 static void TransMat3ToSize(float mat[3][3], float smat[3][3], float size[3])
 {
-       float vec[3];
-       
-       copy_v3_v3(vec, mat[0]);
-       size[0] = normalize_v3(vec);
-       copy_v3_v3(vec, mat[1]);
-       size[1] = normalize_v3(vec);
-       copy_v3_v3(vec, mat[2]);
-       size[2] = normalize_v3(vec);
-       
+       float rmat[3][3];
+
+       mat3_to_rot_size(rmat, size, mat);
+
        /* first tried with dotproduct... but the sign flip is crucial */
-       if (tx_vec_sign_flip(mat[0], smat[0]) ) size[0] = -size[0];
-       if (tx_vec_sign_flip(mat[1], smat[1]) ) size[1] = -size[1];
-       if (tx_vec_sign_flip(mat[2], smat[2]) ) size[2] = -size[2];
+       if (dot_v3v3(rmat[0], smat[0]) < 0.0f) size[0] = -size[0];
+       if (dot_v3v3(rmat[1], smat[1]) < 0.0f) size[1] = -size[1];
+       if (dot_v3v3(rmat[2], smat[2]) < 0.0f) size[2] = -size[2];
 }
 
-
 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
 {
        float tmat[3][3], smat[3][3], center[3];
@@ -3005,7 +3194,7 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
        }
        
        /* local constraint shouldn't alter center */
-       if (transdata_check_local_center(t)) {
+       if (transdata_check_local_center(t, t->around)) {
                copy_v3_v3(center, td->center);
        }
        else if (t->options & CTX_MOVIECLIP) {
@@ -3086,7 +3275,7 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
        constraintTransLim(t, td);
 }
 
-int Resize(TransInfo *t, const int mval[2])
+static void applyResize(TransInfo *t, const int mval[2])
 {
        TransData *td;
        float size[3], mat[3][3];
@@ -3104,10 +3293,9 @@ int Resize(TransInfo *t, const int mval[2])
        
        size[0] = size[1] = size[2] = ratio;
        
-       snapGrid(t, size);
+       snapGridIncrement(t, size);
        
-       if (hasNumInput(&t->num)) {
-               applyNumInput(&t->num, size);
+       if (applyNumInput(&t->num, size)) {
                constraintNumInput(t, size);
        }
        
@@ -3161,25 +3349,35 @@ int Resize(TransInfo *t, const int mval[2])
        recalcData(t);
        
        ED_area_headerprint(t->sa, str);
-       
-       return 1;
 }
+/** \} */
+
 
-/* ************************** SKIN *************************** */
+/* -------------------------------------------------------------------- */
+/* Transform (Skin) */
 
-void initSkinResize(TransInfo *t)
+/** \name Transform Skin
+ * \{ */
+
+static void initSkinResize(TransInfo *t)
 {
        t->mode = TFM_SKIN_RESIZE;
-       t->transform = SkinResize;
+       t->transform = applySkinResize;
        
        initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
        
        t->flag |= T_NULL_ONE;
-       t->num.flag |= NUM_NULL_ONE;
+       t->num.val_flag[0] |= NUM_NULL_ONE;
+       t->num.val_flag[1] |= NUM_NULL_ONE;
+       t->num.val_flag[2] |= NUM_NULL_ONE;
        t->num.flag |= NUM_AFFECT_ALL;
        if (!t->obedit) {
                t->flag |= T_NO_ZERO;
-               t->num.flag |= NUM_NO_ZERO;
+#ifdef USE_NUM_NO_ZERO
+               t->num.val_flag[0] |= NUM_NO_ZERO;
+               t->num.val_flag[1] |= NUM_NO_ZERO;
+               t->num.val_flag[2] |= NUM_NO_ZERO;
+#endif
        }
        
        t->idx_max = 2;
@@ -3188,10 +3386,14 @@ void initSkinResize(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
+       t->num.unit_type[1] = B_UNIT_NONE;
+       t->num.unit_type[2] = B_UNIT_NONE;
 }
 
-int SkinResize(TransInfo *t, const int UNUSED(mval[2]))
+static void applySkinResize(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td;
        float size[3], mat[3][3];
@@ -3202,10 +3404,9 @@ int SkinResize(TransInfo *t, const int UNUSED(mval[2]))
        ratio = t->values[0];
        size[0] = size[1] = size[2] = ratio;
        
-       snapGrid(t, size);
+       snapGridIncrement(t, size);
        
-       if (hasNumInput(&t->num)) {
-               applyNumInput(&t->num, size);
+       if (applyNumInput(&t->num, size)) {
                constraintNumInput(t, size);
        }
        
@@ -3251,19 +3452,23 @@ int SkinResize(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
        
        ED_area_headerprint(t->sa, str);
-       
-       return 1;
 }
+/** \} */
+
 
-/* ************************** TOSPHERE *************************** */
+/* -------------------------------------------------------------------- */
+/* Transform (ToSphere) */
 
-void initToSphere(TransInfo *t)
+/** \name Transform ToSphere
+ * \{ */
+
+static void initToSphere(TransInfo *t)
 {
        TransData *td = t->data;
        int i;
        
        t->mode = TFM_TOSPHERE;
-       t->transform = ToSphere;
+       t->transform = applyToSphere;
        
        initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
        
@@ -3273,9 +3478,11 @@ void initToSphere(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
        
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
 
-       t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
+       t->num.val_flag[0] |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
        t->flag |= T_NO_CONSTRAINT;
        
        // Calculate average radius
@@ -3286,7 +3493,7 @@ void initToSphere(TransInfo *t)
        t->val /= (float)t->total;
 }
 
-int ToSphere(TransInfo *t, const int UNUSED(mval[2]))
+static void applyToSphere(TransInfo *t, const int UNUSED(mval[2]))
 {
        float vec[3];
        float ratio, radius;
@@ -3296,7 +3503,7 @@ int ToSphere(TransInfo *t, const int UNUSED(mval[2]))
        
        ratio = t->values[0];
        
-       snapGrid(t, &ratio);
+       snapGridIncrement(t, &ratio);
        
        applyNumInput(&t->num, &ratio);
        
@@ -3311,7 +3518,7 @@ int ToSphere(TransInfo *t, const int UNUSED(mval[2]))
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
                
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
                
                BLI_snprintf(str, MAX_INFO_LEN, IFACE_("To Sphere: %s %s"), c, t->proptext);
        }
@@ -3344,12 +3551,15 @@ int ToSphere(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
        
        ED_area_headerprint(t->sa, str);
-       
-       return 1;
 }
+/** \} */
+
 
-/* ************************** ROTATION *************************** */
+/* -------------------------------------------------------------------- */
+/* Transform (Rotation) */
 
+/** \name Transform Rotation
+ * \{ */
 
 static void postInputRotation(TransInfo *t, float values[3])
 {
@@ -3358,10 +3568,10 @@ static void postInputRotation(TransInfo *t, float values[3])
        }
 }
 
-void initRotation(TransInfo *t)
+static void initRotation(TransInfo *t)
 {
        t->mode = TFM_ROTATION;
-       t->transform = Rotation;
+       t->transform = applyRotation;
        
        setInputPostFct(&t->mouse, postInputRotation);
        initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
@@ -3369,16 +3579,26 @@ void initRotation(TransInfo *t)
        t->idx_max = 0;
        t->num.idx_max = 0;
        t->snap[0] = 0.0f;
-       t->snap[1] = (float)((5.0 / 180) * M_PI);
-       t->snap[2] = t->snap[1] * 0.2f;
+       t->snap[1] = DEG2RAD(5.0);
+       t->snap[2] = DEG2RAD(1.0);
        
-       t->num.increment = 1.0f;
+       copy_v3_fl(t->num.val_inc, t->snap[2]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
+       t->num.unit_type[0] = B_UNIT_ROTATION;
 
        if (t->flag & T_2D_EDIT)
                t->flag |= T_NO_CONSTRAINT;
 
-       negate_v3_v3(t->axis, t->viewinv[2]);
-       normalize_v3(t->axis);
+       if (t->options & CTX_PAINT_CURVE) {
+               t->axis[0] = 0.0;
+               t->axis[1] = 0.0;
+               t->axis[2] = -1.0;
+       }
+       else {
+               negate_v3_v3(t->axis, t->viewinv[2]);
+               normalize_v3(t->axis);
+       }
 
        copy_v3_v3(t->axis_orig, t->axis);
 }
@@ -3390,9 +3610,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
        const float *center;
 
        /* local constraint shouldn't alter center */
-       if (transdata_check_local_center(t) ||
-           ((around == V3D_LOCAL) && (t->options & CTX_MOVIECLIP)))
-       {
+       if (transdata_check_local_center(t, around)) {
                center = td->center;
        }
        else {
@@ -3414,7 +3632,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, NULL, NULL, NULL, NULL, NULL);
+                       mul_m3_series(fmat, td->smtx, mat, td->mtx);
                        mat3_to_quat(quat, fmat);   // Actual transform
                        
                        if (td->ext->quat) {
@@ -3484,7 +3702,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                if ((t->flag & T_V3D_ALIGN) == 0) { /* align mode doesn't rotate objects itself */
                        /* euler or quaternion/axis-angle? */
                        if (td->ext->rotOrder == ROT_MODE_QUAT) {
-                               mul_serie_m3(fmat, td->ext->r_mtx, mat, td->ext->r_smtx, NULL, NULL, NULL, NULL, NULL);
+                               mul_m3_series(fmat, td->ext->r_smtx, mat, td->ext->r_mtx);
                                
                                mat3_to_quat(quat, fmat); /* Actual transform */
                                
@@ -3499,7 +3717,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                                
                                axis_angle_to_quat(iquat, td->ext->irotAxis, td->ext->irotAngle);
                                
-                               mul_serie_m3(fmat, td->ext->r_mtx, mat, td->ext->r_smtx, NULL, NULL, NULL, NULL, NULL);
+                               mul_m3_series(fmat, td->ext->r_smtx, mat, td->ext->r_mtx);
                                mat3_to_quat(quat, fmat); /* Actual transform */
                                mul_qt_qtqt(tquat, quat, iquat);
                                
@@ -3556,7 +3774,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                        if ((td->ext->rotOrder == ROT_MODE_QUAT) || (td->flag & TD_USEQUAT)) {
                                /* can be called for texture space translate for example, then opt out */
                                if (td->ext->quat) {
-                                       mul_serie_m3(fmat, td->mtx, mat, td->smtx, NULL, NULL, NULL, NULL, NULL);
+                                       mul_m3_series(fmat, td->smtx, mat, td->mtx);
                                        mat3_to_quat(quat, fmat);   // Actual transform
                                        
                                        mul_qt_qtqt(td->ext->quat, quat, td->ext->iquat);
@@ -3570,7 +3788,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                                
                                axis_angle_to_quat(iquat, td->ext->irotAxis, td->ext->irotAngle);
                                
-                               mul_serie_m3(fmat, td->mtx, mat, td->smtx, NULL, NULL, NULL, NULL, NULL);
+                               mul_m3_series(fmat, td->smtx, mat, td->mtx);
                                mat3_to_quat(quat, fmat);   // Actual transform
                                mul_qt_qtqt(tquat, quat, iquat);
                                
@@ -3607,7 +3825,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
        }
 }
 
-static void applyRotation(TransInfo *t, float angle, float axis[3])
+static void applyRotationValue(TransInfo *t, float angle, float axis[3])
 {
        TransData *td = t->data;
        float mat[3][3];
@@ -3635,7 +3853,7 @@ static void applyRotation(TransInfo *t, float angle, float axis[3])
        }
 }
 
-int Rotation(TransInfo *t, const int UNUSED(mval[2]))
+static void applyRotation(TransInfo *t, const int UNUSED(mval[2]))
 {
        char str[MAX_INFO_LEN];
        size_t ofs = 0;
@@ -3644,7 +3862,7 @@ int Rotation(TransInfo *t, const int UNUSED(mval[2]))
 
        final = t->values[0];
 
-       snapGrid(t, &final);
+       snapGridIncrement(t, &final);
 
        if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
                t->con.applyRot(t, NULL, t->axis, NULL);
@@ -3656,17 +3874,17 @@ int Rotation(TransInfo *t, const int UNUSED(mval[2]))
 
        applySnapping(t, &final);
 
+       if (applyNumInput(&t->num, &final)) {
+               /* Clamp between -PI and PI */
+               final = angle_wrap_rad(final);
+       }
+
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
                
-               applyNumInput(&t->num, &final);
-               
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
                
                ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Rot: %s %s %s"), &c[0], t->con.text, t->proptext);
-
-               /* Clamp between -180 and 180 */
-               final = angle_wrap_rad(DEG2RADF(final));
        }
        else {
                ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Rot: %.2f%s %s"),
@@ -3679,37 +3897,44 @@ int Rotation(TransInfo *t, const int UNUSED(mval[2]))
 
        t->values[0] = final;
        
-       applyRotation(t, final, t->axis);
+       applyRotationValue(t, final, t->axis);
        
        recalcData(t);
        
        ED_area_headerprint(t->sa, str);
-       
-       return 1;
 }
+/** \} */
+
 
+/* -------------------------------------------------------------------- */
+/* Transform (Rotation - Trackball) */
 
-/* ************************** TRACKBALL *************************** */
+/** \name Transform Rotation - Trackball
+ * \{ */
 
-void initTrackball(TransInfo *t)
+static void initTrackball(TransInfo *t)
 {
        t->mode = TFM_TRACKBALL;
-       t->transform = Trackball;
+       t->transform = applyTrackball;
 
        initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL);
 
        t->idx_max = 1;
        t->num.idx_max = 1;
        t->snap[0] = 0.0f;
-       t->snap[1] = (float)((5.0 / 180) * M_PI);
-       t->snap[2] = t->snap[1] * 0.2f;
+       t->snap[1] = DEG2RAD(5.0);
+       t->snap[2] = DEG2RAD(1.0);
 
-       t->num.increment = 1.0f;
+       copy_v3_fl(t->num.val_inc, t->snap[2]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
+       t->num.unit_type[0] = B_UNIT_ROTATION;
+       t->num.unit_type[1] = B_UNIT_ROTATION;
 
        t->flag |= T_NO_CONSTRAINT;
 }
 
-static void applyTrackball(TransInfo *t, const float axis1[3], const float axis2[3], float angles[2])
+static void applyTrackballValue(TransInfo *t, const float axis1[3], const float axis2[3], float angles[2])
 {
        TransData *td = t->data;
        float mat[3][3], smat[3][3], totmat[3][3];
@@ -3738,7 +3963,7 @@ static void applyTrackball(TransInfo *t, const float axis1[3], const float axis2
        }
 }
 
-int Trackball(TransInfo *t, const int UNUSED(mval[2]))
+static void applyTrackball(TransInfo *t, const int UNUSED(mval[2]))
 {
        char str[MAX_INFO_LEN];
        size_t ofs = 0;
@@ -3754,20 +3979,17 @@ int Trackball(TransInfo *t, const int UNUSED(mval[2]))
        phi[0] = t->values[0];
        phi[1] = t->values[1];
 
-       snapGrid(t, phi);
+       snapGridIncrement(t, phi);
+
+       applyNumInput(&t->num, phi);
 
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN * 2];
 
-               applyNumInput(&t->num, phi);
-
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
 
                ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Trackball: %s %s %s"),
                                    &c[0], &c[NUM_STR_REP_LEN], t->proptext);
-
-               phi[0] = DEG2RADF(phi[0]);
-               phi[1] = DEG2RADF(phi[1]);
        }
        else {
                ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Trackball: %.2f %.2f %s"),
@@ -3786,26 +4008,33 @@ int Trackball(TransInfo *t, const int UNUSED(mval[2]))
        // TRANSFORM_FIX_ME
        //copy_m3_m3(t->mat, mat);      // used in manipulator
 
-       applyTrackball(t, axis1, axis2, phi);
+       applyTrackballValue(t, axis1, axis2, phi);
 
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
+
 
-/* ************************** TRANSLATION *************************** */
+/* -------------------------------------------------------------------- */
+/* Transform (Translation) */
 
-void initTranslation(TransInfo *t)
+/** \name Transform Translation
+ * \{ */
+
+static void initTranslation(TransInfo *t)
 {
        if (t->spacetype == SPACE_ACTION) {
                /* this space uses time translate */
+               BKE_report(t->reports, RPT_ERROR, 
+                          "Use 'Time_Translate' transform mode instead of 'Translation' mode "
+                          "for translating keyframes in Dope Sheet Editor");
                t->state = TRANS_CANCEL;
        }
 
        t->mode = TFM_TRANSLATION;
-       t->transform = Translation;
+       t->transform = applyTranslation;
 
        initMouseInputMode(t, &t->mouse, INPUT_VECTOR);
 
@@ -3829,19 +4058,31 @@ void initTranslation(TransInfo *t)
        }
        else if (t->spacetype == SPACE_NODE) {
                t->snap[0] = 0.0f;
-               t->snap[1] = 125.0f;
-               t->snap[2] = 25.0f;
+               t->snap[1] = ED_node_grid_size() * NODE_GRID_STEPS;
+               t->snap[2] = ED_node_grid_size();
        }
        else {
                t->snap[0] = 0.0f;
                t->snap[1] = t->snap[2] = 1.0f;
        }
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       if (t->spacetype == SPACE_VIEW3D) {
+               /* Handling units makes only sense in 3Dview... See T38877. */
+               t->num.unit_type[0] = B_UNIT_LENGTH;
+               t->num.unit_type[1] = B_UNIT_LENGTH;
+               t->num.unit_type[2] = B_UNIT_LENGTH;
+       }
+       else {
+               /* SPACE_IPO, SPACE_ACTION, etc. could use some time units, when we have them... */
+               t->num.unit_type[0] = B_UNIT_NONE;
+               t->num.unit_type[1] = B_UNIT_NONE;
+               t->num.unit_type[2] = B_UNIT_NONE;
+       }
 }
 
-/* We assume str is MAX_INFO_LEN long. */
-static void headerTranslation(TransInfo *t, float vec[3], char *str)
+static void headerTranslation(TransInfo *t, float vec[3], char str[MAX_INFO_LEN])
 {
        size_t ofs = 0;
        char tvec[NUM_STR_REP_LEN * 3];
@@ -3850,7 +4091,7 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str)
        float dist;
 
        if (hasNumInput(&t->num)) {
-               outputNumInput(&(t->num), tvec);
+               outputNumInput(&(t->num), tvec, &t->scene->unit);
                dist = len_v3(t->num.val);
        }
        else {
@@ -3861,11 +4102,12 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str)
 
                dist = len_v3(vec);
                if (!(t->flag & T_2D_EDIT) && t->scene->unit.system) {
-                       int i, do_split = t->scene->unit.flag & USER_UNIT_OPT_SPLIT ? 1 : 0;
+                       const bool do_split = (t->scene->unit.flag & USER_UNIT_OPT_SPLIT) != 0;
+                       int i;
 
                        for (i = 0; i < 3; i++) {
                                bUnit_AsString(&tvec[NUM_STR_REP_LEN * i], NUM_STR_REP_LEN, dvec[i] * t->scene->unit.scale_length,
-                                              4, t->scene->unit.system, B_UNIT_LENGTH, do_split, 1);
+                                              4, t->scene->unit.system, B_UNIT_LENGTH, do_split, true);
                        }
                }
                else {
@@ -3875,13 +4117,18 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str)
                }
        }
 
-       if (!(t->flag & T_2D_EDIT) && t->scene->unit.system)
+       if (!(t->flag & T_2D_EDIT) && t->scene->unit.system) {
+               const bool do_split = (t->scene->unit.flag & USER_UNIT_OPT_SPLIT) != 0;
                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 > 1e10f || dist < -1e10f)     /* prevent string buffer overflow */
+                              B_UNIT_LENGTH, do_split, false);
+       }
+       else if (dist > 1e10f || dist < -1e10f)  {
+               /* prevent string buffer overflow */
                BLI_snprintf(distvec, NUM_STR_REP_LEN, "%.4e", dist);
-       else
+       }
+       else {
                BLI_snprintf(distvec, NUM_STR_REP_LEN, "%.4f", dist);
+       }
 
        if (t->flag & T_AUTOIK) {
                short chainlen = t->settings->autoik_chainlen;
@@ -3928,7 +4175,7 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str)
        }
 }
 
-static void applyTranslation(TransInfo *t, float vec[3])
+static void applyTranslationValue(TransInfo *t, float vec[3])
 {
        TransData *td = t->data;
        float tvec[3];
@@ -3944,7 +4191,7 @@ static void applyTranslation(TransInfo *t, float vec[3])
                /* handle snapping rotation before doing the translation */
                if (usingSnappingNormal(t)) {
                        if (validSnappingNormal(t)) {
-                               float *original_normal;
+                               const float *original_normal;
                                float axis[3];
                                float quat[4];
                                float mat[3][3];
@@ -3995,14 +4242,14 @@ static void applyTranslation(TransInfo *t, float vec[3])
 }
 
 /* uses t->vec to store actual translation in */
-int Translation(TransInfo *t, const int UNUSED(mval[2]))
+static void applyTranslation(TransInfo *t, const int UNUSED(mval[2]))
 {
        char str[MAX_INFO_LEN];
 
        if (t->con.mode & CON_APPLY) {
                float pvec[3] = {0.0f, 0.0f, 0.0f};
                float tvec[3];
-               if (hasNumInput(&t->num)) {
+               if (applyNumInput(&t->num, t->values)) {
                        removeAspectRatio(t, t->values);
                }
                applySnapping(t, t->values);
@@ -4011,20 +4258,19 @@ int Translation(TransInfo *t, const int UNUSED(mval[2]))
                headerTranslation(t, pvec, str);
        }
        else {
-               snapGrid(t, t->values);
-               applyNumInput(&t->num, t->values);
-               if (hasNumInput(&t->num)) {
+               snapGridIncrement(t, t->values);
+               if (applyNumInput(&t->num, t->values)) {
                        removeAspectRatio(t, t->values);
                }
                applySnapping(t, t->values);
                headerTranslation(t, t->values, str);
        }
 
-       applyTranslation(t, t->values);
+       applyTranslationValue(t, t->values);
 
        /* evil hack - redo translation if clipping needed */
        if (t->flag & T_CLIP_UV && clipUVTransform(t, t->values, 0)) {
-               applyTranslation(t, t->values);
+               applyTranslationValue(t, t->values);
 
                /* In proportional edit it can happen that */
                /* vertices in the radius of the brush end */
@@ -4038,13 +4284,17 @@ int Translation(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
 
-/* ************************** SHRINK/FATTEN *************************** */
 
-void initShrinkFatten(TransInfo *t)
+/* -------------------------------------------------------------------- */
+/* Transform (Shrink-Fatten) */
+
+/** \name Transform Shrink-Fatten
+ * \{ */
+
+static void initShrinkFatten(TransInfo *t)
 {
        // If not in mesh edit mode, fallback to Resize
        if (t->obedit == NULL || t->obedit->type != OB_MESH) {
@@ -4052,7 +4302,7 @@ void initShrinkFatten(TransInfo *t)
        }
        else {
                t->mode = TFM_SHRINKFATTEN;
-               t->transform = ShrinkFatten;
+               t->transform = applyShrinkFatten;
 
                initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
 
@@ -4062,14 +4312,16 @@ void initShrinkFatten(TransInfo *t)
                t->snap[1] = 1.0f;
                t->snap[2] = t->snap[1] * 0.1f;
 
-               t->num.increment = t->snap[1];
+               copy_v3_fl(t->num.val_inc, t->snap[1]);
+               t->num.unit_sys = t->scene->unit.system;
+               t->num.unit_type[0] = B_UNIT_LENGTH;
 
                t->flag |= T_NO_CONSTRAINT;
        }
 }
 
 
-int ShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
+static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
 {
        float distance;
        int i;
@@ -4079,7 +4331,7 @@ int ShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
 
        distance = -t->values[0];
 
-       snapGrid(t, &distance);
+       snapGridIncrement(t, &distance);
 
        applyNumInput(&t->num, &distance);
 
@@ -4087,7 +4339,7 @@ int ShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
        ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Shrink/Fatten:"), MAX_INFO_LEN - ofs);
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
                ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, " %s", c);
        }
        else {
@@ -4107,7 +4359,7 @@ int ShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
                }
        }
        BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" or Alt) Even Thickness %s"),
-                    (t->flag & T_ALT_TRANSFORM) ? IFACE_("ON") : IFACE_("OFF"));
+                    WM_bool_as_string((t->flag & T_ALT_TRANSFORM) != 0));
        /* done with header string */
 
 
@@ -4133,33 +4385,39 @@ int ShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
 
-/* ************************** TILT *************************** */
 
-void initTilt(TransInfo *t)
+/* -------------------------------------------------------------------- */
+/* Transform (Tilt) */
+
+/** \name Transform Tilt
+ * \{ */
+
+static void initTilt(TransInfo *t)
 {
        t->mode = TFM_TILT;
-       t->transform = Tilt;
+       t->transform = applyTilt;
 
        initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
 
        t->idx_max = 0;
        t->num.idx_max = 0;
        t->snap[0] = 0.0f;
-       t->snap[1] = (float)((5.0 / 180) * M_PI);
-       t->snap[2] = t->snap[1] * 0.2f;
+       t->snap[1] = DEG2RAD(5.0);
+       t->snap[2] = DEG2RAD(1.0);
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[2]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
+       t->num.unit_type[0] = B_UNIT_ROTATION;
 
        t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT;
 }
 
 
-
-int Tilt(TransInfo *t, const int UNUSED(mval[2]))
+static void applyTilt(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td = t->data;
        int i;
@@ -4169,19 +4427,17 @@ int Tilt(TransInfo *t, const int UNUSED(mval[2]))
 
        final = t->values[0];
 
-       snapGrid(t, &final);
+       snapGridIncrement(t, &final);
+
+       applyNumInput(&t->num, &final);
 
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
 
-               applyNumInput(&t->num, &final);
-
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
 
                BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Tilt: %s° %s"), &c[0], t->proptext);
 
-               final = DEG2RADF(final);
-
                /* XXX For some reason, this seems needed for this op, else RNA prop is not updated... :/ */
                t->values[0] = final;
        }
@@ -4204,17 +4460,20 @@ int Tilt(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
 
 
-/* ******************** Curve Shrink/Fatten *************** */
+/* -------------------------------------------------------------------- */
+/* Transform (Curve Shrink/Fatten) */
 
-void initCurveShrinkFatten(TransInfo *t)
+/** \name Transform Curve Shrink/Fatten
+ * \{ */
+
+static void initCurveShrinkFatten(TransInfo *t)
 {
        t->mode = TFM_CURVE_SHRINKFATTEN;
-       t->transform = CurveShrinkFatten;
+       t->transform = applyCurveShrinkFatten;
 
        initMouseInputMode(t, &t->mouse, INPUT_SPRING);
 
@@ -4224,15 +4483,19 @@ void initCurveShrinkFatten(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
 
        t->flag |= T_NO_ZERO;
-       t->num.flag |= NUM_NO_ZERO;
+#ifdef USE_NUM_NO_ZERO
+       t->num.val_flag[0] |= NUM_NO_ZERO;
+#endif
 
        t->flag |= T_NO_CONSTRAINT;
 }
 
-int CurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
+static void applyCurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float ratio;
@@ -4241,7 +4504,7 @@ int CurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
 
        ratio = t->values[0];
 
-       snapGrid(t, &ratio);
+       snapGridIncrement(t, &ratio);
 
        applyNumInput(&t->num, &ratio);
 
@@ -4249,7 +4512,7 @@ int CurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
 
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
                BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shrink/Fatten: %s"), c);
        }
        else {
@@ -4274,15 +4537,20 @@ int CurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
+
 
+/* -------------------------------------------------------------------- */
+/* Transform (Mask Shrink/Fatten) */
 
-void initMaskShrinkFatten(TransInfo *t)
+/** \name Transform Mask Shrink/Fatten
+ * \{ */
+
+static void initMaskShrinkFatten(TransInfo *t)
 {
        t->mode = TFM_MASK_SHRINKFATTEN;
-       t->transform = MaskShrinkFatten;
+       t->transform = applyMaskShrinkFatten;
 
        initMouseInputMode(t, &t->mouse, INPUT_SPRING);
 
@@ -4292,24 +4560,29 @@ void initMaskShrinkFatten(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
 
        t->flag |= T_NO_ZERO;
-       t->num.flag |= NUM_NO_ZERO;
+#ifdef USE_NUM_NO_ZERO
+       t->num.val_flag[0] |= NUM_NO_ZERO;
+#endif
 
        t->flag |= T_NO_CONSTRAINT;
 }
 
-int MaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
+static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td;
        float ratio;
-       int i, initial_feather = FALSE;
+       int i;
+       bool initial_feather = false;
        char str[MAX_INFO_LEN];
 
        ratio = t->values[0];
 
-       snapGrid(t, &ratio);
+       snapGridIncrement(t, &ratio);
 
        applyNumInput(&t->num, &ratio);
 
@@ -4317,7 +4590,7 @@ int MaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
 
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
                BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Feather Shrink/Fatten: %s"), c);
        }
        else {
@@ -4326,7 +4599,7 @@ int MaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
 
        /* detect if no points have feather yet */
        if (ratio > 1.0f) {
-               initial_feather = TRUE;
+               initial_feather = true;
 
                for (td = t->data, i = 0; i < t->total; i++, td++) {
                        if (td->flag & TD_NOACTION)
@@ -4336,7 +4609,7 @@ int MaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
                                continue;
 
                        if (td->ival >= 0.001f)
-                               initial_feather = FALSE;
+                               initial_feather = false;
                }
        }
 
@@ -4363,16 +4636,20 @@ int MaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
+
 
-/* ************************** PUSH/PULL *************************** */
+/* -------------------------------------------------------------------- */
+/* Transform (Push/Pull) */
 
-void initPushPull(TransInfo *t)
+/** \name Transform Push/Pull
+ * \{ */
+
+static void initPushPull(TransInfo *t)
 {
        t->mode = TFM_PUSHPULL;
-       t->transform = PushPull;
+       t->transform = applyPushPull;
 
        initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
 
@@ -4382,11 +4659,13 @@ void initPushPull(TransInfo *t)
        t->snap[1] = 1.0f;
        t->snap[2] = t->snap[1] * 0.1f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_LENGTH;
 }
 
 
-int PushPull(TransInfo *t, const int UNUSED(mval[2]))
+static void applyPushPull(TransInfo *t, const int UNUSED(mval[2]))
 {
        float vec[3], axis[3];
        float distance;
@@ -4396,7 +4675,7 @@ int PushPull(TransInfo *t, const int UNUSED(mval[2]))
 
        distance = t->values[0];
 
-       snapGrid(t, &distance);
+       snapGridIncrement(t, &distance);
 
        applyNumInput(&t->num, &distance);
 
@@ -4404,7 +4683,7 @@ int PushPull(TransInfo *t, const int UNUSED(mval[2]))
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
 
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
 
                BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Push/Pull: %s%s %s"), c, t->con.text, t->proptext);
        }
@@ -4448,18 +4727,22 @@ int PushPull(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
+
 
-/* ************************** BEVEL WEIGHT *************************** */
+/* -------------------------------------------------------------------- */
+/* Transform (Bevel Weight) */
 
-void initBevelWeight(TransInfo *t)
+/** \name Transform Bevel Weight
+ * \{ */
+
+static void initBevelWeight(TransInfo *t)
 {
        t->mode = TFM_BWEIGHT;
-       t->transform = BevelWeight;
+       t->transform = applyBevelWeight;
 
-       initMouseInputMode(t, &t->mouse, INPUT_SPRING);
+       initMouseInputMode(t, &t->mouse, INPUT_SPRING_DELTA);
 
        t->idx_max = 0;
        t->num.idx_max = 0;
@@ -4467,12 +4750,14 @@ void initBevelWeight(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
 
        t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT;
 }
 
-int BevelWeight(TransInfo *t, const int UNUSED(mval[2]))
+static void applyBevelWeight(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float weight;
@@ -4481,10 +4766,9 @@ int BevelWeight(TransInfo *t, const int UNUSED(mval[2]))
 
        weight = t->values[0];
 
-       weight -= 1.0f;
        if (weight > 1.0f) weight = 1.0f;
 
-       snapGrid(t, &weight);
+       snapGridIncrement(t, &weight);
 
        applyNumInput(&t->num, &weight);
 
@@ -4492,7 +4776,7 @@ int BevelWeight(TransInfo *t, const int UNUSED(mval[2]))
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
 
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
 
                if (weight >= 0.0f)
                        BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bevel Weight: +%s %s"), c, t->proptext);
@@ -4521,18 +4805,22 @@ int BevelWeight(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
 
-/* ************************** CREASE *************************** */
 
-void initCrease(TransInfo *t)
+/* -------------------------------------------------------------------- */
+/* Transform (Crease) */
+
+/** \name Transform Crease
+ * \{ */
+
+static void initCrease(TransInfo *t)
 {
        t->mode = TFM_CREASE;
-       t->transform = Crease;
+       t->transform = applyCrease;
 
-       initMouseInputMode(t, &t->mouse, INPUT_SPRING);
+       initMouseInputMode(t, &t->mouse, INPUT_SPRING_DELTA);
 
        t->idx_max = 0;
        t->num.idx_max = 0;
@@ -4540,12 +4828,14 @@ void initCrease(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
 
        t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT;
 }
 
-int Crease(TransInfo *t, const int UNUSED(mval[2]))
+static void applyCrease(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float crease;
@@ -4554,10 +4844,9 @@ int Crease(TransInfo *t, const int UNUSED(mval[2]))
 
        crease = t->values[0];
 
-       crease -= 1.0f;
        if (crease > 1.0f) crease = 1.0f;
 
-       snapGrid(t, &crease);
+       snapGridIncrement(t, &crease);
 
        applyNumInput(&t->num, &crease);
 
@@ -4565,7 +4854,7 @@ int Crease(TransInfo *t, const int UNUSED(mval[2]))
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
 
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
 
                if (crease >= 0.0f)
                        BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Crease: +%s %s"), c, t->proptext);
@@ -4597,36 +4886,45 @@ int Crease(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
+
 
-/* ******************** EditBone (B-bone) width scaling *************** */
+/* -------------------------------------------------------------------- */
+/* Transform (EditBone (B-bone) width scaling) */
 
-void initBoneSize(TransInfo *t)
+/** \name Transform B-bone width scaling
+ * \{ */
+
+static void initBoneSize(TransInfo *t)
 {
        t->mode = TFM_BONESIZE;
-       t->transform = BoneSize;
+       t->transform = applyBoneSize;
 
        initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
 
        t->idx_max = 2;
        t->num.idx_max = 2;
-       t->num.flag |= NUM_NULL_ONE;
+       t->num.val_flag[0] |= NUM_NULL_ONE;
+       t->num.val_flag[1] |= NUM_NULL_ONE;
+       t->num.val_flag[2] |= 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];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
+       t->num.unit_type[1] = B_UNIT_NONE;
+       t->num.unit_type[2] = B_UNIT_NONE;
 }
 
-/* We assume str is MAX_INFO_LEN long. */
-static void headerBoneSize(TransInfo *t, float vec[3], char *str)
+static void headerBoneSize(TransInfo *t, float vec[3], char str[MAX_INFO_LEN])
 {
        char tvec[NUM_STR_REP_LEN * 3];
        if (hasNumInput(&t->num)) {
-               outputNumInput(&(t->num), tvec);
+               outputNumInput(&(t->num), tvec, &t->scene->unit);
        }
        else {
                BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", vec[0]);
@@ -4668,7 +4966,7 @@ static void ElementBoneSize(TransInfo *t, TransData *td, float mat[3][3])
        td->loc[1] = oldy;
 }
 
-int BoneSize(TransInfo *t, const int mval[2])
+static void applyBoneSize(TransInfo *t, const int mval[2])
 {
        TransData *td = t->data;
        float size[3], mat[3][3];
@@ -4687,10 +4985,9 @@ int BoneSize(TransInfo *t, const int mval[2])
        
        size[0] = size[1] = size[2] = ratio;
        
-       snapGrid(t, size);
+       snapGridIncrement(t, size);
        
-       if (hasNumInput(&t->num)) {
-               applyNumInput(&t->num, size);
+       if (applyNumInput(&t->num, size)) {
                constraintNumInput(t, size);
        }
        
@@ -4717,17 +5014,20 @@ int BoneSize(TransInfo *t, const int mval[2])
        recalcData(t);
        
        ED_area_headerprint(t->sa, str);
-       
-       return 1;
 }
+/** \} */
 
 
-/* ******************** EditBone envelope *************** */
+/* -------------------------------------------------------------------- */
+/* Transform (Bone Envelope) */
 
-void initBoneEnvelope(TransInfo *t)
+/** \name Transform Bone Envelope
+ * \{ */
+
+static void initBoneEnvelope(TransInfo *t)
 {
        t->mode = TFM_BONE_ENVELOPE;
-       t->transform = BoneEnvelope;
+       t->transform = applyBoneEnvelope;
        
        initMouseInputMode(t, &t->mouse, INPUT_SPRING);
        
@@ -4737,12 +5037,14 @@ void initBoneEnvelope(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
        
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
 
        t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT;
 }
 
-int BoneEnvelope(TransInfo *t, const int UNUSED(mval[2]))
+static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float ratio;
@@ -4751,7 +5053,7 @@ int BoneEnvelope(TransInfo *t, const int UNUSED(mval[2]))
        
        ratio = t->values[0];
        
-       snapGrid(t, &ratio);
+       snapGridIncrement(t, &ratio);
        
        applyNumInput(&t->num, &ratio);
        
@@ -4759,7 +5061,7 @@ int BoneEnvelope(TransInfo *t, const int UNUSED(mval[2]))
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
                
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
                BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Envelope: %s"), c);
        }
        else {
@@ -4785,11 +5087,16 @@ int BoneEnvelope(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
        
        ED_area_headerprint(t->sa, str);
-       
-       return 1;
 }
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/* Transform (Edge Slide) */
+
+/** \name Transform Edge Slide
+ * \{ */
 
-/* ********************  Edge Slide   *************** */
 static BMEdge *get_other_edge(BMVert *v, BMEdge *e)
 {
        BMIter iter;
@@ -4804,6 +5111,26 @@ static BMEdge *get_other_edge(BMVert *v, BMEdge *e)
        return NULL;
 }
 
+/* interpoaltes along a line made up of 2 segments (used for edge slide) */
+static void interp_line_v3_v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float t)
+{
+       float t_mid, t_delta;
+
+       /* could be pre-calculated */
+       t_mid = line_point_factor_v3(v2, v1, v3);
+
+       t_delta = t - t_mid;
+       if (fabsf(t_delta) < FLT_EPSILON) {
+               copy_v3_v3(p, v2);
+       }
+       else if (t_delta < 0.0f) {
+               interp_v3_v3v3(p, v1, v2, t / t_mid);
+       }
+       else {
+               interp_v3_v3v3(p, v2, v3, (t - t_mid) / (1.0f - t_mid));
+       }
+}
+
 static void len_v3_ensure(float v[3], const float length)
 {
        normalize_v3(v);
@@ -4834,7 +5161,7 @@ static bool bm_loop_calc_opposite_co(BMLoop *l_tmp,
                        const float fac = line_point_factor_v3(tvec, l_iter->v->co, l_iter->next->v->co);
                        /* allow some overlap to avoid missing the intersection because of float precision */
                        if ((fac > -FLT_EPSILON) && (fac < 1.0f + FLT_EPSILON)) {
-                               /* likelyhood of multiple intersections per ngon is quite low,
+                               /* likelihood of multiple intersections per ngon is quite low,
                                 * it would have to loop back on its self, but better support it
                                 * so check for the closest opposite edge */
                                const float tdist = len_v3v3(l_tmp->v->co, tvec);
@@ -4960,8 +5287,8 @@ static void calcNonProportionalEdgeSlide(TransInfo *t, EdgeSlideData *sld, const
                int i = 0;
 
                float v_proj[2];
-               float dist = 0;
-               float min_dist = FLT_MAX;
+               float dist_sq = 0;
+               float dist_min_sq = FLT_MAX;
 
                if (t->spacetype == SPACE_VIEW3D) {
                        /* background mode support */
@@ -4981,9 +5308,9 @@ static void calcNonProportionalEdgeSlide(TransInfo *t, EdgeSlideData *sld, const
                        sv->edge_len = len_v3v3(sv->dir_a, sv->dir_b);
 
                        ED_view3d_project_float_v2_m4(ar, sv->v->co, v_proj, projectMat);
-                       dist = len_squared_v2v2(mval, v_proj);
-                       if (dist < min_dist) {
-                               min_dist = dist;
+                       dist_sq = len_squared_v2v2(mval, v_proj);
+                       if (dist_sq < dist_min_sq) {
+                               dist_min_sq = dist_sq;
                                sld->curr_sv_index = i;
                        }
                }
@@ -5023,7 +5350,7 @@ static bool createEdgeSlideVerts(TransInfo *t)
 
        if ((t->settings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) &&
            /* don't do this at all for non-basis shape keys, too easy to
-                * accidentally break uv maps or vertex colors then */
+            * accidentally break uv maps or vertex colors then */
            (bm->shapenr <= 1))
        {
                sld->use_origfaces = true;
@@ -5034,7 +5361,7 @@ static bool createEdgeSlideVerts(TransInfo *t)
 
        sld->is_proportional = true;
        sld->curr_sv_index = 0;
-       sld->flipped_vtx = FALSE;
+       sld->flipped_vtx = false;
 
        if (!rv3d) {
                /* ok, let's try to survive this */
@@ -5107,7 +5434,17 @@ static bool createEdgeSlideVerts(TransInfo *t)
        while (1) {
                float vec_a[3], vec_b[3];
                BMLoop *l_a, *l_b;
+               BMLoop *l_a_prev, *l_b_prev;
                BMVert *v_first;
+               /* If this succeeds call get_next_loop()
+                * which calculates the direction to slide based on clever checks.
+                *
+                * otherwise we simply use 'e_dir' as an edge-rail.
+                * (which is better when the attached edge is a boundary, see: T40422)
+                */
+#define EDGESLIDE_VERT_IS_INNER(v, e_dir) \
+               ((BM_edge_is_boundary(e_dir) == false) && \
+                (BM_vert_edge_count_nonwire(v) == 2))
 
                v = NULL;
                BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
@@ -5128,7 +5465,6 @@ static bool createEdgeSlideVerts(TransInfo *t)
                e = v->e;
 
                /*first, rewind*/
-               numsel = 0;
                do {
                        e = get_other_edge(v, e);
                        if (!e) {
@@ -5136,8 +5472,6 @@ static bool createEdgeSlideVerts(TransInfo *t)
                                break;
                        }
 
-                       numsel += 1;
-
                        if (!BM_elem_flag_test(BM_edge_other_vert(e, v), BM_ELEM_TAG))
                                break;
 
@@ -5157,10 +5491,12 @@ static bool createEdgeSlideVerts(TransInfo *t)
                        }
                        else {
                                BMLoop *l_tmp = BM_loop_other_edge_loop(l_a, v);
-                               if (BM_vert_edge_count_nonwire(v) == 2)
+                               if (EDGESLIDE_VERT_IS_INNER(v, l_tmp->e)) {
                                        get_next_loop(v, l_a, e, l_tmp->e, vec_a);
-                               else
+                               }
+                               else {
                                        sub_v3_v3v3(vec_a, BM_edge_other_vert(l_tmp->e, v)->co, v->co);
+                               }
                        }
                }
 
@@ -5172,17 +5508,21 @@ static bool createEdgeSlideVerts(TransInfo *t)
                        }
                        else {
                                BMLoop *l_tmp = BM_loop_other_edge_loop(l_b, v);
-                               if (BM_vert_edge_count_nonwire(v) == 2)
+                               if (EDGESLIDE_VERT_IS_INNER(v, l_tmp->e)) {
                                        get_next_loop(v, l_b, e, l_tmp->e, vec_b);
-                               else
+                               }
+                               else {
                                        sub_v3_v3v3(vec_b, BM_edge_other_vert(l_tmp->e, v)->co, v->co);
-
+                               }
                        }
                }
                else {
                        l_b = NULL;
                }
 
+               l_a_prev = NULL;
+               l_b_prev = NULL;
+
                /*iterate over the loop*/
                v_first = v;
                do {
@@ -5200,14 +5540,14 @@ static bool createEdgeSlideVerts(TransInfo *t)
                        copy_v3_v3(sv->v_co_orig, v->co);
                        sv->loop_nr = loop_nr;
 
-                       if (l_a) {
-                               BMLoop *l_tmp = BM_loop_other_edge_loop(l_a, v);
+                       if (l_a || l_a_prev) {
+                               BMLoop *l_tmp = BM_loop_other_edge_loop(l_a ? l_a : l_a_prev, v);
                                sv->v_a = BM_edge_other_vert(l_tmp->e, v);
                                copy_v3_v3(sv->dir_a, vec_a);
                        }
 
-                       if (l_b) {
-                               BMLoop *l_tmp = BM_loop_other_edge_loop(l_b, v);
+                       if (l_b || l_b_prev) {
+                               BMLoop *l_tmp = BM_loop_other_edge_loop(l_b ? l_b : l_b_prev, v);
                                sv->v_b = BM_edge_other_vert(l_tmp->e, v);
                                copy_v3_v3(sv->dir_b, vec_b);
                        }
@@ -5229,7 +5569,7 @@ static bool createEdgeSlideVerts(TransInfo *t)
                                if (l_a) {
                                        BMLoop *l_tmp = BM_loop_other_edge_loop(l_a, v);
                                        sv->v_a = BM_edge_other_vert(l_tmp->e, v);
-                                       if (BM_vert_edge_count_nonwire(v) == 2) {
+                                       if (EDGESLIDE_VERT_IS_INNER(v, l_tmp->e)) {
                                                get_next_loop(v, l_a, e_prev, l_tmp->e, sv->dir_a);
                                        }
                                        else {
@@ -5240,7 +5580,7 @@ static bool createEdgeSlideVerts(TransInfo *t)
                                if (l_b) {
                                        BMLoop *l_tmp = BM_loop_other_edge_loop(l_b, v);
                                        sv->v_b = BM_edge_other_vert(l_tmp->e, v);
-                                       if (BM_vert_edge_count_nonwire(v) == 2) {
+                                       if (EDGESLIDE_VERT_IS_INNER(v, l_tmp->e)) {
                                                get_next_loop(v, l_b, e_prev, l_tmp->e, sv->dir_b);
                                        }
                                        else {
@@ -5256,29 +5596,54 @@ static bool createEdgeSlideVerts(TransInfo *t)
                        l_a_ok_prev = (l_a != NULL);
                        l_b_ok_prev = (l_b != NULL);
 
-                       l_a = l_a ? get_next_loop(v, l_a, e_prev, e, vec_a) : NULL;
-                       l_b = l_b ? get_next_loop(v, l_b, e_prev, e, vec_b) : NULL;
-
-                       /* find the opposite loop if it was missing previously */
-                       if      (l_a == NULL && l_b && (l_b->radial_next != l_b)) l_a = l_b->radial_next;
-                       else if (l_b == NULL && l_a && (l_a->radial_next != l_a)) l_b = l_a->radial_next;
-
-                       /* if there are non-contiguous faces, we can still recover the loops of the new edges faces */
-                       /* note!, the behavior in this case means edges may move in opposite directions,
-                        * this could be made to work more usefully. */
-                       if (!(l_a && l_b) && (e->l != NULL)) {
-                               if (l_a_ok_prev) {
-                                       l_a = e->l;
-                                       if (l_a->radial_next != l_a) {
-                                               l_b = l_a->radial_next;
-                                       }
+                       l_a_prev = l_a;
+                       l_b_prev = l_b;
+
+                       if (l_a) {
+                               l_a = get_next_loop(v, l_a, e_prev, e, vec_a);
+                       }
+                       else {
+                               zero_v3(vec_a);
+                       }
+
+                       if (l_b) {
+                               l_b = get_next_loop(v, l_b, e_prev, e, vec_b);
+                       }
+                       else {
+                               zero_v3(vec_b);
+                       }
+
+
+                       if (l_a && l_b) {
+                               /* pass */
+                       }
+                       else {
+                               if (l_a || l_b) {
+                                       /* find the opposite loop if it was missing previously */
+                                       if      (l_a == NULL && l_b && (l_b->radial_next != l_b)) l_a = l_b->radial_next;
+                                       else if (l_b == NULL && l_a && (l_a->radial_next != l_a)) l_b = l_a->radial_next;
                                }
-                               else if (l_b_ok_prev) {
-                                       l_b = e->l;
-                                       if (l_b->radial_next != l_b) {
-                                               l_a = l_b->radial_next;
+                               else if (e->l != NULL) {
+                                       /* if there are non-contiguous faces, we can still recover the loops of the new edges faces */
+                                       /* note!, the behavior in this case means edges may move in opposite directions,
+                                        * this could be made to work more usefully. */
+
+                                       if (l_a_ok_prev) {
+                                               l_a = e->l;
+                                               l_b = (l_a->radial_next != l_a) ? l_a->radial_next : NULL;
+                                       }
+                                       else if (l_b_ok_prev) {
+                                               l_b = e->l;
+                                               l_a = (l_b->radial_next != l_b) ? l_b->radial_next : NULL;
                                        }
                                }
+
+                               if (!l_a_ok_prev && l_a) {
+                                       get_next_loop(v, l_a, e, e_prev, vec_a);
+                               }
+                               if (!l_b_ok_prev && l_b) {
+                                       get_next_loop(v, l_b, e, e_prev, vec_b);
+                               }
                        }
 
                        BM_elem_flag_disable(v, BM_ELEM_TAG);
@@ -5286,13 +5651,15 @@ static bool createEdgeSlideVerts(TransInfo *t)
                } while ((e != v_first->e) && (l_a || l_b));
 
                loop_nr++;
+
+#undef EDGESLIDE_VERT_IS_INNER
        }
 
        /* use for visibility checks */
        use_btree_disp = (v3d && t->obedit->dt > OB_WIRE && v3d->drawtype > OB_WIRE);
 
        if (use_btree_disp) {
-               btree = BKE_bmbvh_new(em, BMBVH_RESPECT_HIDDEN, NULL, false);
+               btree = BKE_bmbvh_new_from_editmesh(em, BMBVH_RESPECT_HIDDEN, NULL, false);
        }
        else {
                btree = NULL;
@@ -5627,12 +5994,12 @@ void freeEdgeSlideVerts(TransInfo *t)
        recalcData(t);
 }
 
-void initEdgeSlide(TransInfo *t)
+static void initEdgeSlide(TransInfo *t)
 {
        EdgeSlideData *sld;
 
        t->mode = TFM_EDGE_SLIDE;
-       t->transform = EdgeSlide;
+       t->transform = applyEdgeSlide;
        t->handleEvent = handleEventEdgeSlide;
 
        if (!createEdgeSlideVerts(t)) {
@@ -5657,12 +6024,14 @@ void initEdgeSlide(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
 
        t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT;
 }
 
-int handleEventEdgeSlide(struct TransInfo *t, const struct wmEvent *event)
+static eRedrawFlag handleEventEdgeSlide(struct TransInfo *t, const struct wmEvent *event)
 {
        if (t->mode == TFM_EDGE_SLIDE) {
                EdgeSlideData *sld = t->customData;
@@ -5672,16 +6041,16 @@ int handleEventEdgeSlide(struct TransInfo *t, const struct wmEvent *event)
                                case EKEY:
                                        if (event->val == KM_PRESS) {
                                                sld->is_proportional = !sld->is_proportional;
-                                               return 1;
+                                               return TREDRAW_HARD;
                                        }
                                        break;
                                case FKEY:
                                {
                                        if (event->val == KM_PRESS) {
-                                               if (sld->is_proportional == FALSE) {
+                                               if (sld->is_proportional == false) {
                                                        sld->flipped_vtx = !sld->flipped_vtx;
                                                }
-                                               return 1;
+                                               return TREDRAW_HARD;
                                        }
                                        break;
                                }
@@ -5706,7 +6075,7 @@ int handleEventEdgeSlide(struct TransInfo *t, const struct wmEvent *event)
                        }
                }
        }
-       return 0;
+       return TREDRAW_NOTHING;
 }
 
 static void drawEdgeSlide(const struct bContext *C, TransInfo *t)
@@ -5714,22 +6083,18 @@ static void drawEdgeSlide(const struct bContext *C, TransInfo *t)
        if (t->mode == TFM_EDGE_SLIDE) {
                EdgeSlideData *sld = (EdgeSlideData *)t->customData;
                /* Non-Prop mode */
-               if (sld && sld->is_proportional == FALSE) {
+               if (sld && sld->is_proportional == false) {
                        View3D *v3d = CTX_wm_view3d(C);
-                       float marker[3];
-                       float v1[3], v2[3];
-                       float interp_v;
+                       float co_a[3], co_b[3], co_mark[3];
                        TransDataEdgeSlideVert *curr_sv = &sld->sv[sld->curr_sv_index];
+                       const float fac = (sld->perc + 1.0f) / 2.0f;
                        const float ctrl_size = UI_GetThemeValuef(TH_FACEDOT_SIZE) + 1.5f;
                        const float guide_size = ctrl_size - 0.5f;
                        const float line_size = UI_GetThemeValuef(TH_OUTLINE_WIDTH) + 0.5f;
                        const int alpha_shade = -30;
 
-                       add_v3_v3v3(v1, curr_sv->v_co_orig, curr_sv->dir_a);
-                       add_v3_v3v3(v2, curr_sv->v_co_orig, curr_sv->dir_b);
-
-                       interp_v = (sld->perc + 1.0f) / 2.0f;
-                       interp_v3_v3v3(marker, v2, v1, interp_v);
+                       add_v3_v3v3(co_a, curr_sv->v_co_orig, curr_sv->dir_a);
+                       add_v3_v3v3(co_b, curr_sv->v_co_orig, curr_sv->dir_b);
 
                        if (v3d && v3d->zbuf)
                                glDisable(GL_DEPTH_TEST);
@@ -5770,7 +6135,12 @@ static void drawEdgeSlide(const struct bContext *C, TransInfo *t)
                        UI_ThemeColorShadeAlpha(TH_SELECT, 255, alpha_shade);
                        glPointSize(guide_size);
                        bglBegin(GL_POINTS);
-                       bglVertex3fv(marker);
+#if 0
+                       interp_v3_v3v3(co_mark, co_b, co_a, fac);
+                       bglVertex3fv(co_mark);
+#endif
+                       interp_line_v3_v3v3v3(co_mark, co_b, curr_sv->v_co_orig, co_a, fac);
+                       bglVertex3fv(co_mark);
                        bglEnd();
 
 
@@ -5794,7 +6164,7 @@ static int doEdgeSlide(TransInfo *t, float perc)
        sld->perc = perc;
        sv = svlist;
 
-       if (sld->is_proportional == TRUE) {
+       if (sld->is_proportional == true) {
                for (i = 0; i < sld->totsv; i++, sv++) {
                        float vec[3];
                        if (perc > 0.0f) {
@@ -5832,10 +6202,10 @@ static int doEdgeSlide(TransInfo *t, float perc)
                                add_v3_v3v3(co_b, sv->v_co_orig, sv->dir_b);
 
                                if (sld->flipped_vtx) {
-                                       interp_v3_v3v3(sv->v->co, co_b, co_a, fac);
+                                       interp_line_v3_v3v3v3(sv->v->co, co_b, sv->v_co_orig, co_a, fac);
                                }
                                else {
-                                       interp_v3_v3v3(sv->v->co, co_a, co_b, fac);
+                                       interp_line_v3_v3v3v3(sv->v->co, co_a, sv->v_co_orig, co_b, fac);
                                }
                        }
                }
@@ -5846,7 +6216,7 @@ static int doEdgeSlide(TransInfo *t, float perc)
        return 1;
 }
 
-int EdgeSlide(TransInfo *t, const int UNUSED(mval[2]))
+static void applyEdgeSlide(TransInfo *t, const int UNUSED(mval[2]))
 {
        char str[MAX_INFO_LEN];
        float final;
@@ -5854,29 +6224,36 @@ int EdgeSlide(TransInfo *t, const int UNUSED(mval[2]))
        bool flipped = sld->flipped_vtx;
        bool is_proportional = sld->is_proportional;
 
-       const char *on_str = IFACE_("ON");
-       const char *off_str = IFACE_("OFF");
-
        final = t->values[0];
 
-       snapGrid(t, &final);
+       snapGridIncrement(t, &final);
 
        /* only do this so out of range values are not displayed */
        CLAMP(final, -1.0f, 1.0f);
 
+       applyNumInput(&t->num, &final);
+
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
 
-               applyNumInput(&t->num, &final);
+               outputNumInput(&(t->num), c, &t->scene->unit);
 
-               outputNumInput(&(t->num), c);
-
-               BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Edge Slide: %s (E)ven: %s, (F)lipped: %s"),
-                            &c[0], !is_proportional ? on_str : off_str, flipped ? on_str : off_str);
+               if (is_proportional) {
+                       BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Edge Slide: %s (E)ven: %s"),
+                                    &c[0], WM_bool_as_string(!is_proportional));
+               }
+               else {
+                       BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Edge Slide: %s (E)ven: %s, (F)lipped: %s"),
+                                    &c[0], WM_bool_as_string(!is_proportional), WM_bool_as_string(flipped));
+               }
+       }
+       else if (is_proportional) {
+               BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Edge Slide: %.4f (E)ven: %s"),
+                            final, WM_bool_as_string(!is_proportional));
        }
        else {
                BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Edge Slide: %.4f (E)ven: %s, (F)lipped: %s"),
-                            final, !is_proportional ? on_str : off_str, flipped ? on_str : off_str);
+                            final, WM_bool_as_string(!is_proportional), WM_bool_as_string(flipped));
        }
 
        CLAMP(final, -1.0f, 1.0f);
@@ -5889,18 +6266,22 @@ int EdgeSlide(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
+
 
+/* -------------------------------------------------------------------- */
+/* Transform (Vert Slide) */
+
+/** \name Transform Vert Slide
+ * \{ */
 
-/* ******************** Vert Slide *************** */
 static void calcVertSlideCustomPoints(struct TransInfo *t)
 {
        VertSlideData *sld = t->customData;
        TransDataVertSlideVert *sv = &sld->sv[sld->curr_sv_index];
-       float *co_orig = sv->co_orig_2d;
-       float *co_curr = sv->co_link_orig_2d[sv->co_link_curr];
+       const float *co_orig = sv->co_orig_2d;
+       const float *co_curr = sv->co_link_orig_2d[sv->co_link_curr];
        const int mval_start[2] = {co_orig[0], co_orig[1]};
        const int mval_end[2]   = {co_curr[0], co_curr[1]};
 
@@ -5922,14 +6303,14 @@ static void calcVertSlideMouseActiveVert(struct TransInfo *t, const int mval[2])
        TransDataVertSlideVert *sv;
 
        /* set the vertex to use as a reference for the mouse direction 'curr_sv_index' */
-       float dist = 0.0f;
-       float min_dist = FLT_MAX;
+       float dist_sq = 0.0f;
+       float dist_min_sq = FLT_MAX;
        int i;
 
        for (i = 0, sv = sld->sv; i < sld->totsv; i++, sv++) {
-               dist = len_squared_v2v2(mval_fl, sv->co_orig_2d);
-               if (dist < min_dist) {
-                       min_dist = dist;
+               dist_sq = len_squared_v2v2(mval_fl, sv->co_orig_2d);
+               if (dist_sq < dist_min_sq) {
+                       dist_min_sq = dist_sq;
                        sld->curr_sv_index = i;
                }
        }
@@ -6131,12 +6512,12 @@ void freeVertSlideVerts(TransInfo *t)
        recalcData(t);
 }
 
-void initVertSlide(TransInfo *t)
+static void initVertSlide(TransInfo *t)
 {
        VertSlideData *sld;
 
        t->mode = TFM_VERT_SLIDE;
-       t->transform = VertSlide;
+       t->transform = applyVertSlide;
        t->handleEvent = handleEventVertSlide;
 
        if (!createVertSlideVerts(t)) {
@@ -6161,12 +6542,14 @@ void initVertSlide(TransInfo *t)
        t->snap[1] = 0.1f;
        t->snap[2] = t->snap[1] * 0.1f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
 
        t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT;
 }
 
-int handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
+static eRedrawFlag handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
 {
        if (t->mode == TFM_VERT_SLIDE) {
                VertSlideData *sld = t->customData;
@@ -6179,7 +6562,7 @@ int handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
                                                if (sld->flipped_vtx) {
                                                        calcVertSlideCustomPoints(t);
                                                }
-                                               return 1;
+                                               return TREDRAW_HARD;
                                        }
                                        break;
                                case FKEY:
@@ -6187,7 +6570,7 @@ int handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
                                        if (event->val == KM_PRESS) {
                                                sld->flipped_vtx = !sld->flipped_vtx;
                                                calcVertSlideCustomPoints(t);
-                                               return 1;
+                                               return TREDRAW_HARD;
                                        }
                                        break;
                                }
@@ -6197,7 +6580,7 @@ int handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
                                        if (event->val == KM_PRESS) {
                                                t->flag ^= T_ALT_TRANSFORM;
                                                calcVertSlideCustomPoints(t);
-                                               return 1;
+                                               return TREDRAW_HARD;
                                        }
                                        break;
                                }
@@ -6233,7 +6616,7 @@ int handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
                        }
                }
        }
-       return 0;
+       return TREDRAW_NOTHING;
 }
 
 static void drawVertSlide(const struct bContext *C, TransInfo *t)
@@ -6291,7 +6674,7 @@ static void drawVertSlide(const struct bContext *C, TransInfo *t)
                        glPointSize(ctrl_size);
 
                        bglBegin(GL_POINTS);
-                       bglVertex3fv((sld->flipped_vtx && sld->is_proportional == FALSE) ?
+                       bglVertex3fv((sld->flipped_vtx && sld->is_proportional == false) ?
                                     curr_sv->co_link_orig_3d[curr_sv->co_link_curr] :
                                     curr_sv->co_orig_3d);
                        bglEnd();
@@ -6316,7 +6699,7 @@ static int doVertSlide(TransInfo *t, float perc)
        sld->perc = perc;
        sv = svlist;
 
-       if (sld->is_proportional == TRUE) {
+       if (sld->is_proportional == true) {
                for (i = 0; i < sld->totsv; i++, sv++) {
                        interp_v3_v3v3(sv->v->co, sv->co_orig_3d, sv->co_link_orig_3d[sv->co_link_curr], perc);
                }
@@ -6350,7 +6733,7 @@ static int doVertSlide(TransInfo *t, float perc)
        return 1;
 }
 
-int VertSlide(TransInfo *t, const int UNUSED(mval[2]))
+static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2]))
 {
        char str[MAX_INFO_LEN];
        size_t ofs = 0;
@@ -6361,34 +6744,32 @@ int VertSlide(TransInfo *t, const int UNUSED(mval[2]))
        const bool is_clamp = !(t->flag & T_ALT_TRANSFORM);
        const bool is_constrained = !(is_clamp == false || hasNumInput(&t->num));
 
-       const char *on_str = IFACE_("ON");
-       const char *off_str = IFACE_("OFF");
-
        final = t->values[0];
 
-       snapGrid(t, &final);
+       snapGridIncrement(t, &final);
 
        /* only do this so out of range values are not displayed */
        if (is_constrained) {
                CLAMP(final, 0.0f, 1.0f);
        }
 
+       applyNumInput(&t->num, &final);
+
        /* header string */
        ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Vert Slide: "), MAX_INFO_LEN - ofs);
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
-               applyNumInput(&t->num, &final);
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
                ofs += BLI_strncpy_rlen(str + ofs, &c[0], MAX_INFO_LEN - ofs);
        }
        else {
                ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "%.4f ", final);
        }
-       ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("(E)ven: %s, "), !is_proportional ? on_str : off_str);
+       ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("(E)ven: %s, "), WM_bool_as_string(!is_proportional));
        if (!is_proportional) {
-               ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("(F)lipped: %s, "), flipped ? on_str : off_str);
+               ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("(F)lipped: %s, "), WM_bool_as_string(flipped));
        }
-       ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Alt or (C)lamp: %s"), is_clamp ? on_str : off_str);
+       ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Alt or (C)lamp: %s"), WM_bool_as_string(is_clamp));
        /* done with header string */
 
        /* do stuff here */
@@ -6397,32 +6778,38 @@ int VertSlide(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
 
 
-/* ******************** EditBone roll *************** */
+/* -------------------------------------------------------------------- */
+/* Transform (EditBone Roll) */
 
-void initBoneRoll(TransInfo *t)
+/** \name Transform EditBone Roll
+ * \{ */
+
+static void initBoneRoll(TransInfo *t)
 {
        t->mode = TFM_BONE_ROLL;
-       t->transform = BoneRoll;
+       t->transform = applyBoneRoll;
 
        initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
 
        t->idx_max = 0;
        t->num.idx_max = 0;
        t->snap[0] = 0.0f;
-       t->snap[1] = (float)((5.0 / 180) * M_PI);
-       t->snap[2] = t->snap[1] * 0.2f;
+       t->snap[1] = DEG2RAD(5.0);
+       t->snap[2] = DEG2RAD(1.0);
 
-       t->num.increment = 1.0f;
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
+       t->num.unit_type[0] = B_UNIT_ROTATION;
 
        t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT;
 }
 
-int BoneRoll(TransInfo *t, const int UNUSED(mval[2]))
+static void applyBoneRoll(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td = t->data;
        int i;
@@ -6432,18 +6819,16 @@ int BoneRoll(TransInfo *t, const int UNUSED(mval[2]))
 
        final = t->values[0];
 
-       snapGrid(t, &final);
+       snapGridIncrement(t, &final);
+
+       applyNumInput(&t->num, &final);
 
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
 
-               applyNumInput(&t->num, &final);
-
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
 
                BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Roll: %s"), &c[0]);
-
-               final = DEG2RADF(final);
        }
        else {
                BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Roll: %.2f"), RAD2DEGF(final));
@@ -6463,15 +6848,19 @@ int BoneRoll(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/* Transform (Bake-Time) */
 
-/* ************************** BAKE TIME ******************* */
+/** \name Transform Bake-Time
+ * \{ */
 
-void initBakeTime(TransInfo *t)
+static void initBakeTime(TransInfo *t)
 {
-       t->transform = BakeTime;
+       t->transform = applyBakeTime;
        initMouseInputMode(t, &t->mouse, INPUT_NONE);
 
        t->idx_max = 0;
@@ -6480,10 +6869,12 @@ void initBakeTime(TransInfo *t)
        t->snap[1] = 1.0f;
        t->snap[2] = t->snap[1] * 0.1f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;  /* Don't think this uses units? */
 }
 
-int BakeTime(TransInfo *t, const int mval[2])
+static void applyBakeTime(TransInfo *t, const int mval[2])
 {
        TransData *td = t->data;
        float time;
@@ -6501,7 +6892,7 @@ int BakeTime(TransInfo *t, const int mval[2])
                time = (float)(t->center2d[0] - mval[0]) * fac;
        }
 
-       snapGrid(t, &time);
+       snapGridIncrement(t, &time);
 
        applyNumInput(&t->num, &time);
 
@@ -6509,7 +6900,7 @@ int BakeTime(TransInfo *t, const int mval[2])
        if (hasNumInput(&t->num)) {
                char c[NUM_STR_REP_LEN];
 
-               outputNumInput(&(t->num), c);
+               outputNumInput(&(t->num), c, &t->scene->unit);
 
                if (time >= 0.0f)
                        BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Time: +%s %s"), c, t->proptext);
@@ -6541,15 +6932,19 @@ int BakeTime(TransInfo *t, const int mval[2])
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/* Transform (Mirror) */
 
-/* ************************** MIRROR *************************** */
+/** \name Transform Mirror
+ * \{ */
 
-void initMirror(TransInfo *t)
+static void initMirror(TransInfo *t)
 {
-       t->transform = Mirror;
+       t->transform = applyMirror;
        initMouseInputMode(t, &t->mouse, INPUT_NONE);
 
        t->flag |= T_NULL_ONE;
@@ -6558,7 +6953,7 @@ void initMirror(TransInfo *t)
        }
 }
 
-int Mirror(TransInfo *t, const int UNUSED(mval[2]))
+static void applyMirror(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td;
        float size[3], mat[3][3];
@@ -6619,22 +7014,26 @@ int Mirror(TransInfo *t, const int UNUSED(mval[2]))
                else
                        ED_area_headerprint(t->sa, IFACE_("Select a mirror axis (X, Y, Z)"));
        }
-
-       return 1;
 }
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/* Transform (Align) */
 
-/* ************************** ALIGN *************************** */
+/** \name Transform Align
+ * \{ */
 
-void initAlign(TransInfo *t)
+static void initAlign(TransInfo *t)
 {
        t->flag |= T_NO_CONSTRAINT;
 
-       t->transform = Align;
+       t->transform = applyAlign;
 
        initMouseInputMode(t, &t->mouse, INPUT_NONE);
 }
 
-int Align(TransInfo *t, const int UNUSED(mval[2]))
+static void applyAlign(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td = t->data;
        float center[3];
@@ -6675,15 +7074,19 @@ int Align(TransInfo *t, const int UNUSED(mval[2]))
        recalcData(t);
 
        ED_area_headerprint(t->sa, IFACE_("Align"));
-
-       return 1;
 }
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/* Transform (Sequencer Slide) */
 
-/* ************************** SEQ SLIDE *************************** */
+/** \name Transform Sequencer Slide
+ * \{ */
 
-void initSeqSlide(TransInfo *t)
+static void initSeqSlide(TransInfo *t)
 {
-       t->transform = SeqSlide;
+       t->transform = applySeqSlide;
 
        initMouseInputMode(t, &t->mouse, INPUT_VECTOR);
 
@@ -6695,17 +7098,20 @@ void initSeqSlide(TransInfo *t)
        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];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       /* Would be nice to have a time handling in units as well (supporting frames in addition to "natural" time...). */
+       t->num.unit_type[0] = B_UNIT_NONE;
+       t->num.unit_type[1] = B_UNIT_NONE;
 }
 
-/* We assume str is MAX_INFO_LEN long. */
-static void headerSeqSlide(TransInfo *t, float val[2], char *str)
+static void headerSeqSlide(TransInfo *t, float val[2], char str[MAX_INFO_LEN])
 {
        char tvec[NUM_STR_REP_LEN * 3];
        size_t ofs = 0;
 
        if (hasNumInput(&t->num)) {
-               outputNumInput(&(t->num), tvec);
+               outputNumInput(&(t->num), tvec, &t->scene->unit);
        }
        else {
                BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.0f, %.0f", val[0], val[1]);
@@ -6720,10 +7126,10 @@ static void headerSeqSlide(TransInfo *t, float val[2], char *str)
                }
        }
        ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" or Alt) Expand to fit %s"),
-                           (t->flag & T_ALT_TRANSFORM) ? IFACE_("ON") : IFACE_("OFF"));
+                           WM_bool_as_string((t->flag & T_ALT_TRANSFORM) != 0));
 }
 
-static void applySeqSlide(TransInfo *t, const float val[2])
+static void applySeqSlideValue(TransInfo *t, const float val[2])
 {
        TransData *td = t->data;
        int i;
@@ -6746,7 +7152,7 @@ static void applySeqSlide(TransInfo *t, const float val[2])
        }
 }
 
-int SeqSlide(TransInfo *t, const int UNUSED(mval[2]))
+static void applySeqSlide(TransInfo *t, const int UNUSED(mval[2]))
 {
        char str[MAX_INFO_LEN];
 
@@ -6757,7 +7163,7 @@ int SeqSlide(TransInfo *t, const int UNUSED(mval[2]))
                copy_v3_v3(t->values, tvec);
        }
        else {
-               snapGrid(t, t->values);
+               snapGridIncrement(t, t->values);
                applyNumInput(&t->num, t->values);
        }
 
@@ -6765,19 +7171,23 @@ int SeqSlide(TransInfo *t, const int UNUSED(mval[2]))
        t->values[1] = floor(t->values[1] + 0.5f);
 
        headerSeqSlide(t, t->values, str);
-       applySeqSlide(t, t->values);
+       applySeqSlideValue(t, t->values);
 
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
 
-/* ************************** ANIM EDITORS - TRANSFORM TOOLS *************************** */
 
-/* ---------------- Special Helpers for Various Settings ------------- */
+/* -------------------------------------------------------------------- */
+/* Animation Editors - Transform Utils
+ *
+ * Special Helpers for Various Settings
+ */
 
+/** \name Animation Editor Utils
+ * \{ */
 
 /* This function returns the snapping 'mode' for Animation Editors only
  * We cannot use the standard snapping due to NLA-strip scaling complexities.
@@ -6822,55 +7232,15 @@ static short getAnimEdit_SnapMode(TransInfo *t)
        return autosnap;
 }
 
-/* This function is used for testing if an Animation Editor is displaying
- * its data in frames or seconds (and the data needing to be edited as such).
- * Returns 1 if in seconds, 0 if in frames
- */
-static short getAnimEdit_DrawTime(TransInfo *t)
-{
-       short drawtime;
-
-       if (t->spacetype == SPACE_ACTION) {
-               SpaceAction *saction = (SpaceAction *)t->sa->spacedata.first;
-               
-               drawtime = (saction->flag & SACTION_DRAWTIME) ? 1 : 0;
-       }
-       else if (t->spacetype == SPACE_NLA) {
-               SpaceNla *snla = (SpaceNla *)t->sa->spacedata.first;
-               
-               drawtime = (snla->flag & SNLA_DRAWTIME) ? 1 : 0;
-       }
-       else if (t->spacetype == SPACE_IPO) {
-               SpaceIpo *sipo = (SpaceIpo *)t->sa->spacedata.first;
-               
-               drawtime = (sipo->flag & SIPO_DRAWTIME) ? 1 : 0;
-       }
-       else {
-               drawtime = 0;
-       }
-
-       return drawtime;
-}
-
-
 /* 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, TransData2D *td2d, AnimData *adt, short autosnap)
 {
-       /* snap key to nearest frame? */
-       if (autosnap == SACTSNAP_FRAME) {
-
-#if 0   /* 'do_time' disabled for now */
-
+       /* snap key to nearest frame or second? */
+       if (ELEM(autosnap, SACTSNAP_FRAME, SACTSNAP_SECOND)) {
                const Scene *scene = t->scene;
-#if 0   /* NOTE: this works, but may be confusing behavior given the option's label, hence disabled */
-               const short do_time = getAnimEdit_DrawTime(t);
-#else
-               const short do_time = 0;
-#endif
                const double secf = FPS;
-#endif
                double val;
                
                /* convert frame to nla-action time (if needed) */
@@ -6879,16 +7249,12 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, TransData2D *td2d,
                else
                        val = *(td->val);
                
-#if 0   /* 'do_time' disabled for now */
-
                /* do the snapping to nearest frame/second */
-               if (do_time) {
-                       val = (float)(floor((val / secf) + 0.5f) * secf);
+               if (autosnap == SACTSNAP_FRAME) {
+                       val = floorf(val + 0.5);
                }
-               else
-#endif
-               {
-                       val = floor(val + 0.5);
+               else if (autosnap == SACTSNAP_SECOND) {
+                       val = (float)(floor((val / secf) + 0.5) * secf);
                }
                
                /* convert frame out of nla-action time */
@@ -6929,10 +7295,16 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, TransData2D *td2d,
                td2d->h2[0] = td2d->ih2[0] + *td->val - td->ival;
        }
 }
+/** \} */
+
 
-/* ----------------- Translation ----------------------- */
+/* -------------------------------------------------------------------- */
+/* Transform (Animation Translation) */
 
-void initTimeTranslate(TransInfo *t)
+/** \name Transform Animation Translation
+ * \{ */
+
+static void initTimeTranslate(TransInfo *t)
 {
        /* this tool is only really available in the Action Editor... */
        if (!ELEM(t->spacetype, SPACE_ACTION, SPACE_SEQ)) {
@@ -6940,7 +7312,7 @@ void initTimeTranslate(TransInfo *t)
        }
 
        t->mode = TFM_TIME_TRANSLATE;
-       t->transform = TimeTranslate;
+       t->transform = applyTimeTranslate;
 
        initMouseInputMode(t, &t->mouse, INPUT_NONE);
 
@@ -6953,39 +7325,46 @@ void initTimeTranslate(TransInfo *t)
        t->snap[0] = 0.0f;
        t->snap[1] = t->snap[2] = 1.0f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       /* No time unit supporting frames currently... */
+       t->num.unit_type[0] = B_UNIT_NONE;
 }
 
-/* We assume str is MAX_INFO_LEN long. */
-static void headerTimeTranslate(TransInfo *t, char *str)
+static void headerTimeTranslate(TransInfo *t, char str[MAX_INFO_LEN])
 {
        char tvec[NUM_STR_REP_LEN * 3];
 
        /* if numeric input is active, use results from that, otherwise apply snapping to result */
        if (hasNumInput(&t->num)) {
-               outputNumInput(&(t->num), tvec);
+               outputNumInput(&(t->num), tvec, &t->scene->unit);
        }
        else {
                const Scene *scene = t->scene;
                const short autosnap = getAnimEdit_SnapMode(t);
-               const short do_time = getAnimEdit_DrawTime(t);
                const double secf = FPS;
                float val = t->values[0];
                
                /* apply snapping + frame->seconds conversions */
                if (autosnap == SACTSNAP_STEP) {
-                       if (do_time)
-                               val = floorf((double)val / secf + 0.5);
-                       else
-                               val = floorf(val + 0.5f);
+                       /* frame step */
+                       val = floorf(val + 0.5f);
                }
-               else {
-                       if (do_time)
-                               val = (float)((double)val / secf);
+               else if (autosnap == SACTSNAP_TSTEP) {
+                       /* second step */
+                       val = floorf((double)val / secf + 0.5);
+               }
+               else if (autosnap == SACTSNAP_SECOND) {
+                       /* nearest second */
+                       val = (float)((double)val / secf);
                }
                
                if (autosnap == SACTSNAP_FRAME)
                        BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%d.00 (%.4f)", (int)val, val);
+               else if (autosnap == SACTSNAP_SECOND)
+                       BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%d.00 sec (%.4f)", (int)val, val);
+               else if (autosnap == SACTSNAP_TSTEP)
+                       BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f sec", val);
                else
                        BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", val);
        }
@@ -6993,17 +7372,15 @@ static void headerTimeTranslate(TransInfo *t, char *str)
        BLI_snprintf(str, MAX_INFO_LEN, IFACE_("DeltaX: %s"), &tvec[0]);
 }
 
-static void applyTimeTranslate(TransInfo *t, float UNUSED(sval))
+static void applyTimeTranslateValue(TransInfo *t, float UNUSED(sval))
 {
        TransData *td = t->data;
        TransData2D *td2d = t->data2d;
        Scene *scene = t->scene;
        int i;
-
-       const short do_time = getAnimEdit_DrawTime(t);
-       const double secf = FPS;
-
+       
        const short autosnap = getAnimEdit_SnapMode(t);
+       const double secf = FPS;
 
        float deltax, val /* , valprev */;
 
@@ -7018,14 +7395,14 @@ static void applyTimeTranslate(TransInfo *t, float UNUSED(sval))
                /* valprev = *td->val; */ /* UNUSED */
 
                /* check if any need to apply nla-mapping */
-               if (adt && t->spacetype != SPACE_SEQ) {
+               if (adt && (t->spacetype != SPACE_SEQ)) {
                        deltax = t->values[0];
 
-                       if (autosnap == SACTSNAP_STEP) {
-                               if (do_time)
-                                       deltax = (float)(floor(((double)deltax / secf) + 0.5) * secf);
-                               else
-                                       deltax = (float)(floor(deltax + 0.5f));
+                       if (autosnap == SACTSNAP_TSTEP) {
+                               deltax = (float)(floor(((double)deltax / secf) + 0.5) * secf);
+                       }
+                       else if (autosnap == SACTSNAP_STEP) {
+                               deltax = (float)(floor(deltax + 0.5f));
                        }
 
                        val = BKE_nla_tweakedit_remap(adt, td->ival, NLATIME_CONVERT_MAP);
@@ -7035,11 +7412,11 @@ static void applyTimeTranslate(TransInfo *t, float UNUSED(sval))
                else {
                        deltax = val = t->values[0];
 
-                       if (autosnap == SACTSNAP_STEP) {
-                               if (do_time)
-                                       val = (float)(floor(((double)deltax / secf) + 0.5) * secf);
-                               else
-                                       val = (float)(floor(val + 0.5f));
+                       if (autosnap == SACTSNAP_TSTEP) {
+                               val = (float)(floor(((double)deltax / secf) + 0.5) * secf);
+                       }
+                       else if (autosnap == SACTSNAP_STEP) {
+                               val = (float)(floor(val + 0.5f));
                        }
 
                        *(td->val) = td->ival + val;
@@ -7050,7 +7427,7 @@ static void applyTimeTranslate(TransInfo *t, float UNUSED(sval))
        }
 }
 
-int TimeTranslate(TransInfo *t, const int mval[2])
+static void applyTimeTranslate(TransInfo *t, const int mval[2])
 {
        View2D *v2d = (View2D *)t->view;
        float cval[2], sval[2];
@@ -7069,18 +7446,22 @@ int TimeTranslate(TransInfo *t, const int mval[2])
        t->values[0] = t->vec[0];
        headerTimeTranslate(t, str);
 
-       applyTimeTranslate(t, sval[0]);
+       applyTimeTranslateValue(t, sval[0]);
 
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
 
-/* ----------------- Time Slide ----------------------- */
 
-void initTimeSlide(TransInfo *t)
+/* -------------------------------------------------------------------- */
+/* Transform (Animation Time Slide) */
+
+/** \name Transform Animation Time Slide
+ * \{ */
+
+static void initTimeSlide(TransInfo *t)
 {
        /* this tool is only really available in the Action Editor... */
        if (t->spacetype == SPACE_ACTION) {
@@ -7095,7 +7476,7 @@ void initTimeSlide(TransInfo *t)
 
 
        t->mode = TFM_TIME_SLIDE;
-       t->transform = TimeSlide;
+       t->transform = applyTimeSlide;
        t->flag |= T_FREE_CUSTOMDATA;
 
        initMouseInputMode(t, &t->mouse, INPUT_NONE);
@@ -7109,16 +7490,18 @@ void initTimeSlide(TransInfo *t)
        t->snap[0] = 0.0f;
        t->snap[1] = t->snap[2] = 1.0f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       /* No time unit supporting frames currently... */
+       t->num.unit_type[0] = B_UNIT_NONE;
 }
 
-/* We assume str is MAX_INFO_LEN long. */
-static void headerTimeSlide(TransInfo *t, float sval, char *str)
+static void headerTimeSlide(TransInfo *t, float sval, char str[MAX_INFO_LEN])
 {
        char tvec[NUM_STR_REP_LEN * 3];
 
        if (hasNumInput(&t->num)) {
-               outputNumInput(&(t->num), tvec);
+               outputNumInput(&(t->num), tvec, &t->scene->unit);
        }
        else {
                float minx = *((float *)(t->customData));
@@ -7135,7 +7518,7 @@ static void headerTimeSlide(TransInfo *t, float sval, char *str)
        BLI_snprintf(str, MAX_INFO_LEN, IFACE_("TimeSlide: %s"), &tvec[0]);
 }
 
-static void applyTimeSlide(TransInfo *t, float sval)
+static void applyTimeSlideValue(TransInfo *t, float sval)
 {
        TransData *td = t->data;
        int i;
@@ -7182,7 +7565,7 @@ static void applyTimeSlide(TransInfo *t, float sval)
        }
 }
 
-int TimeSlide(TransInfo *t, const int mval[2])
+static void applyTimeSlide(TransInfo *t, const int mval[2])
 {
        View2D *v2d = (View2D *)t->view;
        float cval[2], sval[2];
@@ -7204,20 +7587,24 @@ int TimeSlide(TransInfo *t, const int mval[2])
        t->values[0] = (maxx - minx) * t->vec[0] / 2.0f + sval[0];
 
        headerTimeSlide(t, sval[0], str);
-       applyTimeSlide(t, sval[0]);
+       applyTimeSlideValue(t, sval[0]);
 
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
 }
+/** \} */
 
-/* ----------------- Scaling ----------------------- */
 
-void initTimeScale(TransInfo *t)
+/* -------------------------------------------------------------------- */
+/* Transform (Animation Time Scale) */
+
+/** \name Transform Animation Time Scale
+ * \{ */
+
+static void initTimeScale(TransInfo *t)
 {
-       int center[2];
+       float center[2];
 
        /* this tool is only really available in the Action Editor
         * AND NLA Editor (for strip scaling)
@@ -7227,12 +7614,12 @@ void initTimeScale(TransInfo *t)
        }
 
        t->mode = TFM_TIME_SCALE;
-       t->transform = TimeScale;
+       t->transform = applyTimeScale;
 
        /* recalculate center2d to use CFRA and mouse Y, since that's
         * what is used in time scale */
        t->center[0] = t->scene->r.cfra;
-       projectIntView(t, t->center, center);
+       projectFloatView(t, t->center, center);
        center[1] = t->imval[1];
 
        /* force a reinit with the center2d used here */
@@ -7241,7 +7628,7 @@ void initTimeScale(TransInfo *t)
        initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
 
        t->flag |= T_NULL_ONE;
-       t->num.flag |= NUM_NULL_ONE;
+       t->num.val_flag[0] |= NUM_NULL_ONE;
 
        /* num-input has max of (n-1) */
        t->idx_max = 0;
@@ -7252,23 +7639,24 @@ void initTimeScale(TransInfo *t)
        t->snap[0] = 0.0f;
        t->snap[1] = t->snap[2] = 1.0f;
 
-       t->num.increment = t->snap[1];
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
 }
 
-/* We assume str is MAX_INFO_LEN long. */
-static void headerTimeScale(TransInfo *t, char *str)
+static void headerTimeScale(TransInfo *t, char str[MAX_INFO_LEN])
 {
        char tvec[NUM_STR_REP_LEN * 3];
 
        if (hasNumInput(&t->num))
-               outputNumInput(&(t->num), tvec);
+               outputNumInput(&(t->num), tvec, &t->scene->unit);
        else
                BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", t->values[0]);
 
        BLI_snprintf(str, MAX_INFO_LEN, IFACE_("ScaleX: %s"), &tvec[0]);
 }
 
-static void applyTimeScale(TransInfo *t)
+static void applyTimeScaleValue(TransInfo *t)
 {
        Scene *scene = t->scene;
        TransData *td = t->data;
@@ -7276,7 +7664,6 @@ static void applyTimeScale(TransInfo *t)
        int i;
 
        const short autosnap = getAnimEdit_SnapMode(t);
-       const short do_time = getAnimEdit_DrawTime(t);
        const double secf = FPS;
 
 
@@ -7289,11 +7676,11 @@ static void applyTimeScale(TransInfo *t)
                float startx = CFRA;
                float fac = t->values[0];
 
-               if (autosnap == SACTSNAP_STEP) {
-                       if (do_time)
-                               fac = (float)(floor((double)fac / secf + 0.5) * secf);
-                       else
-                               fac = (float)(floor(fac + 0.5f));
+               if (autosnap == SACTSNAP_TSTEP) {
+                       fac = (float)(floor((double)fac / secf + 0.5) * secf);
+               }
+               else if (autosnap == SACTSNAP_STEP) {
+                       fac = (float)(floor(fac + 0.5f));
                }
 
                /* check if any need to apply nla-mapping */
@@ -7308,7 +7695,7 @@ static void applyTimeScale(TransInfo *t)
        }
 }
 
-int TimeScale(TransInfo *t, const int UNUSED(mval[2]))
+static void applyTimeScale(TransInfo *t, const int UNUSED(mval[2]))
 {
        char str[MAX_INFO_LEN];
        
@@ -7318,35 +7705,21 @@ int TimeScale(TransInfo *t, const int UNUSED(mval[2]))
        t->values[0] = t->vec[0];
        headerTimeScale(t, str);
 
-       applyTimeScale(t);
+       applyTimeScaleValue(t);
 
        recalcData(t);
 
        ED_area_headerprint(t->sa, str);
-
-       return 1;
-}
-
-/* ************************************ */
-
-void BIF_TransformSetUndo(const char *UNUSED(str))
-{
-       // TRANSFORM_FIX_ME
-       //Trans.undostr = str;
 }
+/** \} */
 
 
 /* TODO, move to: transform_queries.c */
-bool checkUseLocalCenter_GraphEdit(TransInfo *t)
-{
-       return ((t->around == V3D_LOCAL) && !ELEM3(t->mode, TFM_TRANSLATION, TFM_TIME_TRANSLATE, TFM_TIME_SLIDE));
-}
-
 bool checkUseAxisMatrix(TransInfo *t)
 {
-       /* currenly only checks for editmode */
+       /* currently only checks for editmode */
        if (t->flag & T_EDIT) {
-               if ((t->around == V3D_LOCAL) && (ELEM4(t->obedit->type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE))) {
+               if ((t->around == V3D_LOCAL) && (ELEM(t->obedit->type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE))) {
                        /* not all editmode supports axis-matrix */
                        return true;
                }