Beispiel #1
0
    // Adds a sprite to the manager at the location and rotation of the client
    // GameObject and with its transform.  Returns a reference to the new sprite
    // Width and height are in world space units
    // lowerLeftUV - the UV coordinate for the upper-left corner
    // UVDimensions - the distance from lowerLeftUV to place the other UV coords
    public MFGuiSprite AddSprite(Matrix4x4 matrix, Rect rect, MFGuiUVCoords uvCoords, MFGuiGrid9 grid9)
    {
        LogFuncCall("AddSprite", name);

        if (availableSprites.Count < 1)
        {
            EnlargeSpriteArrays(allocBlockSize);
        }

        int index = availableSprites.Dequeue();

        if (sprites[index] == null)
        {
            sprites[index] = new MFGuiSprite(this, index);
        }

        rect = rect.MakePixelPerfect();

        // Assign the new sprite:
        MFGuiSprite sprite = sprites[index];

        sprite.matrix   = matrix;
        sprite.size     = new Vector2(rect.width, rect.height);
        sprite.uvCoords = uvCoords;
        sprite.grid9    = grid9 != null ? new MFGuiGrid9Cached(grid9) : default(MFGuiGrid9Cached);
        sprite.visible  = true;

        // Done
        return(sprite);
    }
Beispiel #2
0
    public void SetTextureCoords(int spriteIdx, float UVLeft, float UVTop, float UVWidth, float UVHeight)
    {
        if (m_Sprites == null)
        {
            return;
        }
        if (m_Sprites.Length <= spriteIdx)
        {
            return;
        }

        MFGuiSprite sprite = m_Sprites[spriteIdx].m_Sprite;

        if (sprite == null)
        {
            return;
        }

        MFGuiUVCoords uvCoords = sprite.uvCoords;

        uvCoords.U      = UVLeft;
        uvCoords.V      = 1.0f - (UVTop + UVHeight);
        uvCoords.Width  = UVWidth;
        uvCoords.Height = UVHeight;
        sprite.uvCoords = uvCoords;

        SetModify();
    }
Beispiel #3
0
    //---------------------------------------------------------
    void HideSprite(MFGuiSprite sprite)
    {
        if (sprite != null)
        {
            sprite.visible = false;
        }

        SetModify();
    }
Beispiel #4
0
    //---------------------------------------------------------
    void ShowSprite(MFGuiSprite sprite)
    {
        if (sprite != null)
        {
            sprite.visible = true;
        }

        SetModify();
    }
Beispiel #5
0
    public void RemoveSprite(MFGuiSprite sprite)
    {
        LogFuncCall("RemoveSprite", name);

        // Clean the sprite's settings:
        sprite.matrix  = Matrix4x4.identity;
        sprite.color   = Color.white;
        sprite.offset  = Vector3.zero;
        sprite.visible = false;

        // force release resources
        sprite.ReleaseResources();

        // store available slot
        availableSprites.Enqueue(sprite.index);
    }
Beispiel #6
0
    public MFGuiSprite AddElement(Rect rect, float angle, float depth, MFGuiUVCoords uvCoords, MFGuiGrid9 grid9)
    {
        LogFuncCall("AddElement", name);

        UpdateUISize();

        // create matrix
        Matrix4x4 matrix = Matrix4x4.identity;

        UpdateMatrix(ref matrix, rect, angle, Vector2.one, depth);

        rect = rect.MakePixelPerfect();

        // create sprite
        MFGuiSprite sprite = AddSprite(matrix, rect, uvCoords, grid9);

        return(sprite);
    }
Beispiel #7
0
    public bool GetSpriteSizeAndPosition(MFGuiSprite sprite, out Vector2 size, out Vector3 pos)
    {
        pos  = new Vector2(0, 0);
        size = new Vector2(0, 0);

        if (sprite == null || sprite.index >= sprites.Length ||
            sprites[sprite.index] != sprite || sprite.quads.Length < 1)
        {
            return(false);
        }

        int id = sprite.quads[0].index * 4;

        Vector3 v0 = vertices[id + 0];
        Vector3 v2 = vertices[id + 2];

        pos  = v0;
        size = new Vector2(Mathf.Abs(v2.x - v0.x), Mathf.Abs(v2.y - v0.y));

        return(true);
    }
