/// <summary> /// You can call this directly from start /// </summary> /// <param name="geometry"></param> /// <param name="color"></param> /// <returns></returns> public async Task CreateMaskBrush(CanvasGeometry geometry, Color color) { var geometryMask = await CreateGeometryMask(geometry); var maskBrush = Compositor.CreateMaskBrush(); maskBrush.Mask = Compositor.CreateSurfaceBrush(geometryMask.Surface); maskBrush.Source = Compositor.CreateColorBrush(color); Visual.Brush = maskBrush; }
void CreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args) { // Create a gradient brush, used to control layer opacity. var gradientStops = new CanvasGradientStop[] { new CanvasGradientStop { Position = 0, Color = Colors.White }, new CanvasGradientStop { Position = 0.25f, Color = Colors.White }, new CanvasGradientStop { Position = 1, Color = Colors.Transparent }, }; gradientBrush = new CanvasRadialGradientBrush(sender, gradientStops); // Create a star shaped geometry, used for layer clipping. clipGeometry = Utils.CreateStarGeometry(sender, 1, Vector2.Zero); }
/// <summary> /// Constructor /// </summary> /// <param name="generator">ICompositionMaskGeneratorInternal object</param> /// <param name="size">Size of the MaskSurface</param> /// <param name="geometry">Geometry of the MaskSurface</param> public MaskSurface(ICompositionGeneratorInternal generator, Size size, CanvasGeometry geometry) { if (generator == null) throw new ArgumentNullException(nameof(generator), "CompositionGenerator cannot be null!"); _generator = generator; _surfaceLock = new object(); _geometry = geometry; // Create Mask Surface _surface = _generator.CreateDrawingSurface(_surfaceLock, size); // Set the size Size = _surface?.Size ?? new Size(0, 0); // Subscribe to DeviceReplaced event _generator.DeviceReplaced += OnDeviceReplaced; }
internal CanvasGeometry GetPath() { //if (_OtherGeometry == null) //{ // mBuilder.EndFigure(CanvasFigureLoop.Closed); // CanvasGeometry geometry = CanvasGeometry.CreatePath(mBuilder); // mBuilder.Dispose(); // return geometry; //} //return _OtherGeometry; mBuilder.EndFigure(mFigureLoop); CanvasGeometry geometry = CanvasGeometry.CreatePath(mBuilder); return(geometry); }
private static CanvasGeometry CreateTriangleGeometry(ICanvasResourceCreator resourceCreator, float scale, Vector2 center) { Vector2[] points = { new Vector2(-1, 1), new Vector2(0, -1), new Vector2(1, 1) }; var transformedPoints = from point in points select point * scale + center; var convertedPoints = transformedPoints; return(CanvasGeometry.CreatePolygon(resourceCreator, convertedPoints.ToArray())); }
CanvasGeometry Geometry_5() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.BeginFigure(new Vector2(-19.743F, 15.7650003F)); builder.AddCubicBezier(new Vector2(-19.743F, 15.7650003F), new Vector2(-22.8710003F, -3.98900008F), new Vector2(-22.8710003F, -3.98900008F)); builder.AddCubicBezier(new Vector2(-24.4349995F, -13.8660002F), new Vector2(-18.3190002F, -24.9589996F), new Vector2(-6.24599981F, -26.8710003F)); builder.AddCubicBezier(new Vector2(5.82700014F, -28.7830009F), new Vector2(15.0719995F, -20.1229992F), new Vector2(16.6359997F, -10.2460003F)); builder.AddCubicBezier(new Vector2(16.6359997F, -10.2460003F), new Vector2(16.7929993F, -9.25899982F), new Vector2(16.7929993F, -9.25899982F)); builder.EndFigure(CanvasFigureLoop.Open); result = CanvasGeometry.CreatePath(builder); } return(result); }
CanvasGeometry Geometry_0() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.BeginFigure(new Vector2(0, -34.5F)); builder.AddCubicBezier(new Vector2(19.0540009F, -34.5F), new Vector2(34.5F, -19.0540009F), new Vector2(34.5F, 0)); builder.AddCubicBezier(new Vector2(34.5F, 19.0540009F), new Vector2(19.0540009F, 34.5F), new Vector2(0, 34.5F)); builder.AddCubicBezier(new Vector2(-19.0540009F, 34.5F), new Vector2(-34.5F, 19.0540009F), new Vector2(-34.5F, 0)); builder.AddCubicBezier(new Vector2(-34.5F, -19.0540009F), new Vector2(-19.0540009F, -34.5F), new Vector2(0, -34.5F)); builder.EndFigure(CanvasFigureLoop.Open); result = CanvasGeometry.CreatePath(builder); } return(result); }
private static CanvasGeometry CreateClipGeometry(ICanvasResourceCreator resourceCreator, CropShape cropShape, Size croppedSize) { switch (cropShape) { case CropShape.Rectangular: break; case CropShape.Circular: var radiusX = croppedSize.Width / 2; var radiusY = croppedSize.Height / 2; var center = new Point(radiusX, radiusY); return(CanvasGeometry.CreateEllipse(resourceCreator, center.ToVector2(), (float)radiusX, (float)radiusY)); } return(null); }
static CanvasGeometry CreateTimeSegmentGeometry(CanvasDrawingSession ds, long updateCount, double updatesPerSecond) { double updates = (double)updateCount; double fractionSecond = (updates / updatesPerSecond) % 1.0; double fractionSecondAngle = 2 * Math.PI * fractionSecond; double angle = fractionSecondAngle % (2 * Math.PI); using (var builder = new CanvasPathBuilder(ds)) { builder.BeginFigure(center, center); builder.AddArc(new Vector2(center), radius, radius, (float)Math.PI * 3 / 2, (float)angle); builder.EndFigure(CanvasFigureLoop.Closed); return(CanvasGeometry.CreatePath(builder)); } }
// - - - - - Shape tree root for layer: icon // - - - - Offset:<-3.8320007, 0> // - - - Path 2+Path 1.PathGeometry // - - Path CanvasGeometry Geometry_08() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.BeginFigure(new Vector2(20F, 55F)); builder.AddCubicBezier(new Vector2(36.5690002F, 55F), new Vector2(50F, 30.3759995F), new Vector2(50F, 0F)); builder.AddCubicBezier(new Vector2(50F, -30.3759995F), new Vector2(36.5690002F, -55F), new Vector2(20F, -55F)); builder.AddCubicBezier(new Vector2(3.43099999F, -55F), new Vector2(-10F, -30.3759995F), new Vector2(-10F, 0F)); builder.AddCubicBezier(new Vector2(-10F, 30.3759995F), new Vector2(3.43099999F, 55F), new Vector2(20F, 55F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
// - - - - Shape tree root for layer: icon // - - - Offset:<-3.8320007, 0> // - - Path 2+Path 1.PathGeometry CanvasGeometry Geometry_2() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.BeginFigure(new Vector2(0F, 50F)); builder.AddCubicBezier(new Vector2(16.5690002F, 50F), new Vector2(30F, 27.6140003F), new Vector2(30F, 0F)); builder.AddCubicBezier(new Vector2(30F, -27.6140003F), new Vector2(16.5690002F, -50F), new Vector2(0F, -50F)); builder.AddCubicBezier(new Vector2(-16.5690002F, -50F), new Vector2(-30F, -27.6140003F), new Vector2(-30F, 0F)); builder.AddCubicBezier(new Vector2(-30F, 27.6140003F), new Vector2(-16.5690002F, 50F), new Vector2(0F, 50F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
private static CanvasGeometry CreateTriangleCore(ICanvasResourceCreator resourceCreator, Vector2 leftTop, Vector2 rightTop, Vector2 rightBottom, Vector2 leftBottom, float center) { float minusValue = 1.0f - center; Vector2 center2 = leftTop * minusValue + rightTop * center; // Points Vector2[] points = new Vector2[] { center2, rightBottom, leftBottom, }; // Geometry return(CanvasGeometry.CreatePolygon(resourceCreator, points)); }
/// <summary> /// Create a new dount geometry. /// </summary> /// <param name="resourceCreator"> The resource-creator. </param> /// <param name="transformer"> The source transformer. </param> /// <param name="matrix"> The matrix. </param> /// <param name="holeRadius"> The hole-radius. </param> /// <returns> The product geometry. </returns> public static CanvasGeometry CreateDount(ICanvasResourceCreator resourceCreator, ITransformerLTRB transformer, Matrix3x2 matrix, float holeRadius) { bool zeroHoleRadius = holeRadius == 0; CanvasGeometry outter = TransformerGeometry.CreateEllipse(resourceCreator, transformer, matrix); if (zeroHoleRadius) { return(outter); } else { Vector2 center = Vector2.Transform(transformer.Center, matrix); return(TransformerGeometry.CreateDountCore(outter, holeRadius, center)); } }
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); }
public void DrawBezier(CanvasDrawingSession g2d, List <CalcPoint> pointslist, int xoffset, int yoffset, Color bordercolor, float linesize) { CanvasDevice device = CanvasDevice.GetSharedDevice(); CanvasGeometry geometry; CanvasPathBuilder pathBuilder = new CanvasPathBuilder(device); pathBuilder.BeginFigure(new Vector2(pointslist[0].X + xoffset, pointslist[0].Y + yoffset)); pathBuilder.AddCubicBezier(new Vector2(pointslist[1].X + xoffset, pointslist[1].Y + yoffset), new Vector2(pointslist[2].X + xoffset, pointslist[2].Y + yoffset), new Vector2(pointslist[3].X + xoffset, pointslist[3].Y + yoffset)); pathBuilder.EndFigure(CanvasFigureLoop.Open); geometry = CanvasGeometry.CreatePath(pathBuilder); pathBuilder.Dispose(); g2d.DrawGeometry(geometry, bordercolor, linesize); geometry.Dispose(); }
public static CompositionPath Parse(string data) { var reader = new PathDataReader(data); var segments = reader.read(); if (segments != null) { var builder = new CanvasPathBuilder(null); renderPath(segments, builder); return(new CompositionPath(CanvasGeometry.CreatePath(builder))); } return(null); }
// - - - Shape tree root for layer: icon // - - ShapeGroup: lt CanvasGeometry Geometry_2() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.BeginFigure(new Vector2(-20F, 15F)); builder.AddLine(new Vector2(-20F, 5F)); builder.AddCubicBezier(new Vector2(-20F, -5F), new Vector2(-12.2229996F, -15F), new Vector2(0F, -15F)); builder.AddCubicBezier(new Vector2(12.2229996F, -15F), new Vector2(20F, -5F), new Vector2(20F, 5F)); builder.AddLine(new Vector2(20F, 15F)); builder.EndFigure(CanvasFigureLoop.Open); result = CanvasGeometry.CreatePath(builder); } return(result); }
CanvasGeometry Geometry_2() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.BeginFigure(new Vector2(40.8180008F, -34.526001F)); builder.AddCubicBezier(new Vector2(46.1459999F, -26.2049999F), new Vector2(49.257F, -16.1679993F), new Vector2(49.257F, -5.36199999F)); builder.AddCubicBezier(new Vector2(49.257F, 23.4050007F), new Vector2(27.2049999F, 46.723999F), new Vector2(0.00100000005F, 46.723999F)); builder.AddCubicBezier(new Vector2(-27.2040005F, 46.723999F), new Vector2(-49.257F, 23.4050007F), new Vector2(-49.257F, -5.36199999F)); builder.AddCubicBezier(new Vector2(-49.257F, -22.2180004F), new Vector2(-41.6839981F, -37.2039986F), new Vector2(-29.941F, -46.723999F)); builder.EndFigure(CanvasFigureLoop.Open); result = CanvasGeometry.CreatePath(builder); } return(result); }
/// <summary> /// Constructor /// </summary> /// <param name="generator">ICompositionMaskGeneratorInternal object</param> /// <param name="size">Size of the GeometrySurface</param> /// <param name="geometry">Geometry of the GeometrySurface</param> /// <param name="stroke">Stroke for the geometry</param> /// <param name="fill">Brush to fill the geometry</param> /// <param name="backgroundBrush">Brush to fill the GeometrySurface background surface which is /// not covered by the geometry</param> public GeometrySurface(ICompositionGeneratorInternal generator, Size size, CanvasGeometry geometry, ICanvasStroke stroke, ICanvasBrush fill, ICanvasBrush backgroundBrush) { _generator = generator ?? throw new ArgumentNullException(nameof(generator), "CompositionGenerator cannot be null!"); _surfaceLock = new object(); _geometry = geometry; _stroke = stroke; _fill = fill; _backgroundBrush = backgroundBrush; // Create GeometrySurface _surface = _generator.CreateDrawingSurface(_surfaceLock, size); // Set the size Size = _surface?.Size ?? new Size(0, 0); // Subscribe to DeviceReplaced event _generator.DeviceReplaced += OnDeviceReplaced; }
private CanvasGeometry GetTransformedRectangle( float width, float thickness, float offset, Vector2 position, CanvasGlyphOrientation glyphOrientation) { var geometry = CanvasGeometry.CreateRectangle( resourceCreator, new Rect(0, offset, width, thickness)); var rotate = System.Numerics.Matrix3x2.CreateRotation(GetGlyphOrientationInRadians(glyphOrientation)); var translate = System.Numerics.Matrix3x2.CreateTranslation(position); return(geometry.Transform(rotate * translate)); }
/// <summary> /// Draw a marquee-tool. /// </summary> /// <param name="drawingSession"> The drawing-session. </param> /// <param name="resourceCreator"> The resource-creator. </param> /// <param name="toolType"> The marquee-tool type. </param> /// <param name="marqueeTool"> The marquee-tool. </param> /// <param name="matrix"> The matrix. </param> public static void DrawMarqueeTool(this CanvasDrawingSession drawingSession, ICanvasResourceCreator resourceCreator, MarqueeToolType toolType, MarqueeTool marqueeTool, Matrix3x2 matrix) { if (marqueeTool.IsStarted) { switch (toolType) { case MarqueeToolType.Rectangular: { TransformerRect transformerRect = marqueeTool.TransformerRect; CanvasGeometry canvasGeometry = transformerRect.ToRectangle(resourceCreator, matrix); drawingSession.DrawThickGeometry(canvasGeometry); } break; case MarqueeToolType.Elliptical: { TransformerRect transformerRect = marqueeTool.TransformerRect; CanvasGeometry canvasGeometry = transformerRect.ToEllipse(resourceCreator, matrix); drawingSession.DrawThickGeometry(canvasGeometry); } break; case MarqueeToolType.Polygonal: { Vector2[] points = marqueeTool.Points.ToArray(); CanvasGeometry canvasGeometry = CanvasGeometry.CreatePolygon(resourceCreator, points); CanvasGeometry canvasGeometryTransform = canvasGeometry.Transform(matrix); drawingSession.DrawThickGeometry(canvasGeometryTransform); Vector2 firstPoint = Vector2.Transform(marqueeTool.Points.First(), matrix); Vector2 lastPoint = Vector2.Transform(marqueeTool.Points.Last(), matrix); drawingSession.DrawNode5(firstPoint); drawingSession.DrawNode5(lastPoint); } break; case MarqueeToolType.FreeHand: { Vector2[] points = marqueeTool.Points.ToArray(); CanvasGeometry canvasGeometry = CanvasGeometry.CreatePolygon(resourceCreator, points); CanvasGeometry canvasGeometryTransform = canvasGeometry.Transform(matrix); drawingSession.DrawThickGeometry(canvasGeometryTransform); } break; } } }
private void gauge_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { using (CanvasDrawingSession drawingSession = args.DrawingSession) { Vector2 outputSize = new Vector2((float)(ActualWidth), (float)(ActualHeight)); Vector2 sourceSize = new Vector2(100.0f, -100.0f); drawingSession.Transform = GetDisplayTransform(outputSize, sourceSize); using (var geometry = CanvasGeometry.CreatePath(CreateBackgroundGauge(sender))) { drawingSession.FillGeometry(geometry, Color.FromArgb(255, 25, 25, 25)); // Colors.DarkSlateGray); } using (var geometry2 = CanvasGeometry.CreatePath(CreateForegroundGauge(sender))) { drawingSession.FillGeometry(geometry2, ForegroundColor); } using (var geometry3 = CanvasGeometry.CreatePath(CreateBorderGauge(sender))) { drawingSession.DrawGeometry(geometry3, Colors.White, 2.0f); } string text = string.Format("{0:+#0.0;-#0.0;0.0} °C", Temperature); FontWeight weight = new FontWeight(); weight.Weight = 500; using (CanvasTextFormat textFormat = new CanvasTextFormat { FontSize = 15.0f, FontWeight = weight, WordWrapping = CanvasWordWrapping.NoWrap }) using (CanvasTextLayout layout = new CanvasTextLayout(drawingSession, text, textFormat, 0.0f, 0.0f)) { float xLocation = -(float)layout.DrawBounds.Width / 2; float yLocation = -(float)layout.DrawBounds.Height; outputSize = new Vector2((float)(ActualWidth), (float)(ActualHeight)); sourceSize = new Vector2(100.0f, 100.0f); drawingSession.Transform = GetDisplayTransform(outputSize, sourceSize); drawingSession.DrawTextLayout(layout, xLocation, yLocation, ForegroundColor); } } }
private CanvasGeometry CreateGeometry(ICanvasResourceCreator resourceCreator, GeometryType type) { switch (type) { case GeometryType.Rectangle: return(CanvasGeometry.CreateRectangle(resourceCreator, 100, 100, 300, 350)); case GeometryType.RoundedRectangle: return(CanvasGeometry.CreateRoundedRectangle(resourceCreator, 80, 80, 400, 400, 100, 100)); case GeometryType.Ellipse: return(CanvasGeometry.CreateEllipse(resourceCreator, 275, 275, 225, 275)); case GeometryType.Star: return(Utils.CreateStarGeometry(resourceCreator, 250, new Vector2(250, 250))); case GeometryType.Text: { var textFormat = new CanvasTextFormat { FontFamily = "Comic Sans MS", FontSize = 400, }; var textLayout = new CanvasTextLayout(resourceCreator, "2D", textFormat, 1000, 1000); return(CanvasGeometry.CreateText(textLayout)); } case GeometryType.Group: { CanvasGeometry geo0 = CanvasGeometry.CreateRectangle(resourceCreator, 100, 100, 100, 100); CanvasGeometry geo1 = CanvasGeometry.CreateRoundedRectangle(resourceCreator, 300, 100, 100, 100, 50, 50); CanvasPathBuilder pathBuilder = new CanvasPathBuilder(resourceCreator); pathBuilder.BeginFigure(200, 200); pathBuilder.AddLine(500, 200); pathBuilder.AddLine(200, 350); pathBuilder.EndFigure(CanvasFigureLoop.Closed); CanvasGeometry geo2 = CanvasGeometry.CreatePath(pathBuilder); return(CanvasGeometry.CreateGroup(resourceCreator, new CanvasGeometry[] { geo0, geo1, geo2 })); } } System.Diagnostics.Debug.Assert(false); return(null); }
/// <summary> /// Creates a scale & translation matrix /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="bounds"></param> /// <param name="outBounds"></param> /// <returns></returns> public Matrix3x2 CreateMatrix(int width, int height, out Rect outBounds, out Matrix3x2 mScale, out Matrix3x2 mTranslate) { float scale = 1f; Rect rect = new Rect(_bounds.X, _bounds.Y, _bounds.Width, _bounds.Height); //_cg.ComputeBounds();//(testMatrix, testPen); mScale = new Matrix3x2(); mTranslate = new Matrix3x2(); float sx = (float)(width / rect.Width); float sy = (float)(height / rect.Height); if (sx < sy) { scale = sx; } else { scale = sy; } mScale = Matrix3x2.CreateScale(scale, scale); outBounds = new Rect(0, 0, _bounds.Width * scale, _bounds.Height * scale); _cgBounds = CanvasGeometry.CreateRectangle(_cg.Device, _bounds); _cgBounds = _cgBounds.Transform(mScale); rect = _cgBounds.ComputeBounds(); float transx = 0; float transy = 0; if (rect.X < 0) { transx = (float)(rect.X * -1.0f); } if (rect.Y < 0) { transy = (float)(rect.Y * -1.0f); } mTranslate = Matrix3x2.CreateTranslation(transx, transy); //return Matrix3x2.Add(mScale, mTranslate); return(Matrix3x2.Multiply(mScale, mTranslate)); }//
/// <summary> /// Redraws the GeometrySurface with the given size, geometry, foreground brush and background brush /// </summary> /// <param name="surfaceLock">The object to lock to prevent multiple threads /// from accessing the surface at the same time.</param> /// <param name="surface">CompositionDrawingSurface</param> /// <param name="size">Size ofthe GeometrySurface</param> /// <param name="geometry">Geometry of the GeometrySurface</param> /// <param name="foregroundBrush">The brush with which the geometry has to be filled</param> /// <param name="backgroundBrush">The brush with which the GeometrySurface background has to be filled</param> public void RedrawGeometrySurface(object surfaceLock, CompositionDrawingSurface surface, Size size, CanvasGeometry geometry, ICanvasBrush foregroundBrush, ICanvasBrush backgroundBrush) { // If the surface is not created, create it if (surface == null) { surface = CreateDrawingSurface(surfaceLock, size); } // No need to render if the width and/or height of the surface is zero if (surface.Size.Width.IsZero() || surface.Size.Height.IsZero()) { return; } // // Since multiple threads could be trying to get access to the device/surface // at the same time, we need to do any device/surface work under a lock. // lock (surfaceLock) { // Render the mask to the surface using (var session = CanvasComposition.CreateDrawingSession(surface)) { // First fill the background var brush = backgroundBrush as CanvasSolidColorBrush; if (brush != null) { // If the backgroundBrush is a SolideColorBrush then use the Clear() // method to fill the surface with background color. It is faster. // Clear the surface with the background color session.Clear(brush.Color); } else { // Fill the surface with the background brush. session.FillRectangle(0, 0, size.Width.Single(), size.Height.Single(), backgroundBrush); } // If the geometry is not null then fill the geometry area with the foreground brush. if (geometry != null) { session.FillGeometry(geometry, foregroundBrush); } } } }
// - - - Shape tree root for layer: icon // - - ShapeGroup: Group 2 CanvasGeometry Geometry_1() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.BeginFigure(new Vector2(0F, 35F)); builder.AddCubicBezier(new Vector2(-4.1420002F, 35F), new Vector2(-7.5F, 38.3580017F), new Vector2(-7.5F, 42.5F)); builder.AddCubicBezier(new Vector2(-7.5F, 46.6419983F), new Vector2(-4.1420002F, 50F), new Vector2(0F, 50F)); builder.AddCubicBezier(new Vector2(4.1420002F, 50F), new Vector2(7.5F, 46.6419983F), new Vector2(7.5F, 42.5F)); builder.AddCubicBezier(new Vector2(7.5F, 38.3580017F), new Vector2(4.1420002F, 35F), new Vector2(0F, 35F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
// - - - - Shape tree root for layer: icon // - - - Offset:<-3.8320007, 0> // - - Path 3+Path 1.PathGeometry CanvasGeometry Geometry_5() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.BeginFigure(new Vector2(-40F, 30F)); builder.AddCubicBezier(new Vector2(-28.9540005F, 30F), new Vector2(-20F, 21.0459995F), new Vector2(-20F, 10F)); builder.AddCubicBezier(new Vector2(-20F, -1.046F), new Vector2(-28.9540005F, -10F), new Vector2(-40F, -10F)); builder.AddCubicBezier(new Vector2(-51.0460014F, -10F), new Vector2(-60F, -1.046F), new Vector2(-60F, 10F)); builder.AddCubicBezier(new Vector2(-60F, 21.0459995F), new Vector2(-51.0460014F, 30F), new Vector2(-40F, 30F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
/// <summary> /// Constructor /// </summary> /// <param name="generator">ICompositionMaskGeneratorInternal object</param> /// <param name="size">Size of the MaskSurface</param> /// <param name="geometry">Geometry of the MaskSurface</param> public MaskSurface(ICompositionGeneratorInternal generator, Size size, CanvasGeometry geometry) { if (generator == null) { throw new ArgumentNullException(nameof(generator), "CompositionGenerator cannot be null!"); } _generator = generator; _surfaceLock = new object(); _geometry = geometry; // Create Mask Surface _surface = _generator.CreateDrawingSurface(_surfaceLock, size); // Set the size Size = _surface?.Size ?? new Size(0, 0); // Subscribe to DeviceReplaced event _generator.DeviceReplaced += OnDeviceReplaced; }
// - - - - - Shape tree root for layer: icon // - - - - Offset:<-3.8320007, 0> // - - - Path 3+Path 1.PathGeometry // - - Path CanvasGeometry Geometry_16() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.BeginFigure(new Vector2(70F, 30F)); builder.AddCubicBezier(new Vector2(81.0459976F, 30F), new Vector2(90F, 21.0459995F), new Vector2(90F, 10F)); builder.AddCubicBezier(new Vector2(90F, -1.046F), new Vector2(81.0459976F, -10F), new Vector2(70F, -10F)); builder.AddCubicBezier(new Vector2(58.9539986F, -10F), new Vector2(50F, -1.046F), new Vector2(50F, 10F)); builder.AddCubicBezier(new Vector2(50F, 21.0459995F), new Vector2(58.9539986F, 30F), new Vector2(70F, 30F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
protected void DrawGaugeArc(CanvasControl sender, CanvasDrawingSession ds, float startAngle, float endAngle, Color color, CanvasSweepDirection canvasSweepDirection, CanvasArcSize canvasArcSize) { using (CanvasPathBuilder cp = new CanvasPathBuilder(sender)) { var startPoint = this.Center + Vector2.Transform(Vector2.UnitX, Matrix3x2.CreateRotation(startAngle)) * this.Radius; var endPoint = this.Center + Vector2.Transform(Vector2.UnitX, Matrix3x2.CreateRotation(endAngle)) * this.Radius; cp.BeginFigure(startPoint); cp.AddArc(endPoint, this.Radius, this.Radius, 0, canvasSweepDirection, canvasArcSize); cp.EndFigure(CanvasFigureLoop.Open); using (var geometry = CanvasGeometry.CreatePath(cp)) { ds.DrawGeometry(geometry, color, c_arcThickness, this.ArcStrokeStyle); } } }
private CanvasGeometry CreateGeometry(ICanvasResourceCreator session) { var w = renderSize.X; var h = renderSize.Y; using (var builder = new CanvasPathBuilder(session.Device)) { builder.BeginFigure(new Vector2(0.15f * w, 0.5f * h)); builder.AddLine(0.40f * w, 0.75f * h); builder.AddLine(0.85f * w, 0.25f * h); builder.EndFigure(CanvasFigureLoop.Open); return(CanvasGeometry.CreatePath(builder)); } }
CanvasGeometry Geometry_1() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.BeginFigure(new Vector2(40F, 20F)); builder.AddCubicBezier(new Vector2(45.5229988F, 20F), new Vector2(50F, 15.5229998F), new Vector2(50F, 10F)); builder.AddCubicBezier(new Vector2(50F, 4.47700024F), new Vector2(45.5229988F, 0F), new Vector2(40F, 0F)); builder.AddCubicBezier(new Vector2(34.4770012F, 0F), new Vector2(30F, 4.47700024F), new Vector2(30F, 10F)); builder.AddCubicBezier(new Vector2(30F, 15.5229998F), new Vector2(34.4770012F, 20F), new Vector2(40F, 20F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
// - - - Shape tree root for layer: icon // - - ShapeGroup: Group 3 CanvasGeometry Geometry_0() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.BeginFigure(new Vector2(0F, -80F)); builder.AddCubicBezier(new Vector2(44.1829987F, -80F), new Vector2(80F, -44.1829987F), new Vector2(80F, 0F)); builder.AddCubicBezier(new Vector2(80F, 44.1829987F), new Vector2(44.1829987F, 80F), new Vector2(0F, 80F)); builder.AddCubicBezier(new Vector2(-44.1829987F, 80F), new Vector2(-80F, 44.1829987F), new Vector2(-80F, 0F)); builder.AddCubicBezier(new Vector2(-80F, -44.1829987F), new Vector2(-44.1829987F, -80F), new Vector2(0F, -80F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
static void DrawContactGeometry(CanvasDrawingSession ds, CanvasGeometry geom) { if (geom == null) return; ds.FillGeometry(geom, Colors.Green); ds.DrawGeometry(geom, Colors.Blue, 5); }
void EnsureResources(ICanvasResourceCreatorWithDpi resourceCreator, Size targetSize) { if (!needsResourceRecreation) return; if (textLayout != null) { textLayout.Dispose(); textReference.Dispose(); textBrush.Dispose(); } textLayout = CreateTextLayout(resourceCreator, (float)targetSize.Width, (float)targetSize.Height); textReference = CanvasGeometry.CreateText(textLayout); textBrush = new CanvasSolidColorBrush(resourceCreator, Colors.LightBlue); needsResourceRecreation = false; }
/// <summary> /// Resizes the MaskSurface with the given size and redraws the MaskSurface /// with the new geometry and fills it either with White color /// (if the MaskMode is True) or with the foreground brush /// (if the MaskMode is False). /// </summary> /// <param name="size">New size of the mask</param> /// <param name="geometry">New CanvasGeometry to be applied to the mask</param> public void Redraw(Size size, CanvasGeometry geometry) { // Resize the mask surface _generator.ResizeDrawingSurface(_surfaceLock, _surface, size); // Set the size Size = _surface?.Size ?? new Size(0, 0); // Set the new geometry _geometry = geometry; // Redraw the mask surface RedrawSurfaceInternal(); }
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; } }
/// <summary> /// Creates a scale & translation matrix /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="bounds"></param> /// <param name="outBounds"></param> /// <returns></returns> public Matrix3x2 CreateMatrix(int width, int height, out Rect outBounds, out Matrix3x2 mScale, out Matrix3x2 mTranslate) { float scale = 1f; Rect rect = new Rect(_bounds.X, _bounds.Y, _bounds.Width, _bounds.Height); //_cg.ComputeBounds();//(testMatrix, testPen); mScale = new Matrix3x2(); mTranslate = new Matrix3x2(); float sx = (float)(width / rect.Width); float sy = (float)(height / rect.Height); if (sx < sy) { scale = sx; } else { scale = sy; } mScale = Matrix3x2.CreateScale(scale, scale); outBounds = new Rect(0, 0, _bounds.Width * scale, _bounds.Height * scale); _cgBounds = CanvasGeometry.CreateRectangle(_cg.Device, _bounds); _cgBounds = _cgBounds.Transform(mScale); rect = _cgBounds.ComputeBounds(); float transx = 0; float transy = 0; if (rect.X < 0) transx = (float)(rect.X * -1.0f); if (rect.Y < 0) transy = (float)(rect.Y * -1.0f); mTranslate = Matrix3x2.CreateTranslation(transx, transy); //return Matrix3x2.Add(mScale, mTranslate); return Matrix3x2.Multiply(mScale, mTranslate); }//
/// <summary> /// Creates a MaskSurface having the given size and geometry with MaskMode as True. /// The geometry is filled with white color. The surface not covered by the geometry is /// transparent. /// </summary> /// <param name="size">Size of the mask</param> /// <param name="geometry">Geometry of the mask</param> /// <returns>IMaskSurface</returns> public IMaskSurface CreateMaskSurface(Size size, CanvasGeometry geometry) { // Initialize the mask IMaskSurface mask = new MaskSurface(this, size, geometry); // Render the mask mask.Redraw(); return mask; }
/// <summary> /// Draws a raindrop on canvas at the current position. /// </summary> public void Draw(RainyDay rainyday, CanvasDrawingSession context) { float orgR = r; r = 0.95f * r; if (r < 3) { clipGeo = CanvasGeometry.CreateCircle(context, new Vector2(x, y), r); } else if (colliding != null || yspeed > 2) { if (colliding != null) { var collider = colliding; r = 1.001f * (r > collider.r ? r : collider.r); x += (collider.x - x); colliding = null; } float yr = 1 + 0.1f * yspeed; using (CanvasPathBuilder path = new CanvasPathBuilder(context)) { path.BeginFigure(x - r / yr, y); path.AddCubicBezier(new Vector2(x - r, y - r * 2), new Vector2(x + r, y - r * 2), new Vector2(x + r / yr, y)); path.AddCubicBezier(new Vector2(x + r, y + yr * r), new Vector2(x - r, y + yr * r), new Vector2(x - r / yr, y)); path.EndFigure(CanvasFigureLoop.Closed); clipGeo = CanvasGeometry.CreatePath(path); } } else { clipGeo = CanvasGeometry.CreateCircle(context, new Vector2(x, y), 0.9f * r); } r = orgR; if (rainyday.Reflection != null) { using (context.CreateLayer(1, clipGeo)) { rainyday.Reflection(context, this); } } if (clipGeo != null) { clipGeo.Dispose(); } }
public SharedResources(CanvasDevice device) { Device = device; arrow = MakeDirectionIcon(); }
private async Task<CompositionMaskBrush> CreateMask(Color color, CanvasGeometry geometry, Vector2 size) { var compositionMask = await generator.CreateMaskAsync(size.ToSize(), geometry); var mask = compositor.CreateSurfaceBrush(compositionMask.Surface); var source = compositor.CreateColorBrush(color); var maskBrush = compositor.CreateMaskBrush(); maskBrush.Mask = mask; maskBrush.Source = source; return maskBrush; }
private void canvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args) { arrow = MakeDirectionIcon(sender); var bounds = arrow.ComputeStrokeBounds(3); var outline = arrow.Stroke(2).Outline(); var foregroundBrush = (SolidColorBrush)directionsCombo.Foreground; var color = foregroundBrush.Color; Directions = new List<DirectionInfo>(); foreach (CanvasTextDirection direction in Enum.GetValues(typeof(CanvasTextDirection))) { var arrowImage = new CanvasImageSource(sender, 64, 64); using (var ds = arrowImage.CreateDrawingSession(Colors.Transparent)) { var directionTransform = GetDirectionTransform(direction); ds.Transform = directionTransform * Matrix3x2.CreateTranslation((float)(32 - bounds.Width / 2), (float)(32 - bounds.Height / 2)); ds.DrawGeometry(arrow, color, 1); } Directions.Add(new DirectionInfo(direction, arrowImage)); } // Poke the property so that the control gets a chance to pick up the new images if (PropertyChanged != null) { PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Directions")); PropertyChanged.Invoke(this, new PropertyChangedEventArgs("CurrentDirectionIndex")); } }
/// <summary> /// Resizes the GeometrySurface with the given size and redraws the GeometrySurface /// with the new geometry and fills it with the foreground color and the background /// with the background brush. /// </summary> /// <param name="size">New size of the GeometrySurface</param> /// <param name="geometry">New CanvasGeometry to be applied to the GeometrySurface</param> /// <param name="foregroundColor">Fill color for the geometry</param> /// <param name="backgroundBrush">Brush to fill the GeometrySurface background</param> public void Redraw(Size size, CanvasGeometry geometry, Color foregroundColor, ICanvasBrush backgroundBrush) { _generator.ResizeDrawingSurface(_surfaceLock, _surface, size); // Set the size Size = _surface?.Size ?? new Size(0, 0); // Set the new geometry _geometry = geometry; // Set the foregroundBrush _foregroundBrush = new CanvasSolidColorBrush(_generator.Device, foregroundColor); // Set the backgroundBrush _backgroundBrush = backgroundBrush ?? new CanvasSolidColorBrush(_generator.Device, Colors.Transparent); // Redraw the GeometrySurface RedrawSurfaceInternal(); }
/// <summary> /// Constructor /// </summary> /// <param name="generator">ICompositionMaskGeneratorInternal object</param> /// <param name="size">Size of the GeometrySurface</param> /// <param name="geometry">Geometry of the GeometrySurface</param> /// <param name="foregroundColor">Fill color of the geometry</param> /// <param name="backgroundColor">Brush to fill the GeometrySurface background surface which is /// not covered by the geometry</param> public GeometrySurface(ICompositionGeneratorInternal generator, Size size, CanvasGeometry geometry, Color foregroundColor, Color backgroundColor) { if (generator == null) throw new ArgumentNullException(nameof(generator), "CompositionGenerator cannot be null!"); _generator = generator; _surfaceLock = new object(); _geometry = geometry; _foregroundBrush = new CanvasSolidColorBrush(_generator.Device, foregroundColor); _backgroundBrush = new CanvasSolidColorBrush(_generator.Device, backgroundColor); // Create GeometrySurface _surface = _generator.CreateDrawingSurface(_surfaceLock, size); // Set the size Size = _surface?.Size ?? new Size(0, 0); // Subscribe to DeviceReplaced event _generator.DeviceReplaced += OnDeviceReplaced; }
static void DrawFaceInCenterOfGeometry(CanvasDrawingSession ds, CanvasGeometry geom) { if (geom == null) return; var bounds = geom.ComputeBounds(); var centerX = bounds.X + bounds.Width / 2; var centerY = bounds.Y + bounds.Height / 2; var center = new Vector2((float)centerX, (float)centerY); ds.DrawText("ಠ⌣ಠ", center, Colors.White, new CanvasTextFormat() { FontSize = 36, HorizontalAlignment = CanvasHorizontalAlignment.Center, VerticalAlignment = CanvasVerticalAlignment.Center }); }
public SVGPath(SVGPath path) { _ID = path._ID; _cg = path._cg.Transform(Matrix3x2.Identity); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
/// <summary> /// Creates a GeometrySurface having the given size, geometry, foreground color and /// background color with MaskMode as False. /// </summary> /// <param name="size">Size of the mask</param> /// <param name="geometry">Geometry of the mask</param> /// <param name="foregroundColor">Fill color of the geometry</param> /// <param name="backgroundColor">Fill color of the Mask surface background which is /// not covered by the geometry</param> /// <returns>IGeometrySurface</returns> public IGeometrySurface CreateGeometrySurface(Size size, CanvasGeometry geometry, Color foregroundColor, Color backgroundColor) { // Initialize the mask IGeometrySurface mask = new GeometrySurface(this, size, geometry, foregroundColor, backgroundColor); // Render the mask mask.Redraw(); return mask; }
public void Draw(CanvasRenderTarget crt, Color lineColor, float lineWidth, Color fillColor, Matrix3x2 m) { //CanvasDevice device = CanvasDevice.GetSharedDevice(); //CanvasRenderTarget offscreen = new CanvasRenderTarget(device, width, height, 96); using (CanvasDrawingSession ds = crt.CreateDrawingSession()) { //ds.Clear(Colors.Transparent); //ds.DrawRectangle(100, 200, 5, 6, Colors.Red); // Debug.WriteLine(_cg.ComputeBounds().ToString()); if (m.IsIdentity == false) { _cg = _cg.Transform(m); //Debug.WriteLine(_cg.ComputeBounds().ToString()); } if (!(lineColor == Colors.Transparent)) { ds.DrawGeometry(_cg, lineColor,lineWidth); } if (fillColor != null) ds.FillGeometry(_cg, fillColor); } }
/// <summary> /// Disposes the resources used by the MaskSurface /// </summary> public void Dispose() { _surface?.Dispose(); _geometry?.Dispose(); if (_generator != null) _generator.DeviceReplaced -= OnDeviceReplaced; _surface = null; _generator = null; _geometry = null; }
void EnsureResources(ICanvasResourceCreatorWithDpi resourceCreator, Size targetSize) { if (!needsResourceRecreation) return; if (textLayout != null) { textLayout.Dispose(); textGeometry.Dispose(); } textLayout = CreateTextLayout(resourceCreator, (float)targetSize.Width, (float)targetSize.Height); textGeometry = CanvasGeometry.CreateText(textLayout); needsResourceRecreation = false; }
private void OnLoaded(object sender, RoutedEventArgs e) { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor); _width = 300f; _height = 300f; // Create the combined geometry var ellipse1 = CanvasGeometry.CreateEllipse(_generator.Device, _width / 2, _height / 2, 0.45f * _width, 0.225f * _height); var ellipse2 = CanvasGeometry.CreateEllipse(_generator.Device, _width / 2, _height / 2, 0.225f * _width, 0.45f * _height); _combinedGeometry = ellipse1.CombineWith(ellipse2, Matrix3x2.Identity, CanvasGeometryCombine.Union); // Create custom shaped visual using CompositionMaskBrush _visual1 = _compositor.CreateSpriteVisual(); _visual1.Size = new Vector2(_width, _height); _visual1.Offset = new Vector3(((CompositionGrid1.ActualWidth - _width) / 2).Single(), ((CompositionGrid1.ActualHeight - _height) / 2).Single(), 0); var visualChild = _compositor.CreateSpriteVisual(); visualChild.Size = new Vector2(_width * 0.75f, _height * 0.75f); visualChild.Offset = new Vector3(_width*0.125f, _height*0.125f, 0); _visual1.Children.InsertAtTop(visualChild); // Create the CompositionMask var compositionMask = _generator.CreateMaskSurface(_visual1.Size.ToSize(), _combinedGeometry); // Create SurfaceBrush from CompositionMask var mask = _compositor.CreateSurfaceBrush(compositionMask.Surface); var source = _compositor.CreateColorBrush(Color.FromArgb(255, 0, 173, 239)); // Create mask brush var maskBrush = _compositor.CreateMaskBrush(); maskBrush.Mask = mask; maskBrush.Source = source; _visual1.Brush = maskBrush; ElementCompositionPreview.SetElementChildVisual(CompositionGrid1, _visual1); // Create custom shaped visual using CompositionMaskBrush _visual2 = _compositor.CreateSpriteVisual(); _visual2.Size = new Vector2(_width, _height); _visual2.Offset = new Vector3(((CompositionGrid2.ActualWidth - _width) / 2).Single(), ((CompositionGrid2.ActualHeight - _height) / 2).Single(), 0); // Create the CompositionMask filled with color var compositionMask2 = _generator.CreateGeometrySurface(_visual2.Size.ToSize(), _combinedGeometry, Color.FromArgb(192, 192, 0, 0)); // Create SurfaceBrush from CompositionMask var surfaceBrush = _compositor.CreateSurfaceBrush(compositionMask2.Surface); _visual2.Brush = surfaceBrush; ElementCompositionPreview.SetElementChildVisual(CompositionGrid2, _visual2); // Initialize the visuals for the Animated Canvas // Create the container to host the visuals var container = _compositor.CreateContainerVisual(); container.Size = new Vector2(CompositionGrid3.ActualWidth.Single(), CompositionGrid3.ActualHeight.Single()); // Background Visual _bgVisual = _compositor.CreateSpriteVisual(); _bgVisual.Size = new Vector2(_width, _height); _bgVisual.Offset = new Vector3(((CompositionGrid3.ActualWidth - _width) / 2).Single(), ((CompositionGrid3.ActualHeight - _height) / 2).Single(), 0); var radians = ((45f*Math.PI)/180).Single(); var bgGeometry = _combinedGeometry.Transform(Matrix3x2.CreateRotation(radians, new Vector2(_width/2, _height/2))); var bgMask = _generator.CreateGeometrySurface(_bgVisual.Size.ToSize(), bgGeometry, Color.FromArgb(255, 0, 173, 239)); var bgBrush = _compositor.CreateSurfaceBrush(bgMask.Surface); _bgVisual.Brush = bgBrush; container.Children.InsertAtBottom(_bgVisual); // Animated Visual _animatedVisual = _compositor.CreateSpriteVisual(); _animatedVisual.Size = new Vector2(_width, _height); _animatedVisual.Offset = new Vector3(((CompositionGrid3.ActualWidth - _width) / 2).Single(), ((CompositionGrid3.ActualHeight - _height) / 2).Single(), 0); // Create the Excluded geometry _outerGeometry = CanvasGeometry.CreateRectangle(_generator.Device, 0, 0, _width, _height); var excludedGeometry = _outerGeometry.CombineWith(_combinedGeometry, Matrix3x2.Identity, CanvasGeometryCombine.Exclude); // Create the CompositionMask _animatedMaskSurface = _generator.CreateGeometrySurface(_animatedVisual.Size.ToSize(), excludedGeometry, Color.FromArgb(192, 192, 0, 0)); var animBrush = _compositor.CreateSurfaceBrush(_animatedMaskSurface.Surface); _animatedVisual.Brush = animBrush; container.Children.InsertAtTop(_animatedVisual); ElementCompositionPreview.SetElementChildVisual(CompositionGrid3, container); }
/// <summary> /// Creates a GeometrySurface having the given size, geometry, foreground brush and /// background brush with MaskMode as False. /// </summary> /// <param name="size">Size of the mask</param> /// <param name="geometry">Geometry of the mask</param> /// <param name="foregroundBrush">The brush with which the geometry has to be filled</param> /// <param name="backgroundBrush">The brush to fill the Mask background surface which is /// not covered by the geometry</param> /// <returns>IGeometrySurface</returns> public IGeometrySurface CreateGeometrySurface(Size size, CanvasGeometry geometry, ICanvasBrush foregroundBrush, ICanvasBrush backgroundBrush) { // Initialize the mask IGeometrySurface mask = new GeometrySurface(this, size, geometry, foregroundBrush, backgroundBrush); // Render the mask mask.Redraw(); return mask; }
private void RecreateGeometry(ICanvasResourceCreator resourceCreator) { leftGeometry = CreateGeometry(resourceCreator, LeftGeometryType); rightGeometry = CreateGeometry(resourceCreator, RightGeometryType); if (enableTransform) { Matrix3x2 placeNearOrigin = Matrix3x2.CreateTranslation(-200, -200); Matrix3x2 undoPlaceNearOrigin = Matrix3x2.CreateTranslation(200, 200); Matrix3x2 rotate0 = Matrix3x2.CreateRotation((float)Math.PI / 4.0f); // 45 degrees Matrix3x2 scale0 = Matrix3x2.CreateScale(1.5f); Matrix3x2 rotate1 = Matrix3x2.CreateRotation((float)Math.PI / 6.0f); // 30 degrees Matrix3x2 scale1 = Matrix3x2.CreateScale(2.0f); leftGeometry = leftGeometry.Transform(placeNearOrigin * rotate0 * scale0 * undoPlaceNearOrigin); rightGeometry = rightGeometry.Transform(placeNearOrigin * rotate1 * scale1 * undoPlaceNearOrigin); } combinedGeometry = leftGeometry.CombineWith(rightGeometry, interGeometryTransform, WhichCombineType); if (UseFillOrStroke == FillOrStroke.Stroke) { CanvasStrokeStyle strokeStyle = new CanvasStrokeStyle(); strokeStyle.DashStyle = CanvasDashStyle.Dash; combinedGeometry = combinedGeometry.Stroke(15.0f, strokeStyle); } totalDistanceOnContourPath = combinedGeometry.ComputePathLength(); if (showTessellation) { tessellation = combinedGeometry.Tessellate(); } }
/// <summary> /// Creates a GeometrySurface having the given size, geometry, foreground color and /// background brush with MaskMode as False. /// </summary> /// <param name="size">Size of the mask</param> /// <param name="geometry">Geometry of the mask</param> /// <param name="foregroundColor">Fill color of the geometry</param> /// <param name="backgroundBrush">The brush to fill the Mask background surface which is /// not covered by the geometry</param> /// <returns>IGeometrySurface</returns> public IGeometrySurface CreateGeometrySurface(Size size, CanvasGeometry geometry, Color foregroundColor, ICanvasBrush backgroundBrush) { // Create the foreground brush var foregroundBrush = new CanvasSolidColorBrush(Device, foregroundColor); // Initialize the mask IGeometrySurface mask = new GeometrySurface(this, size, geometry, foregroundBrush, backgroundBrush); // Render the mask mask.Redraw(); return mask; }
/// <summary> /// Redraws the MaskSurface with the given size and geometry /// </summary> /// <param name="surfaceLock">The object to lock to prevent multiple threads /// from accessing the surface at the same time.</param> /// <param name="surface">CompositionDrawingSurface</param> /// <param name="size">Size ofthe MaskSurface</param> /// <param name="geometry">Geometry of the MaskSurface</param> public void RedrawMaskSurface(object surfaceLock, CompositionDrawingSurface surface, Size size, CanvasGeometry geometry) { // If the surface is not created, create it if (surface == null) { surface = CreateDrawingSurface(surfaceLock, size); } // No need to render if the width and/or height of the surface is zero if (surface.Size.Width.IsZero() || surface.Size.Height.IsZero()) return; // // Since multiple threads could be trying to get access to the device/surface // at the same time, we need to do any device/surface work under a lock. // lock (surfaceLock) { // Render the mask to the surface using (var session = CanvasComposition.CreateDrawingSession(surface)) { if (geometry != null) { // If the geometry is not null then fill the geometry area // with the White color. The rest of the area on the surface will be transparent. // When this mask is applied to a visual, only the area that is white will be visible. session.Clear(Colors.Transparent); session.FillGeometry(geometry, Colors.White); } else { // If the geometry is null, then the entire mask should be filled the // the given color. If the color is white, then the masked visual will be seen completely. session.FillRectangle(0, 0, size.Width.Single(), size.Height.Single(), Colors.White); } } } }
void EnsureResources(ICanvasResourceCreatorWithDpi resourceCreator, Size targetSize) { if (resourceRealizationSize != targetSize && !needsResourceRecreation) return; float canvasWidth = (float)targetSize.Width; float canvasHeight = (float)targetSize.Height; if (textLayout != null) { textLayout.Dispose(); textGeometry.Dispose(); } textLayout = CreateTextLayout(resourceCreator, canvasWidth, canvasHeight); textGeometry = CanvasGeometry.CreateText(textLayout); needsResourceRecreation = false; resourceRealizationSize = targetSize; }
/// <summary> /// Redraws the GeometrySurface with the given size, geometry, foreground brush and background brush /// </summary> /// <param name="surfaceLock">The object to lock to prevent multiple threads /// from accessing the surface at the same time.</param> /// <param name="surface">CompositionDrawingSurface</param> /// <param name="size">Size ofthe GeometrySurface</param> /// <param name="geometry">Geometry of the GeometrySurface</param> /// <param name="foregroundBrush">The brush with which the geometry has to be filled</param> /// <param name="backgroundBrush">The brush with which the GeometrySurface background has to be filled</param> public void RedrawGeometrySurface(object surfaceLock, CompositionDrawingSurface surface, Size size, CanvasGeometry geometry, ICanvasBrush foregroundBrush, ICanvasBrush backgroundBrush) { // If the surface is not created, create it if (surface == null) { surface = CreateDrawingSurface(surfaceLock, size); } // No need to render if the width and/or height of the surface is zero if (surface.Size.Width.IsZero() || surface.Size.Height.IsZero()) return; // // Since multiple threads could be trying to get access to the device/surface // at the same time, we need to do any device/surface work under a lock. // lock (surfaceLock) { // Render the mask to the surface using (var session = CanvasComposition.CreateDrawingSession(surface)) { // First fill the background var brush = backgroundBrush as CanvasSolidColorBrush; if (brush != null) { // If the backgroundBrush is a SolideColorBrush then use the Clear() // method to fill the surface with background color. It is faster. // Clear the surface with the background color session.Clear(brush.Color); } else { // Fill the surface with the background brush. session.FillRectangle(0, 0, size.Width.Single(), size.Height.Single(), backgroundBrush); } // If the geometry is not null then fill the geometry area with the foreground brush. if (geometry != null) { session.FillGeometry(geometry, foregroundBrush); } } } }
/// <summary> /// Redraws the MaskSurface with the new geometry /// </summary> /// <param name="geometry">New CanvasGeometry to be applied to the mask</param> public void Redraw(CanvasGeometry geometry) { // Set the new geometry _geometry = geometry; // Redraw the mask surface RedrawSurfaceInternal(); }
void EnsureResources(ICanvasResourceCreatorWithDpi resourceCreator, Size targetSize) { if (!needsResourceRecreation) return; if (textLayout != null) { textLayout.Dispose(); textGeometry.Dispose(); } textLayout = CreateTextLayout(resourceCreator, (float)targetSize.Width, (float)targetSize.Height); if (CurrentTextOutlineGranularityOption == TextOutlineGranularity.Layout) { textGeometry = CanvasGeometry.CreateText(textLayout); } else { GlyphRunsToGeometryConverter converter = new GlyphRunsToGeometryConverter(resourceCreator); textLayout.DrawToTextRenderer(converter, 0, 0); textGeometry = converter.GetGeometry(); } needsResourceRecreation = false; }