Beispiel #1
0
        public void ConfigureInteraction()
        {
            this.interactionSource = VisualInteractionSource.Create(myDrawingVisual);
            this.interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia;
            this.interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;

            this.interactionSource.ScaleSourceMode = InteractionSourceMode.EnabledWithInertia;

            this.tracker = InteractionTracker.CreateWithOwner(this.compositor, this);
            this.tracker.InteractionSources.Add(this.interactionSource);

            this.moveSurfaceExpressionAnimation = this.compositor.CreateExpressionAnimation("-tracker.Position.X");
            this.moveSurfaceExpressionAnimation.SetReferenceParameter("tracker", this.tracker);

            this.moveSurfaceUpDownExpressionAnimation = this.compositor.CreateExpressionAnimation("-tracker.Position.Y");
            this.moveSurfaceUpDownExpressionAnimation.SetReferenceParameter("tracker", this.tracker);

            this.scaleSurfaceUpDownExpressionAnimation = this.compositor.CreateExpressionAnimation("tracker.Scale");
            this.scaleSurfaceUpDownExpressionAnimation.SetReferenceParameter("tracker", this.tracker);

            this.tracker.MinPosition = new System.Numerics.Vector3(0, 0, 0);
            //TODO: use same consts as tilemanager object
            this.tracker.MaxPosition = new System.Numerics.Vector3(TILESIZE * 10000, TILESIZE * 10000, 0);

            this.tracker.MinScale = 0.01f;
            this.tracker.MaxScale = 100.0f;
        }
        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);
        }
Beispiel #3
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]);
            }
        }
        private void page_Loaded(object sender, RoutedEventArgs e)
        {
            this.Loaded -= this.page_Loaded;

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

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

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

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

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

            this.btnScrollVisual.StartAnimation("RotationAngleInDegrees", ExpressionFunctions.Clamp(progress, 0f, 1f) * 180);
            this.btnScrollVisual.CenterPoint = new System.Numerics.Vector3((float)this.btn_Scroll.ActualWidth / 2, (float)this.btn_Scroll.ActualHeight / 2, 0);
            this.spVisual.StartAnimation("Offset.Y", -ExpressionFunctions.Clamp(progress, -0.4f, 1.4f) * tref.MaxPosition.Y);
            gdInfo_SizeChanged(this, null);
        }
Beispiel #5
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.
            //

            var positionExpression = _compositor.CreateExpressionAnimation("-tracker.Position");

            positionExpression.SetReferenceParameter("tracker", _tracker);

            _image.StartAnimation("Offset", positionExpression);
        }
        private void InitializeComposition()
        {
            _containerVisual = ElementCompositionPreview.GetElementVisual(pnlRoot);
            _compositor      = _containerVisual.Compositor;

            _tracker = InteractionTracker.CreateWithOwner(_compositor, this);

            //_cubicBezierEasingFunction = _compositor.CreateCubicBezierEasingFunction(new Vector2(0.8f, 1.0f), new Vector2(0.0f, 1.0f));
            _cubicBezierEasingFunction = _compositor.CreateCubicBezierEasingFunction(new Vector2(.17f, .67f), new Vector2(1f, 1f));

            _containerVisual.Size = new Vector2((float)pnlRoot.ActualWidth, (float)pnlRoot.ActualHeight);
            _props = _compositor.CreatePropertySet();

            VisualInteractionSource interactionSource = VisualInteractionSource.Create(_containerVisual);

            interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia;
            _tracker.InteractionSources.Add(interactionSource);

            pnlRoot.PointerPressed += (s, a) =>
            {
                // Capture the touch manipulation to the InteractionTracker for automatic handling
                if (a.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch)
                {
                    try
                    {
                        interactionSource.TryRedirectForManipulation(a.GetCurrentPoint(s as UIElement));
                    }
                    catch (UnauthorizedAccessException)
                    {
                        // Ignoring the failed redirect to prevent app crashing
                    }
                }
            };
        }
Beispiel #7
0
        public IRefreshInfoProvider Adapt(Image image, Size visualizerSize)
        {
            this.image = image;
            UIElement parent = (UIElement)VisualTreeHelper.GetParent(image);

            Visual     parentVisual = ElementCompositionPreview.GetElementVisual(parent);
            Compositor compositor   = parentVisual.Compositor;

            infoProvider = new RefreshInfoProviderImplementation(refreshPullDirection, visualizerSize, compositor);

            interactionTracker             = InteractionTracker.CreateWithOwner(compositor, infoProvider);
            interactionTracker.MaxPosition = new Vector3(0.0f);
            interactionTracker.MinPosition = new Vector3(0.0f);
            interactionTracker.MaxScale    = 1.0f;
            interactionTracker.MinScale    = 1.0f;

            visualInteractionSource = VisualInteractionSource.Create(parentVisual);
            visualInteractionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly;
            visualInteractionSource.ScaleSourceMode             = InteractionSourceMode.Disabled;
            visualInteractionSource.PositionXSourceMode         = IsOrientationVertical() ? InteractionSourceMode.Disabled : InteractionSourceMode.EnabledWithInertia;
            visualInteractionSource.PositionXChainingMode       = IsOrientationVertical() ? InteractionChainingMode.Auto : InteractionChainingMode.Never;
            visualInteractionSource.PositionYSourceMode         = IsOrientationVertical() ? InteractionSourceMode.EnabledWithInertia : InteractionSourceMode.Disabled;
            visualInteractionSource.PositionYChainingMode       = IsOrientationVertical() ? InteractionChainingMode.Never : InteractionChainingMode.Auto;

            interactionTracker.InteractionSources.Add(visualInteractionSource);

            this.image.PointerPressed     += OnImagePointerPressed;
            infoProvider.RefreshStarted   += InfoProvider_RefreshStarted;
            infoProvider.RefreshCompleted += InfoProvider_RefreshCompleted;

            return(infoProvider);
        }
