Esempio n. 1
0
        private void InitializeAnimations()
        {
            _props.InsertScalar("position", 0);
            _props.InsertScalar("progress", 0);

            var trackerNode = _tracker.GetReference();

            _props.StartAnimation("position", -trackerNode.Position.X);
            _props.StartAnimation("progress", EF.Abs(trackerNode.Position.X) / trackerNode.MaxPosition.X);

            ConfigureTemplateAnimations();
        }
Esempio n. 2
0
        public void ConfigureInteractionTracker()
        {
            var backgroundVisual = ElementCompositionPreview.GetElementVisual(MainGrid);

            backgroundVisual.Size = new Vector2((float)MainGrid.ActualWidth, (float)MainGrid.ActualHeight);

            // Configure interaction tracker
            _tracker             = InteractionTracker.CreateWithOwner(_compositor, this);
            _tracker.MaxPosition = new Vector3((float)backgroundVisual.Size.X * _scenarios.Count, backgroundVisual.Size.Y, 0);
            _tracker.MinPosition = new Vector3();

            // Configure interaction source
            _interactionSource = VisualInteractionSource.Create(backgroundVisual);
            _interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia;
            _tracker.InteractionSources.Add(_interactionSource);

            // Bind interaction tracker output to animation for now
            var positionExpression = -_tracker.GetReference().Position.X;

            _mainContainer.StartAnimation("Offset.X", positionExpression);

            ConfigureRestingPoints();

            var nestedVisuals = _nestedScenario.GetVisuals();
            var exp           = _compositor.CreateExpressionAnimation();

            for (int i = 0; i < nestedVisuals.Count; i++)
            {
                ConfigureParallax(i, nestedVisuals[i]);
            }
        }
Esempio n. 3
0
        public MainPage()
        {
            InitializeComponent();

            _compositor = Window.Current.Compositor;
            _tracker    = InteractionTracker.CreateWithOwner(_compositor, this);
            _progress   = _compositor.CreatePropertySet();

            RenderAdaptiveCard();

            RomeShare.SessionListUpdated += OnSessionListUpdated;
            Loaded += async(s, e) => await RomeShare.DiscoverSessionsAsync();

            // When the size of the app changes, we need to update all the measures.
            SizeChanged += (s, e) =>
            {
                if (_hitTestVisual != null)
                {
                    _hitTestVisual.Size = Card.RenderSize.ToVector2();

                    var distanceFromTop = (float)Card.RelativePosition(this).Y;
                    _maxDistance         = distanceFromTop + _hitTestVisual.Size.Y;
                    _tracker.MaxPosition = new Vector3(_maxDistance);

                    var trackerNode = _tracker.GetReference();
                    _progress.StartAnimation("Progress", trackerNode.Position.Y / _tracker.MaxPosition.Y);
                }
            };
        }
        private void ConfigureInteractionTracker()
        {
            _tracker = InteractionTracker.Create(_compositor);

            _interactionSource = VisualInteractionSource.Create(_root);

            _interactionSource.PositionYSourceMode   = InteractionSourceMode.EnabledWithInertia;
            _interactionSource.PositionYChainingMode = InteractionChainingMode.Always;

            _tracker.InteractionSources.Add(_interactionSource);
            float refreshPanelHeight = (float)RefreshPanel.ActualHeight;

            _tracker.MaxPosition = new Vector3((float)Root.ActualWidth, 0, 0);
            _tracker.MinPosition = new Vector3(-(float)Root.ActualWidth, -refreshPanelHeight, 0);

            //The PointerPressed handler needs to be added using AddHandler method with the handledEventsToo boolean set to "true"
            //instead of the XAML element's "PointerPressed=Window_PointerPressed",
            //because the list view needs to chain PointerPressed handled events as well.
            ContentPanel.AddHandler(PointerPressedEvent, new PointerEventHandler(Window_PointerPressed), true);

            SetupPullToRefreshBehavior(refreshPanelHeight);

            //Apply spring force to pull the content back to Zero
            ConfigureRestingPoint(refreshPanelHeight);

            //
            // Use the Tracker's Position (negated) to apply to the Offset of the Image. The -{refreshPanelHeight} is to hide the refresh panel
            //
            _contentPanelVisual.StartAnimation("Offset.Y", -_tracker.GetReference().Position.Y - refreshPanelHeight);
        }
