public override void Render(Graphics g) { var region = Region; g.DrawEllipse(StrokePen, region.X, region.Y, region.Width, region.Height); g.FillEllipse(FillBrush, region.X + StrokeThickness.Int32(), region.Y + StrokeThickness.Int32(), region.Width - (StrokeThickness.Int32() * 2), region.Height - (StrokeThickness.Int32() * 2)); }
public override int GetHashCode() { return(Location.GetHashCode() ^ Width.GetHashCode() ^ Height.GetHashCode() ^ StrokeThickness.GetHashCode() ^ Fill.GetHashCode()); }
/// <summary> /// Arranges the size for the specified available <see cref="Size"/>. /// </summary> /// <param name="finalSize"> /// The final <see cref="Size"/> of the panel. /// </param> /// <returns> /// The arranged size for all child items. /// </returns> protected override Size ArrangeOverride(Size finalSize) { double strokeThickness = StrokeThickness.Abs(); double margin = strokeThickness / 2.0; boundRect = new Rect( margin, margin, Math.Max(0.0, finalSize.Width - strokeThickness), Math.Max(0.0, finalSize.Height - strokeThickness)); center = new Point(boundRect.Width / 2, boundRect.Height / 2); geometry = null; return(finalSize); }
public override void Render(WriteableBitmap input) { var x1 = Region.X; var y1 = Region.Y; var x2 = Region.X + Region.Width; var y2 = Region.Y + Region.Height; input.FillRectangle(x1, y1, x2, y2, Stroke.Color); x1 += StrokeThickness.Int32(); y1 += StrokeThickness.Int32(); x2 -= StrokeThickness.Int32(); y2 -= StrokeThickness.Int32(); x2 = x2 <= x1 ? x1 + 1 : x2; y2 = y2 <= y1 ? y1 + 1 : y2; input.FillRectangle(x1, y1, x2, y2, Fill.Color); }
public override bool Equals(object obj) { // If parameter is null return false. if (obj == null) { return(false); } // If parameter cannot be cast to Rectangle return false. Rectangle o = obj as Rectangle; if ((System.Object)o == null) { return(false); } // Return true if the fields match: return(Location.Equals(o.Location) && Width.Equals(o.Width) && Height.Equals(o.Height) && StrokeThickness.Equals(o.StrokeThickness) && Fill.Equals(o.Fill)); }
public override void Render(WriteableBitmap input) { var x1 = Region.X; var y1 = Region.Y; var x2 = Region.X + Region.Width; var y2 = Region.Y + Region.Height; if (Style.ColorOverlay.IsEnabled) { input.FillEllipse(x1, y1, x2, y2, Style.ColorOverlay.Color, null); return; } input.FillEllipse(x1, y1, x2, y2, Stroke.Color, null); x1 += StrokeThickness.Int32(); y1 += StrokeThickness.Int32(); x2 -= StrokeThickness.Int32(); y2 -= StrokeThickness.Int32(); x2 = x2 <= x1 ? x1 + 1 : x2; y2 = y2 <= y1 ? y1 + 1 : y2; input.FillEllipse(x1, y1, x2, y2, Fill.Color, null); if (Transform is ScaleTransform) { } if (Transform is SkewTransform) { if ((Transform as SkewTransform).TopLeft != null) { Preview = TransformTool.Shear(input.Bitmap(), (Transform as SkewTransform).TopLeft.X, (Transform as SkewTransform).TopLeft.Y).WriteableBitmap(); } } }
override internal protected void Redraw() { if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this)) { double minX = X1; double minY = Y1; double maxX = X2; double maxY = Y2; if (X1 > X2) { minX = X2; maxX = X1; } if (Y1 > Y2) { minY = Y2; maxY = Y1; } Size shapeActualSize; INTERNAL_ShapesDrawHelpers.PrepareStretch(this, _canvasDomElement, minX, maxX, minY, maxY, Stretch, out shapeActualSize); double horizontalMultiplicator; double verticalMultiplicator; double xOffsetToApplyBeforeMultiplication; double yOffsetToApplyBeforeMultiplication; double xOffsetToApplyAfterMultiplication; double yOffsetToApplyAfterMultiplication; INTERNAL_ShapesDrawHelpers.GetMultiplicatorsAndOffsetForStretch(this, StrokeThickness, minX, maxX, minY, maxY, Stretch, shapeActualSize, out horizontalMultiplicator, out verticalMultiplicator, out xOffsetToApplyBeforeMultiplication, out yOffsetToApplyBeforeMultiplication, out xOffsetToApplyAfterMultiplication, out yOffsetToApplyAfterMultiplication, out _marginOffsets); ApplyMarginToFixNegativeCoordinates(new Point()); if (Stretch == Stretch.None) { ApplyMarginToFixNegativeCoordinates(_marginOffsets); } object context = CSHTML5.Interop.ExecuteJavaScriptAsync(@"$0.getContext('2d')", _canvasDomElement); //Note: we do not use INTERNAL_HtmlDomManager.Get2dCanvasContext here because we need to use the result in ExecuteJavaScript, which requires the value to come from a call of ExecuteJavaScript. //we remove the previous drawing: CSHTML5.Interop.ExecuteJavaScriptAsync("$0.clearRect(0,0, $1, $2)", context, shapeActualSize.Width, shapeActualSize.Height); double preparedX1 = (X1 + xOffsetToApplyBeforeMultiplication) * horizontalMultiplicator + xOffsetToApplyAfterMultiplication; double preparedX2 = (X2 + xOffsetToApplyBeforeMultiplication) * horizontalMultiplicator + xOffsetToApplyAfterMultiplication; double preparedY1 = (Y1 + yOffsetToApplyBeforeMultiplication) * verticalMultiplicator + yOffsetToApplyAfterMultiplication; double preparedY2 = (Y2 + yOffsetToApplyBeforeMultiplication) * verticalMultiplicator + yOffsetToApplyAfterMultiplication; //todo: if possible, manage strokeStyle and lineWidth in their respective methods (Stroke_Changed and StrokeThickness_Changed) then use context.save() and context.restore() (can't get it to work yet). double opacity = Stroke == null ? 1 : Stroke.Opacity; object strokeValue = GetHtmlBrush(this, Stroke, opacity, minX, minY, maxX, maxY, horizontalMultiplicator, verticalMultiplicator, xOffsetToApplyBeforeMultiplication, yOffsetToApplyBeforeMultiplication, shapeActualSize); //we set the StrokeDashArray: if (strokeValue != null && StrokeThickness > 0) { double thickness = StrokeThickness; CSHTML5.Interop.ExecuteJavaScriptAsync(@" $0.strokeStyle = $1", context, strokeValue); CSHTML5.Interop.ExecuteJavaScriptAsync(@" $0.lineWidth = $1", context, StrokeThickness); if (StrokeDashArray != null) { if (CSHTML5.Interop.IsRunningInTheSimulator) { //todo: put a message saying that it doesn't work in certain browsers (maybe use a static boolean to put that message only once) } else { object options = CSHTML5.Interop.ExecuteJavaScript(@"new Array()"); for (int i = 0; i < StrokeDashArray.Count; ++i) { CSHTML5.Interop.ExecuteJavaScriptAsync(@" $0[$1] = $2; ", options, i, StrokeDashArray[i] * thickness); } CSHTML5.Interop.ExecuteJavaScriptAsync(@" if ($0.setLineDash) $0.setLineDash($1)", context, options); //context.setLineDash(str + "]"); } } } INTERNAL_ShapesDrawHelpers.PrepareLine(_canvasDomElement, new Point(preparedX1, preparedY1), new Point(preparedX2, preparedY2)); if (strokeValue != null) { CSHTML5.Interop.ExecuteJavaScriptAsync(@"$0.strokeStyle = $1", context, strokeValue); } //context.strokeStyle = strokeAsString; //set the shape's lines color CSHTML5.Interop.ExecuteJavaScriptAsync("$0.lineWidth= $1", context, StrokeThickness.ToString()); //context.lineWidth = StrokeThickness.ToString(); if (Stroke != null && StrokeThickness > 0) { CSHTML5.Interop.ExecuteJavaScriptAsync("$0.stroke()", context); //draw the line //context.stroke(); //draw the line } } }
override internal protected void Redraw() { if (Points.Count < 2) { // It is fine to have 0 or 1 points but nothing to draw in that case. return; } double minX = Points[0].X; double minY = Points[0].Y; double maxX = Points[0].X; double maxY = Points[0].Y; foreach (var p in Points) { if (p.X < minX) { minX = p.X; } if (p.Y < minY) { minY = p.Y; } if (p.X > maxX) { maxX = p.X; } if (p.Y > maxY) { maxY = p.Y; } } Size shapeActualSize; INTERNAL_ShapesDrawHelpers.PrepareStretch(this, _canvasDomElement, minX, maxX, minY, maxY, Stretch, out shapeActualSize); double horizontalMultiplicator; double verticalMultiplicator; double xOffsetToApplyBeforeMultiplication; double yOffsetToApplyBeforeMultiplication; double xOffsetToApplyAfterMultiplication; double yOffsetToApplyAfterMultiplication; INTERNAL_ShapesDrawHelpers.GetMultiplicatorsAndOffsetForStretch(this, StrokeThickness, minX, maxX, minY, maxY, Stretch, shapeActualSize, out horizontalMultiplicator, out verticalMultiplicator, out xOffsetToApplyBeforeMultiplication, out yOffsetToApplyBeforeMultiplication, out xOffsetToApplyAfterMultiplication, out yOffsetToApplyAfterMultiplication, out _marginOffsets); ApplyMarginToFixNegativeCoordinates(new Point()); if (Stretch == Stretch.None) { ApplyMarginToFixNegativeCoordinates(_marginOffsets); } object context = CSHTML5.Interop.ExecuteJavaScriptAsync(@"$0.getContext('2d')", _canvasDomElement); //we remove the previous drawing: CSHTML5.Interop.ExecuteJavaScriptAsync("$0.clearRect(0,0, $1, $2)", context, shapeActualSize.Width, shapeActualSize.Height); double opacity = Stroke == null ? 1 : Stroke.Opacity; object strokeValue = GetHtmlBrush(this, context, Stroke, opacity, minX, minY, maxX, maxY, horizontalMultiplicator, verticalMultiplicator, xOffsetToApplyBeforeMultiplication, yOffsetToApplyBeforeMultiplication, shapeActualSize); object fillValue = GetHtmlBrush(this, context, Fill, opacity, minX, minY, maxX, maxY, horizontalMultiplicator, verticalMultiplicator, xOffsetToApplyBeforeMultiplication, yOffsetToApplyBeforeMultiplication, shapeActualSize); if (fillValue != null) { CSHTML5.Interop.ExecuteJavaScriptAsync(@"$0.fillStyle = $1", context, fillValue); } else { // If fillValue is not set it will be black. CSHTML5.Interop.ExecuteJavaScriptAsync(@"$0.fillStyle = 'transparent'", context); } INTERNAL_ShapesDrawHelpers.PrepareLines(_canvasDomElement, Points, StrokeThickness, true); if (strokeValue != null) { CSHTML5.Interop.ExecuteJavaScriptAsync(@"$0.strokeStyle = $1", context, strokeValue); } CSHTML5.Interop.ExecuteJavaScriptAsync("$0.lineWidth = $1", context, StrokeThickness.ToString()); if (Stroke != null && StrokeThickness > 0) { CSHTML5.Interop.ExecuteJavaScriptAsync("$0.stroke()", context); } }
private Size GetNaturalSize() { double strokeThickness = StrokeThickness.Abs(); return(new Size(strokeThickness, strokeThickness)); }
public override void Draw(Canvas canvas, RectangleF rectangle, Color color) { rectangle = rectangle.Deflate(Padding); var rx = Rx.Calculate(rectangle.Width); var ry = Ry.Calculate(rectangle.Height); if (FillColor.A > 0) { canvas.FillRoundRect(rectangle, new System.Numerics.Vector2(rx, ry), FillColor * color); } if (StrokeColor.A > 0) { canvas.DrawRoundRect(rectangle, new System.Numerics.Vector2(rx, ry), StrokeColor * color, StrokeThickness.Calculate()); } }