/// <summary>
        /// Fill label mesh.
        /// </summary>
        /// <param name="mesh">Mesh.</param>
        /// <param name="width">Label width.</param>
        /// <param name="height">Label height.</param>
        /// <param name="text">Label text.</param>
        /// <param name="color">Color.</param>
        /// <param name="align">Text align.</param>
        /// <param name="font">Font.</param>
        /// <param name="fontSize">Font size.</param>
        /// <param name="lineHgt">Line height multiplier.</param>
        /// <param name="effect">Effect.</param>
        /// <param name="effectValue">Effect value.</param>
        /// <param name="effectColor">Effect color.</param>
        public static void FillText(
            Mesh mesh, int width, int height, string text, Color color, TextAnchor align, Font font, int fontSize,
            float lineHgt, GuiFontEffect effect = GuiFontEffect.None, Vector2? effectValue = null, Color? effectColor = null)
        {
            if (mesh == null) {
                return;
            }
            mesh.Clear ();
            if (font == null || string.IsNullOrEmpty (text)) {
                return;
            }

            _settings.fontSize = (int) (fontSize * GuiSystem.Instance.VirtualToRealScaleFactor);
            _settings.resizeTextMaxSize = _settings.fontSize;

            var scale = fontSize / (float) _settings.fontSize;

            _settings.font = font;
            _settings.textAnchor = align;
            _settings.generationExtents = new Vector2 (width, height) / scale;
            _settings.lineSpacing = lineHgt;
            _settings.color = color;
            _generator.Invalidate ();
            if (!_generator.Populate (text, _settings)) {
                return;
            }

            _generator.GetVertices (_verts);

            GuiMeshTools.PrepareBuffer (effect, effectValue, effectColor);

            for (int i = 0, iMax = _verts.Count - 4, charID = 0; i < iMax; charID++) {
                if (text[charID] == ' ') {
                    i += 4;
                    continue;
                }
                _uiV = _verts[i++];
                _c = _uiV.color;
                _v0 = _uiV.position * scale;
                _uv0 = _uiV.uv0;

                _uiV = _verts[i++];
                _v1 = _uiV.position * scale;
                _uv1 = _uiV.uv0;

                _uiV = _verts[i++];
                _v2 = _uiV.position * scale;
                _uv2 = _uiV.uv0;

                _uiV = _verts[i++];
                _v3 = _uiV.position * scale;
                _uv3 = _uiV.uv0;
                GuiMeshTools.FillBuffer (ref _v0, ref _v1, ref _v2, ref _v3, ref _uv0, ref _uv1, ref _uv2, ref _uv3, ref _c);
            }

            GuiMeshTools.GetBuffers (mesh, false);
            mesh.bounds = new Bounds (Vector3.zero, new Vector3 (width, height, 0f));
        }
예제 #2
0
 /// <summary>
 /// Prepare mesh buffer for filling.
 /// </summary>
 /// <param name="effect">Effect.</param>
 /// <param name="effectValue">Effect value.</param>
 /// <param name="effectColor">Effect color.</param>
 public static void PrepareBuffer(GuiFontEffect effect = GuiFontEffect.None, Vector2?effectValue = null, Color?effectColor = null)
 {
     _cacheV.Clear();
     _cacheUV.Clear();
     _cacheC.Clear();
     _cacheT.Clear();
     _effect      = effect;
     _effectValue = effectValue.HasValue ? effectValue.Value : Vector2.zero;
     _effectColor = effectColor.HasValue ? effectColor.Value : Color.black;
 }