Beispiel #8
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 });
            }
        }
        private async void AddInteractableImage()
        {
            // 將 containerVisual 與 spriteVisual 新增至 DemoPage6 中
            var containerVisual = compositor.CreateContainerVisual();
            var spriteVisual    = compositor.CreateSpriteVisual();

            containerVisual.Children.InsertAtTop(spriteVisual);
            ElementCompositionPreview.SetElementChildVisual(this, containerVisual);

            // 讀圖
            var targetBrush = await GenerateCompositionBrush();

            // 將圖片讀進 spriteVisual
            spriteVisual.Brush = targetBrush;
            spriteVisual.Size  = new Vector2(300f, 300f);

            // 建立互動來源 (必須指定互動範圍區域)
            interactionSource = VisualInteractionSource.Create(rootVisual);

            // 設定互動方式
            interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;

            // 建立 InteractionTracker
            tracker = InteractionTracker.Create(compositor);

            // 設定位移位置的最大值與最小值
            // 類似 ScrollViewer.ScrollableHeight, ScrollViewer.ScrollableWidth
            tracker.MaxPosition = new Vector3(0, 300f, 0);
            tracker.MinPosition = new Vector3();

            // 將互動來源加至 tracker
            tracker.InteractionSources.Add(interactionSource);

            // 用 tracker 來設定 animation
            const int topMargin        = 100;
            var       offsetYAnimation = compositor.CreateExpressionAnimation("-tracker.Position.Y + topMargin");

            offsetYAnimation.SetReferenceParameter("tracker", tracker);
            offsetYAnimation.SetScalarParameter("topMargin", topMargin);
            spriteVisual.StartAnimation("Offset.Y", offsetYAnimation);

            //=======================================================
            // 讓 interactionSource 支援 Scale

            //tracker.MaxScale = 3.0f;
            //tracker.MinScale = 0.5f;

            //interactionSource.ScaleSourceMode = InteractionSourceMode.EnabledWithoutInertia;

            //var scaleAnimation = compositor.CreateExpressionAnimation("tracker.Scale");
            //scaleAnimation.SetReferenceParameter("tracker", tracker);
            //spriteVisual.StartAnimation("Scale.X", scaleAnimation);
            //spriteVisual.StartAnimation("Scale.Y", scaleAnimation);

            //var maxYAnimation = compositor.CreateExpressionAnimation("spriteVisual.Size.Y * spriteVisual.Scale.Y");
            //maxYAnimation.SetReferenceParameter("spriteVisual", spriteVisual);
            //tracker.StartAnimation("MaxPosition.Y", maxYAnimation);
        }
 private void SetupInput()
 {
     _root                       = ElementCompositionPreview.GetElementVisual(main);
     _compositor                 = _root.Compositor;
     _props                      = _compositor.CreatePropertySet();
     _tracker                    = InteractionTracker.Create(_compositor);
     _tracker.MaxPosition        = new Vector3((float)main.ActualHeight);
     _source                     = VisualInteractionSource.Create(_root);
     _source.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;
     _tracker.InteractionSources.Add(_source);
 }
Beispiel #11
0
        private VisualInteractionSource InitializeScrollInteractionSource()
        {
            var interactionSource = VisualInteractionSource.Create(_rootContainer);

            interactionSource.ScaleSourceMode             = InteractionSourceMode.Disabled;
            interactionSource.PositionXSourceMode         = InteractionSourceMode.Disabled;
            interactionSource.PositionYSourceMode         = InteractionSourceMode.EnabledWithInertia;
            interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadAndPointerWheel;
            interactionSource.IsPositionXRailsEnabled     = false;
            interactionSource.IsPositionYRailsEnabled     = false;
            return(interactionSource);
        }
Beispiel #12
0
        private void ConfigureInteractionTracker()
        {
            _tracker             = InteractionTracker.Create(_compositor);
            _tracker.MaxPosition = new Vector3(0, _backgroundImageVisual.Size.Y * 0.5f, 0);
            _tracker.MinPosition = new Vector3();

            _interactionSource = VisualInteractionSource.Create(_backgroundVisual);
            _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;
            _tracker.InteractionSources.Add(_interactionSource);

            var trackerNode = _tracker.GetReference();
            var progressExp = EF.Clamp(trackerNode.Position.Y / trackerNode.MaxPosition.Y, 0, 1);

            _propertySet.StartAnimation("progress", progressExp);
        }
        private void ConfigureInteractionTracker()
        {
            _tracker = InteractionTracker.Create(_compositor);

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

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

            _image.StartAnimation("Offset", -_tracker.GetReference().Position);
        }
        private void ConfigureInteractionTracker()
        {
            //
            // We're creating two interaction trackers, one nested in the other.  This allows us the user to use
            // pinch/stretch to affect z-position, and not have it change the x-position.  The two work independently.
            //

            _interactionSource1 = VisualInteractionSource.Create(_rootContainer);
            _interactionSource1.ScaleSourceMode = InteractionSourceMode.EnabledWithoutInertia;

            _scaleTracker          = InteractionTracker.CreateWithOwner(_compositor, this);
            _scaleTracker.MinScale = 0.6f;
            _scaleTracker.MaxScale = 5.0f;
            _scaleTracker.ScaleInertiaDecayRate = 0.96f;

            _scaleTracker.InteractionSources.Add(_interactionSource1);

            _interactionSource2 = VisualInteractionSource.Create(_rootContainer2);
            _interactionSource2.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia;

            _positionTracker             = InteractionTracker.CreateWithOwner(_compositor, this);
            _positionTracker.MaxPosition = new Vector3((float)Root.ActualWidth * 1.5f, 0, 0);
            _positionTracker.MinPosition = _positionTracker.MaxPosition * -1;

            _positionTracker.InteractionSources.Add(_interactionSource2);

            //
            // Here's the trick: we take the scale output from the outer (scale) Tracker, and convert
            // it into a value that represents Z.  Then we bind it to the world container's Z position.
            //

            var scaleExpression = _compositor.CreateExpressionAnimation("lerp(0, 1000, (1 - tracker.Scale) / (1 - tracker.MaxScale))");

            scaleExpression.SetReferenceParameter("tracker", _scaleTracker);
            _worldContainer.StartAnimation("Offset.Z", scaleExpression);

            //
            // Bind the output of the inner (xy position) tracker to the world container's XY position.
            //

            var positionExpression = _compositor.CreateExpressionAnimation("-tracker.Position.XY");

            positionExpression.SetReferenceParameter("tracker", _positionTracker);
            _worldContainer.StartAnimation("Offset.XY", positionExpression);
        }
