Beispiel #1
0
        protected override void ComputeFontPosition()
        {
            if (Text == null)
            {
                return;
            }
            Vector2 textDimensions = TextFont.MeasureString(Text);

            FontWrap(ref textDimensions, Dimensions - Vector2.UnitX * (ToggleIndicatorSize + ToggleIndicatorBorder * 2));

            switch (TextAlignment)
            {
            case GUIStyle.TextAlignment.Left:
                _fontPosition = (Dimensions - Vector2.UnitX * (ToggleIndicatorSize + ToggleIndicatorBorder * 2)) / 2 * Vector2.UnitY + _textBorder * Vector2.UnitX - textDimensions / 2 * Vector2.UnitY;
                break;

            case GUIStyle.TextAlignment.Center:
                _fontPosition = (Dimensions - Vector2.UnitX * (ToggleIndicatorSize + ToggleIndicatorBorder * 2)) / 2 - textDimensions / 2;
                break;

            case GUIStyle.TextAlignment.Right:
                _fontPosition = (Dimensions - Vector2.UnitX * (ToggleIndicatorSize + ToggleIndicatorBorder * 2)) * new Vector2(1, 0.5f) - _textBorder * Vector2.UnitX - textDimensions / 2;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #2
0
        protected override void OnLayout(WindowManager uiRenderer)
        {
            var   textSize = TextFont.MeasureString(Text);
            float x        = Bounds.X + (Bounds.Width - textSize.X) / 2;
            float y        = Bounds.Y + (Bounds.Height - textSize.Y) / 2;

            _TextLocation = new Vector2(x, y);
        }
        public void SetText(string text)
        {
            Text = text;
            Vector2 newSize = TextFont.MeasureString(text);
            int     x       = (int)newSize.X;
            int     y       = (int)newSize.Y;

            Rectangle.Size = new Point(x, y);
            //SetSize(new Point((int)newSize.X, (int)newSize.Y));
        }
Beispiel #4
0
        public override Point GetPreferredSize(Point availableSpace)
        {
            if (!AutoSize)
            {
                return(ExplicitSize);
            }
            var size = Vector2.Ceiling(TextFont.MeasureString(Text)).ToPoint();

            size.X += SPRITE_PADDING_X * 2 + Padding.Horizontal;
            size.Y += SPRITE_PADDING_Y * 2 + Padding.Vertical;
            return(size);
        }
        protected override void ComputeFontPosition()
        {
            if (_text == null)
            {
                return;
            }
            _declarationTextDimensions = TextFont.MeasureString(_text);

            //Let's check wrap!

            //FontWrap(ref textDimension, Dimensions);

            _fontPosition = Dimensions * 0.5f * Vector2.UnitY + _textBorder * Vector2.UnitX - _declarationTextDimensions * 0.5f * Vector2.UnitY;
        }
Beispiel #6
0
        /// <summary>
        /// Create a new Label
        /// </summary>
        /// <param name="position"></param>
        /// <param name="text"></param>
        /// <param name="font"></param>
        /// <param name="textColor"></param>
        /// <param name="backgroundColor"></param>
        /// <param name="borderColor"></param>
        /// <param name="borderWidth"></param>
        /// <param name="backgroundImage"></param>
        public Label(Vector2 position, string text, Font font, Color textColor,
                     Color backgroundColor, Color borderColor, int borderWidth = 1, Sprite backgroundImage = null)
            : base(position, text, font, textColor, backgroundColor, borderColor, borderWidth, backgroundImage,
                   (int)font.MeasureString(text).X, (int)font.MeasureString(text).Y)
        {
            OnTextChanged += (sender, args) =>
            {
                if (TextFont == null)
                {
                    return;
                }

                var size = TextFont.MeasureString(args.Text);
                Width  = (int)size.X;
                Height = (int)size.Y;
            };
        }
Beispiel #7
0
        public override void Draw()
        {
            base.Draw();
            Rectangle highlightRect = new Rectangle(Rectangle.Location, Rectangle.Size);

            highlightRect.Width = (int)highlightWidth;
            Universal.SpriteBatch.Draw(Textures.Null, highlightRect, HighlightColor);
            Vector2 textMesurements = TextFont.MeasureString(Text);

            if (CenterText)
            {
                Universal.SpriteBatch.DrawString(TextFont, Text, new Vector2(Rectangle.X + ((Rectangle.Width - textMesurements.X) / 2), Rectangle.Y + ((Rectangle.Height - textMesurements.Y) / 2)), TextColor);
            }
            else
            {
                Universal.SpriteBatch.DrawString(TextFont, Text, new Vector2(Rectangle.X, Rectangle.Y), TextColor);
            }
        }
        protected void ComputeObjectNameLength()
        {
            if (_loadedObjectName.Length > 0)
            {
                //Max length
                Vector2 textDimensions = TextFont.MeasureString(_loadedObjectName);

                float characterLength = textDimensions.X / _loadedObjectName.Length;

                Vector2 buttonLeft     = (_declarationTextDimensions + _fontPosition * 1.5f) * Vector2.UnitX;
                Vector2 spaceAvailable = Dimensions - 2 * Vector2.One * ButtonBorder - buttonLeft -
                                         (2 + _textBorder.X) * Vector2.UnitX;

                int characters = (int)(spaceAvailable.X / characterLength);

                _loadedObjectName.Length = characters < _loadedObjectName.Length ? characters : _loadedObjectName.Length;
            }
        }
Beispiel #9
0
        public override Point GetPreferredSize(Point availableSpace)
        {
            var textSize = Vector2.Ceiling(TextFont.MeasureString(Text)).ToPoint();

            return(new Point(textSize.X + Padding.Horizontal, textSize.Y + Padding.Vertical));
        }
Beispiel #10
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(new Color(16, 36, 35));
            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied);

            //fps counter
            int fps        = Frames.CalculateFrameRate();
            var fontOrigin = TextFont.MeasureString(fps.ToString()) / 2;
            var position   = new Vector2(50, 50);

            spriteBatch.DrawString(TextFont, fps.ToString(), position, Color.LightGreen, 0, fontOrigin, 0.25f, SpriteEffects.None, GameDrawOrder.BACKGROUND_TOP);


            switch (StateProvider.Instance.State)
            {
            case GameState.HIGHSCORE:
                DrawHighscore(spriteBatch);
                break;

            case GameState.MENU:
                MenuController.Draw(spriteBatch, TextFont);
                DrawPlayerMoney(spriteBatch);
                break;

            case GameState.CONTROLS:
                DrawControls(spriteBatch);
                break;

            case GameState.GAMEPAUSED:
                LevelController.CurrentLevel.Draw(spriteBatch);
                break;

            case GameState.LEVEL_INTRO:
                LevelController.CurrentLevel.LevelIntro.Draw(spriteBatch);
                break;

            case GameState.PLAYING_EASY:
                if (LevelController.CurrentLevel != null)
                {
                    LevelController.CurrentLevel.Draw(spriteBatch);
                    DrawPlayerMoney(spriteBatch);
                }
                break;

            case GameState.PLAYING_NORMAL:
                if (LevelController.CurrentLevel != null)
                {
                    LevelController.CurrentLevel.Draw(spriteBatch);
                    DrawPlayerMoney(spriteBatch);
                }
                break;

            case GameState.PLAYING_HARD:
                if (LevelController.CurrentLevel != null)
                {
                    LevelController.CurrentLevel.Draw(spriteBatch);
                    DrawPlayerMoney(spriteBatch);
                }
                break;
            }
            spriteBatch.End();

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }