Пример #1
0
        private void OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            _c = Window.Current.Compositor;
            _g = _c.CreateCompositionGenerator();

            _rootShape      = _c.CreateShapeVisual();
            _rootShape.Size = new Vector2((float)RenderGrid.ActualWidth, (float)RenderGrid.ActualHeight);
            _rootSize       = _rootShape.Size.ToSize();

            var rectGeom = _c.CreatePathGeometry(new CompositionPath(CanvasGeometry.CreateRectangle(_g.Device, new Rect(new Point(), _rootSize))));
            var bgShape  = _c.CreateSpriteShape(rectGeom);

            bgShape.FillBrush = _c.CreateColorBrush(CanvasObject.CreateColor("#161616"));

            _rootShape.Shapes.Add(bgShape);

            for (var i = 0; i < MaxLayerCount; i++)
            {
                var shape = _c.CreateSpriteShape(_c.CreatePathGeometry(GetClip(_rootSize, 0f)));
                // Offset each of the shape to the right to hide the bump of lower layers
                shape.Offset    = HideOffset;
                shape.FillBrush = _c.CreateColorBrush(_colors[i]);
                _rootShape.Shapes.Add(shape);
            }

            _selectedIndex   = -1;
            _swipeRightIndex = -1;
            _swipeLeftIndex  = MaxLayerCount;
            _nextShapeIndex  = -1;
            // Reset offset of top most shape
            _rootShape.Shapes[MaxLayerCount].Offset = Vector2.Zero;

            ElementCompositionPreview.SetElementChildVisual(RenderGrid, _rootShape);
        }
Пример #2
0
        public MainPageWithSwipe()
        {
            InitializeComponent();

            _colors = new[]
            {
                Colors.Crimson,
                CanvasObject.CreateColor("#007aff"),
                CanvasObject.CreateColor("#4cd964"),
                CanvasObject.CreateColor("#ff2d55"),
                CanvasObject.CreateColor("#ff9600")
            };

            // Keeps track of the duration of the swipe
            _sw0 = new Stopwatch();
            _sw0.Reset();
            // Timeline for the top layer whose geometry is being animated
            _sw1 = new Stopwatch();
            _sw1.Reset();
            // Timeline for the lower layer whose offset is being animated
            _sw2 = new Stopwatch();
            _sw2.Reset();

            // The bump will appear at 2/3rd of the height from the top
            _verticalReveal = 1f;
            _swipeDir       = SwipeDirection.None;

            // Duration of the top layer geometry animation
            _a0 = TimeSpan.FromMilliseconds(DefaultGeometryAnimDuration);
            // Duration of the lower layer offset animation
            _a1 = TimeSpan.FromMilliseconds(DefaultOffsetAnimDuration);
        }
Пример #3
0
        private void OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            _c = Window.Current.Compositor;
            _g = _c.CreateCompositionGenerator();

            _rootShape      = _c.CreateShapeVisual();
            _rootShape.Size = new Vector2((float)RenderGrid.ActualWidth, (float)RenderGrid.ActualHeight);
            _rootSize       = _rootShape.Size.ToSize();

            var rectGeom = _c.CreatePathGeometry(new CompositionPath(CanvasGeometry.CreateRectangle(_g.Device, new Rect(new Point(), _rootSize))));
            var bgShape  = _c.CreateSpriteShape(rectGeom);

            bgShape.FillBrush = _c.CreateColorBrush(CanvasObject.CreateColor("#161616"));

            _rootShape.Shapes.Add(bgShape);

            _slideLeftImplicitAnimationCollection = _c.CreateImplicitAnimationCollection();
            var slideLeftAnim = _c.GenerateVector2KeyFrameAnimation()
                                .HavingDuration(700)
                                .ForTarget(() => _c.CreateSpriteShape().Offset);

            slideLeftAnim.InsertFinalValueKeyFrame(1f, _c.CreateEaseInOutBackEasingFunction());
            _slideLeftImplicitAnimationCollection["Offset"] = slideLeftAnim.Animation;

            _slideRightImplicitAnimationCollection = _c.CreateImplicitAnimationCollection();
            var slideRightAnim = _c.GenerateVector2KeyFrameAnimation()
                                 .HavingDuration(2000)
                                 .ForTarget(() => _c.CreateSpriteShape().Offset);

            slideRightAnim.InsertFinalValueKeyFrame(1f, _c.CreateEaseInOutBackEasingFunction());
            _slideRightImplicitAnimationCollection["Offset"] = slideRightAnim.Animation;

            for (var i = 0; i < MaxShapeCount; i++)
            {
                var shape = _c.CreateSpriteShape(_c.CreatePathGeometry(GetClip(_rootSize)));
                shape.Offset    = HideOffset;
                shape.FillBrush = _c.CreateColorBrush(_colors[i]);
                _rootShape.Shapes.Add(shape);
            }

            _selIndex = MaxShapeCount;
            _rootShape.Shapes[_selIndex].Offset = Vector2.Zero;

            ElementCompositionPreview.SetElementChildVisual(RenderGrid, _rootShape);
            PrevBtn.IsEnabled = false;
        }
Пример #4
0
        public MainPage()
        {
            InitializeComponent();
            _sw = new Stopwatch();
            _sw.Reset();

            verReveal     = 1f;
            _animDuration = TimeSpan.FromSeconds(1.5);
            _colors       = new Color[]
            {
                Colors.Crimson,
                CanvasObject.CreateColor("#007aff"),
                CanvasObject.CreateColor("#4cd964"),
                CanvasObject.CreateColor("#ff2d55"),
                CanvasObject.CreateColor("#ff9600")
            };
        }