Пример #1
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    void HandleRezie(int _handleID, Vector3 _oldPos, Vector3 _newPos)
    {
        if (_oldPos == _newPos)
        {
            return;
        }

        exUIElement curEdit = target as exUIElement;

        //
        float dx, dy;

        GetDelatSize(_newPos - _oldPos, out dx, out dy);

        float oldWidth  = curEdit.width;
        float oldHeight = curEdit.height;
        float xRatio    = 1.0f;
        float yRatio    = 1.0f;

        // 0 -- 1 -- 2
        // |         |
        // 7         3
        // |         |
        // 6 -- 5 -- 4

        if (_handleID == 0)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = -1.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = -0.5f; yRatio = 1.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = -0.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = -1.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.MidCenter:   xRatio = -0.5f; yRatio = 0.5f; break;

            case exPlane.Anchor.MidRight:    xRatio = -0.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.BotLeft:     xRatio = -1.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = -0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = -0.0f; yRatio = 0.0f; break;
            }
            curEdit.width -= dx; curEdit.height += dy;
        }
        else if (_handleID == 1)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = 0.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = 0.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = 0.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = 0.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.MidCenter:   xRatio = 0.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.MidRight:    xRatio = 0.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.BotLeft:     xRatio = 0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = 0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = 0.0f; yRatio = 0.0f; break;
            }
            curEdit.height += dy;
        }
        else if (_handleID == 2)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = 0.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = 0.5f; yRatio = 1.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = 1.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = 0.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.MidCenter:   xRatio = 0.5f; yRatio = 0.5f; break;

            case exPlane.Anchor.MidRight:    xRatio = 1.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.BotLeft:     xRatio = 0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = 0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = 1.0f; yRatio = 0.0f; break;
            }
            curEdit.width += dx; curEdit.height += dy;
        }
        else if (_handleID == 3)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = 0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = 0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = 1.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = 0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.MidCenter:   xRatio = 0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.MidRight:    xRatio = 1.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotLeft:     xRatio = 0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = 0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = 1.0f; yRatio = 0.0f; break;
            }
            curEdit.width += dx;
        }
        else if (_handleID == 4)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = 0.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = 0.5f; yRatio = -0.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = 1.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = 0.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.MidCenter:   xRatio = 0.5f; yRatio = -0.5f; break;

            case exPlane.Anchor.MidRight:    xRatio = 1.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.BotLeft:     xRatio = 0.0f; yRatio = -1.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = 0.5f; yRatio = -1.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = 1.0f; yRatio = -1.0f; break;
            }
            curEdit.width += dx; curEdit.height -= dy;
        }
        else if (_handleID == 5)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = 0.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = 0.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = 0.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = 0.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.MidCenter:   xRatio = 0.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.MidRight:    xRatio = 0.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.BotLeft:     xRatio = 0.0f; yRatio = -1.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = 0.0f; yRatio = -1.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = 0.0f; yRatio = -1.0f; break;
            }
            curEdit.height -= dy;
        }
        else if (_handleID == 6)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = -1.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = -0.5f; yRatio = -0.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = -0.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = -1.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.MidCenter:   xRatio = -0.5f; yRatio = -0.5f; break;

            case exPlane.Anchor.MidRight:    xRatio = -0.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.BotLeft:     xRatio = -1.0f; yRatio = -1.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = -0.5f; yRatio = -1.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = -0.0f; yRatio = -1.0f; break;
            }
            curEdit.width -= dx; curEdit.height -= dy;
        }
        else if (_handleID == 7)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = -1.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = -0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = -0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = -1.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.MidCenter:   xRatio = -0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.MidRight:    xRatio = -0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotLeft:     xRatio = -1.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = -0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = -0.0f; yRatio = 0.0f; break;
            }
            curEdit.width -= dx;
        }

        float offsetX = (curEdit.width - oldWidth) * xRatio;
        float offsetY = (curEdit.height - oldHeight) * yRatio;

        curEdit.Translate(offsetX, offsetY);
    }