Beispiel #1
0
        public TextBoxDescriptor(string id, string fontFamily, double fontSize, TextBoxAlignment alignment, TextBoxColor color, bool allCaps, double x, double y, double width, double height, double rotateDegrees) : base(id, x, y, width, height, rotateDegrees)
        {
            FontFamily = fontFamily ?? throw new ArgumentNullException(nameof(fontFamily));

            FontSize = fontSize;

            Alignment = alignment;
            Color     = color;

            AllCaps = allCaps;
        }
        public void DrawTextBox(
            SpriteBatch spriteBatch,
            Rectangle spriteSourceRect,
            Vector2 position,
            Vector2 padding,
            SpriteFont font,
            string message,
            Color textureColor,
            TextBoxAlignment align = TextBoxAlignment.TopLeft,
            float colorIntensity   = 1f)
        {
            var fontWidth    = (int)font.MeasureString(message).X;
            var fontHeight   = (int)font.MeasureString(message).Y;
            var windowWidth  = (int)(fontWidth + padding.X);
            var windowHeight = (int)(fontHeight + padding.Y);

            var x = (int)position.X;
            var y = (int)position.Y;


            // - 4 for shadow (8 / 2)
            switch (align)
            {
            case TextBoxAlignment.TopLeft:
                break;

            case TextBoxAlignment.Top:
                x = ((Game1.options.preferredResolutionX / 2) - (windowWidth / 2) - windowWidth) - x - 4 + (int)(padding.X / 2);
                break;

            case TextBoxAlignment.TopRight:
                x = Game1.options.preferredResolutionX - windowWidth - x;
                break;

            case TextBoxAlignment.MidLeft:
                y = ((Game1.options.preferredResolutionY / 2) - (windowHeight / 2) - windowHeight) - y - 4 + (int)(padding.Y / 2);
                break;

            case TextBoxAlignment.Mid:
                x = ((Game1.options.preferredResolutionX / 2) - (windowWidth / 2) - windowWidth) - x - 4 + (int)(padding.X / 2);
                y = ((Game1.options.preferredResolutionY / 2) - (windowHeight / 2) - windowHeight) - y - 4 + (int)(padding.Y / 2);
                break;

            case TextBoxAlignment.MidRight:
                x = Game1.options.preferredResolutionX - windowWidth - x;
                y = ((Game1.options.preferredResolutionY - windowHeight) / 2) - y;
                break;

            case TextBoxAlignment.BottomLeft:
                break;

            case TextBoxAlignment.Bottom:
                x = ((Game1.options.preferredResolutionX / 2) - (windowWidth / 2) - windowWidth) - x - 4 + (int)(padding.X / 2);
                break;

            case TextBoxAlignment.BottomRight:
                break;
            }

            IClickableMenu.drawTextureBox(spriteBatch, Game1.menuTexture, spriteSourceRect, x, y, windowWidth, windowHeight, textureColor * colorIntensity);
            Utility.drawTextWithShadow(spriteBatch, message, font, new Vector2(x + (windowWidth / 2) - (fontWidth / 2), y + (windowHeight / 2) - (fontHeight / 2)), Game1.textColor);

            //new Rectangle(0, 256, 60, 60), x - width / 2, y, width, height + 4, textureColor * colorIntensity);
            //new Rectangle(0, 256, 60, 60), x - width, y, width, height + 4, textureColor * colorIntensity);
            //new Vector2(x + 16 - width / 2, y + 16), Game1.textColor);
            //new Vector2(x + 16 - width, y + 16), Game1.textColor);

            //switch (aligsn)
            //{
            //    case 0:
            //        IClickableMenu.drawTextureBox(spriteBatch, Game1.menuTexture, new Rectangle(0, 256, 60, 60), x, y, width, height + 4, textureColor * colorIntensity);
            //        Utility.drawTextWithShadow(spriteBatch, message, font, new Vector2(x + 16, y + 16), Game1.textColor);
            //        break;
            //    case 1:
            //        IClickableMenu.drawTextureBox(spriteBatch, Game1.menuTexture, new Rectangle(0, 256, 60, 60), x - width / 2, y, width, height + 4, textureColor * colorIntensity);
            //        Utility.drawTextWithShadow(spriteBatch, message, font, new Vector2(x + 16 - width / 2, y + 16), Game1.textColor);
            //        break;
            //    case 2:
            //        IClickableMenu.drawTextureBox(spriteBatch, Game1.menuTexture, new Rectangle(0, 256, 60, 60), x - width, y, width, height + 4, textureColor * colorIntensity);
            //        Utility.drawTextWithShadow(spriteBatch, message, font, new Vector2(x + 16 - width, y + 16), Game1.textColor);
            //        break;
            //}
        }