예제 #3
0
 /// <summary>
 /// Fill simple sprite.
 /// </summary>
 /// <param name="mesh">Mesh.</param>
 /// <param name="width">Sprite width.</param>
 /// <param name="height">Sprite height.</param>
 /// <param name="color">Sprite color.</param>
 /// <param name="spriteData">Sprite data.</param>
 /// <param name="effect">Effect.</param>
 /// <param name="effectValue">Effect value.</param>
 /// <param name="effectColor">Effect color.</param>
 public static void FillSimpleSprite(Mesh mesh, int width, int height, Color color, GuiSpriteData spriteData,
                                     GuiFontEffect effect = GuiFontEffect.None, Vector2?effectValue = null, Color?effectColor = null)
 {
     if (mesh == null)
     {
         return;
     }
     PrepareBuffer(effect, effectValue, effectColor);
     if (spriteData != null)
     {
         var halfW = 0.5f * width;
         var halfH = 0.5f * height;
         _vRect.Set(-halfW, -halfH, width, height);
         _uvRect.Set(spriteData.CornerX, spriteData.CornerY, spriteData.CornerW, spriteData.CornerH);
         FillBuffer(ref _vRect, ref _uvRect, ref color);
     }
     GetBuffers(mesh);
 }
예제 #4
0
        /// <summary>
        /// Fill round-filled sprite.
        /// </summary>
        /// <param name="mesh">Mesh.</param>
        /// <param name="width">Sprite width.</param>
        /// <param name="height">Sprite height.</param>
        /// <param name="fillValue">Normalized progress of round-filling.</param>
        /// <param name="color">Sprite color.</param>
        /// <param name="spriteData">Sprite data.</param>
        /// <param name="effect">Effect.</param>
        /// <param name="effectValue">Effect value.</param>
        /// <param name="effectColor">Effect color.</param>
        public static void FillRoundFilledSprite(Mesh mesh, int width, int height, float fillValue, Color color, GuiSpriteData spriteData,
                                                 GuiFontEffect effect = GuiFontEffect.None, Vector2?effectValue = null, Color?effectColor = null)
        {
            if (mesh == null)
            {
                return;
            }
            PrepareBuffer(effect, effectValue, effectColor);
            if (spriteData != null && fillValue > 0f)
            {
                var halfW = 0.5f * width;
                var halfH = 0.5f * height;
                _vRect.Set(-halfW, -halfH, width, height);
                _uvRect.Set(spriteData.CornerX, spriteData.CornerY, spriteData.CornerW, spriteData.CornerH);

                var uvHalfW = spriteData.CornerW * 0.5f;
                var uvHalfH = spriteData.CornerH * 0.5f;

                int i;
                for (i = 0; i < 4; i++)
                {
                    _uvRect.Set(
                        RoundFilledUV[i].x * uvHalfW + spriteData.CornerX,
                        RoundFilledUV[i].y * uvHalfH + spriteData.CornerY,
                        uvHalfW, uvHalfH);
                    _vRect.Set(RoundFilledV[i].x * halfW, RoundFilledV[i].y * halfH, halfW, halfH);
                    if (fillValue < (i + 1) * 0.25f)
                    {
                        break;
                    }
                    FillBuffer(ref _vRect, ref _uvRect, ref color);
                }

                if (i < 4)
                {
                    fillValue = (fillValue - i * 0.25f) * 8f;
                    var needFlip = (i & 1) == 0;
                    var uv0      = new Vector2(_uvRect.xMin, _uvRect.yMin);
                    var uv1      = new Vector2(_uvRect.xMin, _uvRect.yMax);
                    var uv2      = new Vector2(_uvRect.xMax, _uvRect.yMax);
                    var uv3      = new Vector2(_uvRect.xMax, _uvRect.yMin);
                    var v0       = new Vector3(_vRect.xMin, _vRect.yMin, 0f);
                    var v1       = new Vector3(_vRect.xMin, _vRect.yMax, 0f);
                    var v2       = new Vector3(_vRect.xMax, _vRect.yMax, 0f);
                    var v3       = new Vector3(_vRect.xMax, _vRect.yMin, 0f);
                    if (needFlip)
                    {
                        var t = uv0.y;
                        uv0.y = uv1.y;
                        uv1.y = t;
                        t     = uv2.y;
                        uv2.y = uv3.y;
                        uv3.y = t;

                        t    = v0.y;
                        v0.y = v1.y;
                        v1.y = t;
                        t    = v2.y;
                        v2.y = v3.y;
                        v3.y = t;
                    }

                    var fvW  = _vRect.width * fillValue;
                    var fvH  = _vRect.height * fillValue;
                    var fuvW = _uvRect.width * fillValue;
                    var fuvH = _uvRect.height * fillValue;

                    if (fillValue >= 1f)
                    {
                        // more than 45 degrees.
                        fvW  -= _vRect.width;
                        fvH  -= _vRect.height;
                        fuvW -= _uvRect.width;
                        fuvH -= _uvRect.height;
                        switch (i)
                        {
                        case 0:
                            v1.y  = _vRect.yMax - fvH;
                            uv1.y = _uvRect.yMax - fuvH;
                            break;

                        case 1:
                            v3.x  = _vRect.xMin + fvW;
                            uv3.x = _uvRect.xMin + fuvW;
                            break;

                        case 2:
                            v3.y  = _vRect.yMin + fvH;
                            uv3.y = _uvRect.yMin + fuvH;
                            break;

                        case 3:
                            v1.x  = _vRect.xMax - fvW;
                            uv1.x = _uvRect.xMax - fuvW;
                            break;
                        }
                    }
                    else
                    {
                        // less than 45 degrees
                        switch (i)
                        {
                        case 0:
                            v0.x  = _vRect.xMax - fvW;
                            uv0.x = _uvRect.xMax - fuvW;
                            uv1   = uv0;
                            v1    = v0;
                            break;

                        case 1:
                            v0.y  = _vRect.yMax - fvH;
                            uv0.y = _uvRect.yMax - fuvH;
                            uv3   = uv0;
                            v3    = v0;
                            break;

                        case 2:
                            v2.x  = _vRect.xMin + fvW;
                            uv2.x = _uvRect.xMin + fuvW;
                            uv3   = uv2;
                            v3    = v2;
                            break;

                        case 3:
                            v2.y  = _vRect.yMin + fvH;
                            uv2.y = _uvRect.yMin + fuvH;
                            uv1   = uv2;
                            v1    = v2;
                            break;
                        }
                    }

                    FillBuffer(ref v0, ref v1, ref v2, ref v3, ref uv0, ref uv1, ref uv2, ref uv3, ref color);
                }
            }
            GetBuffers(mesh);
        }
 /// <summary>
 /// Prepare mesh buffer for filling.
 /// </summary>
 /// <param name="effect">Effect.</param>
 /// <param name="effectValue">Effect value.</param>
 /// <param name="effectColor">Effect color.</param>
 public static void PrepareBuffer(
     GuiFontEffect effect = GuiFontEffect.None, Vector2? effectValue = null, Color? effectColor = null)
 {
     _cacheV.Clear ();
     _cacheUV.Clear ();
     _cacheC.Clear ();
     _cacheT.Clear ();
     _effect = effect;
     _effectValue = effectValue.HasValue ? effectValue.Value : Vector2.zero;
     _effectColor = effectColor.HasValue ? effectColor.Value : Color.black;
 }
 /// <summary>
 /// Fill simple sprite.
 /// </summary>
 /// <param name="mesh">Mesh.</param>
 /// <param name="width">Sprite width.</param>
 /// <param name="height">Sprite height.</param>
 /// <param name="color">Sprite color.</param>
 /// <param name="spriteData">Sprite data.</param>
 /// <param name="effect">Effect.</param>
 /// <param name="effectValue">Effect value.</param>
 /// <param name="effectColor">Effect color.</param>
 public static void FillSimpleSprite(Mesh mesh, int width, int height, Color color, GuiSpriteData spriteData,
                                      GuiFontEffect effect = GuiFontEffect.None, Vector2? effectValue = null,
                                      Color? effectColor = null)
 {
     if (mesh == null) {
         return;
     }
     PrepareBuffer (effect, effectValue, effectColor);
     if (spriteData != null) {
         var halfW = 0.5f * width;
         var halfH = 0.5f * height;
         _vRect.Set (-halfW, -halfH, width, height);
         _uvRect.Set (spriteData.CornerX, spriteData.CornerY, spriteData.CornerW, spriteData.CornerH);
         FillBuffer (ref _vRect, ref _uvRect, ref color);
     }
     GetBuffers (mesh);
 }
        /// <summary>
        /// Fill round-filled sprite.
        /// </summary>
        /// <param name="mesh">Mesh.</param>
        /// <param name="width">Sprite width.</param>
        /// <param name="height">Sprite height.</param>
        /// <param name="fillValue">Normalized progress of round-filling.</param>
        /// <param name="color">Sprite color.</param>
        /// <param name="spriteData">Sprite data.</param>
        /// <param name="effect">Effect.</param>
        /// <param name="effectValue">Effect value.</param>
        /// <param name="effectColor">Effect color.</param>
        public static void FillRoundFilledSprite(
            Mesh mesh, int width, int height, float fillValue, Color color, GuiSpriteData spriteData,
            GuiFontEffect effect = GuiFontEffect.None, Vector2? effectValue = null,
            Color? effectColor = null)
        {
            if (mesh == null) {
                return;
            }
            PrepareBuffer (effect, effectValue, effectColor);
            if (spriteData != null && fillValue > 0f) {
                var halfW = 0.5f * width;
                var halfH = 0.5f * height;
                _vRect.Set (-halfW, -halfH, width, height);
                _uvRect.Set (spriteData.CornerX, spriteData.CornerY, spriteData.CornerW, spriteData.CornerH);

                var uvHalfW = spriteData.CornerW * 0.5f;
                var uvHalfH = spriteData.CornerH * 0.5f;

                int i;
                for (i = 0; i < 4; i++) {
                    _uvRect.Set (
                        RoundFilledUV[i].x * uvHalfW + spriteData.CornerX,
                        RoundFilledUV[i].y * uvHalfH + spriteData.CornerY,
                        uvHalfW, uvHalfH);
                    _vRect.Set (RoundFilledV[i].x * halfW, RoundFilledV[i].y * halfH, halfW, halfH);
                    if (fillValue < (i + 1) * 0.25f) {
                        break;
                    }
                    FillBuffer (ref _vRect, ref _uvRect, ref color);
                }

                if (i < 4) {
                    fillValue = (fillValue - i * 0.25f) * 8f;
                    var needFlip = (i & 1) == 0;
                    var uv0 = new Vector2 (_uvRect.xMin, _uvRect.yMin);
                    var uv1 = new Vector2 (_uvRect.xMin, _uvRect.yMax);
                    var uv2 = new Vector2 (_uvRect.xMax, _uvRect.yMax);
                    var uv3 = new Vector2 (_uvRect.xMax, _uvRect.yMin);
                    var v0 = new Vector3 (_vRect.xMin, _vRect.yMin, 0f);
                    var v1 = new Vector3 (_vRect.xMin, _vRect.yMax, 0f);
                    var v2 = new Vector3 (_vRect.xMax, _vRect.yMax, 0f);
                    var v3 = new Vector3 (_vRect.xMax, _vRect.yMin, 0f);
                    if (needFlip) {
                        var t = uv0.y;
                        uv0.y = uv1.y;
                        uv1.y = t;
                        t = uv2.y;
                        uv2.y = uv3.y;
                        uv3.y = t;

                        t = v0.y;
                        v0.y = v1.y;
                        v1.y = t;
                        t = v2.y;
                        v2.y = v3.y;
                        v3.y = t;
                    }

                    var fvW = _vRect.width * fillValue;
                    var fvH = _vRect.height * fillValue;
                    var fuvW = _uvRect.width * fillValue;
                    var fuvH = _uvRect.height * fillValue;

                    if (fillValue >= 1f) {
                        // more than 45 degrees.
                        fvW -= _vRect.width;
                        fvH -= _vRect.height;
                        fuvW -= _uvRect.width;
                        fuvH -= _uvRect.height;
                        switch (i) {
                        case 0:
                            v1.y = _vRect.yMax - fvH;
                            uv1.y = _uvRect.yMax - fuvH;
                            break;
                        case 1:
                            v3.x = _vRect.xMin + fvW;
                            uv3.x = _uvRect.xMin + fuvW;
                            break;
                        case 2:
                            v3.y = _vRect.yMin + fvH;
                            uv3.y = _uvRect.yMin + fuvH;
                            break;
                        case 3:
                            v1.x = _vRect.xMax - fvW;
                            uv1.x = _uvRect.xMax - fuvW;
                            break;
                        }
                    } else {
                        // less than 45 degrees
                        switch (i) {
                        case 0:
                            v0.x = _vRect.xMax - fvW;
                            uv0.x = _uvRect.xMax - fuvW;
                            uv1 = uv0;
                            v1 = v0;
                            break;
                        case 1:
                            v0.y = _vRect.yMax - fvH;
                            uv0.y = _uvRect.yMax - fuvH;
                            uv3 = uv0;
                            v3 = v0;
                            break;
                        case 2:
                            v2.x = _vRect.xMin + fvW;
                            uv2.x = _uvRect.xMin + fuvW;
                            uv3 = uv2;
                            v3 = v2;
                            break;
                        case 3:
                            v2.y = _vRect.yMin + fvH;
                            uv2.y = _uvRect.yMin + fuvH;
                            uv1 = uv2;
                            v1 = v2;
                            break;
                        }
                    }

                    FillBuffer (ref v0, ref v1, ref v2, ref v3, ref uv0, ref uv1, ref uv2, ref uv3, ref color);
                }
            }
            GetBuffers (mesh);
        }
