public override void DrawBorder(IBorderElement element, Path path) { Pen pen; if (element.GradientStyle == GradientStyles.Solid) { pen = new Pen(element.ForeColor); } else if (element.GradientStyle == GradientStyles.Linear) { GradientStop[] colorStops = new GradientStop[4] { new GradientStop(element.ForeColor, 0.0f), new GradientStop(element.ForeColor2, 0.333f), new GradientStop(element.ForeColor3, 0.666f), new GradientStop(element.ForeColor4, 1f) }; pen = new Pen((Brush)this.CreateLinearGradientBrush(new RectangleF(0.0f, 0.0f, element.BorderSize.Width, element.BorderSize.Height), colorStops, element.GradientAngle).RawBrush); } else { GradientStop[] colorStops = new GradientStop[4] { new GradientStop(element.ForeColor, 0.0f), new GradientStop(element.ForeColor2, 0.333f), new GradientStop(element.ForeColor3, 0.666f), new GradientStop(element.ForeColor4, 1f) }; float num1 = element.BorderSize.Width / 2f; float num2 = element.BorderSize.Height / 2f; pen = new Pen((Brush)this.CreateRadialBrush(new PointF(num1, num2), num1, num2, colorStops).RawBrush); } pen.Alignment = (double)element.Width < 2.0 ? PenAlignment.Inset : PenAlignment.Center; pen.Width = element.Width; pen.DashStyle = element.BorderDashStyle; this.graphics.DrawPath(pen, (GraphicsPath)path.RawPath); pen.Dispose(); }
private void DrawBorderRectImpl( IBorderElement element, RectangleF rectangle, Color[] gradientColors, float width) { if (element.BoxStyle == BorderBoxStyle.FourBorders) { this.DrawFourBorders(element, rectangle); } else { if (element.GradientStyle != GradientStyles.Solid) { return; } using (Pen pen = new Pen(gradientColors[0])) { pen.Width = width; pen.Alignment = PenAlignment.Center; pen.DashStyle = element.BorderDashStyle; this.graphics.DrawRectangle(pen, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); } } }
public static void UpdateBorder(IVisualNativeElementRenderer renderer, IBorderElement backgroundView) { var control = renderer.Control; var ImageButton = backgroundView; if (control == null) { return; } if (ImageButton.BorderColor != null) { control.Layer.BorderColor = ImageButton.BorderColor.ToCGColor(); } control.Layer.BorderWidth = Math.Max(0f, (float)ImageButton.BorderWidth); nfloat cornerRadius = _defaultCornerRadius; if (ImageButton.IsCornerRadiusSet() && ImageButton.CornerRadius != ImageButton.CornerRadiusDefaultValue) { cornerRadius = ImageButton.CornerRadius; } control.Layer.CornerRadius = cornerRadius; }
static void OnControlChanged(object sender, EventArgs e) { IVisualNativeElementRenderer renderer = (IVisualNativeElementRenderer)sender; IBorderElement backgroundView = (IBorderElement)renderer.Element; UpdateBorder(renderer, backgroundView); }
static void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { IVisualNativeElementRenderer renderer = (IVisualNativeElementRenderer)sender; IBorderElement backgroundView = (IBorderElement)renderer.Element; if (e.PropertyName == Button.BorderWidthProperty.PropertyName || e.PropertyName == Button.CornerRadiusProperty.PropertyName || e.PropertyName == Button.BorderColorProperty.PropertyName) { UpdateBorder(renderer, backgroundView); } }
private void DrawOuterInnerBorder(IBorderElement element, RectangleF rect) { this.singleBorderParts[(int)element.GradientStyle](element, rect); float num = -(float)Math.Floor((double)Math.Max(1f, Math.Max(1f, element.Width / 2f))); RectangleF rectangleF = RectangleF.Inflate(rect, num, num); Color[] gradientColors = new Color[4] { element.InnerColor, element.InnerColor2, element.InnerColor3, element.InnerColor4 }; this.singleBorderParts[(int)element.GradientStyle](element, rectangleF); this.DrawBorderRectImpl(element, rectangleF, gradientColors, element.Width); }
private void DrawLinearBorder(IBorderElement element, RectangleF rect) { using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(rect, element.ForeColor, element.ForeColor2, element.GradientAngle)) { using (Pen pen = new Pen((Brush)linearGradientBrush)) { pen.Width = element.Width; pen.Alignment = PenAlignment.Center; pen.DashStyle = element.BorderDashStyle; this.graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); } } }
private void DrawSolidBorder(IBorderElement element, RectangleF rect) { if (element.ForeColor.A == (byte)0) { return; } using (Pen pen = new Pen(element.ForeColor)) { pen.Width = element.Width; pen.Alignment = PenAlignment.Center; pen.DashStyle = element.BorderDashStyle; this.graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); } }
private void DrawRadialBorder(IBorderElement element, RectangleF rect) { using (PathGradientBrush pathGradientBrush = new PathGradientBrush(new PointF[4] { new PointF(rect.X, rect.Y), new PointF(rect.Right, rect.Y), new PointF(rect.Right, rect.Bottom), new PointF(rect.Left, rect.Bottom) })) { pathGradientBrush.CenterColor = element.ForeColor; pathGradientBrush.SurroundColors = new Color[4] { element.ForeColor, element.ForeColor2, element.ForeColor3, element.ForeColor4 }; pathGradientBrush.CenterPoint = new PointF(rect.Width / 2f, rect.Height / 2f); using (Pen pen = new Pen((Brush)pathGradientBrush)) { pen.Width = element.Width; pen.Alignment = PenAlignment.Inset; pen.DashStyle = element.BorderDashStyle; this.graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); } } }
public void DrawBorder(IBorderElement element, RectangleF rect) { this.surface.DrawBorder(element, rect); }
public abstract void DrawBorder(IBorderElement element, RectangleF rect);
public abstract void DrawBorder(IBorderElement element, Path path);
public BorderPrimitiveImpl(IBorderElement borderElement, IPrimitiveElement radElement) { this.borderElement = borderElement; this.primitiveElement = radElement; }
private void DrawFourBorders(IBorderElement borderElement, RectangleF rectangle) { float height1 = (float)Math.Ceiling((double)borderElement.TopWidth == 1.0 ? 1.0 : (double)borderElement.TopWidth / 2.0); float height2 = (float)Math.Ceiling((double)borderElement.BottomWidth == 1.0 ? 1.0 : (double)borderElement.BottomWidth / 2.0); float width1 = (float)Math.Ceiling((double)borderElement.LeftWidth == 1.0 ? 1.0 : (double)borderElement.LeftWidth / 2.0); float width2 = (float)Math.Ceiling((double)borderElement.RightWidth == 1.0 ? 1.0 : (double)borderElement.RightWidth / 2.0); float height3 = (float)Math.Floor((double)borderElement.TopWidth == 1.0 ? 1.0 : (double)borderElement.TopWidth / 2.0); float height4 = (float)Math.Floor((double)borderElement.BottomWidth == 1.0 ? 1.0 : (double)borderElement.BottomWidth / 2.0); float width3 = (float)Math.Floor((double)borderElement.LeftWidth == 1.0 ? 1.0 : (double)borderElement.LeftWidth / 2.0); float width4 = (float)Math.Floor((double)borderElement.RightWidth == 1.0 ? 1.0 : (double)borderElement.RightWidth / 2.0); RectangleF rectangleF = new RectangleF(rectangle.Left + width1, rectangle.Top + height1, rectangle.Width - (width1 + width2), rectangle.Height - (height1 + height2)); if ((double)borderElement.TopWidth > 0.0) { using (Brush brush1 = (Brush) new SolidBrush(borderElement.TopColor)) { using (Brush brush2 = (Brush) new SolidBrush(borderElement.TopShadowColor)) { this.graphics.FillRectangle(brush1, new RectangleF(rectangle.Left, rectangle.Top, rectangle.Width + 1f, height1)); this.graphics.FillRectangle(brush2, new RectangleF(rectangleF.Left, rectangleF.Top, rectangleF.Width + 1f, height3)); } } } if ((double)borderElement.BottomWidth > 0.0) { using (Brush brush1 = (Brush) new SolidBrush(borderElement.BottomColor)) { using (Brush brush2 = (Brush) new SolidBrush(borderElement.BottomShadowColor)) { this.graphics.FillRectangle(brush1, new RectangleF(rectangle.Left, (float)((double)rectangle.Bottom - (double)height2 + 1.0), rectangle.Width + 1f, height2)); this.graphics.FillRectangle(brush2, new RectangleF(rectangleF.Left, (float)((double)rectangleF.Bottom - (double)height4 + 1.0), rectangleF.Width + 1f, height4)); } } } if ((double)borderElement.LeftWidth > 0.0) { using (Brush brush1 = (Brush) new SolidBrush(borderElement.LeftColor)) { using (Brush brush2 = (Brush) new SolidBrush(borderElement.LeftShadowColor)) { float height5 = (float)((double)rectangle.Height - ((double)height1 + (double)height2) + 1.0); float y1 = rectangle.Top + height1; float height6 = (float)((double)rectangleF.Height - ((double)height3 + (double)height4) + 1.0); float y2 = rectangleF.Top + height3; if ((borderElement.BorderDrawMode & BorderDrawModes.LeftOverTop) != BorderDrawModes.HorizontalOverVertical) { height5 += height1; y1 -= height1; height6 += height3; y2 -= height3; } if ((borderElement.BorderDrawMode & BorderDrawModes.LeftOverBottom) != BorderDrawModes.HorizontalOverVertical) { height5 += height2; height6 += height4; } this.graphics.FillRectangle(brush1, new RectangleF(rectangle.Left, y1, width1, height5)); this.graphics.FillRectangle(brush2, new RectangleF(rectangleF.Left, y2, width3, height6)); } } } if ((double)borderElement.RightWidth <= 0.0) { return; } using (Brush brush1 = (Brush) new SolidBrush(borderElement.RightColor)) { using (Brush brush2 = (Brush) new SolidBrush(borderElement.RightShadowColor)) { float height5 = (float)((double)rectangle.Height - ((double)height1 + (double)height2) + 1.0); float y1 = rectangle.Top + height1; float height6 = (float)((double)rectangleF.Height - ((double)height3 + (double)height4) + 1.0); float y2 = rectangleF.Top + height3; if ((borderElement.BorderDrawMode & BorderDrawModes.RightOverTop) != BorderDrawModes.HorizontalOverVertical) { height5 += height1; y1 -= height1; height6 += height3; y2 -= height3; } if ((borderElement.BorderDrawMode & BorderDrawModes.RightOverBottom) != BorderDrawModes.HorizontalOverVertical) { height5 += height2; height6 += height4; } this.graphics.FillRectangle(brush1, new RectangleF((float)((double)rectangle.Right - (double)width2 + 1.0), y1, width2, height5)); this.graphics.FillRectangle(brush2, new RectangleF((float)((double)rectangleF.Right - (double)width4 + 1.0), y2, width4, height6)); } } }
public override void DrawBorder(IBorderElement element, RectangleF rect) { this.borderParts[(int)element.BoxStyle](element, rect); }
private void DrawSingeBorder(IBorderElement element, RectangleF rect) { this.singleBorderParts[(int)element.GradientStyle](element, rect); }
public void DrawBorder(IBorderElement element, Path path) { this.surface.DrawBorder(element, path); }