Beispiel #15
0
        public SwipeDismissPanel()
        {
            m_rootVisual = ElementCompositionPreview.GetElementVisual(this);
            m_compositor = m_rootVisual.Compositor;

            CompletedOffset     = 2000;
            CompletionThreshold = 400;


            m_interactionSource = VisualInteractionSource.Create(m_rootVisual);
            m_interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia;

            var snapHomeEndpoint = InteractionTrackerInertiaRestingValue.Create(m_compositor);

            snapHomeEndpoint.Condition    = m_compositor.CreateExpressionAnimation("true");
            snapHomeEndpoint.RestingValue = m_compositor.CreateExpressionAnimation("0");

            var snapNearConditionExpression = m_compositor.CreateExpressionAnimation(
                "target.Position.X < -target.CompletionThreshold");
            var snapNearValueExpression = m_compositor.CreateExpressionAnimation("-target.CompletedOffset");

            var snapNearEndpoint = InteractionTrackerInertiaRestingValue.Create(m_compositor);

            snapNearEndpoint.Condition    = snapNearConditionExpression;
            snapNearEndpoint.RestingValue = snapNearValueExpression;

            var snapFarConditionExpression = m_compositor.CreateExpressionAnimation(
                "target.Position.X > target.CompletionThreshold");
            var snapFarValueExpression = m_compositor.CreateExpressionAnimation("target.CompletedOffset");

            var snapFarEndpoint = InteractionTrackerInertiaRestingValue.Create(m_compositor);

            snapFarEndpoint.Condition    = snapFarConditionExpression;
            snapFarEndpoint.RestingValue = snapFarValueExpression;

            m_inertiaModifiers = new InteractionTrackerInertiaModifier[] {
                snapNearEndpoint,
                snapFarEndpoint,
                snapHomeEndpoint
            };

            this.Loading  += OnLoading;
            this.Unloaded += OnUnloaded;
        }
Beispiel #16
0
        private void Interaction()
        {
            _interactionTracker = InteractionTracker.Create(_compositor);

            _interactionTracker.MinScale = 0;
            _interactionTracker.MaxScale = 100f;

            _interactionTracker.MaxPosition = new Vector3((float)Window.Current.Bounds.Width * 0.5f, (float)Window.Current.Bounds.Height * 0.5f, 0f);
            _interactionTracker.MinPosition = new Vector3();

            _interactionSource = VisualInteractionSource.Create(ElementCompositionPreview.GetElementVisual(Window.Current.Content));
            _interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia;
            _interactionSource.ScaleSourceMode     = InteractionSourceMode.EnabledWithInertia;

            _interactionTracker.InteractionSources.Add(_interactionSource);

            var blurEffect = new GaussianBlurEffect
            {
                BlurAmount   = 0f,
                Optimization = EffectOptimization.Speed,
                Name         = "blurEffect",
                Source       = new CompositionEffectSourceParameter("image")
            };

            var effectFactory = _compositor.CreateEffectFactory(blurEffect, new[] { "blurEffect.BlurAmount" });

            var blurBrush = effectFactory.CreateBrush();

            blurBrush.SetSourceParameter("image", _compositor.CreateBackdropBrush());

            _sprite       = _compositor.CreateSpriteVisual();
            _sprite.Size  = new Vector2((float)Window.Current.Bounds.Width, (float)Window.Current.Bounds.Height);
            _sprite.Brush = blurBrush;

            var blurAnimation = _compositor.CreateExpressionAnimation("lerp(tracker.MinScale, tracker.MaxScale, clamp(tracker.Position.X / width, 0, 1))");

            blurAnimation.SetReferenceParameter("tracker", _interactionTracker);
            blurAnimation.SetScalarParameter("width", (float)Window.Current.Bounds.Width);

            _sprite.Brush.Properties.StartAnimation("blurEffect.BlurAmount", blurAnimation);

            ElementCompositionPreview.SetElementChildVisual(Image, _sprite);
        }
Beispiel #17
0
        public MainPage()
        {
            InitializeComponent();

            _compositor = Window.Current.Compositor;
            _root       = ElementCompositionPreview.GetElementVisual(Root);

            Loaded += (s, e) =>
            {
                _interactionSource = VisualInteractionSource.Create(_root);
                _interactionSource.PositionYSourceMode     = InteractionSourceMode.EnabledWithInertia;
                _interactionSource.PositionXSourceMode     = InteractionSourceMode.EnabledWithInertia;
                _interactionSource.IsPositionXRailsEnabled = false;
                _interactionSource.IsPositionYRailsEnabled = false;

                ConfigSpringBasedTracker(Image1, 240.0d, 0.4f);
                ConfigSpringBasedTracker(Image2, 180.0d, 0.2f, -240.0f);
                ConfigSpringBasedTracker(Image3, 120.0d, 0.15f, 240.0f);
            };
        }
