Exemplo n.º 1
0
        public void Activate()
        {
            Window window = NUIApplication.GetDefaultWindow();

            root = new View()
            {
                Size                   = window.Size,
                ParentOrigin           = ParentOrigin.Center,
                PivotPoint             = PivotPoint.Center,
                PositionUsesPivotPoint = true,
            };
            window.Add(root);

            canvasView = new CanvasView(window.Size)
            {
                Size                   = window.Size,
                ParentOrigin           = ParentOrigin.Center,
                PivotPoint             = PivotPoint.Center,
                PositionUsesPivotPoint = true,
            };

            RadialGradient roundedRectFillRadialGradient = new RadialGradient()
            {
                ColorStops = new List <ColorStop>()
                {
                    new ColorStop(0.0f, new Color(1.0f, 0.0f, 0.0f, 1.0f)),
                    new ColorStop(0.5f, new Color(0.0f, 1.0f, 0.0f, 1.0f)),
                    new ColorStop(1.0f, new Color(0.0f, 0.0f, 1.0f, 1.0f))
                }.AsReadOnly(),
                           Spread = SpreadType.Reflect,
            };

            roundedRectFillRadialGradient.SetBounds(new Position2D(0, 0), 30);

            roundedRectShape = new Shape()
            {
                FillColor    = new Color(0.5f, 1.0f, 0.0f, 1.0f),
                StrokeColor  = new Color(0.5f, 0.0f, 0.0f, 0.5f),
                StrokeWidth  = 10.0f,
                FillGradient = roundedRectFillRadialGradient,
            };
            roundedRectShape.Translate(100.0f, 100.0f);
            roundedRectShape.Scale(1.2f);
            roundedRectShape.Rotate(45.0f);
            roundedRectShape.AddRect(-50.0f, -50.0f, 100.0f, 100.0f, 0.0f, 0.0f);

            Shape circleMask = new Shape()
            {
                FillColor = new Color(1.0f, 1.0f, 1.0f, 1.0f),
            };

            circleMask.AddRect(-50.0f, -50.0f, 100.0f, 100.0f, 0.0f, 0.0f);
            circleMask.Translate(350.0f, 100.0f);

            circleShape = new Shape()
            {
                Opacity     = 0.5f,
                FillColor   = new Color(0.0f, 0.0f, 1.0f, 1.0f),
                StrokeColor = new Color(1.0f, 1.0f, 0.0f, 1.0f),
                StrokeWidth = 10.0f,
                StrokeDash  = new List <float>()
                {
                    15.0f, 30.0f
                }.AsReadOnly(),
            };
            circleShape.AddCircle(0.0f, 0.0f, 150.0f, 100.0f);
            circleShape.Transform(new float[] { 0.6f, 0.0f, 350.0f, 0.0f, 0.6f, 100.0f, 0.0f, 0.0f, 1.0f });

            circleShape.Mask(circleMask, MaskType.Alpha);

            arcShape = new Shape()
            {
                StrokeColor = new Color(0.0f, 0.5f, 0.0f, 0.5f),
                StrokeWidth = 10.0f,
                StrokeJoin  = Shape.StrokeJoinType.Round,
            };
            arcShape.AddArc(0.0f, 0.0f, 80.0f, 0.0f, 0.0f, true);
            arcShape.Translate(100.0f, 300.0f);

            Shape shape = new Shape()
            {
                Opacity     = 0.5f,
                FillColor   = new Color(0.0f, 0.5f, 0.0f, 0.5f),
                StrokeColor = new Color(0.5f, 0.0f, 0.5f, 0.5f),
                StrokeWidth = 30.0f,
                FillRule    = Shape.FillRuleType.EvenOdd,
                StrokeJoin  = Shape.StrokeJoinType.Round,
            };

            shape.Scale(0.5f);
            shape.Translate(350.0f, 300.0f);

            shape.AddPath(new PathCommands(new PathCommandType[] { PathCommandType.MoveTo,
                                                                   PathCommandType.LineTo,
                                                                   PathCommandType.LineTo,
                                                                   PathCommandType.LineTo,
                                                                   PathCommandType.LineTo,
                                                                   PathCommandType.Close },
                                           new float[] { 0.0f, -160.0f,
                                                         125.0f, 160.0f,
                                                         -180.0f, -45.0f,
                                                         180.0f, -45.0f,
                                                         -125.0f, 160.0f }));

            canvasView.AddDrawable(shape);

            Shape starClipper = new Shape()
            {
                FillColor = new Color(1.0f, 1.0f, 1.0f, 1.0f),
            };

            starClipper.AddCircle(0.0f, 0.0f, 160.0f, 160.0f);
            starClipper.Translate(250.0f, 550.0f);

            LinearGradient starFillLinearGradient = new LinearGradient()
            {
                ColorStops = new List <ColorStop>()
                {
                    new ColorStop(0.0f, new Color(1.0f, 0.0f, 0.0f, 1.0f)),
                    new ColorStop(0.5f, new Color(0.0f, 1.0f, 0.0f, 1.0f)),
                    new ColorStop(1.0f, new Color(0.0f, 0.0f, 1.0f, 1.0f))
                }.AsReadOnly()
            };

            starFillLinearGradient.SetBounds(new Position2D(-50, -50), new Position2D(50, 50));

            LinearGradient starStrokeLinearGradient = new LinearGradient()
            {
                ColorStops = new List <ColorStop>()
                {
                    new ColorStop(0.0f, new Color(1.0f, 0.0f, 1.0f, 1.0f)),
                    new ColorStop(1.0f, new Color(0.0f, 1.0f, 1.0f, 1.0f))
                }.AsReadOnly()
            };

            starStrokeLinearGradient.SetBounds(new Position2D(0, -50), new Position2D(50, 50));

            starShape = new Shape()
            {
                Opacity        = 0.5f,
                FillColor      = new Color(0.0f, 1.0f, 1.0f, 1.0f),
                StrokeColor    = new Color(0.5f, 1.0f, 0.5f, 1.0f),
                StrokeWidth    = 30.0f,
                StrokeCap      = Shape.StrokeCapType.Round,
                FillGradient   = starFillLinearGradient,
                StrokeGradient = starStrokeLinearGradient,
            };

            starShape.Translate(250.0f, 550.0f);
            starShape.Scale(0.5f);
            starShape.AddMoveTo(-1.0f, -165.0f);
            starShape.AddLineTo(53.0f, -56.0f);
            starShape.AddLineTo(174.0f, -39.0f);
            starShape.AddLineTo(87.0f, 45.0f);
            starShape.AddLineTo(107.0f, 166.0f);
            starShape.AddLineTo(-1.0f, 110.0f);
            starShape.AddLineTo(-103.0f, 166.0f);
            starShape.AddLineTo(-88.0f, 46.0f);
            starShape.AddLineTo(-174.0f, -38.0f);
            starShape.AddLineTo(-54.0f, -56.0f);
            starShape.Close();

            starShape.ClipPath(starClipper);

            canvasView.AddDrawable(starShape);

            group1 = new DrawableGroup();
            group1.AddDrawable(roundedRectShape);
            group1.AddDrawable(arcShape);

            group2 = new DrawableGroup();
            group2.AddDrawable(group1);
            group2.AddDrawable(circleShape);
            canvasView.AddDrawable(group2);

            Picture picture = new Picture();

            picture.Load(CommonResource.GetDaliResourcePath() + "DaliDemo/Kid1.svg");
            picture.SetSize(new Size2D(150, 150));
            picture.Translate(300.0f, 550.0f);
            canvasView.AddDrawable(picture);

            // Test Getter
            Position2D p1 = new Position2D(9, 9), p2 = new Position2D(8, 8);

            starFillLinearGradient.GetBounds(ref p1, ref p2);
            log.Debug(tag, "Gradient Bounds : P1 :" + p1.X + " " + p1.Y + " / P2 :" + p2.X + " " + p2.Y + "\n");

            ReadOnlyCollection <ColorStop> stops = starShape.FillGradient.ColorStops;

            for (int i = 0; i < stops.Count; i++)
            {
                log.Debug(tag, "Gradient Stops :" + i + " " + stops[i].Offset + " " + stops[i].Color.R + " " + stops[i].Color.G + " " + stops[i].Color.B + " " + stops[i].Color.A + "\n");
            }

            log.Debug(tag, "picture size : " + picture.GetSize().Width + " " + picture.GetSize().Height + "\n");

            log.Debug(tag, "circleShape Color : " + circleShape.FillColor.R + " " + circleShape.FillColor.G + " " + circleShape.FillColor.B + " " + circleShape.FillColor.A + "\n");
            log.Debug(tag, "circleShape StrokeColor : " + circleShape.StrokeColor.R + " " + circleShape.StrokeColor.G + " " + circleShape.StrokeColor.B + " " + circleShape.StrokeColor.A + "\n");

            log.Debug(tag, "arcShape StrokeCap : " + arcShape.StrokeCap + "\n");

            log.Debug(tag, "shape2 FillRule : " + shape.FillRule + "\n");
            log.Debug(tag, "shape2 StrokeWidth : " + shape.StrokeWidth + "\n");
            log.Debug(tag, "shape2 StrokeJoin : " + shape.StrokeJoin + "\n");
            log.Debug(tag, "shape2 Opacity : " + shape.Opacity + "\n");

            for (int i = 0; i < circleShape.StrokeDash.Count; i++)
            {
                log.Debug(tag, "shape2 StrokeDash : " + circleShape.StrokeDash[i] + "\n");
            }

            // Exception test.
            try
            {
                circleShape.Transform(new float[] { 0.6f, 0.0f });
            }
            catch (ArgumentException e)
            {
                log.Debug(tag, "Transform : " + e.Message + "\n");
            }
            try
            {
                circleShape.Transform(null);
            }
            catch (ArgumentException e)
            {
                log.Debug(tag, "Transform : " + e.Message + "\n");
            }
            try
            {
                circleShape.StrokeDash = null;
            }
            catch (ArgumentException e)
            {
                log.Debug(tag, "StrokeDash setter : " + e.Message + "\n");
            }

            root.Add(canvasView);

            timer       = new Timer(1000 / 32);
            timer.Tick += onTick;
            timer.Start();
        }
