Beispiel #1
0
 public SingleSheetLabelCreator(LabelDefinition labelDefinition, Enums.Alignment hAlign)
 {
     _labelDefinition    = labelDefinition;
     _creator            = new CustomLabelCreator(labelDefinition);
     _label              = new Label(hAlign);
     IncludeLabelBorders = false;
 }
Beispiel #2
0
 public IMGuiTextContent(RectangleF rectangle, Vector2 padding, Enums.Alignment alignment, Color fontColor, bool wrap) : base(rectangle)
 {
     this.padding   = padding;
     this.alignment = alignment;
     this.fontColor = fontColor;
     this.wrap      = wrap;
 }
Beispiel #3
0
 public SingleSheetLabelCreator(LabelDefinition labelDefinition, Enums.Alignment hAlign)
 {
     FontFactory.RegisterDirectories();             //Register all local fonts
     _labelDefinition    = labelDefinition;
     _creator            = new CustomLabelCreator(labelDefinition);
     _label              = new Label(hAlign);
     IncludeLabelBorders = false;
 }
 /// <summary>
 /// A text and panel combination content.
 /// </summary>
 /// <param name="rectangle">Drawing bounds</param>
 /// <param name="padding">The text padding, i.e. how much space the text should be bordered by.</param>
 /// <param name="alignment">The location at which the text is anchored to.</param>
 public IMGuiTextPanelContent(RectangleF rectangle, NineSlice backgroundSlice, Color backgroundColor, Vector2 padding,
                              Enums.Alignment alignment, Color fontColor, bool wrap, float scale) : base(rectangle, backgroundSlice, backgroundColor, scale)
 {
     this.padding   = padding;
     this.alignment = alignment;
     this.fontColor = fontColor;
     this.wrap      = wrap;
 }
Beispiel #5
0
 /// <param name="hAlign">horizontal alignment: LEFT, CENTER, RIGHT</param>
 public Label(Enums.Alignment hAlign)
 {
     _images     = new List <byte[]>();
     _textChunks = new List <TextChunk>();
     _hAlign     = hAlign;
 }
Beispiel #6
0
 /// <param name="hAlign">horizontal alignment: LEFT, CENTER, RIGHT</param>
 public Label(Enums.Alignment hAlign)
 {
     _images = new List<byte[]>();
     _textChunks = new List<TextChunk>();
     _hAlign = hAlign;
 }
Beispiel #7
0
 public Target(ActiveChar character, Enums.Alignment alignment, int distance)
 {
     Character       = character;
     TargetAlignment = alignment;
     Distance        = distance;
 }
Beispiel #8
0
        /// <summary>
        /// Draws text indside the given bounds.
        /// </summary>
        /// <param name="text">The text to draw.</param>
        /// <param name="bounds">The bounds to draw within.</param>
        /// <param name="alignment">The alignment within the given bounds.</param>
        /// <param name="wrapWidth">Defines how wide the text can draw before being wrapped. set to -1 to not wrap.</param>
        /// <param name="overflowAction">Defines what happens when the text overflows on the Y axis (i.e. goes out of bounds.)</param>
        public static void DrawText(SpriteBatch batch, FontInfo fontText, string text, Color color, Rectangle bounds, Enums.Alignment alignment, int wrapWidth, float drawDepth = 0, OverFlowAction overflowAction = OverFlowAction.DontDrawOverflow)
        {
            RasterizerState oldRasterizerState = batch.GraphicsDevice.RasterizerState;

            //SpriteFont font = fontText.font;

            if (wrapWidth != -1)
            {
                text = WrapText(fontText, text, wrapWidth);
            }

            Vector2 size = fontText.StringSize(text).ToVector2();

            if (size.Y > bounds.Size.Y && overflowAction == OverFlowAction.DontDrawAny)
            {
                return;
            }

            Vector2 alignmentOffset = GetAlignmentOffset(fontText, text, bounds, alignment);

            if (overflowAction == OverFlowAction.DontDrawOverflow)
            {               //this might cause issues later down the line. Idk.
                batch.End();
                batch.Begin(SpriteSortMode.Immediate, batch.GraphicsDevice.BlendState, batch.GraphicsDevice.SamplerStates[0], batch.GraphicsDevice.DepthStencilState, scissorTestRasterizerState, null, null);

                //batch.GraphicsDevice.RasterizerState = scissorTestRasterizerState;
                batch.GraphicsDevice.ScissorRectangle = bounds;
            }

            RecreateDrawString(batch, bounds.Location.ToVector2() + alignmentOffset, fontText, text, drawDepth, color);

            if (debugDrawTextBounds)
            {
                batch.DrawHollowRectangle(bounds, 1, Color.Red, 1);
                bounds.Width = wrapWidth;
                batch.DrawHollowRectangle(bounds, 1, Color.Pink, 1);
            }

            if (overflowAction == OverFlowAction.DontDrawOverflow)
            {
                batch.End();
                batch.Begin(SpriteSortMode.Immediate, batch.GraphicsDevice.BlendState, batch.GraphicsDevice.SamplerStates[0], batch.GraphicsDevice.DepthStencilState, oldRasterizerState, null, null);
            }
        }