Beispiel #18
0
        private void SetupModal()
        {
            // Fix display orientation
            DisplayInformation.AutoRotationPreferences = DisplayInformation.GetForCurrentView().CurrentOrientation;

            // Set up visual interaction source
            _root                   = ElementCompositionPreview.GetElementVisual(ITRoot);
            _compositor             = _root.Compositor;
            _is                     = VisualInteractionSource.Create(_root);
            _is.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;

            // Set up interaction tracker owner
            _itowner = new InteractionTrackerOwner();
            _itowner.StateOrValuesChanged += (r, s) => {
                DebugText1.Text = $"State: {s.Item1}\nPos:   {s.Item2.Y}";
                ChangeScroll(s);
                oldPosition = s.Item2;
            };

            // Set up interaction tracker
            _tracker = InteractionTracker.CreateWithOwner(_compositor, _itowner);
            _tracker.InteractionSources.Add(_is);

            UpdateInteractionTrackerValues();

            var exp = _compositor.CreateExpressionAnimation("-tracker.Position");

            exp.SetReferenceParameter("tracker", _tracker);

            var bv = ElementCompositionPreview.GetElementVisual(ModalContent);

            bv.StartAnimation("Offset", exp);

            ExpressionAnimation _titleAnimation = _compositor.CreateExpressionAnimation("Clamp(tracker.Position.Y, 0, tracker.MaxPosition.Y)");

            _titleAnimation.SetReferenceParameter("tracker", _tracker);

            var tv = ElementCompositionPreview.GetElementVisual(TitleBar);

            tv.StartAnimation("Offset.Y", _titleAnimation);
        }
        private void ConfigureInteractionTracker()
        {
            _tracker             = InteractionTracker.Create(_compositor);
            _tracker.MaxPosition = new Vector3(0, _backgroundImageVisual.Size.Y * 0.5f, 0);
            _tracker.MinPosition = new Vector3();

            _interactionSource = VisualInteractionSource.Create(_backgroundVisual);
            _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;

#if SDKVERSION_17763
            if (MainPage.RuntimeCapabilities.IsSdkVersionRuntimeSupported(RuntimeSupportedSDKs.SDKVERSION._17763))
            {
                _interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadAndPointerWheel;
            }
#endif
            _tracker.InteractionSources.Add(_interactionSource);

            var trackerNode = _tracker.GetReference();
            var progressExp = EF.Clamp(trackerNode.Position.Y / trackerNode.MaxPosition.Y, 0, 1);
            _propertySet.StartAnimation("progress", progressExp);
        }
        /// <summary>
        /// 当指针设备在窗口内按下时执行。此时我们来做交互。
        /// </summary>
        private void InteractionTrackerSetup(Compositor compositor, Visual hitTestRoot)
        {
            // #1 Create InteractionTracker object
            var tracker = InteractionTracker.Create(compositor);

            // #2 Set Min and Max positions
            tracker.MinPosition = new Vector3(-1000f);
            tracker.MaxPosition = new Vector3(1000f);

            // #3 Setup the VisualInteractionSourc
            var source = VisualInteractionSource.Create(hitTestRoot);

            // #4 Set the properties for the VisualInteractionSource
            source.ManipulationRedirectionMode =
                VisualInteractionSourceRedirectionMode.CapableTouchpadOnly;
            source.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia;
            source.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;

            // #5 Add the VisualInteractionSource to InteractionTracker
            tracker.InteractionSources.Add(source);
        }
Beispiel #21
0
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            _rootVisual      = Root.Visual();
            _rootVisual.Size = new Vector2((float)Root.ActualWidth, (float)Root.ActualHeight);

            _pathContainerVisual      = PathContainer.Visual();
            _pathContainerVisual.Size = _rootVisual.Size;

            _compositor = _rootVisual.Compositor;

            //CreateMoreShapes();

            _interactionSource = VisualInteractionSource.Create(_rootVisual);
            _interactionSource.PositionXSourceMode         = InteractionSourceMode.EnabledWithInertia;
            _interactionSource.PositionYSourceMode         = InteractionSourceMode.EnabledWithInertia;
            _interactionSource.IsPositionXRailsEnabled     = false;
            _interactionSource.IsPositionYRailsEnabled     = false;
            _interactionSource.ScaleSourceMode             = InteractionSourceMode.EnabledWithInertia;
            _interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly;

            _tracker = InteractionTracker.CreateWithOwner(_compositor, this);
            _tracker.InteractionSources.Add(_interactionSource);
            _tracker.MaxPosition           = new Vector3(_rootVisual.Size, 0.0f) * 3.0f;
            _tracker.MinPosition           = _tracker.MaxPosition * -1.0f;
            _tracker.MinScale              = 0.9f;
            _tracker.MaxScale              = 12.0f;
            _tracker.ScaleInertiaDecayRate = 0.96f;

            var positionAnimation = _compositor.CreateExpressionAnimation("-t.Position");

            positionAnimation.SetReferenceParameter("t", _tracker);
            _pathContainerVisual.StartAnimation("Offset", positionAnimation);

            var scaleAnimation = _compositor.CreateExpressionAnimation("Vector2(t.Scale, t.Scale)");

            scaleAnimation.SetReferenceParameter("t", _tracker);
            _pathContainerVisual.StartAnimation("Scale.XY", scaleAnimation);
        }
