Ejemplo n.º 1
0
        private void SimpleShapeImperative_Click(object sender, RoutedEventArgs e)
        {
            // Grab the compositor for the window
            compositor = Window.Current.Compositor;

            // Create a new ShapeVisual that will contain our drawings
            Windows.UI.Composition.ShapeVisual shape = compositor.CreateShapeVisual();

            // set this as a child of our host shape from XAML
            SetVisualOnElement(shape);



            // Create a circle geometry and set it's radius
            var circleGeometry = compositor.CreateEllipseGeometry();

            circleGeometry.Radius = new System.Numerics.Vector2(30, 30);

            // Create a shape object from the geometry and give it a color and offset
            var circleShape = compositor.CreateSpriteShape(circleGeometry);

            circleShape.FillBrush = compositor.CreateColorBrush(Colors.Orange);
            circleShape.Offset    = new Vector2(50f, 50f);

            // Add the circle to our shape visual
            shape.Shapes.Add(circleShape);
        }
Ejemplo n.º 2
0
        private void SimplePathImperative_Click(object sender, RoutedEventArgs e)
        {
            // Same steps as for SimpleShapeImperative_Click to create, size and host a ShapeVisual
            compositor = Window.Current.Compositor;
            Windows.UI.Composition.ShapeVisual shape = compositor.CreateShapeVisual();
            SetVisualOnElement(shape);

            // use Win2D's CanvasPathBuilder to create a simple path
            CanvasPathBuilder pathBuilder = new CanvasPathBuilder(CanvasDevice.GetSharedDevice());

            pathBuilder.BeginFigure(1, 1);
            pathBuilder.AddLine(300, 300);
            pathBuilder.AddLine(1, 300);
            pathBuilder.EndFigure(CanvasFigureLoop.Closed);

            // create a Win2D CanvasGeomtryobject from the path
            CanvasGeometry triangleGeometry = CanvasGeometry.CreatePath(pathBuilder);

            // create a CompositionPath from the Win2D geometry
            CompositionPath trianglePath = new CompositionPath(triangleGeometry);

            // create a CompositionPathGeometry from the composition path
            CompositionPathGeometry compositionPathGeometry = compositor.CreatePathGeometry(trianglePath);

            // create a SpriteShape from the CompositionPathGeometry, give it a gradient fill and add to our ShapeVisual
            CompositionSpriteShape spriteShape = compositor.CreateSpriteShape(compositionPathGeometry);

            spriteShape.FillBrush = CreateGradientBrush();

            shape.Shapes.Add(spriteShape);
        }
Ejemplo n.º 3
0
        private void PathMorphImperative_Click(object sender, RoutedEventArgs e)
        {
            // Same steps as for SimpleShapeImperative_Click to create, size and host a ShapeVisual
            compositor = Window.Current.Compositor;
            Windows.UI.Composition.ShapeVisual shape = compositor.CreateShapeVisual();
            SetVisualOnElement(shape);

            // Call helper functions that use Win2D to build square and circle path geometries and create CompositionPath's for them
            CanvasGeometry  square     = BuildSquareGeometry();
            CompositionPath squarePath = new CompositionPath(square);

            CanvasGeometry  circle     = BuildCircleGeometry();
            CompositionPath circlePath = new CompositionPath(circle);

            // Create a CompositionPathGeometry, CompositionSpriteShape and set offset and fill
            CompositionPathGeometry compositionPathGeometry = compositor.CreatePathGeometry(squarePath);
            CompositionSpriteShape  spriteShape             = compositor.CreateSpriteShape(compositionPathGeometry);

            spriteShape.Offset    = new Vector2(150, 200);
            spriteShape.FillBrush = CreateGradientBrush();

            // Create a PathKeyFrameAnimation to set up the path morph passing in the circle and square paths
            var playAnimation = compositor.CreatePathKeyFrameAnimation();

            playAnimation.Duration = TimeSpan.FromSeconds(4);
            playAnimation.InsertKeyFrame(0, squarePath);
            playAnimation.InsertKeyFrame(0.3F, circlePath);
            playAnimation.InsertKeyFrame(0.6F, circlePath);
            playAnimation.InsertKeyFrame(1.0F, squarePath);

            // Make animation repeat forever and start it
            playAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            playAnimation.Direction         = Windows.UI.Composition.AnimationDirection.Alternate;
            compositionPathGeometry.StartAnimation("Path", playAnimation);

            // Add the SpriteShape to our shape visual
            shape.Shapes.Add(spriteShape);
        }
Ejemplo n.º 4
0
 internal CompositionShapeCollection(Compositor compositor, ShapeVisual shapeVisual) : base(compositor)
     => this._shapeVisual = shapeVisual;
Ejemplo n.º 5
0
 internal CompositionShapeCollection(ShapeVisual shapeVisual) => this.shapeVisual = shapeVisual;