Beispiel #9
0
        public static Vector2 GetAlignmentOffset(FontInfo font, string text, Rectangle bounds, Enums.Alignment alignment)
        {
            Vector2 size = Vector2.Zero;

            try { size = font.StringSize(text).ToVector2(); }
            catch
            {
                Logger.GetOrCreate("BrUtility").Log(Logger.LogLevel.Error, "Text has no size (empty or invalid string.)");
                return(Vector2.Zero);
            }

            if (alignment == Enums.Alignment.TopLeft)
            {
                return(Vector2.Zero);
            }
            else if (alignment == Enums.Alignment.Left)
            {
                return(new Vector2(0, (bounds.Height / 2) - (size.Y / 2)));
            }
            else if (alignment == Enums.Alignment.BottomLeft)
            {
                return(new Vector2(0, bounds.Height - size.Y));
            }
            else if (alignment == Enums.Alignment.Bottom)
            {
                return(new Vector2((bounds.Width / 2) - (size.X / 2), bounds.Height - size.Y));
            }
            else if (alignment == Enums.Alignment.BottomRight)
            {
                return(new Vector2(bounds.Width - size.X, bounds.Height - size.Y));
            }
            else if (alignment == Enums.Alignment.Right)
            {
                return(new Vector2(bounds.Width - size.X, (bounds.Height / 2) - (size.Y / 2)));
            }
            else if (alignment == Enums.Alignment.TopRight)
            {
                return(new Vector2(bounds.Width - size.X, 0));
            }
            else if (alignment == Enums.Alignment.Top)
            {
                return(new Vector2((bounds.Width / 2) - (size.X / 2), 0));
            }
            else if (alignment == Enums.Alignment.Center)
            {
                return(new Vector2((bounds.Width / 2) - (size.X / 2), (bounds.Height / 2) - (size.Y / 2)));
            }
            else
            {
                return(Vector2.Zero);
            }
        }
Beispiel #10
0
        public static Vector2 GetLastCharacterPosition(FontInfo fontInfo, string text, Rectangle bounds, Enums.Alignment alignment)
        {
            Vector2 alignmentOffset = GetAlignmentOffset(fontInfo, text, bounds, alignment);
            Vector2 drawPosition    = bounds.Location.ToVector2() + alignmentOffset;

            string wrapped = WrapText(fontInfo, text, bounds.Width);

            string[] lines = wrapped.Split('\n');

            Vector2 size = fontInfo.StringSize(wrapped).ToVector2();

            float ypos = size.Y - fontInfo.LineSpacing;
            float xpos = fontInfo.StringWidth(lines.Last());

            return(drawPosition + new Vector2(xpos, ypos));
        }