public static void DrawPanelPartial(string collection, Rectangle bounds, PanelSides ps) { var images = new[] { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" }; var ss = images.Select(i => ChromeProvider.GetImage(collection, i)).ToArray(); DrawPanelPartial(ss, bounds, ps); }
public static void DrawPanelPartial(Rectangle bounds, PanelSides ps, Sprite borderTop, Sprite borderBottom, Sprite borderLeft, Sprite borderRight, Sprite cornerTopLeft, Sprite cornerTopRight, Sprite cornerBottomLeft, Sprite cornerBottomRight, Sprite background) { var marginLeft = borderLeft == null ? 0 : (int)borderLeft.Size.X; var marginTop = borderTop == null ? 0 : (int)borderTop.Size.Y; var marginRight = borderRight == null ? 0 : (int)borderRight.Size.X; var marginBottom = borderBottom == null ? 0 : (int)borderBottom.Size.Y; var marginWidth = marginRight + marginLeft; var marginHeight = marginBottom + marginTop; // Background if (ps.HasFlags(PanelSides.Center) && background != null) FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Top + marginTop, bounds.Width - marginWidth, bounds.Height - marginHeight), background); // Left border if (ps.HasFlags(PanelSides.Left) && borderLeft != null) FillRectWithSprite(new Rectangle(bounds.Left, bounds.Top + marginTop, marginLeft, bounds.Height - marginHeight), borderLeft); // Right border if (ps.HasFlags(PanelSides.Right) && borderRight != null) FillRectWithSprite(new Rectangle(bounds.Right - marginRight, bounds.Top + marginTop, marginLeft, bounds.Height - marginHeight), borderRight); // Top border if (ps.HasFlags(PanelSides.Top) && borderTop != null) FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Top, bounds.Width - marginWidth, marginTop), borderTop); // Bottom border if (ps.HasFlags(PanelSides.Bottom) && borderBottom != null) FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Bottom - marginBottom, bounds.Width - marginWidth, marginTop), borderBottom); if (ps.HasFlags(PanelSides.Left | PanelSides.Top) && cornerTopLeft != null) DrawRGBA(cornerTopLeft, new float2(bounds.Left, bounds.Top)); if (ps.HasFlags(PanelSides.Right | PanelSides.Top) && cornerTopRight != null) DrawRGBA(cornerTopRight, new float2(bounds.Right - cornerTopRight.Size.X, bounds.Top)); if (ps.HasFlags(PanelSides.Left | PanelSides.Bottom) && cornerBottomLeft != null) DrawRGBA(cornerBottomLeft, new float2(bounds.Left, bounds.Bottom - cornerBottomLeft.Size.Y)); if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom) && cornerBottomRight != null) DrawRGBA(cornerBottomRight, new float2(bounds.Right - cornerBottomRight.Size.X, bounds.Bottom - cornerBottomRight.Size.Y)); }
public static void DrawPanelPartial(string collection, Rectangle Bounds, PanelSides ps) { var images = new[] { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" }; var ss = images.Select(i => ChromeProvider.GetImage(collection, i)).ToArray(); // Background FillRectWithSprite(new Rectangle(Bounds.Left + (int)ss[2].size.X, Bounds.Top + (int)ss[0].size.Y, Bounds.Right - (int)ss[3].size.X - Bounds.Left - (int)ss[2].size.X, Bounds.Bottom - (int)ss[1].size.Y - Bounds.Top - (int)ss[0].size.Y), ss[8]); // Left border if (ps.HasFlags(PanelSides.Left)) FillRectWithSprite(new Rectangle(Bounds.Left, Bounds.Top + (int)ss[0].size.Y, (int)ss[2].size.X, Bounds.Bottom - (int)ss[1].size.Y - Bounds.Top - (int)ss[0].size.Y), ss[2]); // Right border if (ps.HasFlags(PanelSides.Right)) FillRectWithSprite(new Rectangle(Bounds.Right - (int)ss[3].size.X, Bounds.Top + (int)ss[0].size.Y, (int)ss[2].size.X, Bounds.Bottom - (int)ss[1].size.Y - Bounds.Top - (int)ss[0].size.Y), ss[3]); // Top border if (ps.HasFlags(PanelSides.Top)) FillRectWithSprite(new Rectangle(Bounds.Left + (int)ss[2].size.X, Bounds.Top, Bounds.Right - (int)ss[3].size.X - Bounds.Left - (int)ss[2].size.X, (int)ss[0].size.Y), ss[0]); // Bottom border if (ps.HasFlags(PanelSides.Bottom)) FillRectWithSprite(new Rectangle(Bounds.Left + (int)ss[2].size.X, Bounds.Bottom - (int)ss[1].size.Y, Bounds.Right - (int)ss[3].size.X - Bounds.Left - (int)ss[2].size.X, (int)ss[0].size.Y), ss[1]); if (ps.HasFlags(PanelSides.Left | PanelSides.Top)) DrawRGBA(ss[4], new float2(Bounds.Left, Bounds.Top)); if (ps.HasFlags(PanelSides.Right | PanelSides.Top)) DrawRGBA(ss[5], new float2(Bounds.Right - ss[5].size.X, Bounds.Top)); if (ps.HasFlags(PanelSides.Left | PanelSides.Bottom)) DrawRGBA(ss[6], new float2(Bounds.Left, Bounds.Bottom - ss[6].size.Y)); if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom)) DrawRGBA(ss[7], new float2(Bounds.Right - ss[7].size.X, Bounds.Bottom - ss[7].size.Y)); }
public static void DrawPanelPartial(string collection, Rectangle bounds, PanelSides ps) { DrawPanelPartial(bounds, ps, ChromeProvider.GetImage(collection, "border-t"), ChromeProvider.GetImage(collection, "border-b"), ChromeProvider.GetImage(collection, "border-l"), ChromeProvider.GetImage(collection, "border-r"), ChromeProvider.GetImage(collection, "corner-tl"), ChromeProvider.GetImage(collection, "corner-tr"), ChromeProvider.GetImage(collection, "corner-bl"), ChromeProvider.GetImage(collection, "corner-br"), ChromeProvider.GetImage(collection, "background")); }
public static void DrawPanelPartial(Sprite[] ss, Rectangle bounds, PanelSides ps) { // Background if (ps.HasFlags(PanelSides.Center)) FillRectWithSprite(new Rectangle(bounds.Left + (int)ss[2].size.X, bounds.Top + (int)ss[0].size.Y, bounds.Right - (int)ss[3].size.X - bounds.Left - (int)ss[2].size.X, bounds.Bottom - (int)ss[1].size.Y - bounds.Top - (int)ss[0].size.Y), ss[8]); // Left border if (ps.HasFlags(PanelSides.Left)) FillRectWithSprite(new Rectangle(bounds.Left, bounds.Top + (int)ss[0].size.Y, (int)ss[2].size.X, bounds.Bottom - (int)ss[1].size.Y - bounds.Top - (int)ss[0].size.Y), ss[2]); // Right border if (ps.HasFlags(PanelSides.Right)) FillRectWithSprite(new Rectangle(bounds.Right - (int)ss[3].size.X, bounds.Top + (int)ss[0].size.Y, (int)ss[2].size.X, bounds.Bottom - (int)ss[1].size.Y - bounds.Top - (int)ss[0].size.Y), ss[3]); // Top border if (ps.HasFlags(PanelSides.Top)) FillRectWithSprite(new Rectangle(bounds.Left + (int)ss[2].size.X, bounds.Top, bounds.Right - (int)ss[3].size.X - bounds.Left - (int)ss[2].size.X, (int)ss[0].size.Y), ss[0]); // Bottom border if (ps.HasFlags(PanelSides.Bottom)) FillRectWithSprite(new Rectangle(bounds.Left + (int)ss[2].size.X, bounds.Bottom - (int)ss[1].size.Y, bounds.Right - (int)ss[3].size.X - bounds.Left - (int)ss[2].size.X, (int)ss[0].size.Y), ss[1]); if (ps.HasFlags(PanelSides.Left | PanelSides.Top)) DrawRGBA(ss[4], new float2(bounds.Left, bounds.Top)); if (ps.HasFlags(PanelSides.Right | PanelSides.Top)) DrawRGBA(ss[5], new float2(bounds.Right - ss[5].size.X, bounds.Top)); if (ps.HasFlags(PanelSides.Left | PanelSides.Bottom)) DrawRGBA(ss[6], new float2(bounds.Left, bounds.Bottom - ss[6].size.Y)); if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom)) DrawRGBA(ss[7], new float2(bounds.Right - ss[7].size.X, bounds.Bottom - ss[7].size.Y)); }
public static void DrawPanelPartial(Sprite[] ss, Rectangle bounds, PanelSides ps) { var marginLeft = ss[2] == null ? 0 : (int)ss[2].size.X; var marginTop = ss[0] == null ? 0 : (int)ss[0].size.Y; var marginRight = ss[3] == null ? 0 : (int)ss[3].size.X; var marginBottom = ss[1] == null ? 0 : (int)ss[1].size.Y; var marginWidth = marginRight + marginLeft; var marginHeight = marginBottom + marginTop; // Background if (ps.HasFlags(PanelSides.Center) && ss[8] != null) FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Top + marginTop, bounds.Width - marginWidth, bounds.Height - marginHeight), ss[8]); // Left border if (ps.HasFlags(PanelSides.Left) && ss[2] != null) FillRectWithSprite(new Rectangle(bounds.Left, bounds.Top + marginTop, marginLeft, bounds.Height - marginHeight), ss[2]); // Right border if (ps.HasFlags(PanelSides.Right) && ss[3] != null) FillRectWithSprite(new Rectangle(bounds.Right - marginRight, bounds.Top + marginTop, marginLeft, bounds.Height - marginHeight), ss[3]); // Top border if (ps.HasFlags(PanelSides.Top) && ss[0] != null) FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Top, bounds.Width - marginWidth, marginTop), ss[0]); // Bottom border if (ps.HasFlags(PanelSides.Bottom) && ss[1] != null) FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Bottom - marginBottom, bounds.Width - marginWidth, marginTop), ss[1]); if (ps.HasFlags(PanelSides.Left | PanelSides.Top) && ss[4] != null) DrawRGBA(ss[4], new float2(bounds.Left, bounds.Top)); if (ps.HasFlags(PanelSides.Right | PanelSides.Top) && ss[5] != null) DrawRGBA(ss[5], new float2(bounds.Right - ss[5].size.X, bounds.Top)); if (ps.HasFlags(PanelSides.Left | PanelSides.Bottom) && ss[6] != null) DrawRGBA(ss[6], new float2(bounds.Left, bounds.Bottom - ss[6].size.Y)); if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom) && ss[7] != null) DrawRGBA(ss[7], new float2(bounds.Right - ss[7].size.X, bounds.Bottom - ss[7].size.Y)); }
static bool HasFlags(this PanelSides a, PanelSides b) { // PERF: Enum.HasFlag is slower and requires allocations. return((a & b) == b); }
public static void DrawPanelPartial(Rectangle bounds, PanelSides ps, Sprite borderTop, Sprite borderBottom, Sprite borderLeft, Sprite borderRight, Sprite cornerTopLeft, Sprite cornerTopRight, Sprite cornerBottomLeft, Sprite cornerBottomRight, Sprite background) { var marginLeft = borderLeft == null ? 0 : (int)borderLeft.Size.X; var marginTop = borderTop == null ? 0 : (int)borderTop.Size.Y; var marginRight = borderRight == null ? 0 : (int)borderRight.Size.X; var marginBottom = borderBottom == null ? 0 : (int)borderBottom.Size.Y; var marginWidth = marginRight + marginLeft; var marginHeight = marginBottom + marginTop; // Background if (ps.HasFlags(PanelSides.Center) && background != null) { FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Top + marginTop, bounds.Width - marginWidth, bounds.Height - marginHeight), background); } // Left border if (ps.HasFlags(PanelSides.Left) && borderLeft != null) { FillRectWithSprite(new Rectangle(bounds.Left, bounds.Top + marginTop, marginLeft, bounds.Height - marginHeight), borderLeft); } // Right border if (ps.HasFlags(PanelSides.Right) && borderRight != null) { FillRectWithSprite(new Rectangle(bounds.Right - marginRight, bounds.Top + marginTop, marginLeft, bounds.Height - marginHeight), borderRight); } // Top border if (ps.HasFlags(PanelSides.Top) && borderTop != null) { FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Top, bounds.Width - marginWidth, marginTop), borderTop); } // Bottom border if (ps.HasFlags(PanelSides.Bottom) && borderBottom != null) { FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Bottom - marginBottom, bounds.Width - marginWidth, marginTop), borderBottom); } if (ps.HasFlags(PanelSides.Left | PanelSides.Top) && cornerTopLeft != null) { DrawRGBA(cornerTopLeft, new float2(bounds.Left, bounds.Top)); } if (ps.HasFlags(PanelSides.Right | PanelSides.Top) && cornerTopRight != null) { DrawRGBA(cornerTopRight, new float2(bounds.Right - cornerTopRight.Size.X, bounds.Top)); } if (ps.HasFlags(PanelSides.Left | PanelSides.Bottom) && cornerBottomLeft != null) { DrawRGBA(cornerBottomLeft, new float2(bounds.Left, bounds.Bottom - cornerBottomLeft.Size.Y)); } if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom) && cornerBottomRight != null) { DrawRGBA(cornerBottomRight, new float2(bounds.Right - cornerBottomRight.Size.X, bounds.Bottom - cornerBottomRight.Size.Y)); } }
static bool HasFlags(this PanelSides a, PanelSides b) { return((a & b) == b); }
public static void DrawPanelPartial(Sprite[] ss, Rectangle bounds, PanelSides ps) { var marginLeft = ss[2] == null ? 0 : (int)ss[2].size.X; var marginTop = ss[0] == null ? 0 : (int)ss[0].size.Y; var marginRight = ss[3] == null ? 0 : (int)ss[3].size.X; var marginBottom = ss[1] == null ? 0 : (int)ss[1].size.Y; var marginWidth = marginRight + marginLeft; var marginHeight = marginBottom + marginTop; // Background if (ps.HasFlags(PanelSides.Center) && ss[8] != null) { FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Top + marginTop, bounds.Width - marginWidth, bounds.Height - marginHeight), ss[8]); } // Left border if (ps.HasFlags(PanelSides.Left) && ss[2] != null) { FillRectWithSprite(new Rectangle(bounds.Left, bounds.Top + marginTop, marginLeft, bounds.Height - marginHeight), ss[2]); } // Right border if (ps.HasFlags(PanelSides.Right) && ss[3] != null) { FillRectWithSprite(new Rectangle(bounds.Right - marginRight, bounds.Top + marginTop, marginLeft, bounds.Height - marginHeight), ss[3]); } // Top border if (ps.HasFlags(PanelSides.Top) && ss[0] != null) { FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Top, bounds.Width - marginWidth, marginTop), ss[0]); } // Bottom border if (ps.HasFlags(PanelSides.Bottom) && ss[1] != null) { FillRectWithSprite(new Rectangle(bounds.Left + marginLeft, bounds.Bottom - marginBottom, bounds.Width - marginWidth, marginTop), ss[1]); } if (ps.HasFlags(PanelSides.Left | PanelSides.Top) && ss[4] != null) { DrawRGBA(ss[4], new float2(bounds.Left, bounds.Top)); } if (ps.HasFlags(PanelSides.Right | PanelSides.Top) && ss[5] != null) { DrawRGBA(ss[5], new float2(bounds.Right - ss[5].size.X, bounds.Top)); } if (ps.HasFlags(PanelSides.Left | PanelSides.Bottom) && ss[6] != null) { DrawRGBA(ss[6], new float2(bounds.Left, bounds.Bottom - ss[6].size.Y)); } if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom) && ss[7] != null) { DrawRGBA(ss[7], new float2(bounds.Right - ss[7].size.X, bounds.Bottom - ss[7].size.Y)); } }
static bool HasFlags(this PanelSides a, PanelSides b) { return (a & b) == b; }
public static void DrawPanelPartial(Sprite[] ss, Rectangle bounds, PanelSides ps) { // Background if (ps.HasFlags(PanelSides.Center)) { FillRectWithSprite(new Rectangle(bounds.Left + (int)ss[2].size.X, bounds.Top + (int)ss[0].size.Y, bounds.Right - (int)ss[3].size.X - bounds.Left - (int)ss[2].size.X, bounds.Bottom - (int)ss[1].size.Y - bounds.Top - (int)ss[0].size.Y), ss[8]); } // Left border if (ps.HasFlags(PanelSides.Left)) { FillRectWithSprite(new Rectangle(bounds.Left, bounds.Top + (int)ss[0].size.Y, (int)ss[2].size.X, bounds.Bottom - (int)ss[1].size.Y - bounds.Top - (int)ss[0].size.Y), ss[2]); } // Right border if (ps.HasFlags(PanelSides.Right)) { FillRectWithSprite(new Rectangle(bounds.Right - (int)ss[3].size.X, bounds.Top + (int)ss[0].size.Y, (int)ss[2].size.X, bounds.Bottom - (int)ss[1].size.Y - bounds.Top - (int)ss[0].size.Y), ss[3]); } // Top border if (ps.HasFlags(PanelSides.Top)) { FillRectWithSprite(new Rectangle(bounds.Left + (int)ss[2].size.X, bounds.Top, bounds.Right - (int)ss[3].size.X - bounds.Left - (int)ss[2].size.X, (int)ss[0].size.Y), ss[0]); } // Bottom border if (ps.HasFlags(PanelSides.Bottom)) { FillRectWithSprite(new Rectangle(bounds.Left + (int)ss[2].size.X, bounds.Bottom - (int)ss[1].size.Y, bounds.Right - (int)ss[3].size.X - bounds.Left - (int)ss[2].size.X, (int)ss[0].size.Y), ss[1]); } if (ps.HasFlags(PanelSides.Left | PanelSides.Top)) { DrawRGBA(ss[4], new float2(bounds.Left, bounds.Top)); } if (ps.HasFlags(PanelSides.Right | PanelSides.Top)) { DrawRGBA(ss[5], new float2(bounds.Right - ss[5].size.X, bounds.Top)); } if (ps.HasFlags(PanelSides.Left | PanelSides.Bottom)) { DrawRGBA(ss[6], new float2(bounds.Left, bounds.Bottom - ss[6].size.Y)); } if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom)) { DrawRGBA(ss[7], new float2(bounds.Right - ss[7].size.X, bounds.Bottom - ss[7].size.Y)); } }
public static bool HasSide(this PanelSides self, PanelSides m) { // PERF: Enum.HasFlag is slower and requires allocations. return((self & m) == m); }