Beispiel #8
0
    //---------------------------------------------------------
    public void SetValue(int idx, int type)
    {
        if (idx >= 0 && idx < m_MaxCount)
        {
            // set correct UV
            MFGuiSprite s = m_Widget.GetSprite(idx + 1);

            if (s != null)
            {
                if (type == -1)
                {
                    // TODO - nerenderovat nic
                    //s.lowerLeftUV	= usedSpritesUV[0].lowerLeftUV;
                    //s.uvDimensions	= usedSpritesUV[0].uvDimensions;
                }
                else if (type >= 0 && type < m_UsedSprites.Length)
                {
                    s.uvCoords = new MFGuiUVCoords(m_UsedSpritesUV[idx].m_LowerLeftUV, m_UsedSpritesUV[idx].m_UvDimensions);
                }
            }
        }
    }
Beispiel #9
0
    public void UpdateSprite(MFGuiSprite sprite, Rect rect, float angle, Vector2 scale, float depth, MFGuiGrid9 grid9)
    {
        LogFuncCall("UpdateSpritePosSize", name);

        // update matrix
        UpdateMatrix(ref sprite.matrix, rect, angle, scale, depth);

        rect = rect.MakePixelPerfect();

        // setup surface
        sprite.size = new Vector2(rect.width, rect.height);

        // we can't allow to change grid9 once it has been assigned
        // but we can assign one if there is not any yet
        if (sprite.grid9 == null && grid9 != null)
        {
            sprite.grid9 = new MFGuiGrid9Cached(grid9);
        }

        // we can transform sprite now
        Transform(sprite);
    }
Beispiel #10
0
    public void PrepareSprites(int count)
    {
        if (m_GuiRenderer == null)
        {
            return;
        }
        if (m_Sprites != null && m_Sprites.Length == count)
        {
            return;
        }

        // prepare temp list
        S_Sprite[] sprites = new S_Sprite[count];

        int spriteIdx = 0;

        // remove all unwanted sprites
        if (m_Sprites != null)
        {
            for (int idx = 0; idx < m_Sprites.Length; ++idx)
            {
                if (m_Sprites[idx].m_Sprite == null)
                {
                    continue;
                }

                if (spriteIdx < count)
                {
                    sprites[spriteIdx++] = m_Sprites[idx];
                }
                else
                {
                    m_GuiRenderer.RemoveSprite(m_Sprites[idx].m_Sprite);
                }
            }
        }

        // add new sprites if needed
        while (spriteIdx < count)
        {
            MFGuiSprite sprite = AddSprite(
                new Rect(0, 0, 0, 0),
                0,
                ComputedWidgetLayer * -(1.0f / GUIBase_Layout.MAX_LAYERS),
                0,
                0,
                0,
                0,
                null);

            sprites[spriteIdx++].m_Sprite = sprite;
        }

        // store new list
        m_Sprites = sprites;

        // update visibility
        for (int idx = 0; idx < m_Sprites.Length; ++idx)
        {
            ShowSprite(idx, Visible);
        }
    }
Beispiel #11
0
    //---------------------------------------------------------
    //public int AddSprite(Rect inSprite, Vector2 inScale, float inRotAngle, Rect inSpriteTextCoord)
    public int AddSprite(Vector2 centerSpritePos,
                         float width,
                         float height,
                         float scaleWidth,
                         float scaleHeight,
                         float rotAngle,
                         int texU,
                         int texV,
                         int texW,
                         int texH,
                         MFGuiGrid9 grid9 = null)
    {
        int resIdx = -1;

        float rx = centerSpritePos.x - 0.5f * width * scaleWidth;
        float ry = centerSpritePos.y - 0.5f * height * scaleHeight;

        MFGuiSprite sprite = AddSprite(
            new Rect(rx, ry, width * scaleWidth, height * scaleHeight),
            rotAngle,
            ComputedWidgetLayer * -(1.0f / GUIBase_Layout.MAX_LAYERS),
            texU,
            texV,
            texW,
            texH,
            grid9);

        //	Debug.Log(name + " depth = " + (-((float)m_Layout.m_LayoutLayer + (float)m_GuiWidgetLayer * 0.1f)));

        if (sprite != null)
        {
            if (m_Sprites == null)
            {
                ReserveSprites(1);
                resIdx = m_UnusedSpriteIndex++;
            }
            else if (ReservedSpritesSize > 0 && m_UnusedSpriteIndex < ReservedSpritesSize)
            {
                resIdx = m_UnusedSpriteIndex++;
            }
            else
            {
                // reallocate (add 1 sprite)
                ReallocateSprites(m_Sprites.Length + 1);
                resIdx = m_UnusedSpriteIndex++;
            }

            m_Sprites[resIdx].m_Sprite    = sprite;
            m_Sprites[resIdx].m_IsVisible = false;
            m_Sprites[resIdx].m_Pos       = centerSpritePos;
            m_Sprites[resIdx].m_Width     = width;
            m_Sprites[resIdx].m_Height    = height;
            m_Sprites[resIdx].m_Grid9     = grid9;

            // Show sprite ?
            ShowSprite(resIdx, Visible);
        }

        //Debug.Log("AddSprite = "+ resIdx +" for "+ gameObject.name);

        return(resIdx);
    }