Beispiel #22
0
        /// <summary>
        /// Inializes a new instance of the <see cref="SideDrawer"/> class.
        /// </summary>
        public SideDrawer()
        {
            this.InitializeComponent();

            Visual rootVisual = ElementCompositionPreview.GetElementVisual(rootgrid);

            _compositor = rootVisual.Compositor;

            // Main content
            _mainVisual = ElementCompositionPreview.GetElementVisual(main);
            ElementCompositionPreview.SetIsTranslationEnabled(main, true);

            // Main left panel
            _leftVisual = ElementCompositionPreview.GetElementVisual(left1);
            ElementCompositionPreview.SetIsTranslationEnabled(left1, true);

            // Secondary left panel
            _left2Visual = ElementCompositionPreview.GetElementVisual(left2);
            ElementCompositionPreview.SetIsTranslationEnabled(left2, true);

            // Right panel
            _rightVisual = ElementCompositionPreview.GetElementVisual(right);
            ElementCompositionPreview.SetIsTranslationEnabled(right, true);

            // Tracker
            _tracker           = InteractionTracker.Create(_compositor);
            _interactionSource = VisualInteractionSource.Create(_mainVisual);
            _interactionSource.IsPositionXRailsEnabled = true;
            _interactionSource.PositionXChainingMode   = InteractionChainingMode.Always;
            _interactionSource.PositionXSourceMode     = InteractionSourceMode.EnabledWithInertia;

            // Inertia resting
            _startPoint = InteractionTrackerInertiaRestingValue.Create(_compositor);
            _midPoint   = InteractionTrackerInertiaRestingValue.Create(_compositor);
            _endPoint   = InteractionTrackerInertiaRestingValue.Create(_compositor);

            Loading += OnLoading;
        }
Beispiel #23
0
        private void SetupTracker()
        {
            m_tracker = InteractionTracker.CreateWithOwner(compositor, this);
            InitTrackerPositions();

            m_source = VisualInteractionSource.Create(ReaderViewVisual);
            m_source.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly;

            m_source.IsPositionXRailsEnabled = false;
            m_source.PositionXChainingMode   = InteractionChainingMode.Never;
            m_source.PositionXSourceMode     = InteractionSourceMode.EnabledWithoutInertia;

            m_source.IsPositionYRailsEnabled = false;
            m_source.PositionYChainingMode   = InteractionChainingMode.Never;
            m_source.PositionYSourceMode     = InteractionSourceMode.Disabled;

            m_tracker.InteractionSources.Add(m_source);

            OffsetBind = compositor.CreateExpressionAnimation("-tracker.Position");
            OffsetBind.SetReferenceParameter("tracker", m_tracker);

            PanelVisual.StartAnimation("Offset", OffsetBind);
        }
        private void ConfigureInteractionTracker()
        {
            _interactionSource = VisualInteractionSource.Create(_hitTest);

            //Configure for y-direction panning
            _interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly;
            _interactionSource.PositionXSourceMode         = InteractionSourceMode.EnabledWithInertia;
            _interactionSource.PositionXChainingMode       = InteractionChainingMode.Never;
            _interactionSource.IsPositionXRailsEnabled     = true;

            //Create tracker and associate interaction source
            _tracker = InteractionTracker.CreateWithOwner(_visual.Compositor, this);
            _tracker.InteractionSources.Add(_interactionSource);

            _tracker.MaxPosition = new Vector3(_reply ? 72 : 0);
            _tracker.MinPosition = new Vector3(_forward ? -72 : 0);

            _tracker.Properties.InsertBoolean("CanReply", _reply);
            _tracker.Properties.InsertBoolean("CanForward", _forward);

            //ConfigureAnimations(_visual, null);
            ConfigureRestingPoints();
        }
