Example #1
0
        public static void DrawTextCentered(string text, Rectangle area, Color color)
        {
            var wrapped = new WrappingText(() => DefaultFont.Font, () => area.Width).Wrap(text);
            var size    = DefaultFont.Font.MeasureString(wrapped);

            DrawText(wrapped, GetCenteredPosition(area, size), color);
        }
Example #2
0
        public static void DrawTextAligned(string text, Rectangle area, Color color, string font, HorizontalAlignment horizontalAlignment)
        {
            var spriteFont = Resources.Load <SpriteFont>(font);
            var wrapped    = new WrappingText(() => spriteFont, () => area.Width).Wrap(text);
            var size       = spriteFont.MeasureString(wrapped);

            DrawText(wrapped, _alignPositions[horizontalAlignment](area, size), color, font);
        }
Example #3
0
        public static void DrawTextCentered(string text, Rectangle area, Color color, string font)
        {
            var spriteFont = Resources.Load <SpriteFont>(font);
            var wrapped    = new WrappingText(() => spriteFont, () => area.Width).Wrap(text);
            var size       = spriteFont.MeasureString(wrapped);

            DrawText(wrapped, GetCenteredPosition(area, size), color, font);
        }
 public void Draw(IEntities entities, SpriteBatch sprites)
 {
     entities.With <TextDisplay>((o, t) => {
         var spriteFont = Resources.Load <SpriteFont>(t.Font);
         var wrapped    = new WrappingText(() => spriteFont, () => o.Transform.WithPadding(t.Margin).ToRectangle().Width).Wrap(t.Text());
         var size       = spriteFont.MeasureString(wrapped);
         sprites.DrawString(spriteFont, wrapped, _alignPositions[t.Align](o.Transform.WithPadding(t.Margin).ToRectangle(), size), t.Color,
                            o.Transform.Rotation.Value * .017453292519f, Vector2.Zero, 1, SpriteEffects.None, 1);
     });
 }
Example #5
0
        private static void RenderText(SpriteBatch sprites, TextDisplay t, GameObject o, IViewport viewport)
        {
            var spriteFont     = GameInstance.TheGame.Content.Load <SpriteFont>(t.Font);
            var wrapped        = new WrappingText(() => spriteFont, () => o.World.WithPadding(t.Margin).ToRectangle().Width).Wrap(t.Text());
            var size           = spriteFont.MeasureString(wrapped);
            var screenPosition = viewport.GetScreenPosition(o.World.WithPadding(t.Margin));

            sprites.DrawString(spriteFont, wrapped,
                               AlignPositions[t.Align](screenPosition.ToRectangle(), size).ToPoint().ToVector2(), t.Color,
                               screenPosition.Rotation.Radians, Vector2.Zero, 1, SpriteEffects.None, (o.World.ZIndex + 1).AsDepth());
        }
Example #6
0
        WrappingText CalcGeneralInstructionsLayout(string description, int originalX, int originalY, int width, Graphics graphics)
        {
            int x = originalX;
            int y = originalY;

            var wrappingText = new WrappingText();

            // Text
            using var font = BuildFont();             // !!!
            CalcWrappingString(wrappingText.tokens, wrappingText.regularTexts, description, font, ref x, ref y, originalX, width, graphics);
            y += rowHeight;
            wrappingText.Bounds = new Rectangle(originalX, originalY, width, y - originalY);

            return(wrappingText);
        }
Example #7
0
        void DrawOption(WrappingText data, Graphics graphics, Font regFont, Font boldFont)
        {
            foreach (var tp in data.tokens)
            {
                imageDrawer.Draw(graphics, tp.TokenImg, tp.Rect);
            }

            var verticalAlignCenter = new StringFormat {
                LineAlignment = StringAlignment.Center
            };

            foreach (var sp in data.regularTexts)
            {
                graphics.DrawString(sp.Text, regFont, Brushes.Black, sp.Bounds, verticalAlignCenter);
            }

            foreach (var sp in data.boldTexts)
            {
                graphics.DrawString(sp.Text, boldFont, Brushes.Black, sp.Bounds, verticalAlignCenter);
            }
        }
Example #8
0
        public InnateLayout(InnatePower power, int x, int y, int width, float textHeightMultiplier, Graphics graphics)
        {
            textEmSize = width * textHeightMultiplier;

            iconDimension = (int)(textEmSize * 1.9f);
            elementHeight = (int)(textEmSize * 2.3f);
            rowHeight     = (int)(textEmSize * 2.5f);

            int margin       = (int)(width * .02f);       // 2% of width
            int workingWidth = width - margin * 2;

            // "All-Enveloping Green"
            TitleBounds = new Rectangle(x + margin, y + margin, workingWidth, (int)(workingWidth * .12f));               // Height is 10% of width;				// output - titleRect

            // brown box
            AttributeBounds     = new Rectangle(x + margin, TitleBounds.Bottom, workingWidth, (int)(workingWidth * .15f));
            AttributeRows       = AttributeBounds.SplitVerticallyAt(0.40f);
            AttributeLabelCells = AttributeRows[0].SplitHorizontally(3);
            AttributeValueCells = AttributeRows[1].SplitHorizontally(3);

            // Options
            var options = new List <WrappingText_InnateOptions>();
            int optionY = AttributeBounds.Bottom + (int)(rowHeight * 0.25f);

            // General instructions
            if (!string.IsNullOrEmpty(power.GeneralInstructions))
            {
                GeneralInstructions = CalcGeneralInstructionsLayout(power.GeneralInstructions, AttributeBounds.Left, optionY, workingWidth, graphics);
                optionY             = GeneralInstructions.Bounds.Bottom;
            }

            foreach (var innatePowerOption in power.DrawableOptions)
            {
                var wrapInfo = CalcInnateOptionLayout(innatePowerOption, AttributeBounds.Left, optionY, workingWidth, graphics);
                options.Add(wrapInfo);
                optionY = wrapInfo.Bounds.Bottom;
            }
            Options = options.ToArray();
            Bounds  = new Rectangle(x, y, width, optionY - y);
        }