Example #1
0
        private View CreateTile(string name, string title, Vector3 sizeMultiplier, Vector2 position)
        {
            ImageView focusableTile = new ImageView();

            focusableTile.SetStyleName("DemoTile");
            focusableTile.ResourceUrl            = CommonResource.GetDaliResourcePath() + "DaliDemo/demo-tile-texture.9.png";
            focusableTile.PositionUsesPivotPoint = true;
            focusableTile.ParentOrigin           = ParentOrigin.Center;
            focusableTile.WidthResizePolicy      = focusableTile.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
            focusableTile.SetSizeModeFactor(sizeMultiplier);
            focusableTile.Name = name;

            // Set the tile to be keyboard focusable
            focusableTile.Focusable = true;

            // Register a property with the ImageView. This allows us to inject the scroll-view position into the shader.
            PropertyValue value         = new PropertyValue(new Vector3(0.0f, 0.0f, 0.0f));
            int           propertyIndex = focusableTile.RegisterProperty("uCustomPosition", value);

            // Create an ImageView for the 9-patch border around the tile.
            ImageView borderImage = new ImageView();

            borderImage.SetStyleName("DemoTileBorder");
            borderImage.ResourceUrl            = CommonResource.GetDaliResourcePath() + "DaliDemo/item-background.9.png";
            borderImage.PositionUsesPivotPoint = true;
            borderImage.PivotPoint             = PivotPoint.Center;
            borderImage.ParentOrigin           = ParentOrigin.Center;
            borderImage.WidthResizePolicy      = borderImage.HeightResizePolicy = ResizePolicyType.FillToParent;
            borderImage.Opacity = 0.8f;
            focusableTile.Add(borderImage);

            TextLabel label = new TextLabel();

            label.PositionUsesPivotPoint = true;
            label.PivotPoint             = PivotPoint.Center;
            label.ParentOrigin           = ParentOrigin.Center;
            label.SetStyleName("LauncherLabel");
            label.MultiLine           = true;
            label.Text                = title;
            label.HorizontalAlignment = HorizontalAlignment.Center;
            label.VerticalAlignment   = VerticalAlignment.Center;
            label.WidthResizePolicy   = ResizePolicyType.FillToParent;
            label.HeightResizePolicy  = ResizePolicyType.FillToParent;

            var fit = new PropertyMap();

            fit.Add("enable", new PropertyValue(true)).Add("minSize", new PropertyValue(5.0f)).Add("maxSize", new PropertyValue(50.0f));
            label.TextFit = fit;

            // Pad around the label as its size is the same as the 9-patch border. It will overlap it without padding.
            label.SetPadding(new PaddingType((int)TILE_LABEL_PADDING, (int)TILE_LABEL_PADDING, (int)TILE_LABEL_PADDING, (int)TILE_LABEL_PADDING));

            focusableTile.Add(label);

            // Connect to the touch events
            focusableTile.TouchEvent += OnTilePressed;

            return(focusableTile);
        }
Example #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,
            };

            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();
        }
Example #3
0
        public View NewItemView(uint itemId)
        {
            // Create an image view for this item
            string imagePath = CommonResource.GetDaliResourcePath() + "ItemViewDemo/gallery/gallery-medium-";
            uint   id        = itemId % 53;

            imagePath += id.ToString();
            imagePath += ".jpg";
            PropertyMap propertyMap = new PropertyMap();

            propertyMap.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
            propertyMap.Insert(ImageVisualProperty.URL, new PropertyValue(imagePath));
            propertyMap.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int)VisualFittingModeType.FitKeepAspectRatio));
            ImageView actor = new ImageView();

            actor.Image = propertyMap;

            // Add a border image child actor
            ImageView borderActor = new ImageView();

            borderActor.ParentOrigin           = ParentOrigin.Center;
            borderActor.PivotPoint             = PivotPoint.Center;
            borderActor.PositionUsesPivotPoint = true;
            borderActor.HeightResizePolicy     = ResizePolicyType.SizeFixedOffsetFromParent;
            borderActor.WidthResizePolicy      = ResizePolicyType.SizeFixedOffsetFromParent;
            borderActor.SetSizeModeFactor(new Vector3(2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f));
            borderActor.SetColorMode(ColorMode.UseParentColor);

            PropertyMap borderProperty = new PropertyMap();

            borderProperty.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Border));
            borderProperty.Insert(BorderVisualProperty.Color, new PropertyValue(Color.White));
            borderProperty.Insert(BorderVisualProperty.Size, new PropertyValue(ITEM_BORDER_SIZE));
            borderProperty.Insert(BorderVisualProperty.AntiAliasing, new PropertyValue(true));
            borderActor.Image = borderProperty;

            actor.Add(borderActor);

            Size spiralItemSize = new Size(30, 30, 0);
            // Add a checkbox child actor; invisible until edit-mode is enabled
            ImageView checkBox = new ImageView();

            checkBox.Name = "CheckBox";
            checkBox.SetColorMode(ColorMode.UseParentColor);
            checkBox.ParentOrigin = ParentOrigin.TopRight;
            checkBox.PivotPoint   = PivotPoint.TopRight;
            checkBox.Size         = spiralItemSize;
            checkBox.PositionZ    = 0.1f;

            PropertyMap solidColorProperty = new PropertyMap();

            solidColorProperty.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Color));
            solidColorProperty.Insert(ColorVisualProperty.MixColor, new PropertyValue(new Color(0.0f, 0.0f, 0.0f, 0.6f)));
            checkBox.Image = solidColorProperty;

            if (Mode.MODE_REMOVE_MANY != mMode &&
                Mode.MODE_INSERT_MANY != mMode &&
                Mode.MODE_REPLACE_MANY != mMode)
            {
                checkBox.Hide();
            }
            borderActor.Add(checkBox);

            ImageView tick = new ImageView(SELECTED_IMAGE);

            tick.Name         = "Tick";
            tick.ParentOrigin = ParentOrigin.TopRight;
            tick.PivotPoint   = PivotPoint.TopRight;
            tick.Size         = spiralItemSize;
            tick.Hide();
            checkBox.Add(tick);

            if (mTapDetector)
            {
                mTapDetector.Attach(actor);
            }
            return(actor);
        }
Example #4
0
 static void Main(string[] args)
 {
     new DaliDemo(CommonResource.GetDaliResourcePath() + @"../../style/demo-theme.json").Run(args);
 }