public PathIcon() { _path = new Shapes.Path(); _path.Fill = Foreground; _path.Stretch = Stretch.None; AddIconElementView(_path); }
/// <summary> /// Applies FillStyle, StrokeStyle + Adds the figures to the canvas' context, then calls the Fill method. /// </summary> internal protected override void DefineInCanvas(Shapes.Path path, object canvasDomElement, double horizontalMultiplicator, double verticalMultiplicator, double xOffsetToApplyBeforeMultiplication, double yOffsetToApplyBeforeMultiplication, double xOffsetToApplyAfterMultiplication, double yOffsetToApplyAfterMultiplication, Size shapeActualSize) { //we define the Fillstyle and StrokeStyle: //StrokeStyle: if (shapeActualSize.Width > 0 && shapeActualSize.Height > 0) { //this will change the context in the canvas to draw itself. foreach (PathFigure figure in Figures) { //Add the figure to the canvas: figure.DefineInCanvas(xOffsetToApplyBeforeMultiplication, yOffsetToApplyBeforeMultiplication, xOffsetToApplyAfterMultiplication, yOffsetToApplyAfterMultiplication, horizontalMultiplicator, verticalMultiplicator, canvasDomElement, _strokeThickness, shapeActualSize); } } }
internal protected override void DefineInCanvas(Shapes.Path path, object canvasDomElement, double horizontalMultiplicator, double verticalMultiplicator, double xOffsetToApplyBeforeMultiplication, double yOffsetToApplyBeforeMultiplication, double xOffsetToApplyAfterMultiplication, double yOffsetToApplyAfterMultiplication, Size shapeActualSize) { dynamic ctx = INTERNAL_HtmlDomManager.Get2dCanvasContext(canvasDomElement); ctx.ellipse( Center.X + xOffsetToApplyBeforeMultiplication + xOffsetToApplyAfterMultiplication, Center.Y + yOffsetToApplyBeforeMultiplication + yOffsetToApplyAfterMultiplication, RadiusX, RadiusY, 0, 0, 2 * Math.PI); }
internal override void DefineInCanvas(Shapes.Path path, object canvasDomElement, double horizontalMultiplicator, double verticalMultiplicator, double xOffsetToApplyBeforeMultiplication, double yOffsetToApplyBeforeMultiplication, double xOffsetToApplyAfterMultiplication, double yOffsetToApplyAfterMultiplication, Size shapeActualSize) { string strokeAsString = string.Empty; if (path.Stroke == null || path.Stroke is SolidColorBrush) //todo: make sure we want the same behaviour when it is null and when it is a SolidColorBrush (basically, check if null means default value) { if (path.Stroke != null) //if stroke is null, we want to set it as an empty string, otherwise, it is a SolidColorBrush and we want to get its color. { strokeAsString = ((SolidColorBrush)path.Stroke).INTERNAL_ToHtmlString(); } } else { throw new NotSupportedException("The specified brush is not supported."); } dynamic context = INTERNAL_HtmlDomManager.Get2dCanvasContext(canvasDomElement); double actualWidth = RadiusX * 2; //it's a radius and we want the whole width (basically a "diameter") double actualHeight = RadiusY * 2; //it's a radius and we want the whole height INTERNAL_ShapesDrawHelpers.PrepareEllipse(canvasDomElement, actualWidth, actualHeight, Center.X + xOffsetToApplyBeforeMultiplication + xOffsetToApplyAfterMultiplication, Center.Y + yOffsetToApplyBeforeMultiplication + yOffsetToApplyAfterMultiplication); context.strokeStyle = strokeAsString; }
private string Path(Shapes.Path path) { sb.Clear(); var(x, y) = path.Points[0]; sb.Append("M "); sb.Append(Coord.CoordX(x)); sb.Append(" "); sb.Append(Coord.CoordY(y)); for (var j = 1; j < path.Points.Count; j++) { (x, y) = path.Points[j]; sb.Append(" L "); sb.Append(Coord.CoordX(x)); sb.Append(" "); sb.Append(Coord.CoordY(y)); } return(sb.ToString()); }