예제 #8
0
        /// <summary>
        /// Fill label mesh.
        /// </summary>
        /// <param name="mesh">Mesh.</param>
        /// <param name="width">Label width.</param>
        /// <param name="height">Label height.</param>
        /// <param name="text">Label text.</param>
        /// <param name="color">Color.</param>
        /// <param name="align">Text align.</param>
        /// <param name="font">Font.</param>
        /// <param name="fontSize">Font size.</param>
        /// <param name="lineHgt">Line height multiplier.</param>
        /// <param name="effect">Effect.</param>
        /// <param name="effectValue">Effect value.</param>
        /// <param name="effectColor">Effect color.</param>
        public static void FillText(Mesh mesh, int width, int height, string text, Color color, TextAnchor align, Font font, int fontSize, float lineHgt, GuiFontEffect effect = GuiFontEffect.None, Vector2?effectValue = null, Color?effectColor = null)
        {
            if (mesh == null)
            {
                return;
            }
            mesh.Clear();
            if (font == null || string.IsNullOrEmpty(text))
            {
                return;
            }

            _settings.fontSize          = (int)(fontSize * GuiSystem.Instance.VirtualToRealScaleFactor);
            _settings.resizeTextMaxSize = _settings.fontSize;

            var scale = fontSize / (float)_settings.fontSize;

            _settings.font              = font;
            _settings.textAnchor        = align;
            _settings.generationExtents = new Vector2(width, height) / scale;
            _settings.lineSpacing       = lineHgt;
            _settings.color             = color;
            _generator.Invalidate();
            if (!_generator.Populate(text, _settings))
            {
                return;
            }

            _generator.GetVertices(_verts);

            GuiMeshTools.PrepareBuffer(effect, effectValue, effectColor);

            for (int i = 0, iMax = _verts.Count - 4, charID = 0; i < iMax; charID++)
            {
                if (text[charID] == ' ')
                {
                    i += 4;
                    continue;
                }
                _uiV = _verts[i++];
                _c   = _uiV.color;
                _v0  = _uiV.position * scale;
                _uv0 = _uiV.uv0;

                _uiV = _verts[i++];
                _v1  = _uiV.position * scale;
                _uv1 = _uiV.uv0;

                _uiV = _verts[i++];
                _v2  = _uiV.position * scale;
                _uv2 = _uiV.uv0;

                _uiV = _verts[i++];
                _v3  = _uiV.position * scale;
                _uv3 = _uiV.uv0;
                GuiMeshTools.FillBuffer(ref _v0, ref _v1, ref _v2, ref _v3, ref _uv0, ref _uv1, ref _uv2, ref _uv3, ref _c);
            }

            GuiMeshTools.GetBuffers(mesh, false);
            mesh.bounds = new Bounds(Vector3.zero, new Vector3(width, height, 0f));
        }