Beispiel #12
0
 //---------------------------------------------------------
 void UpdateSprite(MFGuiSprite sprite, Rect rect, float rotAngle, Vector2 scale, float depth, MFGuiGrid9 grid9)
 {
     m_GuiRenderer.UpdateSprite(sprite, rect, rotAngle, scale, depth, grid9);
 }
Beispiel #13
0
    // Updates the vertices of a sprite based on the transform
    // of its client GameObject
    public void Transform(MFGuiSprite sprite)
    {
        LogFuncCall("Transform", name);

        sprite.UpdateSurface();
    }
Beispiel #14
0
    //-----------------------------------------------------
    void SetNumber(int number, int max, bool force)
    {
        if (m_Value == number && false == force)
        {
            return;
        }

        int absNumber = Mathf.Abs(number);

        if (absNumber > max)
        {
            absNumber = max;
        }

        m_Value = number;

        int div1 = 1;
        int div2 = 10;

        int visibleDigits = 0;

        for (int digitIdx = 0; digitIdx < numberDigits; ++digitIdx)
        {
            int rest = (absNumber % div2) / div1;

            if ((absNumber > (div1 - 1)) || (digitIdx == 0) || m_KeepZeros)
            {
                // Show digit
                m_Widget.ShowSprite(digitIdx, true);

                // set correct UV
                MFGuiSprite   s        = m_Widget.GetSprite(digitIdx);
                MFGuiUVCoords uvCoords = s.uvCoords;
                uvCoords.U = m_UvLeft + m_UvWidth * rest;
                uvCoords.V = 1.0f - (m_UvTop + m_UvHeight);
                s.uvCoords = uvCoords;

                visibleDigits++;
            }
            else
            {
                // Hide digit
                m_Widget.ShowSprite(digitIdx, false);
            }

            div1  = div2;
            div2 *= 10;
        }

        if (visibleDigits == 0)
        {
            return;
        }
        if (visibleDigits == m_LastVisibleDigits && force == false)
        {
            return;
        }
        m_LastVisibleDigits = visibleDigits;

        Transform trans = transform;
        Vector3   scale = trans.lossyScale;

        float   width     = m_Widget.GetWidth() / numberDigits;
        float   height    = m_Widget.GetHeight();
        float   halfWidth = m_Widget.GetWidth() * scale.x * 0.5f;
        Vector3 deltaPos  = new Vector3(halfWidth, 0.0f);
        Vector3 rightPos  = m_Widget.GetOrigPos() + deltaPos;

        Vector3 delta;

        switch (m_Alignment)
        {
        case TextAlignment.Left:
            delta       = deltaPos / (numberDigits * 0.5f);
            rightPos.x -= (numberDigits - visibleDigits) * delta.x;
            break;

        case TextAlignment.Center:
            delta = deltaPos / (visibleDigits * 0.5f);
            break;

        default:
            delta = deltaPos / (numberDigits * 0.5f);
            break;
        }

        for (int idx = 0; idx < visibleDigits; ++idx)
        {
            m_Widget.UpdateSpritePosAndSize(idx, rightPos.x - (idx + 0.5f) * delta.x, rightPos.y - (idx + 0.5f) * delta.y, width, height);
        }
    }