using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Windows.Forms; namespace LYFZ.OtherExpansion.SkinClass { public sealed class ControlPaintEx { public static void DrawCheckedFlag(Graphics graphics, Rectangle rect, Color color) { PointF[] points = new PointF[] { new PointF((float)rect.X + (float)rect.Width / 4.5f, (float)rect.Y + (float)rect.Height / 2.5f), new PointF((float)rect.X + (float)rect.Width / 2.5f, (float)rect.Bottom - (float)rect.Height / 3f), new PointF((float)rect.Right - (float)rect.Width / 4f, (float)rect.Y + (float)rect.Height / 4.5f) }; using (Pen pen = new Pen(color, 2f)) { graphics.DrawLines(pen, points); } } public static void DrawGlass(Graphics g, RectangleF glassRect, int alphaCenter, int alphaSurround) { ControlPaintEx.DrawGlass(g, glassRect, Color.White, alphaCenter, alphaSurround); } public static void DrawGlass(Graphics g, RectangleF glassRect, Color glassColor, int alphaCenter, int alphaSurround) { using (GraphicsPath path = new GraphicsPath()) { path.AddEllipse(glassRect); using (PathGradientBrush brush = new PathGradientBrush(path)) { brush.CenterColor = Color.FromArgb(alphaCenter, glassColor); brush.SurroundColors = new Color[] { Color.FromArgb(alphaSurround, glassColor) }; brush.CenterPoint = new PointF(glassRect.X + glassRect.Width / 2f, glassRect.Y + glassRect.Height / 2f); g.FillPath(brush, path); } } } public static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect) { ControlPaintEx.DrawBackgroundImage(g, backgroundImage, backColor, backgroundImageLayout, bounds, clipRect, Point.Empty, RightToLeft.No); } public static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset) { ControlPaintEx.DrawBackgroundImage(g, backgroundImage, backColor, backgroundImageLayout, bounds, clipRect, scrollOffset, RightToLeft.No); } public static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft) { if (g == null) { throw new ArgumentNullException("g"); } if (backgroundImageLayout == ImageLayout.Tile) { using (TextureBrush brush = new TextureBrush(backgroundImage, WrapMode.Tile)) { if (scrollOffset != Point.Empty) { Matrix transform = brush.Transform; transform.Translate((float)scrollOffset.X, (float)scrollOffset.Y); brush.Transform = transform; } g.FillRectangle(brush, clipRect); return; } } Rectangle rect = ControlPaintEx.CalculateBackgroundImageRectangle(bounds, backgroundImage, backgroundImageLayout); if (rightToLeft == RightToLeft.Yes && backgroundImageLayout == ImageLayout.None) { rect.X += clipRect.Width - rect.Width; } using (SolidBrush brush2 = new SolidBrush(backColor)) { g.FillRectangle(brush2, clipRect); } if (!clipRect.Contains(rect)) { if (backgroundImageLayout == ImageLayout.Stretch || backgroundImageLayout == ImageLayout.Zoom) { rect.Intersect(clipRect); g.DrawImage(backgroundImage, rect); return; } if (backgroundImageLayout == ImageLayout.None) { rect.Offset(clipRect.Location); Rectangle destRect = rect; destRect.Intersect(clipRect); Rectangle rectangle3 = new Rectangle(Point.Empty, destRect.Size); g.DrawImage(backgroundImage, destRect, rectangle3.X, rectangle3.Y, rectangle3.Width, rectangle3.Height, GraphicsUnit.Pixel); return; } Rectangle rectangle4 = rect; rectangle4.Intersect(clipRect); Rectangle rectangle5 = new Rectangle(new Point(rectangle4.X - rect.X, rectangle4.Y - rect.Y), rectangle4.Size); g.DrawImage(backgroundImage, rectangle4, rectangle5.X, rectangle5.Y, rectangle5.Width, rectangle5.Height, GraphicsUnit.Pixel); return; } else { ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetWrapMode(WrapMode.TileFlipXY); g.DrawImage(backgroundImage, rect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAttr); imageAttr.Dispose(); } } public static Rectangle CalculateBackgroundImageRectangle(Rectangle bounds, Image backgroundImage, ImageLayout imageLayout) { Rectangle rectangle = bounds; if (backgroundImage != null) { switch (imageLayout) { case ImageLayout.None: rectangle.Size = backgroundImage.Size; return rectangle; case ImageLayout.Tile: return rectangle; case ImageLayout.Center: { rectangle.Size = backgroundImage.Size; Size size = bounds.Size; if (size.Width > rectangle.Width) { rectangle.X = (size.Width - rectangle.Width) / 2; } if (size.Height > rectangle.Height) { rectangle.Y = (size.Height - rectangle.Height) / 2; } return rectangle; } case ImageLayout.Stretch: rectangle.Size = bounds.Size; return rectangle; case ImageLayout.Zoom: { Size size2 = backgroundImage.Size; float num = (float)bounds.Width / (float)size2.Width; float num2 = (float)bounds.Height / (float)size2.Height; if (num >= num2) { rectangle.Height = bounds.Height; rectangle.Width = (int)((double)((float)size2.Width * num2) + 0.5); if (bounds.X >= 0) { rectangle.X = (bounds.Width - rectangle.Width) / 2; } return rectangle; } rectangle.Width = bounds.Width; rectangle.Height = (int)((double)((float)size2.Height * num) + 0.5); if (bounds.Y >= 0) { rectangle.Y = (bounds.Height - rectangle.Height) / 2; } return rectangle; } } } return rectangle; } } }