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() + "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);

            // We create a constraint to perform a precalculation on the scroll-view X offset
            // and pass it to the shader uniform, along with the tile's position.
            //Constraint shaderPosition = Constraint::New<Vector3>(focusableTile, propertyIndex, TileShaderPositionConstraint(mPageWidth, position.x));
            //shaderPosition.AddSource(Source(mScrollView, ScrollView::Property::SCROLL_POSITION) );
            //shaderPosition.SetRemoveAction(Constraint::Discard );
            //shaderPosition.Apply();
            //focusableTile.Add( tileContent );

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

            borderImage.SetStyleName("DemoTileBorder");
            borderImage.ResourceUrl            = CommonResource.GetDaliResourcePath() + "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.HeightResizePolicy  = ResizePolicyType.FillToParent;

            // 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;
            //focusableTile.HoverEvent += OnTileHovered;

            return(focusableTile);
        }
Example #2
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;
            actor.PositionZ = 0.0f;
            actor.Position  = new Position(1000.0f, 0, -1000.0f);

            // 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);
            //static_cast < ItemLayout &> (*mSpiralLayout).GetItemSize(0u, Vector3(Stage::GetCurrent().GetSize()), spiralItemSize);
            // 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.SetColorMode(ColorMode.UseParentColor);
            tick.ParentOrigin = ParentOrigin.TopRight;
            tick.PivotPoint   = PivotPoint.TopRight;
            tick.Size         = spiralItemSize;
            tick.Hide();
            checkBox.Add(tick);

            if (mTapDetector)
            {
                mTapDetector.Attach(actor);
            }
            return(actor);
        }