public override object CreateInstance(ITypeDescriptorContext objContext, IDictionary objPropertyValues) { CornerRadius padding; CornerRadiusValue value2 = (CornerRadiusValue)objContext.PropertyDescriptor.GetValue(objContext.Instance); int intAll = (int)objPropertyValues["All"]; if (value2.All != intAll) { padding = new CornerRadius(intAll); } else { padding = new CornerRadius((int)objPropertyValues["TopLeft"], (int)objPropertyValues["TopRight"], (int)objPropertyValues["BottomRight"], (int)objPropertyValues["BottomLeft"]); } return Activator.CreateInstance(value2.GetType(), new object[] { padding }); }
/// <summary> /// Updates or creates a sublayer to render a border-like shape. /// </summary> /// <param name="view">The view to which we should add the layers</param> /// <param name="background">The background brush of the border</param> /// <param name="borderThickness">The border thickness</param> /// <param name="borderBrush">The border brush</param> /// <param name="cornerRadius">The corner radius</param> /// <param name="padding">The padding to apply on the content</param> public void UpdateLayers( FrameworkElement view, Brush background, Thickness borderThickness, Brush borderBrush, CornerRadius cornerRadius, Thickness padding, bool willUpdateMeasures = false ) { // This is required because android Height and Width are hidden by Control. var baseView = view as View; var targetSize = new global::System.Drawing.Size(baseView.Width, baseView.Height); var drawArea = new Windows.Foundation.Rect(0, 0, targetSize.Width, targetSize.Height); var newState = new LayoutState(drawArea, background, borderThickness, borderBrush, cornerRadius, padding); var previousLayoutState = _currentState; if (!newState.Equals(previousLayoutState)) { bool imageHasChanged = newState.BackgroundImageSource != previousLayoutState?.BackgroundImageSource; bool shouldDisposeEagerly = imageHasChanged || newState.BackgroundImageSource == null; if (shouldDisposeEagerly) { // Clear previous value anyway in order to make sure the previous values are unset before the new ones. // This prevents the case where a second update would set a new background and then set the background to null when disposing the previous. _layerDisposable.Disposable = null; } if ( background != null || (borderThickness != Thickness.Empty && borderBrush != null) ) { Action onImageSet = null; var disposable = InnerCreateLayers(view, drawArea, background, borderThickness, borderBrush, cornerRadius, () => onImageSet?.Invoke()); // Most of the time we immediately dispose the previous layer. In the case where we're using an ImageBrush, // and the backing image hasn't changed, we dispose the previous layer at the moment the new background is applied, // to prevent a visible flicker. if (shouldDisposeEagerly) { _layerDisposable.Disposable = disposable; } else { onImageSet = () => _layerDisposable.Disposable = disposable; } } if (willUpdateMeasures) { view.RequestLayout(); } else { view.Invalidate(); } _currentState = newState; } }
/// <summary> /// Default constructor. /// </summary> public Window() { CornerRadius = new CornerRadius(8); }
protected override void OnRender(DrawingContext dc) { bool useLayoutRounding = this.UseLayoutRounding; if (_useComplexRenderCodePath) { Brush brush; StreamGeometry borderGeometry = BorderGeometryCache; if (borderGeometry != null && (brush = BorderBrush) != null) { dc.DrawGeometry(brush, null, borderGeometry); } StreamGeometry backgroundGeometry = BackgroundGeometryCache; if (backgroundGeometry != null && (brush = Background) != null) { dc.DrawGeometry(brush, null, backgroundGeometry); } } else { Thickness border = BorderThickness; Brush borderBrush; CornerRadius cornerRadius = CornerRadius; double outerCornerRadius = cornerRadius.TopLeft; // Already validated that all corners have the same radius bool roundedCorners = !DoubleUtil.IsZero(outerCornerRadius); // If we have a brush with which to draw the border, do so. // NB: We double draw corners right now. Corner handling is tricky (bevelling, &c...) and // we need a firm spec before doing "the right thing." (greglett, ffortes) if (!DoubleUtil.IsZero(border) && (borderBrush = BorderBrush) != null) { // Initialize the first pen. Note that each pen is created via new() // and frozen if possible. Doing this avoids the pen // being copied when used in the DrawLine methods. Pen pen = LeftPenCache; if (pen == null) { pen = new Pen(); pen.Brush = borderBrush; if (useLayoutRounding) { pen.Thickness = this.RoundLayoutValue(border.Left, DoubleUtil.DpiScaleX); } else { pen.Thickness = border.Left; } if (borderBrush.IsFrozen) { pen.Freeze(); } LeftPenCache = pen; } double halfThickness; if (DoubleUtil.IsUniform(border)) { halfThickness = pen.Thickness * 0.5; // Create rect w/ border thickness, and round if applying layout rounding. Rect rect = new Rect(new Point(halfThickness, halfThickness), new Point(RenderSize.Width - halfThickness, RenderSize.Height - halfThickness)); if (roundedCorners) { dc.DrawRoundedRectangle( null, pen, rect, outerCornerRadius, outerCornerRadius); } else { dc.DrawRectangle( null, pen, rect); } } else { // Nonuniform border; stroke each edge. if (DoubleUtil.GreaterThan(border.Left, 0)) { halfThickness = pen.Thickness * 0.5; dc.DrawLine( pen, new Point(halfThickness, 0), new Point(halfThickness, RenderSize.Height)); } if (DoubleUtil.GreaterThan(border.Right, 0)) { pen = RightPenCache; if (pen == null) { pen = new Pen(); pen.Brush = borderBrush; if (useLayoutRounding) { pen.Thickness = this.RoundLayoutValue(border.Right, DoubleUtil.DpiScaleX); } else { pen.Thickness = border.Right; } if (borderBrush.IsFrozen) { pen.Freeze(); } RightPenCache = pen; } halfThickness = pen.Thickness * 0.5; dc.DrawLine( pen, new Point(RenderSize.Width - halfThickness, 0), new Point(RenderSize.Width - halfThickness, RenderSize.Height)); } if (DoubleUtil.GreaterThan(border.Top, 0)) { pen = TopPenCache; if (pen == null) { pen = new Pen(); pen.Brush = borderBrush; if (useLayoutRounding) { pen.Thickness = this.RoundLayoutValue(border.Top, DoubleUtil.DpiScaleY); } else { pen.Thickness = border.Top; } if (borderBrush.IsFrozen) { pen.Freeze(); } TopPenCache = pen; } halfThickness = pen.Thickness * 0.5; dc.DrawLine( pen, new Point(0, halfThickness), new Point(RenderSize.Width, halfThickness)); } if (DoubleUtil.GreaterThan(border.Bottom, 0)) { pen = BottomPenCache; if (pen == null) { pen = new Pen(); pen.Brush = borderBrush; if (useLayoutRounding) { pen.Thickness = this.RoundLayoutValue(border.Bottom, DoubleUtil.DpiScaleY); } else { pen.Thickness = border.Bottom; } if (borderBrush.IsFrozen) { pen.Freeze(); } BottomPenCache = pen; } halfThickness = pen.Thickness * 0.5; dc.DrawLine( pen, new Point(0, RenderSize.Height - halfThickness), new Point(RenderSize.Width, RenderSize.Height - halfThickness)); } } } // Draw background in rectangle inside border. Brush background = Background; if (background != null) { // Intialize background Point ptTL, ptBR; if (useLayoutRounding) { ptTL = new Point(this.RoundLayoutValue(border.Left, DoubleUtil.DpiScaleX), this.RoundLayoutValue(border.Top, DoubleUtil.DpiScaleY)); //if (FrameworkAppContextSwitches.DoNotApplyLayoutRoundingToMarginsAndBorderThickness) //{ // ptBR = new Point(this.RoundLayoutValue(RenderSize.Width - border.Right, DoubleUtil.DpiScaleX), // this.RoundLayoutValue(RenderSize.Height - border.Bottom, DoubleUtil.DpiScaleY)); //} //else { ptBR = new Point(RenderSize.Width - this.RoundLayoutValue(border.Right, DoubleUtil.DpiScaleX), RenderSize.Height - this.RoundLayoutValue(border.Bottom, DoubleUtil.DpiScaleY)); } } else { ptTL = new Point(border.Left, border.Top); ptBR = new Point(RenderSize.Width - border.Right, RenderSize.Height - border.Bottom); } // Do not draw background if the borders are so large that they overlap. if (ptBR.X > ptTL.X && ptBR.Y > ptTL.Y) { if (roundedCorners) { Radii innerRadii = new Radii(cornerRadius, border, false); // Determine the inner edge radius double innerCornerRadius = innerRadii.TopLeft; // Already validated that all corners have the same radius dc.DrawRoundedRectangle(background, null, new Rect(ptTL, ptBR), innerCornerRadius, innerCornerRadius); } else { dc.DrawRectangle(background, null, new Rect(ptTL, ptBR)); } } } } }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var strValue = value?.ToString(); if (strValue != null) { strValue = strValue.Trim(); char[] delimiter = { ' ' }; if (strValue.StartsWith(Ellipse, true, culture)) { return(new Ellipse()); } if (strValue.StartsWith(Line, true, culture)) { var parts = strValue.Split(delimiter, 2); PointCollectionConverter pointCollectionConverter = new PointCollectionConverter(); PointCollection points = pointCollectionConverter.ConvertFromString(parts[1]) as PointCollection; if (points == null || points.Count == 0) { return(new Line()); } Point p1 = points[0]; if (points.Count == 1) { return new Line { X1 = p1.X, Y1 = p1.Y } } ; Point p2 = points[1]; return(new Line { X1 = p1.X, Y1 = p1.Y, X2 = p2.X, Y2 = p2.Y }); } if (strValue.StartsWith(Path, true, culture)) { var parts = strValue.Split(delimiter, 2); PathGeometryConverter pathGeometryConverter = new PathGeometryConverter(); Geometry pathGeometry = pathGeometryConverter.ConvertFromInvariantString(parts[1]) as Geometry; if (pathGeometry == null) { return(new Path()); } return(new Path { Data = pathGeometry }); } if (strValue.StartsWith(Polygon, true, culture)) { var parts = strValue.Split(delimiter, 2); PointCollectionConverter pointCollectionConverter = new PointCollectionConverter(); PointCollection points = pointCollectionConverter.ConvertFromString(parts[1]) as PointCollection; if (points == null || points.Count == 0) { return(new Polygon()); } return(new Polygon { Points = points }); } if (strValue.StartsWith(Polyline, true, culture)) { var parts = strValue.Split(delimiter, 2); PointCollectionConverter pointCollectionConverter = new PointCollectionConverter(); PointCollection points = pointCollectionConverter.ConvertFromString(parts[1]) as PointCollection; if (points == null || points.Count == 0) { return(new Polyline()); } return(new Polyline { Points = points }); } if (strValue.StartsWith(Rectangle, true, culture)) { return(new Rectangle()); } if (strValue.StartsWith(RoundRectangle, true, culture)) { var parts = strValue.Split(delimiter, 2); CornerRadius cornerRadius = new CornerRadius(); if (parts.Length > 1) { CornerRadiusTypeConverter cornerRadiusTypeConverter = new CornerRadiusTypeConverter(); cornerRadius = (CornerRadius)cornerRadiusTypeConverter.ConvertFromString(parts[1]); } return(new RoundRectangle { CornerRadius = cornerRadius }); } } throw new InvalidOperationException($"Cannot convert \"{strValue}\" into {typeof(Shape)}"); } }
private static bool IsOverBorder(Point position, Size borderSize, Thickness borderTickness, CornerRadius cornerRadius) { return position.X < borderTickness.Left || position.Y < borderTickness.Top || borderSize.Width - position.X < borderTickness.Right || borderSize.Height - position.Y < borderTickness.Bottom; // cornerRadius is ignored }
public void ResetCornerRadius() { CornerRadius = new CornerRadius(); }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); Thickness border_thickness = BorderThickness; CornerRadius corner_radius = CornerRadius; double actual_width = ActualWidth; double actual_height = ActualHeight; double uniform_corner_radius = corner_radius.BottomLeft; Brush border_brush = BorderBrush; StreamGeometry geometry; StreamGeometryContext stream_geometry_context; CreateBackgroundShape create_background_shape; if (Utility.IsUniform(border_thickness) && uniform_corner_radius == corner_radius.BottomRight && uniform_corner_radius == corner_radius.TopLeft && uniform_corner_radius == corner_radius.TopRight) { double uniform_border_thickness = border_thickness.Bottom; if (border_brush != null) { drawingContext.DrawRoundedRectangle(null, new Pen(border_brush, uniform_border_thickness), new Rect(uniform_border_thickness / 2, uniform_border_thickness / 2, actual_width - uniform_border_thickness, actual_height - uniform_border_thickness), uniform_corner_radius, uniform_corner_radius); } if (Background != null) { double background_radius = uniform_corner_radius - 0.5; if (background_radius < 0) { background_radius = 0; } drawingContext.DrawRoundedRectangle(Background, null, new Rect(uniform_border_thickness, uniform_border_thickness, actual_width - 2 * uniform_border_thickness, actual_height - 2 * uniform_border_thickness), background_radius, background_radius); } } else if (Utility.IsVoid(corner_radius) && border_brush is SolidColorBrush && ((SolidColorBrush)border_brush).Color.A == 0xFF) { drawingContext.DrawLine(new Pen(border_brush, border_thickness.Left), new Point(border_thickness.Left / 2, 0), new Point(border_thickness.Left / 2, actual_height)); drawingContext.DrawLine(new Pen(border_brush, border_thickness.Right), new Point(actual_width - border_thickness.Right / 2, 0), new Point(actual_width - border_thickness.Right / 2, actual_height)); drawingContext.DrawLine(new Pen(border_brush, border_thickness.Top), new Point(0, border_thickness.Top / 2), new Point(actual_width, border_thickness.Top / 2)); drawingContext.DrawLine(new Pen(border_brush, border_thickness.Bottom), new Point(0, actual_height - border_thickness.Bottom / 2), new Point(actual_width, actual_height - border_thickness.Bottom / 2)); if (Background != null) { drawingContext.DrawRectangle(Background, null, new Rect(border_thickness.Left, border_thickness.Top, actual_width - border_thickness.Left - border_thickness.Right, actual_height - border_thickness.Top - border_thickness.Bottom)); } } else if (Utility.IsVoid(corner_radius)) { create_background_shape = delegate(StreamGeometryContext context) { context.BeginFigure(new Point(border_thickness.Left, border_thickness.Top), true, true); context.LineTo(new Point(actual_width - border_thickness.Right, border_thickness.Top), false, false); context.LineTo(new Point(actual_width - border_thickness.Right, actual_height - border_thickness.Bottom), false, false); context.LineTo(new Point(border_thickness.Left, actual_height - border_thickness.Bottom), false, false); context.LineTo(new Point(border_thickness.Left, border_thickness.Top), false, false); }; if (border_brush != null) { geometry = new StreamGeometry(); using (stream_geometry_context = geometry.Open()) { stream_geometry_context.BeginFigure(new Point(0, 0), true, true); stream_geometry_context.LineTo(new Point(actual_width, 0), false, false); stream_geometry_context.LineTo(new Point(actual_width, actual_height), false, false); stream_geometry_context.LineTo(new Point(0, actual_height), false, false); stream_geometry_context.LineTo(new Point(0, 0), false, false); create_background_shape(stream_geometry_context); } geometry.Freeze(); drawingContext.DrawGeometry(border_brush, null, geometry); } if (Background != null) { geometry = new StreamGeometry(); using (stream_geometry_context = geometry.Open()) { create_background_shape(stream_geometry_context); } geometry.Freeze(); drawingContext.DrawGeometry(Background, null, geometry); } } else { //FIXME: This needs to be clipped. actual_width = Math.Max(actual_width, border_thickness.Left + border_thickness.Right); actual_height = Math.Max(actual_height, border_thickness.Top + border_thickness.Bottom); double top_left_radius_x = corner_radius.TopLeft; double top_left_radius_y = top_left_radius_x; double bottom_left_radius_x = corner_radius.BottomLeft; double bottom_left_radius_y = bottom_left_radius_x; double top_right_radius_x = corner_radius.TopRight; double top_right_radius_y = top_right_radius_x; double bottom_right_radius_x = corner_radius.BottomRight; double bottom_right_radius_y = bottom_right_radius_x; //double inner_top_left_arc_area_x = ZeroIfNegative(top_left_radius_x - border_thickness.Left); //double inner_top_left_arc_area_y = ZeroIfNegative(top_left_radius_y - border_thickness.Top); //double inner_bottom_left_arc_area_x = ZeroIfNegative(bottom_left_radius_x - border_thickness.Left); //double inner_bottom_left_arc_area_y = ZeroIfNegative(bottom_left_radius_y - border_thickness.Bottom); //double inner_top_right_arc_area_x = ZeroIfNegative(top_right_radius_x - border_thickness.Right); //double inner_top_right_arc_area_y = ZeroIfNegative(top_right_radius_y - border_thickness.Top); //double inner_bottom_right_arc_area_x = ZeroIfNegative(bottom_right_radius_x - border_thickness.Right); //double inner_bottom_right_arc_area_y = ZeroIfNegative(bottom_right_radius_y - border_thickness.Bottom); double inner_width = ZeroIfNegative(actual_width - border_thickness.Left - border_thickness.Right); double inner_height = ZeroIfNegative(actual_height - border_thickness.Top - border_thickness.Bottom); //Scale(inner_width, ref inner_top_left_arc_area_x, ref inner_top_right_arc_area_x); //Scale(inner_width, ref inner_bottom_left_arc_area_x, ref inner_bottom_right_arc_area_x); //Scale(inner_height, ref inner_top_left_arc_area_y, ref inner_bottom_left_arc_area_y); //Scale(inner_height, ref inner_top_right_arc_area_y, ref inner_bottom_right_arc_area_y); //double inner_left_straight_section_lenght = inner_height - inner_top_left_arc_area_y - inner_bottom_left_arc_area_y; //double inner_right_straight_section_lenght = inner_height - inner_top_right_arc_area_y - inner_bottom_right_arc_area_y; //double inner_top_straight_section_lenght = inner_width - inner_top_left_arc_area_x - inner_top_right_arc_area_x; //double inner_bottom_straight_section_lenght = inner_width - inner_bottom_left_arc_area_x - inner_bottom_right_arc_area_x; //double top_left_arc_area_x = inner_top_left_arc_area_x + border_thickness.Left; //double top_left_arc_area_y = inner_top_left_arc_area_y + border_thickness.Top; //double bottom_left_arc_area_x = inner_bottom_left_arc_area_x + border_thickness.Left; //double bottom_left_arc_area_y = inner_bottom_left_arc_area_y + border_thickness.Bottom; //double top_right_arc_area_x = inner_top_right_arc_area_x + border_thickness.Right; //double top_right_arc_area_y = inner_top_right_arc_area_y + border_thickness.Top; //double bottom_right_arc_area_x = inner_bottom_right_arc_area_x + border_thickness.Right; //double bottom_right_arc_area_y = inner_bottom_right_arc_area_y + border_thickness.Bottom; double left_straight_section_lenght = ZeroIfNegative(actual_height - top_left_radius_y - bottom_left_radius_y); double right_straight_section_lenght = ZeroIfNegative(actual_height - top_right_radius_y - bottom_right_radius_y); double top_straight_section_lenght = ZeroIfNegative(actual_width - top_left_radius_x - top_right_radius_x); double bottom_straight_section_lenght = ZeroIfNegative(actual_width - bottom_left_radius_x - bottom_right_radius_x); Scale(actual_width, ref top_left_radius_x, ref top_right_radius_x); Scale(actual_width, ref bottom_left_radius_x, ref bottom_right_radius_x); Scale(actual_height, ref top_left_radius_y, ref top_right_radius_y); Scale(actual_height, ref bottom_left_radius_y, ref bottom_right_radius_y); create_background_shape = delegate(StreamGeometryContext context) { context.BeginFigure(new Point(top_left_radius_x + border_thickness.Left / 2, border_thickness.Top), true, true); double width = top_right_radius_x - border_thickness.Right / 2; double height = top_right_radius_y - border_thickness.Top / 2; context.LineTo(new Point(actual_width - (width > 0 ? top_right_radius_x + border_thickness.Right / 2 : border_thickness.Right), border_thickness.Top), false, false); if (width >= 0 && height >= 0) { context.ArcTo(new Point(actual_width - border_thickness.Right, top_right_radius_y + border_thickness.Top / 2), new Size(width, height), 0, false, SweepDirection.Clockwise, false, false); } width = bottom_right_radius_x - border_thickness.Right / 2; height = bottom_right_radius_y - border_thickness.Bottom / 2; context.LineTo(new Point(actual_width - border_thickness.Right, actual_height - (height > 0 ? bottom_right_radius_y + border_thickness.Bottom / 2 : border_thickness.Bottom)), false, false); if (width >= 0 && height >= 0) { context.ArcTo(new Point(actual_width - bottom_right_radius_x - border_thickness.Right / 2, actual_height - border_thickness.Bottom), new Size(width, height), 0, false, SweepDirection.Clockwise, false, false); } width = bottom_left_radius_x - border_thickness.Left / 2; height = bottom_left_radius_y - border_thickness.Bottom / 2; context.LineTo(new Point(width > 0 ? bottom_left_radius_x + border_thickness.Left / 2 : border_thickness.Left, actual_height - border_thickness.Bottom), false, false); context.ArcTo(new Point(border_thickness.Left, actual_height - (height > 0 ? bottom_left_radius_y + border_thickness.Bottom / 2 : border_thickness.Bottom)), new Size(width > 0 ? width : 0, height > 0 ? height : 0), 0, false, SweepDirection.Clockwise, false, false); width = top_left_radius_x - border_thickness.Left / 2; height = top_left_radius_y - border_thickness.Top / 2; context.LineTo(new Point(border_thickness.Left, height > 0 ? top_left_radius_y + border_thickness.Top / 2 : border_thickness.Top), false, false); context.ArcTo(new Point(top_left_radius_x + border_thickness.Left / 2, border_thickness.Top), new Size(width > 0 ? width : 0, height > 0 ? height : 0), 0, false, SweepDirection.Clockwise, false, false); }; if (border_brush != null) { geometry = new StreamGeometry(); using (stream_geometry_context = geometry.Open()) { stream_geometry_context.BeginFigure(new Point(top_left_radius_x + border_thickness.Left / 2, 0), true, true); stream_geometry_context.LineTo(new Point(top_left_radius_x + top_straight_section_lenght - border_thickness.Right / 2, 0), false, false); stream_geometry_context.ArcTo(new Point(top_left_radius_x + top_straight_section_lenght + top_right_radius_x, top_right_radius_y + border_thickness.Top / 2), new Size(top_right_radius_x + border_thickness.Right / 2, top_right_radius_y + border_thickness.Top / 2), 0, false, SweepDirection.Clockwise, false, false); stream_geometry_context.LineTo(new Point(bottom_left_radius_x + bottom_straight_section_lenght + bottom_right_radius_x, top_right_radius_y + right_straight_section_lenght - border_thickness.Bottom / 2), false, false); stream_geometry_context.ArcTo(new Point(bottom_left_radius_x + bottom_straight_section_lenght - border_thickness.Right / 2, top_right_radius_y + right_straight_section_lenght + bottom_right_radius_y), new Size(bottom_right_radius_x + border_thickness.Right / 2, bottom_right_radius_y + border_thickness.Bottom / 2), 0, false, SweepDirection.Clockwise, false, false); stream_geometry_context.LineTo(new Point(bottom_left_radius_x + border_thickness.Left / 2, top_left_radius_y + left_straight_section_lenght + bottom_left_radius_y), false, false); stream_geometry_context.ArcTo(new Point(0, top_left_radius_y + left_straight_section_lenght - border_thickness.Bottom / 2), new Size(bottom_left_radius_x + border_thickness.Left / 2, bottom_left_radius_y + border_thickness.Bottom / 2), 0, false, SweepDirection.Clockwise, false, false); stream_geometry_context.LineTo(new Point(0, top_left_radius_y + border_thickness.Top / 2), false, false); stream_geometry_context.ArcTo(new Point(top_left_radius_x + border_thickness.Left / 2, 0), new Size(top_left_radius_x + border_thickness.Left / 2, top_left_radius_y + border_thickness.Top / 2), 0, false, SweepDirection.Clockwise, false, false); if (inner_width > 0 && inner_height > 0) { create_background_shape(stream_geometry_context); } } geometry.Freeze(); drawingContext.DrawGeometry(border_brush, null, geometry); } if (Background != null) { if (inner_width > 0 && inner_height > 0) { geometry = new StreamGeometry(); using (stream_geometry_context = geometry.Open()) { create_background_shape(stream_geometry_context); } geometry.Freeze(); drawingContext.DrawGeometry(Background, null, geometry); } } } }
public bool Equals(CornerRadius cornerRadius);
/// <summary> /// Gets the HitArea from the current /// mouse position /// </summary> /// <param name="objArg"></param> /// <returns></returns> private eHitArea GetHitArea(MouseEventArgs objArg) { if (IsMutable == true) { CornerRadius cornerRadius = new CornerRadius(5); Rectangle r = GetViewRect(ref cornerRadius); //if (r.Width > 10) { Rectangle r2 = new Rectangle(r.X, r.Y + (r.Height / 2) - 2, 5, 5); if ((_ViewEnds & eViewEnds.PartialLeft) == 0) { r2.X = r.X - 3; r2.Inflate(2, 2); if (r2.Contains(objArg.Location)) return (eHitArea.LeftResize); } if ((_ViewEnds & eViewEnds.PartialRight) == 0) { r2.X = r.Right - 2; r2.Inflate(2, 2); if (r2.Contains(objArg.Location)) return (eHitArea.RightResize); } } // By default we are in the move area return (eHitArea.Move); } return (eHitArea.None); }
/// <summary> /// Gets a path defining the item /// </summary> /// <param name="viewRect"></param> /// <param name="radius"></param> /// <param name="cornerRadius"></param> /// <returns></returns> private GraphicsPath GetItemPath(Rectangle viewRect, int radius, CornerRadius cornerRadius) { GraphicsPath path = new GraphicsPath(); Rectangle r = viewRect; Rectangle ar = new Rectangle(r.Right - radius, r.Bottom - radius, radius, radius); if (cornerRadius.BottomRight > 0) path.AddArc(ar, 0, 90); else path.AddLine(r.Right, r.Bottom, r.Right, r.Bottom); ar.X = r.X; if (cornerRadius.BottomLeft > 0) path.AddArc(ar, 90, 90); else path.AddLine(r.Left, r.Bottom, r.Left, r.Bottom); ar.Y = r.Y; if (cornerRadius.TopLeft > 0) path.AddArc(ar, 180, 90); else path.AddLine(r.Left, r.Top, r.Left, r.Top); ar.X = r.Right - radius; if (cornerRadius.TopRight > 0) path.AddArc(ar, 270, 90); else path.AddLine(r.Right, r.Top, r.Right, r.Top); path.CloseAllFigures(); return (path); }
/// <summary> /// Gets the view rect for the appointment /// </summary> /// <param name="cornerRadius">Corner radius</param> /// <returns>View rect</returns> private Rectangle GetViewRect(ref CornerRadius cornerRadius) { Rectangle r = DisplayRectangle; r.Intersect(ParentBounds); if (r.Left == ParentBounds.Left) { r.X++; r.Width--; } if (r.Right == ParentBounds.Right) r.Width--; if ((_ViewEnds & eViewEnds.PartialLeft) == eViewEnds.PartialLeft) cornerRadius.TopLeft = cornerRadius.BottomLeft = 0; if ((_ViewEnds & eViewEnds.PartialRight) == eViewEnds.PartialRight) cornerRadius.TopRight = cornerRadius.BottomRight = 0; // If the view is selected, then allow // for a thicker selection rect if (IsSelected == true) r.Height--; return (r); }
private void DrawDefaultAppointment(ItemPaintArgs e, Rectangle r, int n, CornerRadius cornerRadius) { Graphics g = e.Graphics; using (GraphicsPath path = GetItemPath(r, n * 2, cornerRadius)) { using (Brush br = BackBrush(r)) g.FillPath(br, path); if (BaseView.CalendarView.DoAppointmentViewPreRender(this, g, r, path) == false) { DrawContent(e, r); BaseView.CalendarView.DoAppointmentViewPostRender(this, g, r, path); } DrawDefaultBorder(e, r, path, n); } }
/// <summary> /// Paint processing /// </summary> /// <param name="e">ItemPaintArgs</param> public override void Paint(ItemPaintArgs e) { SetViewEnds(); AppointmentColor.SetColorTable(); int n = (Bounds.Width < 20) ? 0 : 5; CornerRadius cornerRadius = new CornerRadius(n); Rectangle r = GetViewRect(ref cornerRadius); if (r.Width > 1 && r.Height > 0) { if (EffectiveStyle == eDotNetBarStyle.Office2010 || EffectiveStyle == eDotNetBarStyle.Metro) DrawMetroAppointment(e, r); else DrawDefaultAppointment(e, r, n, cornerRadius); if (IsMutable == true) DrawGribits(e, r); } }
/// <summary> /// Calculates the value this animation believes should be the current value for the property. /// </summary> /// <param name="defaultOriginValue"> /// This value is the suggested origin value provided to the animation /// to be used if the animation does not have its own concept of a /// start value. If this animation is the first in a composition chain /// this value will be the snapshot value if one is available or the /// base property value if it is not; otherise this value will be the /// value returned by the previous animation in the chain with an /// animationClock that is not Stopped. /// </param> /// <param name="defaultDestinationValue"> /// This value is the suggested destination value provided to the animation /// to be used if the animation does not have its own concept of an /// end value. This value will be the base value if the animation is /// in the first composition layer of animations on a property; /// otherwise this value will be the output value from the previous /// composition layer of animations for the property. /// </param> /// <param name="animationClock"> /// This is the animationClock which can generate the CurrentTime or /// CurrentProgress value to be used by the animation to generate its /// output value. /// </param> /// <returns> /// The value this animation believes should be the current value for the property. /// </returns> protected abstract CornerRadius GetCurrentValueCore(CornerRadius defaultOriginValue, CornerRadius defaultDestinationValue, AnimationClock animationClock);
public void OnCornerRadiusChanged(CornerRadius newValue) { //根据密码框边框圆角自动设置图标背景框圆角 this.IconCornerRadius = new CornerRadius(newValue.TopLeft, 0, 0, newValue.BottomLeft); }
public static void SetCornerRadius(Expander expander, CornerRadius value) { expander.SetValue(CornerRadiusProperty, value); }
public RoundRectangleStub(CornerRadius cornerRadius) : this() { CornerRadius = cornerRadius; }
protected override void OnRender(System.Windows.Media.DrawingContext dc) { base.OnRender(dc); bool useLayoutRounding = base.UseLayoutRounding; Thickness borderThickness = this.BorderThickness; CornerRadius cornerRadius = this.CornerRadius; double topLeft = cornerRadius.TopLeft; bool flag = !DoubleUtil.IsZero(topLeft); Brush borderBrush = null; Pen pen = null; if (pen == null) { pen = new Pen(); borderBrush = LeftBorderBrush; pen.Brush = LeftBorderBrush; if (useLayoutRounding) { pen.Thickness = UlementEx.RoundLayoutValue(borderThickness.Left, DoubleUtil.DpiScaleX); } else { pen.Thickness = borderThickness.Left; } if (borderBrush != null) { if (borderBrush.IsFrozen) { pen.Freeze(); } } if (DoubleUtil.GreaterThan(borderThickness.Left, 0.0)) { double num = pen.Thickness * 0.5; dc.DrawLine(pen, new Point(num, 0.0), new Point(num, base.RenderSize.Height)); } if (DoubleUtil.GreaterThan(borderThickness.Right, 0.0)) { pen = new Pen(); pen.Brush = RightBorderBrush; if (useLayoutRounding) { pen.Thickness = UlementEx.RoundLayoutValue(borderThickness.Right, DoubleUtil.DpiScaleX); } else { pen.Thickness = borderThickness.Right; } if (borderBrush != null) { if (borderBrush.IsFrozen) { pen.Freeze(); } } double num = pen.Thickness * 0.5; dc.DrawLine(pen, new Point(base.RenderSize.Width - num, 0.0), new Point(base.RenderSize.Width - num, base.RenderSize.Height)); } if (DoubleUtil.GreaterThan(borderThickness.Top, 0.0)) { pen = new Pen(); pen.Brush = TopBorderBrush; if (useLayoutRounding) { pen.Thickness = UlementEx.RoundLayoutValue(borderThickness.Top, DoubleUtil.DpiScaleY); } else { pen.Thickness = borderThickness.Top; } if (borderBrush != null) { if (borderBrush.IsFrozen) { pen.Freeze(); } } double num = pen.Thickness * 0.5; dc.DrawLine(pen, new Point(0.0, num), new Point(base.RenderSize.Width, num)); } if (DoubleUtil.GreaterThan(borderThickness.Bottom, 0.0)) { pen = new Pen(); pen.Brush = BottomBorderBrush; if (useLayoutRounding) { pen.Thickness = UlementEx.RoundLayoutValue(borderThickness.Bottom, DoubleUtil.DpiScaleY); } else { pen.Thickness = borderThickness.Bottom; } if (borderBrush != null) { if (borderBrush.IsFrozen) { pen.Freeze(); } } double num = pen.Thickness * 0.5; dc.DrawLine(pen, new Point(0.0, base.RenderSize.Height - num), new Point(base.RenderSize.Width, base.RenderSize.Height - num)); } } }
internal Radii(CornerRadius radii, Thickness borders, bool outer) { double left = 0.5 * borders.Left; double top = 0.5 * borders.Top; double right = 0.5 * borders.Right; double bottom = 0.5 * borders.Bottom; if (outer) { if (DoubleUtil.IsZero(radii.TopLeft)) { LeftTop = TopLeft = 0.0; } else { LeftTop = radii.TopLeft + left; TopLeft = radii.TopLeft + top; } if (DoubleUtil.IsZero(radii.TopRight)) { TopRight = RightTop = 0.0; } else { TopRight = radii.TopRight + top; RightTop = radii.TopRight + right; } if (DoubleUtil.IsZero(radii.BottomRight)) { RightBottom = BottomRight = 0.0; } else { RightBottom = radii.BottomRight + right; BottomRight = radii.BottomRight + bottom; } if (DoubleUtil.IsZero(radii.BottomLeft)) { BottomLeft = LeftBottom = 0.0; } else { BottomLeft = radii.BottomLeft + bottom; LeftBottom = radii.BottomLeft + left; } } else { LeftTop = Math.Max(0.0, radii.TopLeft - left); TopLeft = Math.Max(0.0, radii.TopLeft - top); TopRight = Math.Max(0.0, radii.TopRight - top); RightTop = Math.Max(0.0, radii.TopRight - right); RightBottom = Math.Max(0.0, radii.BottomRight - right); BottomRight = Math.Max(0.0, radii.BottomRight - bottom); BottomLeft = Math.Max(0.0, radii.BottomLeft - bottom); LeftBottom = Math.Max(0.0, radii.BottomLeft - left); } }
private void UpdateCornerRadius(CornerRadius radius) => UpdateBorder();
private void SetCornerRadius(CornerRadius cornerRadius) { Control.RadiusX = cornerRadius.TopLeft; Control.RadiusY = cornerRadius.BottomRight; }
public static bool IsCornerRadiusValid(CornerRadius cornerRadius) { return(Utility.IsDoubleFiniteAndNonNegative(cornerRadius.TopLeft) && Utility.IsDoubleFiniteAndNonNegative(cornerRadius.TopRight) && Utility.IsDoubleFiniteAndNonNegative(cornerRadius.BottomLeft) && Utility.IsDoubleFiniteAndNonNegative(cornerRadius.BottomRight)); }
protected override Size ArrangeOverride(Size finalSize) { Thickness borders = BorderThickness; if (this.UseLayoutRounding) { borders = new Thickness( this.RoundLayoutValue(borders.Left, DoubleUtil.DpiScaleX), this.RoundLayoutValue(borders.Top, DoubleUtil.DpiScaleY), this.RoundLayoutValue(borders.Right, DoubleUtil.DpiScaleX), this.RoundLayoutValue(borders.Bottom, DoubleUtil.DpiScaleY)); } Rect boundRect = new Rect(finalSize); Rect innerRect = HelperDeflateRect(boundRect, borders); // arrange child UIElement child = Child; if (child != null) { Rect childRect = HelperDeflateRect(innerRect, Padding); child.Arrange(childRect); } CornerRadius radii = CornerRadius; Brush borderBrush = BorderBrush; bool uniformCorners = AreUniformCorners(radii); // decide which code path to execute. complex (geometry path based) rendering // is used if one of the following is true: // 1. there are non-uniform rounded corners _useComplexRenderCodePath = !uniformCorners; if (!_useComplexRenderCodePath && borderBrush != null) { SolidColorBrush originIndependentBrush = borderBrush as SolidColorBrush; bool uniformBorders = DoubleUtil.IsUniform(borders); _useComplexRenderCodePath = // 2. the border brush is origin dependent (the only origin independent brush is a solid color brush) (originIndependentBrush == null) // 3. the border brush is semi-transtarent solid color brush AND border thickness is not uniform // (for uniform semi-transparent border Border.OnRender draws rectangle outline - so it works fine) || ((originIndependentBrush.Color.A < 0xff) && !uniformBorders) // 4. there are rounded corners AND the border thickness is not uniform || (!DoubleUtil.IsZero(radii.TopLeft) && !uniformBorders) //5. is border like cyber || IsCyber; } if (_useComplexRenderCodePath) { Radii innerRadii = new Radii(radii, borders, false); StreamGeometry backgroundGeometry = null; // calculate border / background rendering geometry if (!DoubleUtil.IsZero(innerRect.Width) && !DoubleUtil.IsZero(innerRect.Height)) { backgroundGeometry = new StreamGeometry(); using (StreamGeometryContext ctx = backgroundGeometry.Open()) { GenerateGeometry(ctx, innerRect, innerRadii); } backgroundGeometry.Freeze(); BackgroundGeometryCache = backgroundGeometry; } else { BackgroundGeometryCache = null; } if (!DoubleUtil.IsZero(boundRect.Width) && !DoubleUtil.IsZero(boundRect.Height)) { Radii outerRadii = new Radii(radii, borders, true); StreamGeometry borderGeometry = new StreamGeometry(); using (StreamGeometryContext ctx = borderGeometry.Open()) { GenerateGeometry(ctx, boundRect, outerRadii); if (backgroundGeometry != null) { GenerateGeometry(ctx, innerRect, innerRadii); } } borderGeometry.Freeze(); BorderGeometryCache = borderGeometry; } else { BorderGeometryCache = null; } } else { BackgroundGeometryCache = null; BorderGeometryCache = null; } return(finalSize); }
public RobotShape(Canvas pCanvas) { //th = new Thread(DrawCircle); //DrawCircle(); //th.IsBackground = true; //th.Start(); ToolTip = ""; ToolTipOpening += ChangeToolTipContent; props.isSelected = false; props.isHovering = false; ContextMenu = new ContextMenu(); //=================================== MenuItem editItem = new MenuItem(); editItem.Header = "Edit"; editItem.Click += EditMenu; //=================================== MenuItem removeItem = new MenuItem(); removeItem.Header = "Remove"; removeItem.Click += RemoveMenu; ContextMenu.Items.Add(editItem); ContextMenu.Items.Add(removeItem); //====================EVENT===================== //MouseLeave += MouseLeavePath; //MouseMove += MouseHoverPath; //MouseLeftButtonDown += MouseLeftButtonDownPath; //MouseRightButtonDown += MouseRightButtonDownPath; //===================CREATE===================== Name = "Robotx" + Global_Mouse.EncodeTransmissionTimestamp(); props.name = Name; props.position = new Point(); props.mainGrid = new Grid(); props.statusGrid = new Grid(); props.statusBorder = new Border(); props.rbID = new Label(); props.rbTask = new Label(); props.headLed = new Rectangle(); props.tailLed = new Rectangle(); props.eightCorner = new List <Point>(); for (int i = 0; i < 8; i++) { Point temp = new Point(); props.eightCorner.Add(temp); } props.rbRotateTransform = new RotateTransform(); props.rbTranslate = new TranslateTransform(); props.rbTransformGroup = new TransformGroup(); props.contentRotateTransform = new RotateTransform(); props.contentTranslate = new TranslateTransform(); props.contentTransformGroup = new TransformGroup(); robotProperties = new Properties(this); //===================STYLE===================== //Robot border Width = 22; Height = 15; BorderThickness = new Thickness(1); BorderBrush = new SolidColorBrush(Colors.Linen); Background = new SolidColorBrush(Colors.Black); CornerRadius = new CornerRadius(3); RenderTransformOrigin = new Point(0.5, 0.5); //mainGrid props.mainGrid.Background = new SolidColorBrush(Colors.Transparent); for (int i = 0; i < 3; i++) { ColumnDefinition colTemp = new ColumnDefinition(); colTemp.Name = Name + "xL" + i; if ((i == 0) || (i == 2)) { colTemp.Width = new GridLength(1); } props.mainGrid.ColumnDefinitions.Add(colTemp); } //headLed props.headLed.Height = 7; props.headLed.Fill = new SolidColorBrush(Colors.DodgerBlue); Grid.SetColumn(props.headLed, 2); //tailLed props.tailLed.Height = 7; props.tailLed.Fill = new SolidColorBrush(Colors.OrangeRed); Grid.SetColumn(props.tailLed, 0); //statusBorder props.statusBorder.Width = 10; props.statusBorder.Height = 13; props.statusBorder.RenderTransformOrigin = new Point(0.5, 0.5); Grid.SetColumn(props.statusBorder, 1); //statusGrid for (int i = 0; i < 2; i++) { RowDefinition rowTemp = new RowDefinition(); rowTemp.Name = Name + "xR" + i; props.statusGrid.RowDefinitions.Add(rowTemp); } //rbID props.rbID.Padding = new Thickness(0); props.rbID.Margin = new Thickness(-5, 0, -5, 0); props.rbID.HorizontalAlignment = HorizontalAlignment.Center; props.rbID.VerticalAlignment = VerticalAlignment.Bottom; props.rbID.Content = "27"; props.rbID.Foreground = new SolidColorBrush(Colors.Yellow); props.rbID.FontFamily = new FontFamily("Calibri"); props.rbID.FontSize = 6; props.rbID.FontWeight = FontWeights.Bold; Grid.SetRow(props.rbID, 0); //rbTask props.rbTask.Padding = new Thickness(0); props.rbTask.Margin = new Thickness(-5, -1, -5, -1); props.rbTask.HorizontalAlignment = HorizontalAlignment.Center; props.rbTask.VerticalAlignment = VerticalAlignment.Top; props.rbTask.Content = "9999"; props.rbTask.Foreground = new SolidColorBrush(Colors.LawnGreen); props.rbTask.FontFamily = new FontFamily("Calibri"); props.rbTask.FontSize = 6; props.rbTask.FontWeight = FontWeights.Bold; Grid.SetRow(props.rbTask, 1); //===================CHILDREN=================== props.statusGrid.Children.Add(props.rbID); props.statusGrid.Children.Add(props.rbTask); props.statusBorder.Child = props.statusGrid; props.mainGrid.Children.Add(props.headLed); props.mainGrid.Children.Add(props.tailLed); props.mainGrid.Children.Add(props.statusBorder); props.rbTransformGroup.Children.Add(props.rbRotateTransform); props.rbTransformGroup.Children.Add(props.rbTranslate); RenderTransform = props.rbTransformGroup; props.contentTransformGroup.Children.Add(props.contentRotateTransform); props.contentTransformGroup.Children.Add(props.contentTranslate); props.statusBorder.RenderTransform = props.contentTransformGroup; props.canvas = pCanvas; Child = props.mainGrid; props.canvas.Children.Add(this); //====================FINAL===================== }
public static void SetCornerRadius(UIElement element, CornerRadius value) { element.SetValue(CornerRadiusProperty, value); }
public void SetCornerRadius(CornerRadius radius) { p.Radius = radius.TopLeft; }
private static IDisposable InnerCreateLayers(BindableView view, Windows.Foundation.Rect drawArea, Brush background, Thickness borderThickness, Brush borderBrush, CornerRadius cornerRadius, Action onImageSet ) { var disposables = new CompositeDisposable(); var physicalBorderThickness = borderThickness.LogicalToPhysicalPixels(); if (cornerRadius != 0) { using (Path path = new Path()) { path.SetFillType(Path.FillType.EvenOdd); var radius = new CornerRadius( topLeft: ViewHelper.LogicalToPhysicalPixels(cornerRadius.TopLeft), topRight: ViewHelper.LogicalToPhysicalPixels(cornerRadius.TopRight), bottomRight: ViewHelper.LogicalToPhysicalPixels(cornerRadius.BottomRight), bottomLeft: ViewHelper.LogicalToPhysicalPixels(cornerRadius.BottomLeft) ); var adjustedLineWidth = physicalBorderThickness.Top; var area = new Windows.Foundation.Rect(drawArea.Left, drawArea.Top, drawArea.Width, drawArea.Height); area.Inflate(-adjustedLineWidth / 2, -adjustedLineWidth / 2); // This represents the doubled radii used to draw arcs, with each one maxed at the area's size. // The width and height can vary for the same corner (elliptical arc) var topLeftDiameterHeight = Math.Min(radius.TopLeft * 2, area.Height); var topLeftDiameterWidth = Math.Min(radius.TopLeft * 2, area.Width); var topRightDiameterHeight = Math.Min(radius.TopRight * 2, area.Height); var topRightDiameterWidth = Math.Min(radius.TopRight * 2, area.Width); var bottomLeftDiameterHeight = Math.Min(radius.BottomLeft * 2, area.Height); var bottomLeftDiameterWidth = Math.Min(radius.BottomLeft * 2, area.Width); var bottomRightDiameterHeight = Math.Min(radius.BottomRight * 2, area.Height); var bottomRightDiameterWidth = Math.Min(radius.BottomRight * 2, area.Width); // Top line path.MoveTo((float)(area.X + topLeftDiameterWidth / 2), (float)(area.Y)); path.LineTo((float)(area.Right - topRightDiameterWidth / 2), (float)(area.Y)); // Top right corner path.ArcTo( new RectF( left: (float)(area.Right - topRightDiameterWidth), top: (float)(area.Y), bottom: (float)(area.Y + topRightDiameterHeight), right: (float)(area.Right) ), startAngle: 270, sweepAngle: 90 ); // Right line path.LineTo((float)area.Right, (float)(area.Bottom - bottomRightDiameterHeight / 2)); // Bottom right corner path.ArcTo( new RectF( left: (float)(area.Right - bottomRightDiameterWidth), top: (float)(area.Bottom - bottomRightDiameterHeight), bottom: (float)area.Bottom, right: (float)area.Right ), startAngle: 0, sweepAngle: 90 ); // Bottom line path.LineTo((float)(area.X + bottomLeftDiameterWidth / 2), (float)area.Bottom); // Bottom left corner path.ArcTo( new RectF( left: (float)area.X, top: (float)(area.Bottom - bottomLeftDiameterHeight), bottom: (float)area.Bottom, right: (float)(area.X + bottomLeftDiameterWidth) ), startAngle: 90, sweepAngle: 90 ); // Left line path.LineTo((float)area.X, (float)(area.Y + topLeftDiameterHeight / 2)); // Top left corner path.ArcTo( new RectF( left: (float)area.X, top: (float)area.Y, bottom: (float)(area.Y + topLeftDiameterHeight), right: (float)(area.X + topLeftDiameterWidth) ), startAngle: 180, sweepAngle: 90 ); path.Close(); //We only need to set a background if the drawArea is non-zero if (!drawArea.HasZeroArea()) { var imageBrushBackground = background as ImageBrush; if (imageBrushBackground != null) { //Copy the path because it will be disposed when we exit the using block var pathCopy = new Path(path); var setBackground = DispatchSetImageBrushAsBackground(view, imageBrushBackground, drawArea, onImageSet, pathCopy); disposables.Add(setBackground); } else { var fillPaint = background?.GetFillPaint(drawArea) ?? new Paint() { Color = Android.Graphics.Color.Transparent }; ExecuteWithNoRelayout(view, v => v.SetBackgroundDrawable(GetBackgroundDrawable(background, drawArea, fillPaint, path))); } disposables.Add(() => ExecuteWithNoRelayout(view, v => v.SetBackgroundDrawable(null))); } if (borderThickness != Thickness.Empty && borderBrush != null && !(borderBrush is ImageBrush)) { using (var strokePaint = new Paint(borderBrush.GetStrokePaint(drawArea))) { var overlay = GetOverlayDrawable(strokePaint, physicalBorderThickness, new global::System.Drawing.Size((int)drawArea.Width, (int)drawArea.Height), path); if (overlay != null) { overlay.SetBounds(0, 0, view.Width, view.Height); SetOverlay(view, disposables, overlay); } } } } } else // No corner radius { //We only need to set a background if the drawArea is non-zero if (!drawArea.HasZeroArea()) { var imageBrushBackground = background as ImageBrush; if (imageBrushBackground != null) { var setBackground = DispatchSetImageBrushAsBackground(view, imageBrushBackground, drawArea, onImageSet); disposables.Add(setBackground); } else { var fillPaint = background?.GetFillPaint(drawArea) ?? new Paint() { Color = Android.Graphics.Color.Transparent }; ExecuteWithNoRelayout(view, v => v.SetBackgroundDrawable(GetBackgroundDrawable(background, drawArea, fillPaint))); } disposables.Add(() => ExecuteWithNoRelayout(view, v => v.SetBackgroundDrawable(null))); } if (borderBrush != null && !(borderBrush is ImageBrush)) { //TODO: Handle case that BorderBrush is an ImageBrush using (var strokePaint = borderBrush.GetStrokePaint(drawArea)) { var overlay = GetOverlayDrawable(strokePaint, physicalBorderThickness, new global::System.Drawing.Size(view.Width, view.Height)); if (overlay != null) { overlay.SetBounds(0, 0, view.Width, view.Height); SetOverlay(view, disposables, overlay); } } } } return(disposables); }
partial void OnCornerRadiusChangedPartial(CornerRadius oldValue, CornerRadius newValue) { UpdateBackground(); }
public LayoutState(Windows.Foundation.Rect area, Brush background, Thickness borderThickness, Brush borderBrush, CornerRadius cornerRadius, Thickness padding) { Area = area; Background = background; BorderBrush = borderBrush; CornerRadius = cornerRadius; BorderThickness = borderThickness; Padding = padding; var imageBrushBackground = Background as ImageBrush; BackgroundImageSource = imageBrushBackground?.ImageSource; BackgroundColor = (Background as SolidColorBrush)?.Color; }
protected virtual void OnInnerCornerRadiusChanged(CornerRadius oldValue, CornerRadius newValue) { // TODO: Add your property changed side-effects. Descendants can override as well. }
/// <summary> /// Constructor /// </summary> /// <param name="corners">CornerRadius</param> /// <param name="borders">BorderThickness</param> /// <param name="padding">Padding</param> /// <param name="isOuterBorder">Flag to indicate whether outer or inner border needs /// to be calculated</param> internal CompositionPathInfo(CornerRadius corners, Thickness borders, Thickness padding, bool isOuterBorder) { var factor = 0.5; var left = factor * (borders.Left + padding.Left); var top = factor * (borders.Top + padding.Top); var right = factor * (borders.Right + padding.Right); var bottom = factor * (borders.Bottom + padding.Bottom); if (isOuterBorder) { if (corners.TopLeft.IsZero()) { LeftTop = TopLeft = 0.0; } else { LeftTop = corners.TopLeft + left; TopLeft = corners.TopLeft + top; } if (corners.TopRight.IsZero()) { TopRight = RightTop = 0.0; } else { TopRight = corners.TopRight + top; RightTop = corners.TopRight + right; } if (corners.BottomRight.IsZero()) { RightBottom = BottomRight = 0.0; } else { RightBottom = corners.BottomRight + right; BottomRight = corners.BottomRight + bottom; } if (corners.BottomLeft.IsZero()) { BottomLeft = LeftBottom = 0.0; } else { BottomLeft = corners.BottomLeft + bottom; LeftBottom = corners.BottomLeft + left; } } else { LeftTop = Math.Max(0.0, corners.TopLeft - left); TopLeft = Math.Max(0.0, corners.TopLeft - top); TopRight = Math.Max(0.0, corners.TopRight - top); RightTop = Math.Max(0.0, corners.TopRight - right); RightBottom = Math.Max(0.0, corners.BottomRight - right); BottomRight = Math.Max(0.0, corners.BottomRight - bottom); BottomLeft = Math.Max(0.0, corners.BottomLeft - bottom); LeftBottom = Math.Max(0.0, corners.BottomLeft - left); } }
/// <summary> /// Returns new CornerRadius with values eased from startValue to endValue using a time percentage 0 -> 1. /// </summary> public static CornerRadius EaseValue(CornerRadius startValue, CornerRadius endValue, double percent) { return new CornerRadius( EaseValue(startValue.TopLeft, endValue.TopLeft, percent), EaseValue(startValue.TopRight, endValue.TopRight, percent), EaseValue(startValue.BottomLeft, endValue.BottomLeft, percent), EaseValue(startValue.BottomRight, endValue.BottomRight, percent) ); }
/// <summary> /// Verifies if the CornerRadius contains only zero values /// </summary> /// <param name="corner">CornerRadius</param> /// <returns>Size</returns> public static bool IsZero(CornerRadius corner) { return(DoubleUtil.IsZero(corner.TopLeft) && DoubleUtil.IsZero(corner.TopRight) && DoubleUtil.IsZero(corner.BottomRight) && DoubleUtil.IsZero(corner.BottomLeft)); }
protected override double GetRadius(CornerRadius cornerRadius) => cornerRadius.BottomLeft;
public static void SetCornerRadius(DependencyObject obj, CornerRadius value) { obj.SetValue(CornerRadiusProperty, value); }
public static void SetCornerRadius(DependencyObject element, CornerRadius value) { element.SetValue(CornerRadiusProperty, value); }
partial void OnCornerRadiusChangedPartial(CornerRadius oldValue, CornerRadius newValue) { UpdateBorder(); }
internal static void SetElevationInternal(this DependencyObject element, double elevation, Color shadowColor, DependencyObject host = null, CornerRadius cornerRadius = default(CornerRadius))
private static bool AreUniformCorners(CornerRadius borderRadii) { double topLeft = borderRadii.TopLeft; return DoubleUtil.AreClose(topLeft, borderRadii.TopRight) && DoubleUtil.AreClose(topLeft, borderRadii.BottomLeft) && DoubleUtil.AreClose(topLeft, borderRadii.BottomRight); }
void DrawBackground(ACanvas canvas, int width, int height, CornerRadius cornerRadius, bool pressed) { using (var paint = new Paint { AntiAlias = true }) using (Path.Direction direction = Path.Direction.Cw) using (Paint.Style style = Paint.Style.Fill) { var path = new Path(); if (_pancake.Sides != 4) { path = ShapeUtils.CreatePolygonPath(width, height, _pancake.Sides, _pancake.CornerRadius.TopLeft, _pancake.OffsetAngle); } else { float topLeft = _convertToPixels(cornerRadius.TopLeft); float topRight = _convertToPixels(cornerRadius.TopRight); float bottomRight = _convertToPixels(cornerRadius.BottomRight); float bottomLeft = _convertToPixels(cornerRadius.BottomLeft); path = ShapeUtils.CreateRoundedRectPath(width, height, topLeft, topRight, bottomRight, bottomLeft); } if ((_pancake.BackgroundGradientStartColor != default(Xamarin.Forms.Color) && _pancake.BackgroundGradientEndColor != default(Xamarin.Forms.Color)) || (_pancake.BackgroundGradientStops != null && _pancake.BackgroundGradientStops.Any())) { var angle = _pancake.BackgroundGradientAngle / 360.0; // Calculate the new positions based on angle between 0-360. var a = width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.75) / 2)), 2); var b = height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.0) / 2)), 2); var c = width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.25) / 2)), 2); var d = height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.5) / 2)), 2); if (_pancake.BackgroundGradientStops != null && _pancake.BackgroundGradientStops.Count > 0) { // A range of colors is given. Let's add them. var orderedStops = _pancake.BackgroundGradientStops.OrderBy(x => x.Offset).ToList(); var colors = orderedStops.Select(x => x.Color.ToAndroid().ToArgb()).ToArray(); var locations = orderedStops.Select(x => x.Offset).ToArray(); var shader = new LinearGradient(width - (float)a, (float)b, width - (float)c, (float)d, colors, locations, Shader.TileMode.Clamp); paint.SetShader(shader); } else { // Only two colors provided, use that. var shader = new LinearGradient(width - (float)a, (float)b, width - (float)c, (float)d, _pancake.BackgroundGradientStartColor.ToAndroid(), _pancake.BackgroundGradientEndColor.ToAndroid(), Shader.TileMode.Clamp); paint.SetShader(shader); } } else { global::Android.Graphics.Color color = _pancake.BackgroundColor.ToAndroid(); paint.SetStyle(style); paint.Color = color; } canvas.DrawPath(path, paint); } }
public CornerRadiusValue(CornerRadius objValue) { this.mobjValue = objValue; }
public RoundRectangleGeometry(CornerRadius cornerRadius, Rect rect) { CornerRadius = cornerRadius; Rect = rect; }