Exemplo n.º 2
0
        public void Activate()
        {
            Window window = NUIApplication.GetDefaultWindow();

            root = new View()
            {
                Size                   = window.Size,
                ParentOrigin           = ParentOrigin.Center,
                PivotPoint             = PivotPoint.Center,
                PositionUsesPivotPoint = true,
            };
            window.Add(root);

            canvasView = new CanvasView(window.Size)
            {
                Size                   = window.Size,
                ParentOrigin           = ParentOrigin.Center,
                PivotPoint             = PivotPoint.Center,
                PositionUsesPivotPoint = true,
            };

            Shape shape1 = new Shape()
            {
                FillColor   = new Color(0.5f, 1.0f, 0.0f, 1.0f),
                StrokeColor = new Color(0.5f, 0.0f, 0.0f, 0.5f),
                StrokeWidth = 10.0f,
            };

            shape1.Translate(100.0f, 100.0f);
            shape1.Scale(1.2f);
            shape1.Rotate(45.0f);
            shape1.AddRect(-50.0f, -50.0f, 100.0f, 100.0f, 10.0f, 10.0f);

            canvasView.AddDrawable(shape1);

            Shape shape2 = new Shape()
            {
                Opacity     = 0.5f,
                FillColor   = new Color(0.0f, 0.0f, 1.0f, 1.0f),
                StrokeColor = new Color(1.0f, 1.0f, 0.0f, 1.0f),
                StrokeWidth = 10.0f,
                StrokeDash  = new List <float>()
                {
                    15.0f, 30.0f
                }.AsReadOnly(),
            };

            shape2.AddCircle(0.0f, 0.0f, 150.0f, 100.0f);
            shape2.Transform(new float[] { 0.6f, 0.0f, 350.0f, 0.0f, 0.6f, 100.0f, 0.0f, 0.0f, 1.0f });

            canvasView.AddDrawable(shape2);

            Shape shape3 = new Shape()
            {
                StrokeColor = new Color(0.0f, 0.5f, 0.0f, 0.5f),
                StrokeWidth = 10.0f,
                StrokeJoin  = Shape.StrokeJoinType.Miter,
            };

            shape3.Translate(100.0f, 300.0f);
            shape3.AddArc(0.0f, 0.0f, 80.0f, 10.0f, 120.0f, true);

            canvasView.AddDrawable(shape3);

            Shape shape4 = new Shape()
            {
                Opacity     = 0.5f,
                FillColor   = new Color(0.0f, 0.5f, 0.0f, 0.5f),
                StrokeColor = new Color(0.5f, 0.0f, 0.5f, 0.5f),
                StrokeWidth = 30.0f,
                FillRule    = Shape.FillRuleType.EvenOdd,
                StrokeJoin  = Shape.StrokeJoinType.Round,
            };

            shape4.Scale(0.5f);
            shape4.Translate(350.0f, 300.0f);
            shape4.AddMoveTo(0.0f, -160.0f);
            shape4.AddLineTo(125.0f, 160.0f);
            shape4.AddLineTo(-180.0f, -45.0f);
            shape4.AddLineTo(180.0f, -45.0f);
            shape4.AddLineTo(-125.0f, 160.0f);
            shape4.Close();

            canvasView.AddDrawable(shape4);

            shape = new Shape()
            {
                Opacity     = 0.5f,
                FillColor   = new Color(0.0f, 1.0f, 1.0f, 1.0f),
                StrokeColor = new Color(0.5f, 1.0f, 0.5f, 1.0f),
                StrokeWidth = 30.0f,
                StrokeCap   = Shape.StrokeCapType.Round,
            };
            shape.Translate(250.0f, 550.0f);
            shape.Scale(0.5f);
            shape.AddMoveTo(-1.0f, -165.0f);
            shape.AddLineTo(53.0f, -56.0f);
            shape.AddLineTo(174.0f, -39.0f);
            shape.AddLineTo(87.0f, 45.0f);
            shape.AddLineTo(107.0f, 166.0f);
            shape.AddLineTo(-1.0f, 110.0f);
            shape.AddLineTo(-103.0f, 166.0f);
            shape.AddLineTo(-88.0f, 46.0f);
            shape.AddLineTo(-174.0f, -38.0f);
            shape.AddLineTo(-54.0f, -56.0f);
            shape.Close();

            canvasView.AddDrawable(shape);

            // Test Getter
            log.Debug(tag, "Shape2 Color : " + shape2.FillColor.R + " " + shape2.FillColor.G + " " + shape2.FillColor.B + " " + shape2.FillColor.A + "\n");
            log.Debug(tag, "Shape2 StrokeColor : " + shape2.StrokeColor.R + " " + shape2.StrokeColor.G + " " + shape2.StrokeColor.B + " " + shape2.StrokeColor.A + "\n");

            log.Debug(tag, "Shape3 StrokeCap : " + shape3.StrokeCap + "\n");

            log.Debug(tag, "Shape4 FillRule : " + shape4.FillRule + "\n");
            log.Debug(tag, "Shape4 StrokeWidth : " + shape4.StrokeWidth + "\n");
            log.Debug(tag, "Shape4 StrokeJoin : " + shape4.StrokeJoin + "\n");
            log.Debug(tag, "Shape4 Opacity : " + shape4.Opacity + "\n");

            for (int i = 0; i < shape2.StrokeDash.Count; i++)
            {
                log.Debug(tag, "Shape4 StrokeDash : " + shape2.StrokeDash[i] + "\n");
            }

            // Exception test.
            try
            {
                shape2.Transform(new float[] { 0.6f, 0.0f });
            }
            catch (ArgumentException e)
            {
                log.Debug(tag, "Transform : " + e.Message + "\n");
            }
            try
            {
                shape2.Transform(null);
            }
            catch (ArgumentException e)
            {
                log.Debug(tag, "Transform : " + e.Message + "\n");
            }
            try
            {
                shape2.StrokeDash = null;
            }
            catch (ArgumentException e)
            {
                log.Debug(tag, "StrokeDash setter : " + e.Message + "\n");
            }

            root.Add(canvasView);

            timer       = new Timer(1000 / 32);
            timer.Tick += onTick;
            timer.Start();
        }