Beispiel #25
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;
        }
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            ThumbnailList.ItemsSource = new List <Item>
            {
                new Item {
                    Name = "Daren"
                },
                new Item {
                    Name = "Kendra"
                },
                new Item {
                    Name = "Gavin"
                },
                new Item {
                    Name = "Naia"
                },
                new Item {
                    Name = "Frodo"
                },
                new Item {
                    Name = "Stella"
                },
                new Item {
                    Name = "DJ"
                },
                new Item {
                    Name = "Stasch"
                }
            };

            // InteractionTracker and VisualInteractionSource setup.
            _root = ElementCompositionPreview.GetElementVisual(Root);
            _contentPanelVisual = ElementCompositionPreview.GetElementVisual(ContentPanel);
            _compositor         = _root.Compositor;
            _tracker            = InteractionTracker.Create(_compositor);
            _interactionSource  = VisualInteractionSource.Create(_root);
            _interactionSource.PositionYSourceMode   = InteractionSourceMode.EnabledWithInertia;
            _interactionSource.PositionYChainingMode = InteractionChainingMode.Always;
            _tracker.InteractionSources.Add(_interactionSource);
            var refreshPanelHeight = (float)RefreshPanel.ActualHeight;

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

            // Use the Tacker's Position (negated) to apply to the Offset of the Image.
            // The -{refreshPanelHeight} is to hide the refresh panel
            m_positionExpression =
                _compositor.CreateExpressionAnimation($"-tracker.Position.Y - {refreshPanelHeight} ");
            m_positionExpression.SetReferenceParameter("tracker", _tracker);
            _contentPanelVisual.StartAnimation("Offset.Y", m_positionExpression);

            var resistanceModifier  = CompositionConditionalValue.Create(_compositor);
            var resistanceCondition = _compositor.CreateExpressionAnimation(
                $"-tracker.Position.Y < {pullToRefreshDistance}");

            resistanceCondition.SetReferenceParameter("tracker", _tracker);
            var resistanceAlternateValue = _compositor.CreateExpressionAnimation(
                "source.DeltaPosition.Y / 3");

            resistanceAlternateValue.SetReferenceParameter("source", _interactionSource);
            resistanceModifier.Condition = resistanceCondition;
            resistanceModifier.Value     = resistanceAlternateValue;

            var stoppingModifier  = CompositionConditionalValue.Create(_compositor);
            var stoppingCondition = _compositor.CreateExpressionAnimation(
                $"-tracker.Position.Y >= {pullToRefreshDistance}");

            stoppingCondition.SetReferenceParameter("tracker", _tracker);
            var stoppingAlternateValue = _compositor.CreateExpressionAnimation("0");

            stoppingModifier.Condition = stoppingCondition;
            stoppingModifier.Value     = stoppingAlternateValue;
            //Now add the 2 source modifiers to the InteractionTracker.
            var modifierList = new List <CompositionConditionalValue> {
                resistanceModifier, stoppingModifier
            };

            _interactionSource.ConfigureDeltaPositionYModifiers(modifierList);

            //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);
        }
        public void SetupInteraction(UIElement DetachedHeader)
        {
            //Set up tracker
            var containerVisual = compositor.CreateContainerVisual();

            contentVis  = ElementCompositionPreview.GetElementVisual(content);
            contentVis2 = ElementCompositionPreview.GetElementVisual(DetachedHeader);
            ElementCompositionPreview.SetIsTranslationEnabled(content, true);
            ElementCompositionPreview.SetIsTranslationEnabled(DetachedHeader, true);
            contentVis.Properties.InsertVector3("Translation", Vector3.Zero);
            contentVis2.Properties.InsertVector3("Translation", Vector3.Zero);

            interactionSource = VisualInteractionSource.Create(rootVisual);
            interactionSource.IsPositionXRailsEnabled = true;
            //If the chaining mode is set to always, it is impossible to go past by the minimum and maximum scrolling points by "stretching" the X axis
            interactionSource.PositionXChainingMode = InteractionChainingMode.Always;
            interactionSource.PositionXSourceMode   = InteractionSourceMode.EnabledWithInertia;


            tracker = InteractionTracker.Create(compositor);

            tracker.MaxPosition = new Vector3(width - 72, 0, 0);
            tracker.MinPosition = new Vector3(-width, 0, 0);
            tracker.TryUpdatePosition(new Vector3(0, 0, 0));
            tracker.InteractionSources.Add(interactionSource);


            // Define expression animations
            contentAnimation = compositor.CreateExpressionAnimation("-tracker.Position.X");
            contentAnimation.SetReferenceParameter("tracker", tracker);
            contentVis.StartAnimation("Translation.X", contentAnimation);
            contentVis2.StartAnimation("Translation.X", contentAnimation);
            //LEFT PANEL
            leftcache1 = ElementCompositionPreview.GetElementVisual(leftPanelCache);
            leftpanel1 = ElementCompositionPreview.GetElementVisual(leftPanel);
            ElementCompositionPreview.SetIsTranslationEnabled(leftPanel, true);

            leftPanelFadeAnimation = compositor.CreateExpressionAnimation("Clamp((-tracker.Position.X/width)*(-0.5)+0.25,0,1)");
            leftPanelFadeAnimation.SetScalarParameter("width", width);
            leftPanelFadeAnimation.SetReferenceParameter("tracker", tracker);
            leftcache1.StartAnimation("Opacity", leftPanelFadeAnimation);

            leftPanelTranslateAnimation = compositor.CreateExpressionAnimation("-24+((-tracker.Position.X/width)*24)");
            leftPanelTranslateAnimation.SetReferenceParameter("tracker", tracker);
            leftPanelTranslateAnimation.SetScalarParameter("width", width);
            leftpanel1.StartAnimation("Translation.X", leftPanelTranslateAnimation);

            //SECONDARY LEFT PANEL
            leftcache2 = ElementCompositionPreview.GetElementVisual(leftSecondaryPanelCache);
            leftpanel2 = ElementCompositionPreview.GetElementVisual(leftSecondaryPanel);
            ElementCompositionPreview.SetIsTranslationEnabled(leftSecondaryPanel, true);

            leftPanelFadeAnimation2 = compositor.CreateExpressionAnimation("Clamp((-tracker.Position.X/width)*(-0.25)+0.25, 0, 1)");
            leftPanelFadeAnimation2.SetScalarParameter("width", width);
            leftPanelFadeAnimation2.SetReferenceParameter("tracker", tracker);
            leftcache2.StartAnimation("Opacity", leftPanelFadeAnimation2);

            leftPanelTranslateAnimation2 = compositor.CreateExpressionAnimation("-tracker.Position.X/width*72");
            leftPanelTranslateAnimation2.SetReferenceParameter("tracker", tracker);
            leftPanelTranslateAnimation2.SetScalarParameter("width", width);
            leftpanel2.StartAnimation("Translation.X", leftPanelTranslateAnimation2);

            //RIGHT PANEL
            rightcache = ElementCompositionPreview.GetElementVisual(rightPanelCache);
            rightpanel = ElementCompositionPreview.GetElementVisual(rightSide);
            ElementCompositionPreview.SetIsTranslationEnabled(rightSide, true);

            rightPanelFadeAnimation = compositor.CreateExpressionAnimation("Clamp((tracker.Position.X/width)*(-0.25)+0.25, 0, 1)");
            rightPanelFadeAnimation.SetScalarParameter("width", width - 72);
            rightPanelFadeAnimation.SetReferenceParameter("tracker", tracker);
            rightcache.StartAnimation("Opacity", rightPanelFadeAnimation);

            rightPanelTranslateAnimation = compositor.CreateExpressionAnimation("-tracker.Position.X/width*72");
            rightPanelTranslateAnimation.SetReferenceParameter("tracker", tracker);
            rightPanelTranslateAnimation.SetScalarParameter("width", width - 72);
            rightpanel.StartAnimation("Translation.X", rightPanelTranslateAnimation);

            SetSnapPoints(-width, 0, width - 72);

            //UI Stuff
            MediumTrigger.MinWindowWidth     = Storage.Settings.RespUiM;
            LargeTrigger.MinWindowWidth      = Storage.Settings.RespUiL;
            ExtraLargeTrigger.MinWindowWidth = Storage.Settings.RespUiXl;
            var state = VisualStateGroup.CurrentState;


            if (App.CinematicMode)
            {
                SmallTrigger.MinWindowWidth      = 0;
                MediumTrigger.MinWindowWidth     = 0;
                LargeTrigger.MinWindowWidth      = 1;
                ExtraLargeTrigger.MinWindowWidth = 100000;
                maingrid.Margin   = new Thickness(54, 0, 54, 0);
                leftPanel.Margin  = new Thickness(-54, 0, 0, 0);
                leftPanel.Padding = new Thickness(54, 0, 0, 0);
                rightSide.Margin  = new Thickness(0, 0, 54, 0);
                rightSide.Padding = new Thickness(0, 0, -54, 0);
            }
            VisualStateGroup_CurrentStateChanged(null, new VisualStateChangedEventArgs()
            {
                OldState = Small
            });
        }
        private void ConfigureInteractionTracker()
        {
            _interactionSource = VisualInteractionSource.Create(_rootContainer);
            _interactionSource.ScaleSourceMode     = InteractionSourceMode.EnabledWithInertia;
            _interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia;

            _tracker          = InteractionTracker.CreateWithOwner(_compositor, this);
            _tracker.MinScale = 0.6f;
            _tracker.MaxScale = 5.0f;

            _tracker.MaxPosition = new Vector3((float)Root.ActualWidth * 1.5f, 0, 0);
            _tracker.MinPosition = _tracker.MaxPosition * -1;

            _tracker.ScaleInertiaDecayRate = 0.96f;

            _tracker.InteractionSources.Add(_interactionSource);

            var tracker = _tracker.GetReference();

            //
            // Here's the trick: we take the scale output from the tracker, and convert it into a
            // value that represents Z.  Then we bind it to the world container's Z position.
            //

            var scaleExpression = EF.Lerp(0, 1000, (1 - tracker.Scale) / (1 - tracker.MaxScale));

            _worldContainer.StartAnimation("Offset.Z", scaleExpression);

            //
            // Bind the output of the tracker to the world container's XY position.
            //

            _worldContainer.StartAnimation("Offset.XY", -tracker.Position.XY);


            //
            // Scaling usually affects position.  This depends on the center point of the scale.
            // But for our UI, we want don't scale to adjust the position (since we're using scale
            // to change Offset.Z).  So to prevent scale from affecting position, we must always use
            // the top-left corner of the WorldContainer as the center point (note: we could also
            // use the tracker's negated position, since that's where WorldContainer is getting its
            // offset).
            //
            // Create input modifiers to override the center point value.
            //

            var centerpointXModifier = CompositionConditionalValue.Create(_compositor);
            var centerpointYModifier = CompositionConditionalValue.Create(_compositor);

            centerpointXModifier.Condition = _compositor.CreateExpressionAnimation("true");
            centerpointXModifier.Value     = _compositor.CreateExpressionAnimation("world.Offset.X");
            centerpointXModifier.Value.SetReferenceParameter("world", _worldContainer);

            _interactionSource.ConfigureCenterPointXModifiers(new[] { centerpointXModifier });
            _tracker.ConfigureCenterPointXInertiaModifiers(new[] { centerpointXModifier });


            centerpointYModifier.Condition = _compositor.CreateExpressionAnimation("true");
            centerpointYModifier.Value     = _compositor.CreateExpressionAnimation("world.Offset.Y");
            centerpointYModifier.Value.SetReferenceParameter("world", _worldContainer);

            _interactionSource.ConfigureCenterPointYModifiers(new[] { centerpointYModifier });
            _tracker.ConfigureCenterPointYInertiaModifiers(new[] { centerpointYModifier });
        }
