using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; namespace DevComponents.DotNetBar { /// /// Represents class that holds User Interface static methods. /// internal class UIGraphics { private UIGraphics() { } /// /// Gets the graphics path that represents triangle. /// /// Top left position of the triangle. /// Size of the triangle. /// Pointing direction of the triangle. /// Returns graphics path for the triangle of given size and pointing in given direction. public static GraphicsPath GetTrianglePath(Point p, int size, eTriangleDirection direction) { GraphicsPath path=new GraphicsPath(); switch(direction) { case eTriangleDirection.Left: { p.X--; path.AddLine(p.X+size/2,p.Y,p.X+size/2,p.Y+size); path.AddLine(p.X,p.Y+size/2,p.X+size/2,p.Y); path.CloseAllFigures(); break; } case eTriangleDirection.Right: { path.AddLine(p.X,p.Y,p.X,p.Y+size); path.AddLine(p.X+size/2,p.Y+size/2,p.X,p.Y); path.CloseAllFigures(); break; } case eTriangleDirection.Top: { int midY = (int)Math.Ceiling(p.Y + (float)size / 2); int midX = (int)Math.Ceiling(p.X + (float)size / 2); path.AddLine(p.X, midY, p.X + size, midY); path.AddLine(midX, p.Y, p.X, midY); path.CloseAllFigures(); break; } case eTriangleDirection.Bottom: { int midY = (int)Math.Floor(p.Y + (float)size / 2); int midX = (int)Math.Floor(p.X + (float)size / 2); path.AddLine(p.X, p.Y, p.X + size - 1, p.Y); // -1 hack for GDI+ FillPath bug path.AddLine(midX, midY, p.X, p.Y); path.CloseAllFigures(); break; } } return path; } /// /// Creates the double arrow >> collapse expand image for the collapsable controls. /// /// Indicates the direction of the arrow /// Color for the arrows /// Indicates whether image is for vertical collapse/expand /// public static Image CreateExpandButtonImage(bool collapse, Color color, bool verticalCollapse) { Bitmap bmp = new Bitmap(16, 16, PixelFormat.Format24bppRgb); bmp.MakeTransparent(); Image img = bmp; Graphics g = Graphics.FromImage(img); g.SmoothingMode = SmoothingMode.AntiAlias; if (collapse) { if (verticalCollapse) { using (Pen pen = new Pen(color, 1)) { g.DrawLine(pen, 4, 7, 7, 4); g.DrawLine(pen, 7, 4, 10, 7); g.DrawLine(pen, 5, 7, 7, 5); g.DrawLine(pen, 7, 5, 9, 7); g.DrawLine(pen, 4, 10, 7, 7); g.DrawLine(pen, 7, 7, 10, 10); g.DrawLine(pen, 5, 10, 7, 8); g.DrawLine(pen, 7, 8, 9, 10); } } else { using (Pen pen = new Pen(color, 1)) { g.DrawLine(pen, 7, 4, 4, 7); g.DrawLine(pen, 4, 7, 7, 10); g.DrawLine(pen, 7, 5, 5, 7); g.DrawLine(pen, 5, 7, 7, 9); g.DrawLine(pen, 10, 4, 7, 7); g.DrawLine(pen, 7, 7, 10, 10); g.DrawLine(pen, 10, 5, 8, 7); g.DrawLine(pen, 8, 7, 10, 9); } } } else { if (verticalCollapse) { using (Pen pen = new Pen(color, 1)) { g.DrawLine(pen, 4, 4, 7, 7); g.DrawLine(pen, 7, 7, 10, 4); g.DrawLine(pen, 5, 4, 7, 6); g.DrawLine(pen, 7, 6, 9, 4); g.DrawLine(pen, 4, 7, 7, 10); g.DrawLine(pen, 7, 10, 10, 7); g.DrawLine(pen, 5, 7, 7, 9); g.DrawLine(pen, 7, 9, 9, 7); } } else { using (Pen pen = new Pen(color, 1)) { g.DrawLine(pen, 4, 4, 7, 7); g.DrawLine(pen, 7, 7, 4, 10); g.DrawLine(pen, 4, 5, 6, 7); g.DrawLine(pen, 6, 7, 4, 9); g.DrawLine(pen, 7, 4, 10, 7); g.DrawLine(pen, 10, 7, 7, 10); g.DrawLine(pen, 7, 5, 9, 7); g.DrawLine(pen, 9, 7, 7, 9); } } } g.Dispose(); return img; } } /// /// Specifies the pointing direction of triangle. /// internal enum eTriangleDirection { /// /// Triangle point to the left. /// Left, /// /// Triangle point to the right. /// Right, /// /// Triangle point to the top. /// Top, /// /// Triangle point to the bottom. /// Bottom } }