private void Build() { if (ReadyToDraw) { return; } filtered.Clear(); CanvasCachedGeometry = CreateCachedGeometry(Scale, Thickness); //Random rand = new Random(); //if (rand.NextDouble() < 0.5f) //{ // Color = Colors.Red; // CanvasCachedGeometry = CreateCachedGeometry(Scale, Thickness); //} //else //{ // Color = Colors.Blue; // CanvasCachedGeometry = CreateCachedGeometryPreviousVersion(Scale, Thickness); //} midPoints.Clear(); leftPoints.Clear(); rightPoints.Clear(); }
public SVGPath(SVGPath path) { _ID = path._ID; _cg = path._cg.Transform(Matrix3x2.Identity); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
public void CreateResources(ICanvasResourceCreator resourceCreator) { DestroyResources(); // define path var pb = new CanvasPathBuilder(resourceCreator); var radiusH = HexUtils.GetRadiusHeight(Radius); pb.BeginFigure(-1 * Radius * HexUtils.COS60, radiusH); pb.AddLine(Radius * HexUtils.COS60, radiusH); pb.AddLine(Radius, 0); pb.AddLine(Radius * HexUtils.COS60, -1 * radiusH); pb.AddLine(-1 * Radius * HexUtils.COS60, -1 * radiusH); pb.AddLine(-1 * Radius, 0); pb.EndFigure(CanvasFigureLoop.Closed); // create and cache _strokeStyle = new CanvasStrokeStyle(); var geo = CanvasGeometry.CreatePath(pb); if (Filled) { _geo = CanvasCachedGeometry.CreateFill(geo); } else { _geo = CanvasCachedGeometry.CreateStroke(geo, Style.StrokeWidth, _strokeStyle); } }
public SVGPath(String unicodeHex, String path) { String hex = ""; CanvasDevice device = CanvasDevice.GetSharedDevice(); hex = unicodeHex; _ID = int.Parse(unicodeHex.Replace(";", ""), System.Globalization.NumberStyles.HexNumber);//Convert.ToInt32(hex); CanvasPathBuilder pb = new CanvasPathBuilder(device); parsePath(pb, path); //L 1.5 = 2650 pixel units in the svg font file //double L1_5 = 2650; //_cg = _cg.Transform(Matrix3x2.CreateScale(0.2f)); _cg = _cg.Transform(Matrix3x2.CreateScale(0.0188679245283019f)); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
public void CreateResources(ICanvasResourceCreator resourceCreator) { DestroyResources(); // create and cache if (Rounded) { _strokeStyle = new CanvasStrokeStyle() { LineJoin = CanvasLineJoin.Round } } ; else { _strokeStyle = new CanvasStrokeStyle(); } var geo = CanvasGeometry.CreateRectangle(resourceCreator, Width / -2.0f, Height / -2.0f, Width, Height); if (Filled) { _geo = CanvasCachedGeometry.CreateFill(geo); } else { _geo = CanvasCachedGeometry.CreateStroke(geo, Style.StrokeWidth, _strokeStyle); } }
void CreateClockFace(ICanvasResourceCreator sender) { const float begin = center - radius - lineLength / 2; const float end = center + radius + lineLength / 2; using (var builder = new CanvasPathBuilder(sender)) { // Since we have concentric circles that we want to remain filled we want to use Winding to determine the filled region. builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.AddCircleFigure(new Vector2(center), radius); builder.AddCircleFigure(new Vector2(center), radius * 0.6f); builder.AddOneLineFigure(center, begin, center, begin + lineLength); builder.AddOneLineFigure(center, end - lineLength, center, end); builder.AddOneLineFigure(begin, center, begin + lineLength, center); builder.AddOneLineFigure(end - lineLength, center, end, center); using (CanvasGeometry clockFaceGeometry = CanvasGeometry.CreatePath(builder)) { clockFaceCachedFill = CanvasCachedGeometry.CreateFill(clockFaceGeometry); clockFaceCachedStroke18 = CanvasCachedGeometry.CreateStroke(clockFaceGeometry, 18, timeCircleStrokeStyle); clockFaceCachedStroke16 = CanvasCachedGeometry.CreateStroke(clockFaceGeometry, 16, timeCircleStrokeStyle); } } }
private CanvasCachedGeometry getCashedValve16(ICanvasResourceCreator resourceCreator) { if (cachedGeometry2 == null) { var radius = 16; cachedGeometry2 = CanvasCachedGeometry.CreateFill(CreateValve(resourceCreator, radius)); } return(cachedGeometry2); }
public void Dispose() { points?.Clear(); midPoints?.Clear(); leftPoints?.Clear(); rightPoints?.Clear(); filtered?.Clear(); points = midPoints = leftPoints = rightPoints = filtered = null; CanvasCachedGeometry?.Dispose(); CanvasCachedGeometry = null; }
public SVGPath(String unicodeHex, String path, ICanvasResourceCreator rc) { _ID = int.Parse(unicodeHex.Replace(";", ""), System.Globalization.NumberStyles.HexNumber); CanvasPathBuilder pb = new CanvasPathBuilder(rc); parsePath(pb, path); _cg = _cg.Transform(Matrix3x2.CreateScale(0.2f)); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
public void DestroyResources() { if (_geo == null) { return; } _geo.Dispose(); _geo = null; _strokeStyle.Dispose(); _strokeStyle = null; }
public void CreateResources(ICanvasResourceCreator resourceCreator) { DestroyResources(); // create stroke _strokeStyle = new CanvasStrokeStyle(); // create geometry var body = CanvasGeometry.CreateCircle(resourceCreator, new Vector2(0.0f), 24); var cannon = CanvasGeometry.CreateRectangle(resourceCreator, 23, -3, 10, 6); var comb = body.CombineWith(cannon, Matrix3x2.Identity, CanvasGeometryCombine.Union); // cache _geo = CanvasCachedGeometry.CreateStroke(comb, Style.StrokeWidth, _strokeStyle); }
private void _TextOverlaysCanvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args) { CanvasPathBuilder pathBuilder = new CanvasPathBuilder(sender); pathBuilder.BeginFigure(0, 2.5f); pathBuilder.AddLine(2, 0); pathBuilder.AddLine(6, 4); pathBuilder.AddLine(10, 0); pathBuilder.AddLine(14, 4); pathBuilder.AddLine(18, 0); pathBuilder.AddLine(22, 4); pathBuilder.AddLine(24, 1.5f); pathBuilder.EndFigure(CanvasFigureLoop.Open); CanvasGeometry canvasGeometry = CanvasGeometry.CreatePath(pathBuilder); _SquigglyLineGeometry = CanvasCachedGeometry.CreateStroke(canvasGeometry, 1); CreateOverlayResources?.Invoke(sender, args); }
protected virtual void Dispose(Boolean disposing) { if (!disposed) { if (disposing == true && _cg != null) { _cg.Dispose(); _cg = null; } if (disposing == true && _ccgStroke != null) { _ccgStroke.Dispose(); _ccgStroke = null; } if (disposing == true && _ccgFill != null) { _ccgFill.Dispose(); _ccgFill = null; } disposed = true; } }
/** * Draw the entire dancer's path as a translucent colored line * @param ds Canvas to draw to */ public void drawPath(CanvasDrawingSession ds) { if (pathpath == null) { var savebeat = lastbeat; CanvasPathBuilder pathBuilder = new CanvasPathBuilder(ds); animateComputed(0.0); var loc = location; pathBuilder.BeginFigure(loc.X, loc.Y); for (double beat = 0.1; beat <= beats; beat += 0.1) { animateComputed(beat); loc = location; pathBuilder.AddLine(loc.X, loc.Y); } pathBuilder.EndFigure(CanvasFigureLoop.Open); var cg = CanvasGeometry.CreatePath(pathBuilder); pathpath = CanvasCachedGeometry.CreateStroke(cg, 0.1f); animate(savebeat); // restore current position } ds.DrawCachedGeometry(pathpath, Color.FromArgb(80, fillColor.R, fillColor.G, fillColor.B)); }
public static void DrawGeometry(Tile.Feature feature, float scale, CanvasDrawingSession session, Windows.UI.Color fillColor, Windows.UI.Color strokeColor, float innerLineWidth, float outerLineWidth, CanvasStrokeStyle strokeStyle) { Queue <uint> q = new Queue <uint>(feature.Geometries); float cx = 0; float cy = 0; List <System.Numerics.Vector2> poly = new List <System.Numerics.Vector2>(); while (q.Count > 0) { var cmd = DecodeCommand(q.Dequeue()); switch (cmd.Item1) { case GeometryCommand.MoveTo: cx += DecodeParameter(q.Dequeue()) * scale; cy += DecodeParameter(q.Dequeue()) * scale; poly.Add(new System.Numerics.Vector2(cx, cy)); break; case GeometryCommand.LineTo: for (int it = 0; it < cmd.count; it++) { cx += DecodeParameter(q.Dequeue()) * scale; cy += DecodeParameter(q.Dequeue()) * scale; poly.Add(new System.Numerics.Vector2(cx, cy)); } break; case GeometryCommand.ClosePath: if (feature.Type == Tile.GeomType.Polygon) { CanvasGeometry geom = CanvasGeometry.CreatePolygon(session.Device, poly.ToArray()); var cf = CanvasCachedGeometry.CreateFill(geom); var cd = CanvasCachedGeometry.CreateStroke(geom, 1); cache.Add(cf); cache.Add(cd); session.DrawCachedGeometry(cf, fillColor); session.DrawCachedGeometry(cd, strokeColor); //session.FillGeometry(geom, fillColor); //session.DrawGeometry(geom, strokeColor); } poly.Clear(); break; } } if (feature.Type == Tile.GeomType.Linestring) { CanvasPathBuilder pathBuilder = new CanvasPathBuilder(session); pathBuilder.SetSegmentOptions(CanvasFigureSegmentOptions.ForceRoundLineJoin); pathBuilder.BeginFigure(poly[0]); for (int it = 1; it < (poly.Count); it++) { pathBuilder.AddLine(poly[it]); //if(outerLineWidth > 0) // session.DrawLine(poly[it], poly[it + 1], strokeColor, outerLineWidth, strokeStyle); //if (innerLineWidth > 0) // session.DrawLine(poly[it], poly[it + 1], fillColor, innerLineWidth, strokeStyle); } pathBuilder.EndFigure(CanvasFigureLoop.Open); var geometry = CanvasGeometry.CreatePath(pathBuilder); if (outerLineWidth > 0) { var cg = CanvasCachedGeometry.CreateStroke(geometry, outerLineWidth, strokeStyle); cache.Add(cg); session.DrawCachedGeometry(cg, strokeColor); //session.DrawGeometry(geometry, strokeColor, outerLineWidth, strokeStyle); } if (innerLineWidth > 0) { var cg = CanvasCachedGeometry.CreateStroke(geometry, innerLineWidth, strokeStyle); cache.Add(cg); session.DrawCachedGeometry(cg, fillColor); //session.DrawGeometry(geometry, fillColor, innerLineWidth, strokeStyle); } poly.Clear(); } }
public SVGPath(String unicodeHex, String path) { String hex = ""; CanvasDevice device = CanvasDevice.GetSharedDevice(); hex = unicodeHex; _ID = Convert.ToInt32(hex); CanvasPathBuilder pb = new CanvasPathBuilder(device); parsePath(pb, path); //L 1.5 = 2650 pixel units in the svg font file //double L1_5 = 2650; //_cg = _cg.Transform(Matrix3x2.CreateScale(0.2f)); _cg = _cg.Transform(Matrix3x2.CreateScale(0.0188679245283019f)); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
private void UpdateOutlineChanges(ICanvasResourceCreator canvas, ITextModel leftControl, ITextModel rightControl, double controlHeight) { if (leftControl == null || rightControl == null) { return; } int lineCountOrg = leftControl.ValidLineCount; int lineCountCur = rightControl.ValidLineCount; int maxLineCount = Math.Max(lineCountOrg, lineCountCur); int singleOrgLineHeight = (int)(controlHeight / lineCountOrg); int singleCurLineHeight = (int)(controlHeight / lineCountCur); var removedGeo = new List <CanvasGeometry>(); var addedGeo = new List <CanvasGeometry>(); // Draw removals int lineNo = 0; for (int i = 0; i < leftControl.LineCount; i++) { var textLine = leftControl.GetLine(i); if (textLine is DiffTextLine diffLine) { if (diffLine.ChangeType != DiffLineType.Empty) { lineNo++; } if (diffLine.ChangeType == DiffLineType.Remove) { int ypos = (int)((double)lineNo / maxLineCount * controlHeight); removedGeo.Add(CanvasGeometry.CreateRectangle(canvas, new Rect(12.0, ypos + (int)_leftFileTop, 16.0, singleOrgLineHeight + 1))); } } } lineNo = 0; for (int i = 0; i < rightControl.LineCount; i++) { var textLine = rightControl.GetLine(i); if (textLine is DiffTextLine diffLine) { if (diffLine.ChangeType != DiffLineType.Empty) { lineNo++; } if (diffLine.ChangeType == DiffLineType.Insert) { int ypos = (int)((double)lineNo / maxLineCount * controlHeight); addedGeo.Add(CanvasGeometry.CreateRectangle(canvas, new Rect(40.0, ypos + (int)_rightFileTop, 16.0, singleCurLineHeight + 1))); } } } // Save the results into a cached geo var groupedRemovedGeo = CanvasGeometry.CreateGroup(canvas, removedGeo.ToArray()); var groupedAddedGeo = CanvasGeometry.CreateGroup(canvas, addedGeo.ToArray()); _outlineChangesRemoved = CanvasCachedGeometry.CreateFill(groupedRemovedGeo); _outlineChangesAdded = CanvasCachedGeometry.CreateFill(groupedAddedGeo); }
public SVGPath(String unicodeHex, String path, ICanvasResourceCreator rc) { _ID = Convert.ToInt32(unicodeHex); CanvasPathBuilder pb = new CanvasPathBuilder(rc); parsePath(pb, path); _cg = _cg.Transform(Matrix3x2.CreateScale(0.2f)); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
}// public void Transform(Matrix3x2 m) { _cg = _cg.Transform(m); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); _bounds = _cg.ComputeBounds(); }
/// <summary> /// Adds a dot to the current stroke. /// </summary> /// <param name="dot">Coordinate data received from the pen</param> public void Add(Dot dot) { CanvasCachedGeometry?.Dispose(); CanvasCachedGeometry = null; points.Add(new DrawablePoint(dot)); }