Beispiel #29
0
        private void ConfigureInteractionTracker()
        {
            if (InfoContent == null)
            {
                return;
            }
            if (HittestContent == null)
            {
                return;
            }

            // Configure hittestVisual size for the interaction (size needs to be explicitly set in order for the hittesting to work correctly due to XAML-COMP interop policy)
            _hittestVisual.Size = new Vector2((float)HittestContent.ActualWidth, (float)HittestContent.ActualHeight);

            _props = _compositor.CreatePropertySet();

            Visual infoVisual  = ElementCompositionPreview.GetElementVisual(InfoContent);
            Visual photoVisual = ElementCompositionPreview.GetElementVisual(PhotoContent);

            photoVisual.Size = new Vector2((float)PhotoContent.ActualWidth, (float)PhotoContent.ActualHeight);

            photoVisual.CenterPoint = new Vector3((float)PhotoContent.ActualWidth * .5f, (float)PhotoContent.ActualHeight * .5f, 0f);
            infoVisual.CenterPoint  = new Vector3((float)InfoContent.ActualWidth * .5f, (float)InfoContent.ActualHeight * .5f, 0f);

            VisualInteractionSource interactionSource = VisualInteractionSource.Create(_hittestVisual);

            //Configure for y-direction panning
            interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;

            //Create tracker and associate interaction source
            _tracker.InteractionSources.Add(interactionSource);

            //Configure tracker boundaries
            _tracker.MaxPosition = new Vector3((float)HittestContent.ActualHeight);

            SpriteVisual shadowVisual = _compositor.CreateSpriteVisual();

            shadowVisual.Size = photoVisual.Size;
            ElementCompositionPreview.SetElementChildVisual(InfoContainer, shadowVisual);

            ConfigureAnimations(photoVisual, infoVisual, shadowVisual);

            ConfigureRestingPoints();

            HittestContent.PointerPressed += (s, a) =>
            {
                // Capture the touch manipulation to the InteractionTracker for automatic handling
                if (a.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch)
                {
                    try
                    {
                        interactionSource.TryRedirectForManipulation(a.GetCurrentPoint(s as UIElement));
                    }
                    catch (UnauthorizedAccessException)
                    {
                        // Ignoring the failed redirect to prevent app crashing
                    }
                }
                // Update the InteractionTracker's position to change between min and max for other input types
                else
                {
                    float direction = 1;
                    if (_isExpanded)
                    {
                        direction = -1;
                    }
                    _tracker.TryUpdatePositionWithAdditionalVelocity(new Vector3(0f, direction * 1000f, 0f));
                }
            };
        }
