Ejemplo n.º 1
0
        /// <summary>
        /// Draw the text with a border
        /// </summary>
        /// <param name="g">The Graphics used for drawing</param>
        /// <param name="textRect">The bounds within which the text should be drawn</param>
        /// <param name="text">The text to draw</param>
        protected void DrawBorderedText(Graphics g, Rectangle textRect, string text, Font font, float opacity)
        {
            Rectangle borderRect = textRect;

            if (this.BorderWidth > 0.0f)
            {
                borderRect.Inflate((int)this.BorderWidth / 2, (int)this.BorderWidth / 2);
            }

            borderRect.Y -= 1; // Looks better a little higher

            using (GraphicsPath path = ShapeSprite.GetRoundedRect(borderRect, this.CornerRounding * this.Scale)) {
                if (this.HasBackground)
                {
                    using (Brush brush = this.GetBackgroundBrush(opacity)) {
                        g.FillPath(brush, path);
                    }
                }

                using (Brush textBrush = this.GetTextBrush(opacity)) {
                    g.DrawString(text, font, textBrush, textRect, this.StringFormat);
                }

                if (this.HasBorder)
                {
                    using (Pen pen = this.GetBorderPen(opacity)) {
                        g.DrawPath(pen, path);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected virtual GraphicsPath GetGraphicsPath(Rectangle r)
        {
            GraphicsPath path        = new GraphicsPath();
            int          minimumAxis = Math.Min(r.Width, r.Height);
            Point        midPoint    = new Point(r.X + r.Width / 2, r.Y + r.Height / 2);

            switch (this.Shape)
            {
            case Shapes.Rectangle:
                path.AddRectangle(new Rectangle(Point.Empty, r.Size));
                break;

            case Shapes.RoundedRectangle:
                path = ShapeSprite.GetRoundedRect(r, this.CornerRounding);
                break;

            case Shapes.Circle:
                path.AddEllipse(midPoint.X - minimumAxis / 2, midPoint.Y - minimumAxis / 2, minimumAxis, minimumAxis);
                break;

            case Shapes.Oval:
                path.AddEllipse(r);
                break;

            case Shapes.Square:
                path.AddRectangle(new Rectangle(midPoint.X - minimumAxis / 2, midPoint.Y - minimumAxis / 2,
                                                minimumAxis, minimumAxis));
                break;

            case Shapes.Triangle:
                path.AddLines(new Point[] {
                    new Point(r.Left, r.Top),
                    new Point(r.Left, r.Bottom),
                    new Point(r.Right, r.Top),
                    new Point(r.Left, r.Top)
                });
                break;

            case Shapes.IsoTriangle:
                path.AddLines(new Point[] {
                    new Point(r.Left, r.Bottom),
                    new Point(r.Right, r.Bottom),
                    new Point(midPoint.X, r.Top),
                    new Point(r.Left, r.Bottom)
                });
                break;

            case Shapes.EquiTriangle:
                //TODO
                break;

            default:
                break;
            }

            return(path);
        }