예제 #1
0
        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.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);
        }
        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);
        }
예제 #3
0
        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);
        }