Esempio n. 5
0
        private void page_Loaded(object sender, RoutedEventArgs e)
        {
            Loaded -= page_Loaded;

            spVisual        = ElementCompositionPreview.GetElementVisual(spContent);
            btnScrollVisual = ElementCompositionPreview.GetElementVisual(btn_Scroll);
            compositor      = spVisual.Compositor;
            tracker         = InteractionTracker.Create(compositor);
            var tref = tracker.GetReference();

            var trackerTarget = ExpressionValues.Target.CreateInteractionTrackerTarget();
            var endpoint1     = InteractionTrackerInertiaRestingValue.Create(compositor);

            endpoint1.SetCondition(trackerTarget.NaturalRestingPosition.Y < (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2);
            endpoint1.SetRestingValue(trackerTarget.MinPosition.Y);
            var endpoint2 = InteractionTrackerInertiaRestingValue.Create(compositor);

            endpoint2.SetCondition(trackerTarget.NaturalRestingPosition.Y >= (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2);
            endpoint2.SetRestingValue(trackerTarget.MaxPosition.Y);
            tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { endpoint1, endpoint2 });

            interactionSource = VisualInteractionSource.Create(spVisual);
            interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;
            tracker.InteractionSources.Add(interactionSource);
            propertySet = compositor.CreatePropertySet();
            propertySet.InsertScalar("progress", 0.0f);
            propertySet.StartAnimation("progress", tref.Position.Y / tref.MaxPosition.Y);
            var progress = propertySet.GetReference().GetScalarProperty("progress");

            btnScrollVisual.StartAnimation("RotationAngleInDegrees", ExpressionFunctions.Clamp(progress, 0f, 1f) * 180);
            btnScrollVisual.CenterPoint = new System.Numerics.Vector3((float)btn_Scroll.ActualWidth / 2, (float)btn_Scroll.ActualHeight / 2, 0);
            spVisual.StartAnimation("Offset.Y", -ExpressionFunctions.Clamp(progress, -0.4f, 1.4f) * tref.MaxPosition.Y);
            gdInfo_SizeChanged(this, null);
        }
Esempio n. 6
0
        private void SetupInteractionTracker()
        {
            // Setup the HitTest visual of the InteractionTracker.
            _hitTestVisual      = VisualExtensions.GetVisual(Card);
            _hitTestVisual.Size = Card.RenderSize.ToVector2();
            // TODO: Why this doesn't work?
            //_hitTestVisual.RelativeSizeAdjustment = Vector2.One;

            // In this sample, we only want interactions happening on the Y-axis.
            _interactionSource = VisualInteractionSource.Create(_hitTestVisual);
            _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;
            _tracker.InteractionSources.Add(_interactionSource);

            // Setup max position of the InteractionTracker.
            var distanceFromTop = (float)Card.RelativePosition(this).Y;

            _maxDistance         = distanceFromTop + _hitTestVisual.Size.Y;
            _tracker.MaxPosition = new Vector3(_maxDistance);

            // Initialize the manipulation progress.
            // Note: In this simple demo, we could have used the trackerNode.Position.Y to manipulate the offset
            // directly. But we use the manipulation progress here so we could control more things such as the
            // scale or opacity of the "copy" in the future.
            _progress.InsertScalar("Progress", 0);

            // Create an animation that tracks the progress of the manipulation and stores it in a the PropertySet _progress.
            var trackerNode = _tracker.GetReference();

            // Note here we don't want to EF.Clamp the value 'cause we want the overpan which gives a more natural feel
            // when you pan it.
            _progress.StartAnimation("Progress", trackerNode.Position.Y / _tracker.MaxPosition.Y);

            ConfigureRestingPoints();

            void ConfigureRestingPoints()
            {
                // Setup a possible inertia endpoint (snap point) for the InteractionTracker's minimum position.
                var endpoint1 = InteractionTrackerInertiaRestingValue.Create(_compositor);

                // Use this endpoint when the natural resting position of the interaction is less than the halfway point.
                var trackerTarget = ExpressionValues.Target.CreateInteractionTrackerTarget();

                endpoint1.SetCondition(trackerTarget.NaturalRestingPosition.Y < (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2);

                // Set the result for this condition to make the InteractionTracker's y position the minimum y position.
                endpoint1.SetRestingValue(trackerTarget.MinPosition.Y);

                // Setup a possible inertia endpoint (snap point) for the InteractionTracker's maximum position.
                var endpoint2 = InteractionTrackerInertiaRestingValue.Create(_compositor);

                // Use this endpoint when the natural resting position of the interaction is more than the halfway point.
                endpoint2.SetCondition(trackerTarget.NaturalRestingPosition.Y >= (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2);

                // Set the result for this condition to make the InteractionTracker's y position the maximum y position.
                endpoint2.SetRestingValue(trackerTarget.MaxPosition.Y);

                _tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { endpoint1, endpoint2 });
            }
        }
Esempio n. 7
0
        private void InitializeSnapAnimationModifiers()
        {
            var trackerNode = _tracker.GetReference();

            ScalarNode closedPosition = 0;

            var snapClosed = InteractionTrackerInertiaRestingValue.Create(_compositor);

            snapClosed.SetCondition(trackerNode.NaturalRestingPosition.Y < openSize / 2);
            snapClosed.SetRestingValue(closedPosition);

            var snapOpen = InteractionTrackerInertiaRestingValue.Create(_compositor);

            snapOpen.SetCondition(trackerNode.NaturalRestingPosition.Y < openSize * 1.5f);
            snapOpen.SetRestingValue((ScalarNode)openSize);

            var modifiers = new InteractionTrackerInertiaRestingValue[] { snapClosed, snapOpen };

            _tracker.ConfigurePositionYInertiaModifiers(modifiers);
        }
Esempio n. 8
0
        private void ConfigureInteractionTracker()
        {
            _tracker = InteractionTracker.Create(_compositor);

            _interactionSource = VisualInteractionSource.Create(_root);
            _interactionSource.PositionYSourceMode         = InteractionSourceMode.EnabledWithInertia;
            _interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly;
            _tracker.InteractionSources.Add(_interactionSource);
            _tracker.MaxPosition = new Vector3(0, (float)Root.ActualHeight, 0);

            //
            // Use the Tacker's Position (negated) to apply to the Offset of the Image.
            //

            _image.StartAnimation("Offset", -_tracker.GetReference().Position);
        }
Esempio n. 9
0
        private void ConfigureParallax(int index, Visual visual)
        {
            var parallaxExpression = _compositor.CreateExpressionAnimation(
                "this.startingvalue + " +
                "tracker.PositionVelocityInPixelsPerSecond.X *" +
                "index / 100");

            parallaxExpression.SetReferenceParameter("tracker", _tracker);
            parallaxExpression.SetScalarParameter("index", index);

            var parallaxExpression2 = ExpressionValues.StartingValue.CreateScalarStartingValue() +
                                      _tracker.GetReference().PositionVelocityInPixelsPerSecond.X *
                                      index / 50;

            visual.StartAnimation("Offset.X", parallaxExpression2);
        }
Esempio n. 10
0
        private void InitializeComposition()
        {
            this.compositor  = ElementCompositionPreview.GetElementVisual(this).Compositor;
            this.thumbVisual = ElementCompositionPreview.GetElementVisual(thumb);
            this.trackVisual = ElementCompositionPreview.GetElementVisual(trackCanvas);

            propSet = this.compositor.CreatePropertySet();
            trackCanvas.PointerWheelChanged += new PointerEventHandler(PointerWheel_Changed);
            trackCanvas.PointerMoved        += new PointerEventHandler(MousePointer_Moved);
            trackCanvas.PointerReleased     += new PointerEventHandler(MousePointer_Released);

            // These pointer events are needed if want to click-to-seek. Weird eventing issues between when these get called and when need to call OnDragStart() and OnDragStop() methods
            // trackCanvas.PointerPressed += new PointerEventHandler(MousePointer_Pressed);
            // thumb.PointerPressed += new PointerEventHandler(MousePointer_ThumbPressed);
            this.interactionSource = VisualInteractionSource.Create(this.trackVisual);
            this.interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia;
            this.tracker = InteractionTracker.CreateWithOwner(this.compositor, this);
            this.tracker.InteractionSources.Add(this.interactionSource);

            // This is the Expression that we will use to drive the position of the Thumb Scrubber
            // Idea is that we will then update the position of InteractionTracker to move thes scrubber around - this is done via the Pointer Events tied to the TrackCanvas object
            // Note: this is using ExpressionBuilder
            this.thumbExpressionAnimation = -tracker.GetReference().Position.X;
        }