Exemple #1
0
        internal static Vector2 MeasureDecimalString(SpriteFont spriteFont, float value, uint decimalPlaces)
        {
            if (spriteFont == null)
            {
                throw new ArgumentNullException("spriteFont");
            }

            Vector2 size = SpriteBatchEx.MeasureIntegerString(spriteFont, XenMath.RoundFloatToInt(value));

            if (decimalPlaces > 0)
            {
                Vector2 strVec = spriteFont.MeasureString(".");
                size.X += strVec.X;
                size.Y  = Math.Max(size.Y, strVec.Y);

                // Draw each decimal digit afterwards one-by-one because otherwise the leading-0's disappear
                for (int i = 0; i < decimalPlaces; i++)
                {
                    value   = (value - (int)value) * 10;
                    strVec  = SpriteBatchEx.MeasureIntegerString(spriteFont, (int)value);
                    size.X += strVec.X;
                    size.Y  = Math.Max(size.Y, strVec.Y);
                }
            }
            return(size);
        }
Exemple #2
0
        public void Reset(SpriteFont spriteFont, int value)
        {
            _type              = XenStringType.Integer;
            ValueInt           = value;
            Text               = null;
            _nextString        = null;
            SpriteFont         = spriteFont;
            IsTemporary        = false;
            FloatDecimalPlaces = _defaultDecimalPlaces;

            if (SpriteFont != null)
            {
                RenderingExtent.Reset(SpriteBatchEx.MeasureIntegerString(SpriteFont, value));
            }
        }