Exemplo n.º 1
0
        internal override void Draw(DrawHelper helper, Vector2 offset)
        {
            string[] lines = Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            float maxWidth = 0;
            float height = 0;

            foreach (var line in lines)
            {
                var txtSize = helper.MeasureString(FontName, line);
                maxWidth = txtSize.X > maxWidth ? txtSize.X : maxWidth;
                height += txtSize.Y;
            }

            var rectangle = new Rectangle((int) Location.X, (int) Location.Y, (int) maxWidth, (int) height);
            rectangle.Offset(offset);

            if (BackgroundColor != Color.Transparent)
                helper.DrawRectangle(rectangle, BackgroundColor);

            height = 0;
            foreach (var line in lines)
            {
                var txtSize = helper.MeasureString(FontName, line);
                helper.DrawString(this, Location + offset + new Vector2(0, height), line, TextColor);
                height += txtSize.Y + LineSpacing;
            }
        }
Exemplo n.º 2
0
Arquivo: Button.cs Projeto: JWeel/Hex
        internal override void Draw(DrawHelper helper, Vector2 offset)
        {
            var rectangle = HitBox;

            rectangle.Offset(offset);
            var start = Location + offset;

            var topLeftOffset  = Vector2.Zero;
            var topRightOffset = Vector2.Zero;
            var hover          = IsHovering ? new Color(255, 255, 255, 240) : Color.White;
            var blend          = IsPressed ? new Color(205, 205, 205, 230) : hover;

            if (!string.IsNullOrEmpty(BtnLeftTexture))
            {
                topLeftOffset = helper.DrawTextureWithOffset(start, BtnLeftTexture, blend);
            }
            if (!string.IsNullOrEmpty(BtnRightTexture))
            {
                topRightOffset = helper.DrawTextureWithOffset(start + new Vector2(Size.X, 0), BtnRightTexture, blend, DrawHelper.AlignOffset.TopRight);
            }

            if (string.IsNullOrEmpty(BtnMiddleTexture))
            {
                helper.DrawRectangle(rectangle, BackgroundColor.Blend(blend));
            }
            else
            {
                helper.DrawTextureRepeat(start + new Vector2(topLeftOffset.X, 0),
                                         start + new Vector2(Size.X - topRightOffset.X, topLeftOffset.Y), BtnMiddleTexture, blend);
            }

            var txtSize = helper.MeasureString(FontName, Text);

            helper.DrawString(this, Location + AlignmentHelper.Align(Size, txtSize, TextAlign) + offset, Text, TextColor, Zoom);
        }
Exemplo n.º 3
0
        internal override void Draw(DrawHelper helper, Vector2 offset)
        {
            var txtSize   = helper.MeasureString(FontName, Text);
            var rectangle = new Rectangle((int)Location.X, (int)Location.Y, (int)txtSize.X, (int)txtSize.Y);

            rectangle.Offset(offset);

            if (BackgroundColor != Color.Transparent)
            {
                helper.DrawRectangle(rectangle, BackgroundColor);
            }
            helper.DrawString(this, Location + offset, Text, TextColor);
        }
Exemplo n.º 4
0
        internal override void Draw(DrawHelper helper, Vector2 offset)
        {
            if (!IsVisible)
            {
                return;
            }

            var topLeftOffset     = Vector2.Zero;
            var topRightOffset    = Vector2.Zero;
            var bottomLeftOffset  = Vector2.Zero;
            var bottomRightOffset = Vector2.Zero;

            if (!string.IsNullOrEmpty(WinTopLeftTexture))
            {
                topLeftOffset = helper.DrawTextureWithOffset(Location, WinTopLeftTexture);
            }
            if (!string.IsNullOrEmpty(WinTopRightTexture))
            {
                topRightOffset = helper.DrawTextureWithOffset(Location + new Vector2(Size.X, 0), WinTopRightTexture, DrawHelper.AlignOffset.TopRight);
            }
            if (!string.IsNullOrEmpty(WinBottomLeftTexture))
            {
                bottomLeftOffset = helper.DrawTextureWithOffset(Location + new Vector2(0, Size.Y), WinBottomLeftTexture, DrawHelper.AlignOffset.BottomLeft);
            }
            if (!string.IsNullOrEmpty(WinBottomRightTexture))
            {
                bottomRightOffset = helper.DrawTextureWithOffset(Location + new Vector2(Size.X, Size.Y), WinBottomRightTexture, DrawHelper.AlignOffset.BottomRight);
            }

            //Top
            if (!string.IsNullOrEmpty(WinTopTexture))
            {
                helper.DrawTextureRepeat(Location + new Vector2(topLeftOffset.X, 0),
                                         Location + new Vector2(Size.X - topRightOffset.X, topLeftOffset.Y), WinTopTexture);
            }
            //Bottom
            if (!string.IsNullOrEmpty(WinBottomTexture))
            {
                helper.DrawTextureRepeat(Location + new Vector2(topLeftOffset.X, Size.Y - bottomLeftOffset.Y),
                                         Location + new Vector2(Size.X - topRightOffset.X, Size.Y), WinBottomTexture);
            }
            //Left
            if (!string.IsNullOrEmpty(WinLeftTexture))
            {
                helper.DrawTextureRepeat(Location + new Vector2(0, topLeftOffset.Y),
                                         Location + new Vector2(topLeftOffset.X, Size.Y - bottomLeftOffset.Y), WinLeftTexture);
            }
            //Right
            if (!string.IsNullOrEmpty(WinRightTexture))
            {
                helper.DrawTextureRepeat(Location + new Vector2(Size.X - topRightOffset.X, topLeftOffset.Y),
                                         Location + new Vector2(Size.X, Size.Y - bottomLeftOffset.Y), WinRightTexture);
            }


            //Fill
            var rectangle = new Rectangle((int)(Location.X + topLeftOffset.X), (int)(Location.Y + topLeftOffset.Y),
                                          (int)(Size.X - topLeftOffset.X - topRightOffset.X), (int)(Size.Y - topLeftOffset.Y - bottomLeftOffset.Y));

            helper.DrawRectangle(rectangle, BackgroundColor);

            helper.DrawString(this, Location + new Vector2(10, 6), Title, Color.White);

            foreach (var control in Controls)
            {
                if (control.IsVisible)
                {
                    control.Draw(helper, Location);
                }
            }
        }