private void setStyle(BevelStyle astyle) { if (astyle != this.style) { this.style = astyle; this.Invalidate(); } }
/// <summary> /// Draws a bevel around a rectangle /// </summary> /// <param name="GS">Graphics surface to draw on</param> /// <param name="ReferenceBorder">Rectangle representing the starting border of the bevel</param> /// <param name="Width">Border width (pixels)</param> /// <param name="Style">Sunk or raised</param> /// <param name="Direction">Direction to draw, referenced to ReferenceBorder</param> protected void DrawBevel(Graphics GS, Rectangle ReferenceBorder, int Width, BevelStyle Style, BevelDirection Direction) { int Inflator; //number of pixels to inflate ReferenceBorder //draw appropriate number of 1-pixel thick rectangles for (int i = 0; i != Width; i++) { Pen TLPen; Pen BRPen; //select the proper colors if (Style == BevelStyle.Raised) { TLPen = new Pen(SystemColors.ControlLight, 1); BRPen = new Pen(SystemColors.ControlDark, 1); } else { TLPen = new Pen(SystemColors.ControlDark, 1); BRPen = new Pen(SystemColors.ControlLight, 1); } if (Direction == BevelDirection.Outward) { Inflator = i; } else { Inflator = -i; } //draw the borders GS.DrawLine(TLPen, ReferenceBorder.Left - Inflator, ReferenceBorder.Bottom + Inflator, ReferenceBorder.Left - Inflator, ReferenceBorder.Top - Inflator); GS.DrawLine(TLPen, ReferenceBorder.Left - Inflator, ReferenceBorder.Top - Inflator, ReferenceBorder.Right + Inflator, ReferenceBorder.Top - Inflator); GS.DrawLine(BRPen, ReferenceBorder.Right + Inflator, ReferenceBorder.Top - Inflator, ReferenceBorder.Right + Inflator, ReferenceBorder.Bottom + Inflator); GS.DrawLine(BRPen, ReferenceBorder.Right + Inflator, ReferenceBorder.Bottom + Inflator, ReferenceBorder.Left - Inflator, ReferenceBorder.Bottom + Inflator); } }
public static void DrawDiamond(PaintArgs p, Rectangle r, BevelStyle style, int thickness, Color color) { if (style != 0) { try { thickness = checked (thickness - 1); } catch (OverflowException) { thickness = -2147483648; } iColors.FaceColorLight = iColors.Lighten3(color); iColors.FaceColorDark = iColors.Darken1(color); bool invert = style == BevelStyle.Sunken && true; int x = (r.Left + r.Right) / 2; int y = (r.Top + r.Bottom) / 2; Point[] array = new Point[4] { new Point(r.Left, y), new Point(r.Left + thickness, y), new Point(x, r.Top + thickness), new Point(x, r.Top) }; p.Graphics.FillPolygon(p.Graphics.Brush(iColors.ToFaceColor(FaceReference.Top, p.Rotation, invert)), array); p.Graphics.DrawPolygon(p.Graphics.Pen(iColors.ToFaceColor(FaceReference.Top, p.Rotation, invert)), array); array[0] = new Point(x, r.Top); array[1] = new Point(x, r.Top + thickness); array[2] = new Point(r.Right - thickness, y); array[3] = new Point(r.Right, y); p.Graphics.FillPolygon(p.Graphics.Brush(iColors.ToFaceColor(FaceReference.Right, p.Rotation, invert)), array); p.Graphics.DrawPolygon(p.Graphics.Pen(iColors.ToFaceColor(FaceReference.Right, p.Rotation, invert)), array); array[0] = new Point(x, r.Bottom); array[1] = new Point(x, r.Bottom - thickness); array[2] = new Point(r.Right - thickness, y); array[3] = new Point(r.Right, y); p.Graphics.FillPolygon(p.Graphics.Brush(iColors.ToFaceColor(FaceReference.Bottom, p.Rotation, invert)), array); p.Graphics.DrawPolygon(p.Graphics.Pen(iColors.ToFaceColor(FaceReference.Bottom, p.Rotation, invert)), array); array[0] = new Point(x, r.Bottom); array[1] = new Point(x, r.Bottom - thickness); array[2] = new Point(r.Left + thickness, y); array[3] = new Point(r.Left, y); p.Graphics.FillPolygon(p.Graphics.Brush(iColors.ToFaceColor(FaceReference.Left, p.Rotation, invert)), array); p.Graphics.DrawPolygon(p.Graphics.Pen(iColors.ToFaceColor(FaceReference.Left, p.Rotation, invert)), array); } }
protected void Draw(PaintArgs p, Rectangle r, ShapeBasic type, BevelStyle style, int thickness, Color color) { switch (type) { case ShapeBasic.Rectangle: BorderSpecial.DrawRectangle(p, r, style, thickness, color); break; case ShapeBasic.Ellipse: BorderSpecial.DrawEllipse(p, r, style, (float)thickness, color); break; case ShapeBasic.Diamond: BorderSpecial.DrawDiamond(p, r, style, thickness, color); break; } }
public static void DrawRoundedSides(PaintArgs p, Rectangle r, BevelStyle style, int thickness, Color color) { Point[] array = new Point[4]; Color color2 = iColors.Darken1(color); array[0] = new Point(r.Left, r.Top); array[1] = new Point(r.Left, r.Bottom); array[2] = new Point(thickness, r.Bottom - thickness); array[3] = new Point(thickness, r.Top + thickness); GraphicsPath graphicsPath = Shapes.CreatePointsPath(array); LinearGradientBrush linearGradientBrush = new LinearGradientBrush(graphicsPath.GetBounds(), color2, color, 0f); linearGradientBrush.WrapMode = WrapMode.TileFlipXY; p.Graphics.FillPath(linearGradientBrush, graphicsPath); linearGradientBrush.Dispose(); array[0] = new Point(r.Left, r.Top); array[1] = new Point(thickness, thickness); array[2] = new Point(r.Right - thickness, thickness); array[3] = new Point(r.Right, r.Top); graphicsPath = Shapes.CreatePointsPath(array); linearGradientBrush = new LinearGradientBrush(graphicsPath.GetBounds(), color2, color, 90f); linearGradientBrush.WrapMode = WrapMode.TileFlipXY; p.Graphics.FillPath(linearGradientBrush, graphicsPath); linearGradientBrush.Dispose(); array[0] = new Point(r.Right, r.Top); array[1] = new Point(r.Right - thickness, r.Top + thickness); array[2] = new Point(r.Right - thickness, r.Bottom - thickness); array[3] = new Point(r.Right, r.Bottom); graphicsPath = Shapes.CreatePointsPath(array); linearGradientBrush = new LinearGradientBrush(graphicsPath.GetBounds(), color2, color, 180f); linearGradientBrush.WrapMode = WrapMode.TileFlipXY; p.Graphics.FillPath(linearGradientBrush, graphicsPath); linearGradientBrush.Dispose(); array[0] = new Point(r.Left, r.Bottom); array[1] = new Point(r.Left + thickness, r.Bottom - thickness); array[2] = new Point(r.Right - thickness, r.Bottom - thickness); array[3] = new Point(r.Right, r.Bottom); graphicsPath = Shapes.CreatePointsPath(array); linearGradientBrush = new LinearGradientBrush(graphicsPath.GetBounds(), color2, color, 270f); linearGradientBrush.WrapMode = WrapMode.TileFlipXY; p.Graphics.FillPath(linearGradientBrush, graphicsPath); linearGradientBrush.Dispose(); }
public static void DrawEllipse(PaintArgs p, Rectangle r, BevelStyle style, float thickness, Color color) { if (style != 0) { Rectangle rect = new Rectangle(r.Left, r.Top, r.Width - 1, r.Height - 1); if (style == BevelStyle.Sunken) { iColors.FaceColorLight = iColors.Darken2(color); iColors.FaceColorDark = Color.White; } else { iColors.FaceColorLight = Color.White; iColors.FaceColorDark = iColors.Darken2(color); } float angle = (p.Rotation != 0) ? ((p.Rotation != RotationQuad.X090) ? ((p.Rotation != RotationQuad.X180) ? 135f : 225f) : 315f) : 45f; GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddEllipse(rect); LinearGradientBrush linearGradientBrush = new LinearGradientBrush(r, iColors.FaceColorLight, iColors.FaceColorDark, angle); p.Graphics.FillPath(linearGradientBrush, graphicsPath); linearGradientBrush.Dispose(); graphicsPath.Dispose(); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void DrawPart(Renderer renderer, Rectangle rect, BevelBorder pos, BevelStyle style, bool all) { SkinLayer layer = Skin.Layers["Control"]; Color c1 = Utilities.ParseColor(layer.Attributes["LightColor"].Value); Color c2 = Utilities.ParseColor(layer.Attributes["DarkColor"].Value); Color c3 = Utilities.ParseColor(layer.Attributes["FlatColor"].Value); if (Color != UndefinedColor) c3 = Color; Texture2D img = Skin.Layers["Control"].Image.Resource; int x1 = 0; int y1 = 0; int w1 = 0; int h1 = 0; int x2 = 0; int y2 = 0; int w2 = 0; int h2 = 0; if (style == BevelStyle.Bumped || style == BevelStyle.Etched) { if (all && (pos == BevelBorder.Top || pos == BevelBorder.Bottom)) { rect = new Rectangle(rect.Left + 1, rect.Top, rect.Width - 2, rect.Height); } else if (all && (pos == BevelBorder.Left)) { rect = new Rectangle(rect.Left, rect.Top, rect.Width, rect.Height - 1); } switch (pos) { case BevelBorder.Left: { x1 = rect.Left; y1 = rect.Top; w1 = 1; h1 = rect.Height; x2 = x1 + 1; y2 = y1; w2 = w1; h2 = h1; break; } case BevelBorder.Top: { x1 = rect.Left; y1 = rect.Top; w1 = rect.Width; h1 = 1; x2 = x1; y2 = y1 + 1; w2 = w1; h2 = h1; break; } case BevelBorder.Right: { x1 = rect.Left + rect.Width - 2; y1 = rect.Top; w1 = 1; h1 = rect.Height; x2 = x1 + 1; y2 = y1; w2 = w1; h2 = h1; break; } case BevelBorder.Bottom: { x1 = rect.Left; y1 = rect.Top + rect.Height - 2; w1 = rect.Width; h1 = 1; x2 = x1; y2 = y1 + 1; w2 = w1; h2 = h1; break; } } } else { switch (pos) { case BevelBorder.Left: { x1 = rect.Left; y1 = rect.Top; w1 = 1; h1 = rect.Height; break; } case BevelBorder.Top: { x1 = rect.Left; y1 = rect.Top; w1 = rect.Width; h1 = 1; break; } case BevelBorder.Right: { x1 = rect.Left + rect.Width - 1; y1 = rect.Top; w1 = 1; h1 = rect.Height; break; } case BevelBorder.Bottom: { x1 = rect.Left; y1 = rect.Top + rect.Height - 1; w1 = rect.Width; h1 = 1; break; } } } switch (Style) { case BevelStyle.Bumped: { renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c1); renderer.Draw(img, new Rectangle(x2, y2, w2, h2), c2); break; } case BevelStyle.Etched: { renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c2); renderer.Draw(img, new Rectangle(x2, y2, w2, h2), c1); break; } case BevelStyle.Raised: { Color c = c1; if (pos == BevelBorder.Left || pos == BevelBorder.Top) c = c1; else c = c2; renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c); break; } case BevelStyle.Lowered: { Color c = c1; if (pos == BevelBorder.Left || pos == BevelBorder.Top) c = c2; else c = c1; renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c); break; } default: { renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c3); break; } } }
} // DrawControl private void DrawPart(Rectangle rect, BevelBorder pos, BevelStyle style, bool all) { SkinLayer layer = SkinInformation.Layers["Control"]; Color c1 = Utilities.ParseColor(layer.Attributes["LightColor"].Value); Color c2 = Utilities.ParseColor(layer.Attributes["DarkColor"].Value); Color c3 = Utilities.ParseColor(layer.Attributes["FlatColor"].Value); if (Color != UndefinedColor) c3 = Color; Texture texture = SkinInformation.Layers["Control"].Image.Texture; int x1 = 0; int y1 = 0; int w1 = 0; int h1 = 0; int x2 = 0; int y2 = 0; int w2 = 0; int h2 = 0; if (style == BevelStyle.Bumped || style == BevelStyle.Etched) { if (all && (pos == BevelBorder.Top || pos == BevelBorder.Bottom)) { rect = new Rectangle(rect.Left + 1, rect.Top, rect.Width - 2, rect.Height); } else if (all && (pos == BevelBorder.Left)) { rect = new Rectangle(rect.Left, rect.Top, rect.Width, rect.Height - 1); } switch (pos) { case BevelBorder.Left: { x1 = rect.Left; y1 = rect.Top; w1 = 1; h1 = rect.Height; x2 = x1 + 1; y2 = y1; w2 = w1; h2 = h1; break; } case BevelBorder.Top: { x1 = rect.Left; y1 = rect.Top; w1 = rect.Width; h1 = 1; x2 = x1; y2 = y1 + 1; w2 = w1; h2 = h1; break; } case BevelBorder.Right: { x1 = rect.Left + rect.Width - 2; y1 = rect.Top; w1 = 1; h1 = rect.Height; x2 = x1 + 1; y2 = y1; w2 = w1; h2 = h1; break; } case BevelBorder.Bottom: { x1 = rect.Left; y1 = rect.Top + rect.Height - 2; w1 = rect.Width; h1 = 1; x2 = x1; y2 = y1 + 1; w2 = w1; h2 = h1; break; } } } else { switch (pos) { case BevelBorder.Left: { x1 = rect.Left; y1 = rect.Top; w1 = 1; h1 = rect.Height; break; } case BevelBorder.Top: { x1 = rect.Left; y1 = rect.Top; w1 = rect.Width; h1 = 1; break; } case BevelBorder.Right: { x1 = rect.Left + rect.Width - 1; y1 = rect.Top; w1 = 1; h1 = rect.Height; break; } case BevelBorder.Bottom: { x1 = rect.Left; y1 = rect.Top + rect.Height - 1; w1 = rect.Width; h1 = 1; break; } } } switch (Style) { case BevelStyle.Bumped: { Renderer.Draw(texture.Resource, new Rectangle(x1, y1, w1, h1), c1); Renderer.Draw(texture.Resource, new Rectangle(x2, y2, w2, h2), c2); break; } case BevelStyle.Etched: { Renderer.Draw(texture.Resource, new Rectangle(x1, y1, w1, h1), c2); Renderer.Draw(texture.Resource, new Rectangle(x2, y2, w2, h2), c1); break; } case BevelStyle.Raised: { Color c = c1; if (pos == BevelBorder.Left || pos == BevelBorder.Top) c = c1; else c = c2; Renderer.Draw(texture.Resource, new Rectangle(x1, y1, w1, h1), c); break; } case BevelStyle.Lowered: { Color c = c1; if (pos == BevelBorder.Left || pos == BevelBorder.Top) c = c2; else c = c1; Renderer.Draw(texture.Resource, new Rectangle(x1, y1, w1, h1), c); break; } default: { Renderer.Draw(texture.Resource, new Rectangle(x1, y1, w1, h1), c3); break; } } } // DrawPart
/// <param name="all">Indicates if the bevel is applied to a single side (false) or all sides (true) of the control.</param> /// <param name="style">Specifies the style of beveling to apply to the control.</param> /// <param name="pos">Specifies which side of the control is beveled.</param> /// <param name="rect">Bounds of the control the bevel is applied to.</param> /// <param name="renderer">Render management object.</param> /// <summary> /// Draws a piece of the beveled control based on the bevel's border and style. /// </summary> private void DrawPart(Renderer renderer, Rectangle rect, BevelBorder pos, BevelStyle style, bool all) { // Get the skin's control layer and parse the bevel color values. var layer = Skin.Layers["Control"]; var c1 = Utilities.ParseColor(layer.Attributes["LightColor"].Value); var c2 = Utilities.ParseColor(layer.Attributes["DarkColor"].Value); var c3 = Utilities.ParseColor(layer.Attributes["FlatColor"].Value); if (Color != UndefinedColor) { c3 = Color; } // Get the control's image asset. var img = Skin.Layers["Control"].Image.Resource; var x1 = 0; var y1 = 0; var w1 = 0; var h1 = 0; var x2 = 0; var y2 = 0; var w2 = 0; var h2 = 0; if (style == BevelStyle.Bumped || style == BevelStyle.Etched) { if (all && (pos == BevelBorder.Top || pos == BevelBorder.Bottom)) { rect = new Rectangle(rect.Left + 1, rect.Top, rect.Width - 2, rect.Height); } else if (all && (pos == BevelBorder.Left)) { rect = new Rectangle(rect.Left, rect.Top, rect.Width, rect.Height - 1); } switch (pos) { case BevelBorder.Left: { x1 = rect.Left; y1 = rect.Top; w1 = 1; h1 = rect.Height; x2 = x1 + 1; y2 = y1; w2 = w1; h2 = h1; break; } case BevelBorder.Top: { x1 = rect.Left; y1 = rect.Top; w1 = rect.Width; h1 = 1; x2 = x1; y2 = y1 + 1; w2 = w1; h2 = h1; break; } case BevelBorder.Right: { x1 = rect.Left + rect.Width - 2; y1 = rect.Top; w1 = 1; h1 = rect.Height; x2 = x1 + 1; y2 = y1; w2 = w1; h2 = h1; break; } case BevelBorder.Bottom: { x1 = rect.Left; y1 = rect.Top + rect.Height - 2; w1 = rect.Width; h1 = 1; x2 = x1; y2 = y1 + 1; w2 = w1; h2 = h1; break; } } } else { switch (pos) { case BevelBorder.Left: { x1 = rect.Left; y1 = rect.Top; w1 = 1; h1 = rect.Height; break; } case BevelBorder.Top: { x1 = rect.Left; y1 = rect.Top; w1 = rect.Width; h1 = 1; break; } case BevelBorder.Right: { x1 = rect.Left + rect.Width - 1; y1 = rect.Top; w1 = 1; h1 = rect.Height; break; } case BevelBorder.Bottom: { x1 = rect.Left; y1 = rect.Top + rect.Height - 1; w1 = rect.Width; h1 = 1; break; } } } switch (Style) { case BevelStyle.Bumped: { renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c1); renderer.Draw(img, new Rectangle(x2, y2, w2, h2), c2); break; } case BevelStyle.Etched: { renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c2); renderer.Draw(img, new Rectangle(x2, y2, w2, h2), c1); break; } case BevelStyle.Raised: { var c = c1; if (pos == BevelBorder.Left || pos == BevelBorder.Top) { c = c1; } else { c = c2; } renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c); break; } case BevelStyle.Lowered: { var c = c1; if (pos == BevelBorder.Left || pos == BevelBorder.Top) { c = c2; } else { c = c1; } renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c); break; } default: { renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c3); break; } } }
void IBevelThick.Draw(PaintArgs p, Rectangle r, ShapeBasic type, BevelStyle style, int thickness, Color color) { this.Draw(p, r, type, style, thickness, color); }