Beispiel #30
0
        /// <summary>
        /// Setup interactions with sliding touch controls.
        /// </summary>
        /// <param name="detachedHeader">Uneffected element.</param>
        public void SetupInteraction(UIElement detachedHeader = null)
        {
            // Set up tracker
            var containerVisual = _compositor.CreateContainerVisual();

            contentVis = ElementCompositionPreview.GetElementVisual(content);
            if (detachedHeader != null)
            {
                contentVis2 = ElementCompositionPreview.GetElementVisual(detachedHeader);
            }

            ElementCompositionPreview.SetIsTranslationEnabled(content, true);
            if (detachedHeader != null)
            {
                ElementCompositionPreview.SetIsTranslationEnabled(detachedHeader, true);
            }

            contentVis.Properties.InsertVector3("Translation", Vector3.Zero);
            if (detachedHeader != null)
            {
                contentVis2.Properties.InsertVector3("Translation", Vector3.Zero);
            }

            _interactionSource = VisualInteractionSource.Create(_rootVisual);
            _interactionSource.IsPositionXRailsEnabled = true;

            // If the chaining mode is set to always, it is impossible to go past by the minimum and maximum scrolling points by "stretching" the X axis
            _interactionSource.PositionXChainingMode = InteractionChainingMode.Always;
            _interactionSource.PositionXSourceMode   = InteractionSourceMode.EnabledWithInertia;
            _tracker             = InteractionTracker.Create(_compositor);
            _tracker.MaxPosition = new Vector3(width - 72, 0, 0);
            _tracker.MinPosition = new Vector3(-width, 0, 0);
            _tracker.TryUpdatePosition(new Vector3(0, 0, 0));
            _tracker.InteractionSources.Add(_interactionSource);

            // Define expression animations
            _contentAnimation = _compositor.CreateExpressionAnimation("-tracker.Position.X");
            _contentAnimation.SetReferenceParameter("tracker", _tracker);
            contentVis.StartAnimation("Translation.X", _contentAnimation);
            if (detachedHeader != null)
            {
                contentVis2.StartAnimation("Translation.X", _contentAnimation);
            }

            // LEFT PANEL
            leftcache1 = ElementCompositionPreview.GetElementVisual(leftPanelCache);
            leftpanel1 = ElementCompositionPreview.GetElementVisual(leftPanel);
            ElementCompositionPreview.SetIsTranslationEnabled(leftPanel, true);
            _leftPanelFadeAnimation = _compositor.CreateExpressionAnimation("Clamp((-tracker.Position.X/width)*(-0.5)+0.25,0,1)");
            _leftPanelFadeAnimation.SetScalarParameter("width", width);
            _leftPanelFadeAnimation.SetReferenceParameter("tracker", _tracker);
            leftcache1.StartAnimation("Opacity", _leftPanelFadeAnimation);
            leftPanelTranslateAnimation = _compositor.CreateExpressionAnimation("-24+((-tracker.Position.X/width)*24)");
            leftPanelTranslateAnimation.SetReferenceParameter("tracker", _tracker);
            leftPanelTranslateAnimation.SetScalarParameter("width", width);
            leftpanel1.StartAnimation("Translation.X", leftPanelTranslateAnimation);

            // SECONDARY LEFT PANEL
            leftcache2 = ElementCompositionPreview.GetElementVisual(leftSecondaryPanelCache);
            leftpanel2 = ElementCompositionPreview.GetElementVisual(leftSecondaryPanel);
            ElementCompositionPreview.SetIsTranslationEnabled(leftSecondaryPanel, true);
            _leftPanelFadeAnimation2 = _compositor.CreateExpressionAnimation("Clamp((-tracker.Position.X/width)*(-0.25)+0.25, 0, 1)");
            _leftPanelFadeAnimation2.SetScalarParameter("width", width);
            _leftPanelFadeAnimation2.SetReferenceParameter("tracker", _tracker);
            leftcache2.StartAnimation("Opacity", _leftPanelFadeAnimation2);
            _leftPanelTranslateAnimation2 = _compositor.CreateExpressionAnimation("-tracker.Position.X/width*72");
            _leftPanelTranslateAnimation2.SetReferenceParameter("tracker", _tracker);
            _leftPanelTranslateAnimation2.SetScalarParameter("width", width);
            leftpanel2.StartAnimation("Translation.X", _leftPanelTranslateAnimation2);

            // RIGHT PANEL
            rightcache = ElementCompositionPreview.GetElementVisual(rightPanelCache);
            rightpanel = ElementCompositionPreview.GetElementVisual(rightSide);
            ElementCompositionPreview.SetIsTranslationEnabled(rightSide, true);
            rightPanelFadeAnimation = _compositor.CreateExpressionAnimation("Clamp((tracker.Position.X/width)*(-0.25)+0.25, 0, 1)");
            rightPanelFadeAnimation.SetScalarParameter("width", width - 72);
            rightPanelFadeAnimation.SetReferenceParameter("tracker", _tracker);
            rightcache.StartAnimation("Opacity", rightPanelFadeAnimation);
            rightPanelTranslateAnimation = _compositor.CreateExpressionAnimation("-tracker.Position.X/width*72");
            rightPanelTranslateAnimation.SetReferenceParameter("tracker", _tracker);
            rightPanelTranslateAnimation.SetScalarParameter("width", width - 72);
            rightpanel.StartAnimation("Translation.X", rightPanelTranslateAnimation);
            SetSnapPoints(-width, 0, width - 72);

            // UI Stuff
            var state = VisualStateGroup.CurrentState;

            VisualStateGroup_CurrentStateChanged(null, new VisualStateChangedEventArgs()
            {
                OldState = Small
            });
        }