Handles.ScaleValueHandle inverted?

Hello, I’m making a 2D game using meshes (only simple shapes, way less heavy in memory than a 512x512 texture) and I want to recreate the SpriteRenderer handles, like this:

alt text
alt text

But the bottom and left handles are behaving oddly, they take the opposite of the mouse delta. I can’t figure out how to fix it.

Here is the code :

using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor(typeof(MeshRenderer))]
public class MeshHandles : Editor
{
    GameObject _target;

    void OnSceneGUI()
    {
        Vector3 pos = _target.transform.position;
        Vector3 scale = _target.transform.localScale;
        float scaleX = scale.x;
        float scaleY = scale.y;
        Vector3[] verts = new Vector3[] 
        { 
            new Vector3(pos.x - scale.x,    pos.y - scale.y,0), //-1,-1
            new Vector3(pos.x - scale.x,    pos.y + scale.y,0), //-1,1
            new Vector3(pos.x + scale.x,    pos.y + scale.y,0), //1,1
            new Vector3(pos.x + scale.x,    pos.y - scale.y,0)  //1,-1
        };

        Handles.DrawSolidRectangleWithOutline(verts, new Color(1f, 1f, 1f, 0.05f), new Color(1f, 1f, 1f, 1f));

        scaleX = Handles.ScaleValueHandle(scaleX, new Vector3(pos.x + scale.x, pos.y, 0), Quaternion.identity, 1, Handles.CubeCap, 1);
        scaleX = Handles.ScaleValueHandle(scaleX, new Vector3(pos.x - scale.x, pos.y, 0), Quaternion.identity, 1, Handles.CubeCap, 1);

        scaleY = Handles.ScaleValueHandle(scaleY, new Vector3(pos.x, pos.y + scale.y, 0), Quaternion.identity, 1, Handles.CubeCap, 1);
        scaleY = Handles.ScaleValueHandle(scaleY, new Vector3(pos.x, pos.y - scale.y, 0), Quaternion.identity, 1, Handles.CubeCap, 1);

        scale = new Vector3(scaleX, scaleY);
        _target.transform.localScale = scale;

        
    }

    void OnEnable()
    {
        Tools.hidden = true;
        MeshRenderer mesh = target as MeshRenderer;
        _target = mesh.gameObject;
    }

    void OnDisable()
    {
        Tools.hidden = false;
    }
}

Thanks in advance.

I got it to work by doing this:

Vector3 xOffset = Math3d.SetVectorLength(-gameObject.transform.right, gameObject.transform.localScale.x / 2f);
position = gameObject.transform.position + xOffset;
position = Handles.Slider(position, gameObject.transform.right, size, Handles.DotCap, snap);
float scale = Vector3.Magnitude(gameObject.transform.position - position) * 2;
gameObject.transform.localScale = new Vector3(scale, gameObject.transform.localScale.y, gameObject.transform.localScale.z);

Math3d is from here:
http://wiki.unity3d.com/index.php/3d_Math_functions