public CanvasScrollControllerConsumer(ListBox lstLog, Canvas canvas, FrameworkElement scrolledElement, bool isLogging)
        {
            this.lstLog          = lstLog;
            this.canvas          = canvas;
            this.scrolledElement = scrolledElement;
            this.IsLogging       = isLogging;

            scrolledElement.ManipulationStarting  += ScrolledElementManipulationStarting;
            scrolledElement.ManipulationDelta     += ScrolledElementManipulationDelta;
            scrolledElement.ManipulationCompleted += ScrolledElementManipulationCompleted;

            Visual     visual     = ElementCompositionPreview.GetElementVisual(lstLog);
            Compositor compositor = visual.Compositor;

            horizontalPS = compositor.CreatePropertySet();
            horizontalPS.InsertScalar("CustomMinOffset", 0.0f);
            horizontalPS.InsertScalar("CustomMaxOffset", 0.0f);
            horizontalPS.InsertScalar("CustomOffset", 0.0f);
            horizontalPS.InsertScalar("CustomViewport", 0.0f);

            verticalPS = compositor.CreatePropertySet();
            verticalPS.InsertScalar("CustomMinOffset", 0.0f);
            verticalPS.InsertScalar("CustomMaxOffset", 0.0f);
            verticalPS.InsertScalar("CustomOffset", 0.0f);
            verticalPS.InsertScalar("CustomViewport", 0.0f);

            SetHorizontalInfo(Math.Max(0.0, scrolledElement.ActualWidth - canvas.ActualWidth), canvas.ActualWidth);
            SetVerticalInfo(Math.Max(0.0, scrolledElement.ActualHeight - canvas.ActualHeight), canvas.ActualWidth);
        }
예제 #2
0
        protected override void OnConnected(UIElement newElement)
        {
            element = newElement;

            compositor = ElementCompositionPreview.GetElementVisual(Window.Current.Content).Compositor;
            var spotlight = compositor.CreateSpotLight();
            spotlight.InnerConeAngleInDegrees = 10f;
            spotlight.OuterConeAngleInDegrees = 20f;
            spotlight.InnerConeColor = Colors.FloralWhite;
            spotlight.OuterConeColor = Colors.FloralWhite;
            spotlight.ConstantAttenuation = 0f;
            spotlight.LinearAttenuation = 0f;
            spotlight.QuadraticAttenuation = 0f;
            CompositionLight = spotlight;

            PropSet = compositor.CreatePropertySet();
            PropSet.InsertScalar("OffsetX", 0f);
            PropSet.InsertScalar("OffsetY", 0f);
            PropSet.InsertScalar("OffsetZ", 300f);

            SpotLightOffsetAnimation = compositor.CreateExpressionAnimation("Vector3(PropSet.OffsetX ,PropSet.OffsetY ,PropSet.OffsetZ)");
            SpotLightOffsetAnimation.SetReferenceParameter("PropSet", PropSet);
            CompositionLight.StartAnimation("Offset", SpotLightOffsetAnimation);
            cbEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.42f, 0f), new Vector2(1f, 1f));
            line = compositor.CreateLinearEasingFunction();
            var an = compositor.CreateScalarKeyFrameAnimation();
            an.InsertKeyFrame(0f, 0f, cbEasing);
            an.InsertKeyFrame(1f, 60f, cbEasing);
            an.Duration = TimeSpan.FromSeconds(10);
            an.IterationBehavior = AnimationIterationBehavior.Forever;
        }
        private void TheGrid_OnLoaded(object sender, RoutedEventArgs e)
        {
            var bounds = Window.Current.Bounds;

            var hostVisual = ElementCompositionPreview.GetElementVisual(TheGrid);
            var visual     = hostVisual.Compositor.CreateSpriteVisual();

            visual.Brush  = hostVisual.Compositor.CreateColorBrush(Colors.Red);
            visual.Size   = new Vector2(100, 100);
            visual.Offset = new Vector3(((float)TheGrid.ActualWidth - visual.Size.X) / 2.0f, (float)(TheGrid.ActualHeight - visual.Size.Y) / 2.0f, 0);
            ElementCompositionPreview.SetElementChildVisual(TheGrid, visual);


            var anim = visual.Compositor.CreateExpressionAnimation("Vector3(This.CurrentValue.X >= shared.step ? (This.CurrentValue.X <= (shared.width - shared.step) ? (This.CurrentValue.X + (shared.pitch == 0 ? 0 : shared.pitch > 0 ? shared.step : -shared.step) ) : shared.pitch >= 0 ? shared.width : shared.width - shared.step) : shared.pitch <= 0 ? 0 : shared.step,This.CurrentValue.Y >= shared.step ? (This.CurrentValue.Y <= (shared.height - shared.step) ? (This.CurrentValue.Y + (shared.roll == 0 ? 0 : shared.roll > 0 ? shared.step : -shared.step) ) : shared.roll >= 0 ? shared.height : shared.height - shared.step) : shared.roll <= 0 ? 0 : shared.step,This.CurrentValue.Z)");

            _propertySet = visual.Compositor.CreatePropertySet();
            _propertySet.InsertScalar("roll", 0);
            _propertySet.InsertScalar("pitch", 0);
            _propertySet.InsertScalar("step", 3);
            _propertySet.InsertScalar("width", (float)Math.Floor(bounds.Width) - visual.Size.X);
            _propertySet.InsertScalar("height", (float)Math.Floor(bounds.Height) - visual.Size.Y);

            anim.SetReferenceParameter("shared", _propertySet);
            visual.StartAnimation(nameof(visual.Offset), anim);
            _inclinometer.ReadingTransform = DisplayOrientations.LandscapeFlipped;
            _inclinometer.ReadingChanged  += InclinometerOnReadingChanged;
        }
예제 #4
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(SCRpost);
            _compositor          = _scrollerPropertySet.Compositor;
            _props = _compositor.CreatePropertySet();
            _props.InsertScalar("progress", 0);
            _props.InsertScalar("clampSize", 150);
            _props.InsertScalar("scaleFactor", 0.7f);

            var progressAnimation = _compositor.CreateExpressionAnimation("Clamp(-scrollingProperties.Translation.Y/150,0,1)");

            progressAnimation.SetReferenceParameter("scrollingProperties", _scrollerPropertySet);
            _props.StartAnimation("progress", progressAnimation);
            Visual headerVisual = ElementCompositionPreview.GetElementVisual(Header);

            /*
             * var headerScaleAnimation = _compositor.CreateExpressionAnimation("Lerp(1,1.25f,Clamp(scrollingProperties.Translation.Y/50,0,1))");
             * headerScaleAnimation.SetReferenceParameter("scrollingProperties", _scrollerPropertySet);
             * headerVisual.StartAnimation("Scale.X", headerScaleAnimation);
             * headerVisual.StartAnimation("Scale.Y", headerScaleAnimation);
             * headerVisual.CenterPoint= new Vector3((float)(Header.ActualWidth / 2), (float)Header.ActualHeight, 0);*/
            var headerOffsetAnimation = _compositor.CreateExpressionAnimation("-150*props.progress");

            headerOffsetAnimation.SetReferenceParameter("props", _props);
            headerVisual.StartAnimation("Offset.Y", headerOffsetAnimation);
            Visual photoVisual           = ElementCompositionPreview.GetElementVisual(RECTback);
            var    photoOpacityAnimation = _compositor.CreateExpressionAnimation("1-props.progress");

            photoOpacityAnimation.SetReferenceParameter("props", _props);
            photoVisual.StartAnimation("Opacity", photoOpacityAnimation);
            Visual overlayVisual           = ElementCompositionPreview.GetElementVisual(OverlayRectangle);
            var    overlayOpacityAnimation = _compositor.CreateExpressionAnimation("props.progress");

            overlayOpacityAnimation.SetReferenceParameter("props", _props);
            overlayVisual.StartAnimation("Opacity", overlayOpacityAnimation);
            Visual blurbVisual          = ElementCompositionPreview.GetElementVisual(Blurb);
            var    textOpacityAnimation = _compositor.CreateExpressionAnimation("Clamp(1-(props.progress*2),0,1)");

            textOpacityAnimation.SetReferenceParameter("props", _props);
            var scaleAnimation = _compositor.CreateExpressionAnimation("Lerp(1,0.7f,props.progress)");

            scaleAnimation.SetReferenceParameter("props", _props);
            blurbVisual.StartAnimation("Opacity", textOpacityAnimation);
            blurbVisual.StartAnimation("Scale.X", scaleAnimation);
            blurbVisual.StartAnimation("Scale.Y", scaleAnimation);
            Visual titleVisual            = ElementCompositionPreview.GetElementVisual(TitleBlock);
            Visual buttonVisual           = ElementCompositionPreview.GetElementVisual(ButtonPanel);
            var    contentOffsetAnimation = _compositor.CreateExpressionAnimation("(props.progress)*120");
            var    titleScaleAnimation    = _compositor.CreateExpressionAnimation("Lerp(1,1.05f,props.progress)");

            contentOffsetAnimation.SetReferenceParameter("props", _props);
            titleScaleAnimation.SetReferenceParameter("props", _props);
            titleVisual.StartAnimation("Offset.Y", contentOffsetAnimation);
            titleVisual.StartAnimation("Scale.X", titleScaleAnimation);
            titleVisual.StartAnimation("Scale.Y", titleScaleAnimation);
            var buttonOffsetAnimation = _compositor.CreateExpressionAnimation("(props.progress*30)");

            buttonOffsetAnimation.SetReferenceParameter("props", _props);
            buttonVisual.StartAnimation("Offset.Y", buttonOffsetAnimation);
        }
예제 #5
0
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var compositor = Window.Current.Compositor;

            _sharedProperties = compositor.CreatePropertySet();
            _sharedProperties.InsertScalar("Radius", 200);
            _sharedProperties.InsertScalar("Angle", 0);
            _sharedProperties.InsertScalar("OffsetX", (float)VisualElement.ActualWidth / 2.0f);
            _sharedProperties.InsertScalar("OffsetY", (float)VisualElement.ActualHeight / 2.0f);
            var offsetExpression = compositor.CreateExpressionAnimation(
                "Vector3(" +
                "sharedProperties.OffsetX + sharedProperties.Radius * Cos(ToRadians(sharedProperties.Angle)) ," +
                "sharedProperties.OffsetY+ sharedProperties.Radius * Sin(ToRadians(sharedProperties.Angle)), " +
                "0)");

            offsetExpression.SetReferenceParameter("sharedProperties", _sharedProperties);

            _spriteVisual             = compositor.CreateSpriteVisual();
            _spriteVisual.Brush       = compositor.CreateColorBrush(Colors.Red);
            _spriteVisual.Size        = new Vector2(50, 50);
            _spriteVisual.AnchorPoint = new Vector2(0.5f, 0.5f);
            //_spriteVisual.Offset = new Vector3(25f, (float)VisualElement.ActualHeight / 2.0f, 0);

            ElementCompositionPreview.SetElementChildVisual(VisualElement, _spriteVisual);

            var rotateExpression = compositor.CreateExpressionAnimation("sharedProperties.Angle");

            rotateExpression.SetReferenceParameter("sharedProperties", _sharedProperties);
            _spriteVisual.StartAnimation("Offset", offsetExpression);
            _spriteVisual.StartAnimation(nameof(Visual.RotationAngleInDegrees), rotateExpression);
        }
        private void UpdateScrollableHeightInScrollViewerPropertySet()
        {
            _scrollerViewerManipulation.InsertScalar("MaxOverpan", (float)_scrollViewer.ViewportHeight * ScrollViewerMaxOverpanViewportRatio);

            if (PullDirection == PullDirection.BottomUp)
            {
                _scrollerViewerManipulation.InsertScalar("ScrollableHeight", (float)_scrollViewer.ScrollableHeight);
            }
        }
        /// <summary>
        /// Show the header
        /// </summary>
        public void Show()
        {
            if (_headerVisual != null && _scrollViewer != null)
            {
                _previousVerticalScrollOffset = _scrollViewer.VerticalOffset;

                _animationProperties.InsertScalar("OffsetY", 0.0f);
            }
        }
예제 #8
0
        protected override void OnConnected(UIElement element)
        {
            host    = ElementCompositionPreview.GetElementVisual(element);
            propset = host.Compositor.CreatePropertySet();
            propset.InsertScalar("offsetx", 0f);
            propset.InsertScalar("offsety", 0f);
            propset.InsertScalar("degress", 0f);
            propset.InsertVector3("axis", Vector3.UnitZ);

            UpdateTo();

            var group = host.Compositor.CreateAnimationGroup();

            var step = host.Compositor.CreateStepEasingFunction();

            offset = host.Compositor.CreateVector3KeyFrameAnimation();
            offset.InsertExpressionKeyFrame(0f, "this.StartingValue");
            offset.InsertExpressionKeyFrame(0.99f, "Vector3(this.FinalValue.X + prop.offsetx,this.FinalValue.Y + prop.offsety,this.FinalValue.Z)");
            offset.InsertExpressionKeyFrame(1f, "this.FinalValue", step);
            offset.SetReferenceParameter("host", host);
            offset.SetReferenceParameter("prop", propset);
            offset.Duration = Duration;
            offset.Target   = "Offset";

            axis = host.Compositor.CreateVector3KeyFrameAnimation();
            axis.InsertExpressionKeyFrame(0f, "prop.axis", step);
            axis.InsertExpressionKeyFrame(1f, "prop.axis", step);
            axis.SetReferenceParameter("prop", propset);
            axis.Duration = Duration;
            axis.Target   = "RotationAxis";

            degress = host.Compositor.CreateScalarKeyFrameAnimation();
            degress.InsertExpressionKeyFrame(0f, "this.StartingValue");
            degress.InsertExpressionKeyFrame(0.99f, "this.FinalValue + prop.degress");
            degress.InsertExpressionKeyFrame(1f, "this.FinalValue", step);
            degress.SetReferenceParameter("host", host);
            degress.SetReferenceParameter("prop", propset);
            degress.Duration = Duration;
            degress.Target   = "RotationAngleInDegrees";

            opacity = host.Compositor.CreateScalarKeyFrameAnimation();
            opacity.InsertExpressionKeyFrame(0f, "this.StartingValue");
            opacity.InsertKeyFrame(1f, 0f);
            opacity.Duration = Duration;
            opacity.Target   = "Opacity";

            group.Add(offset);
            group.Add(axis);
            group.Add(degress);
            group.Add(opacity);

            Animation = group;
        }
예제 #9
0
        /// <summary>
        /// Refresh the move
        /// </summary>
        private void RefreshMove(double x, double y)
        {
            lock (_lockerOffset)
            {
                if (Strategy == UIStrategy.Composition)
                {
                    if (_propertyOffsetModulo == null)
                    {
                        return;
                    }

                    _propertyOffsetModulo.InsertScalar("offsetX", (float)x);
                    _propertyOffsetModulo.InsertScalar("offsetY", (float)y);
                }
                else
                {
                    var orientation = ScrollOrientation;

                    var scrollviewer = _scrollviewer;

                    double scrollX = 0;
                    double scrollY = 0;

                    if (scrollviewer != null)
                    {
                        var speedRatio = ParallaxSpeedRatio;

                        scrollX = -((scrollviewer.HorizontalOffset * scrollviewer.ActualWidth) / scrollviewer.ViewportWidth) * speedRatio;
                        scrollY = -((scrollviewer.VerticalOffset * scrollviewer.ActualHeight) / scrollviewer.ViewportHeight) * speedRatio;
                    }

                    if (orientation == ScrollOrientation.Both || orientation == ScrollOrientation.Horizontal)
                    {
                        _containerTranslate.X = GetOffsetModulo(x + scrollX, _imageSize.Width);

                        if (orientation == ScrollOrientation.Horizontal)
                        {
                            _containerTranslate.Y = 0;
                        }
                    }

                    if (orientation == ScrollOrientation.Both || orientation == ScrollOrientation.Vertical)
                    {
                        _containerTranslate.Y = GetOffsetModulo(y + scrollY, _imageSize.Height);

                        if (orientation == ScrollOrientation.Vertical)
                        {
                            _containerTranslate.X = 0;
                        }
                    }
                }
            }
        }
예제 #10
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();
        }
        /// <summary>
        /// Refresh the move
        /// </summary>
        private void RefreshMove(double x, double y)
        {
            lock (_lockerOffset)
            {
                if (_propertySetModulo == null)
                {
                    return;
                }

                _propertySetModulo.InsertScalar("offsetX", (float)x);
                _propertySetModulo.InsertScalar("offsetY", (float)y);
            }
        }
예제 #12
0
        public override void OnPointerEnter(Vector2 pointerPosition, CompositionImage image)
        {
            _propertySet = _compositor.CreatePropertySet();
            _propertySet.InsertScalar("Scale", 1.25f);
            _propertySet.InsertScalar("Rotation", 0f);
            _propertySet.InsertVector2("Translate", new Vector2(0f, 0f));
            _propertySet.InsertVector2("CenterPointOffset", new Vector2((float)_lightMap.Size.Width / 2f, 0f));

            _transformExpression.SetReferenceParameter("props", _propertySet);

            image.Brush.StartAnimation("LightMapTransform.TransformMatrix", _transformExpression);
            _propertySet.StartAnimation("Rotation", _enterAnimation);
        }
예제 #13
0
        private void StartAnimation(bool pointerOver, float translation, float shadowOpacity, float blurRadius)
        {
            _propertySet.InsertScalar("TranslateTo", translation);
            var visual = ElementCompositionPreview.GetElementVisual(this);

            visual.StartAnimation("Translation.Y", _translationY);

            _propertySet.InsertScalar("Opacity", shadowOpacity);
            _propertySet.InsertScalar("BlurRadius", blurRadius);
            _animationGroup.RemoveAll();
            _animationGroup.Add(pointerOver ? _blurShadowIn : _blurShadowOut);
            _animationGroup.Add(_opacityShadow);
            _shadow.StartAnimationGroup(_animationGroup);
        }
예제 #14
0
        private void startAnimation(CompositionSurfaceBrush brush)
        {
            animatingPropset = compositor.CreatePropertySet();
            animatingPropset.InsertScalar("xcoord", 1.0f);
            animatingPropset.StartAnimation("xcoord", moveSurfaceExpressionAnimation);

            animatingPropset.InsertScalar("ycoord", 1.0f);
            animatingPropset.StartAnimation("ycoord", moveSurfaceUpDownExpressionAnimation);

            animateMatrix = compositor.CreateExpressionAnimation("Matrix3x2(1.0, 0.0, 0.0, 1.0, props.xcoord, props.ycoord)");
            animateMatrix.SetReferenceParameter("props", animatingPropset);

            brush.StartAnimation(nameof(brush.TransformMatrix), animateMatrix);
        }
예제 #15
0
        protected void List_Loaded(object sender, RoutedEventArgs e)
        {
            var scrollingHost = ScrollingHost.GetScrollViewer();

            if (scrollingHost != null)
            {
                //ScrollingHost.ItemsPanelRoot.SizeChanged += ItemsPanelRoot_SizeChanged;
                //ScrollingHost.ItemsPanelRoot.MinHeight = ActualHeight + ProfileHeader.ActualHeight;
                Canvas.SetZIndex(ScrollingHost.ItemsPanelRoot, -1);

                var properties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollingHost);
                var visual     = ElementCompositionPreview.GetElementVisual(HeaderPanel);
                var panel      = ElementCompositionPreview.GetElementVisual(ScrollingHost.ItemsPanelRoot);

                panel.Clip = panel.Compositor.CreateInsetClip();

                ElementCompositionPreview.SetIsTranslationEnabled(HeaderPanel, true);

                _properties = visual.Compositor.CreatePropertySet();
                _properties.InsertScalar("ActualHeight", ProfileHeader.ActualSize.Y + 16);
                _properties.InsertScalar("TopPadding", TopPadding);

                var translation = visual.Compositor.CreateExpressionAnimation(
                    "scrollViewer.Translation.Y > -properties.ActualHeight ? 0 : -scrollViewer.Translation.Y - properties.ActualHeight");
                translation.SetReferenceParameter("scrollViewer", properties);
                translation.SetReferenceParameter("properties", _properties);

                visual.StartAnimation("Translation.Y", translation);

                var clip = visual.Compositor.CreateExpressionAnimation(
                    "scrollViewer.Translation.Y > -properties.ActualHeight ? 0 : -scrollViewer.Translation.Y - properties.ActualHeight - properties.TopPadding");
                clip.SetReferenceParameter("scrollViewer", properties);
                clip.SetReferenceParameter("properties", _properties);

                panel.Clip.StartAnimation("TopInset", clip);

                //void handler(object _, object args)
                //{
                //    scrollingHost.LayoutUpdated -= handler;
                //    scrollingHost.ChangeView(null, ViewModel.VerticalOffset, null, true);
                //}

                //scrollingHost.InvalidateScrollInfo();
                //scrollingHost.ChangeView(null, ViewModel.VerticalOffset, null, true);

                //scrollingHost.LayoutUpdated += handler;
                scrollingHost.ViewChanged += OnViewChanged;
            }
        }
예제 #16
0
 private void OnSizeChanged(object sender, SizeChangedEventArgs e)
 {
     if (_scrollViewer != null)
     {
         _propertySet.InsertScalar("ScrollableHeight", (float)_scrollViewer.ScrollableHeight);
     }
 }
예제 #17
0
        private void Header_Loaded(object sender, RoutedEventArgs e)
        {
            var scrollviewer = MainScroller;

            _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollviewer);
            _compositor          = _scrollerPropertySet.Compositor;

            _props = _compositor.CreatePropertySet();
            _props.InsertScalar("progress", 0);

            // Get references to our property sets for use with ExpressionNodes
            var scrollingProperties = _scrollerPropertySet.GetSpecializedReference <ManipulationPropertySetReferenceNode>();
            var props        = _props.GetReference();
            var progressNode = props.GetScalarProperty("progress");

            // Create and start an ExpressionAnimation to track scroll progress over the desired distance
            ExpressionNode progressAnimation = EF.Clamp(-scrollingProperties.Translation.Y / ((float)Header.Height), 0, 1);

            _props.StartAnimation("progress", progressAnimation);

            var headerbgVisual         = ElementCompositionPreview.GetElementVisual(HeaderBG);
            var bgblurOpacityAnimation = EF.Clamp(progressNode, 0, 1);

            headerbgVisual.StartAnimation("Opacity", bgblurOpacityAnimation);
        }
예제 #18
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);
        }
예제 #19
0
 public static void InsertValue <T>(CompositionPropertySet prop, string name, T value) where T : struct
 {
     { if (value is float v)
       {
           prop.InsertScalar(name, v);
       }
     }
     { if (value is Vector2 v)
       {
           prop.InsertVector2(name, v);
       }
     }
     { if (value is Vector3 v)
       {
           prop.InsertVector3(name, v);
       }
     }
     { if (value is Vector4 v)
       {
           prop.InsertVector4(name, v);
       }
     }
     { if (value is Quaternion v)
       {
           prop.InsertQuaternion(name, v);
       }
     }
 }
예제 #20
0
 private void OnScrollViewerSizeChanged(object sender, SizeChangedEventArgs e)
 {
     if (sender is ScrollViewer scrollViewer)
     {
         propSet.InsertScalar("viewportheight", (float)scrollViewer.ViewportHeight);
     }
 }
예제 #21
0
        private void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            var animationService = ConnectedAnimationService.GetForCurrentView();
            var animation        = animationService.GetAnimation(Constants.ConnectedAnimationKey);

            if (animation != null)
            {
                animation.TryStart(CoverImage, new UIElement[] { SetImage });
            }

            // Get the PropertySet that contains the scroll values from MyScrollViewer
            _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(MyScrollviewer);
            _compositor          = _scrollerPropertySet.Compositor;

            // Create a PropertySet that has values to be referenced in the ExpressionAnimations below
            _props = _compositor.CreatePropertySet();
            _props.InsertScalar("progress", 0);
            _props.InsertScalar("clampSize", 100);

            // Get references to our property sets for use with ExpressionNodes
            var scrollingProperties = _scrollerPropertySet.GetSpecializedReference <ManipulationPropertySetReferenceNode>();
            var props         = _props.GetReference();
            var progressNode  = props.GetScalarProperty("progress");
            var clampSizeNode = props.GetScalarProperty("clampSize");

            // Create and start an ExpressionAnimation to track scroll progress over the desired distance
            var progressAnimation = ExpressionFunctions.Clamp(-scrollingProperties.Translation.Y / clampSizeNode, 0, 1);

            _props.StartAnimation("progress", progressAnimation);

            // Get the backing visual for the header so that its properties can be animated
            var headerVisual = ElementCompositionPreview.GetElementVisual(Header);

            // Create and start an ExpressionAnimation to clamp the header's offset to keep it onscreen
            var headerTranslationAnimation = ExpressionFunctions.Conditional(progressNode < 1, 0, -scrollingProperties.Translation.Y - clampSizeNode);

            headerVisual.StartAnimation("Offset.Y", headerTranslationAnimation);

            // Create and start an ExpressionAnimation to scale the header during overpan
            var headerScaleAnimation = ExpressionFunctions.Lerp(1, 1.25f, ExpressionFunctions.Clamp(scrollingProperties.Translation.Y / 50, 0, 1));

            headerVisual.StartAnimation("Scale.X", headerScaleAnimation);
            headerVisual.StartAnimation("Scale.Y", headerScaleAnimation);

            //Set the header's CenterPoint to ensure the overpan scale looks as desired
            headerVisual.CenterPoint = new Vector3((float)(Header.ActualWidth / 2), (float)Header.ActualHeight, 0);
        }
예제 #22
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 });
            }
        }
예제 #23
0
 public RefreshInfoProviderImpl(Compositor compositor)
 {
     executionRatio        = 0.8f;
     compositionProperties = compositor.CreatePropertySet();
     compositionProperties.InsertScalar(InteractionRatioCompositionProperty, 0.0f);
     isInteractingForRefresh = false;
     OnRefreshCompletedCalls = 0;
     OnRefreshStartedCalls   = 0;
 }
예제 #24
0
        /// <summary>
        /// Creates a PerspectiveProjection with default properties.
        /// Fov = Pi / 2
        /// Near = 1
        /// Far = 1000
        /// </summary>
        /// <param name="compositor"></param>
        /// <exception cref="System.ArgumentException">Thrown when constructor is passed a null value.</exception>
        public PerspectiveProjection(Compositor compositor)
        {
            if (compositor == null)
            {
                throw new System.ArgumentException("Compositor cannot be null");
            }

            _compositor  = compositor;
            _propertySet = _compositor.CreatePropertySet();

            // Create the properties for the projection
            _propertySet.InsertScalar("Fov", MathF.PI / 2);
            _propertySet.InsertScalar("Near", 1f);
            _propertySet.InsertScalar("Far", 1000f);
            _propertySet.InsertMatrix4x4("ProjectionMatrix", Matrix4x4.Identity);

            StartAnimationonProjectionMatrix();
        }
예제 #25
0
        private PlayerService()
        {
            Playlist = new Playlist();

            _compositionPropertySet = CompositionManager.Compositor.CreatePropertySet();
            _compositionPropertySet.InsertScalar("InputData", 0);

            InitializeMediaPlayer();
        }
예제 #26
0
        private void Header_Loaded(object sender, RoutedEventArgs e)
        {
            var scrollviewer = MainScroller;

            _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollviewer);
            _compositor          = _scrollerPropertySet.Compositor;

            _props = _compositor.CreatePropertySet();
            _props.InsertScalar("progress", 0);
            _props.InsertScalar("clampSize", (float)HeaderBG.Height);
            _props.InsertScalar("scaleFactor", 0.7f);

            // Get references to our property sets for use with ExpressionNodes
            var scrollingProperties = _scrollerPropertySet.GetSpecializedReference <ManipulationPropertySetReferenceNode>();
            var props           = _props.GetReference();
            var progressNode    = props.GetScalarProperty("progress");
            var clampSizeNode   = props.GetScalarProperty("clampSize");
            var scaleFactorNode = props.GetScalarProperty("scaleFactor");

            // Create and start an ExpressionAnimation to track scroll progress over the desired distance
            var progressAnimation = EF.Clamp(-scrollingProperties.Translation.Y / clampSizeNode, 0, 1);

            _props.StartAnimation("progress", progressAnimation);

            var headerbgVisual         = ElementCompositionPreview.GetElementVisual(HeaderBG);
            var bgblurOpacityAnimation = EF.Clamp(progressNode, 0, 1);

            headerbgVisual.StartAnimation("Opacity", bgblurOpacityAnimation);

            var headerVisual   = ElementCompositionPreview.GetElementVisual(HeroTitle);
            var scaleAnimation = EF.Lerp(1, scaleFactorNode, progressNode);

            headerVisual.StartAnimation("Scale.X", scaleAnimation);
            headerVisual.StartAnimation("Scale.Y", scaleAnimation);

            var offsetAnimation  = EF.Lerp(160f, 32f, progressNode);
            var opacityAnimation = EF.Lerp(1f, 0.6f, progressNode);

            var containerVisual = ElementCompositionPreview.GetElementVisual(TextContainer);

            containerVisual.StartAnimation("Offset.Y", offsetAnimation);
            containerVisual.StartAnimation("Opacity", opacityAnimation);
        }
예제 #27
0
        protected void ProfileHeader_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            _properties?.InsertScalar("ActualHeight", (float)e.NewSize.Height + 16);

            //var panel = ScrollingHost.ItemsPanelRoot;
            //if (panel != null)
            //{
            //    panel.MinHeight = ActualHeight + e.NewSize.Height;
            //}
        }
예제 #28
0
        private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
        {
            var scroll = (ScrollViewer)sender;

            if (UseQuickBack)
            {
                var DeltaY = Convert.ToSingle(scroll.VerticalOffset - LastY);
                LastY = scroll.VerticalOffset;

                CumulativeDeltaY += DeltaY;
                if (CumulativeDeltaY <= 0)
                {
                    CumulativeDeltaY = 0;
                    if (LastState != HeaderState.Start)
                    {
                        OnScrollHeaderStateChanged(HeaderState.Start);
                    }
                }
                else if (CumulativeDeltaY >= Threshold)
                {
                    CumulativeDeltaY = Convert.ToSingle(Threshold);
                    if (LastState != HeaderState.Final)
                    {
                        OnScrollHeaderStateChanged(HeaderState.Final);
                    }
                }
                else
                {
                    OnScrollHeaderStateChanged(HeaderState.Changing);
                }
                PropSet.InsertScalar("DeltaY", CumulativeDeltaY);
            }
            else
            {
                LastY = scroll.VerticalOffset;
                if (scroll.VerticalOffset <= 0)
                {
                    if (LastState != HeaderState.Start)
                    {
                        OnScrollHeaderStateChanged(HeaderState.Start);
                    }
                }
                else if (scroll.VerticalOffset >= Threshold)
                {
                    if (LastState != HeaderState.Final)
                    {
                        OnScrollHeaderStateChanged(HeaderState.Final);
                    }
                }
                else
                {
                    OnScrollHeaderStateChanged(HeaderState.Changing);
                }
            }
        }
예제 #29
0
        public WaveProgressControl()
        {
            InitializeComponent();

            _compositor = Window.Current.Compositor;

            _percentPropertySet = _compositor.CreatePropertySet();
            _percentPropertySet.InsertScalar("Value", 0.0f);

            Loaded += OnLoaded;
        }
        public override void OnPointerEnter(Vector2 pointerPosition, CompositionImage image)
        {
            _propertySet = _compositor.CreatePropertySet();
            _propertySet.InsertScalar("Scale", 1.25f);
            _propertySet.InsertScalar("Rotation", 0f);
            _propertySet.InsertVector2("Translate", new Vector2(0f, 0f));
            _propertySet.InsertVector2("CenterPointOffset", new Vector2((float)_lightMap.Size.Width / 2f, 0f));

            _transformExpression.SetReferenceParameter("props", _propertySet);

            image.Brush.StartAnimation("LightMapTransform.TransformMatrix", _transformExpression);
            _propertySet.StartAnimation("Rotation", _enterAnimation);
        }
예제 #31
0
        private void CreateCompositionScene(Compositor compositor)
        {
            // Create the property driving the animations
            _animationPropertySet = _compositor.CreatePropertySet();
            _animationPropertySet.InsertScalar("currentZ", selectedLayerIndex);

            // Create the layer effect
            var layerEffectDesc = new GaussianBlurEffect
            {
                Name = "blur",
                BorderMode = EffectBorderMode.Hard,
                BlurAmount = 0,
                Source = new SaturationEffect
                {
                    Name = "saturation",
                    Saturation = 1,
                    Source = new CompositionEffectSourceParameter("source")
                }
            };

            var layerEffectFactory = _compositor.CreateEffectFactory(layerEffectDesc,
                new[] { "blur.BlurAmount", "saturation.Saturation" });

            // Create the host visual
            _rootVisual = compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(compositionHostPanel, _rootVisual);

            // Create the scene visuals
            for (int layerIndex = 0; layerIndex < layers.Count; ++layerIndex)
            {
                var layer = layers[layerIndex];
                layer.CreateVisuals(compositor);

                _rootVisual.Children.InsertAtBottom(layer.LayerVisual);
                layer.LayerVisual.Effect = layerEffectFactory.CreateBrush();
                SetupLayerAnimations(layer, layerIndex);
            }

            UpdateVisualLayout();
        }
        public override void OnPointerEnter(Vector2 pointerPosition, CompositionImage image)
        {
            _propertySet = _compositor.CreatePropertySet();
            _propertySet.InsertScalar("Scale", 1f);
            Vector2 positionNormalized = new Vector2((pointerPosition.X / (float)image.Width) - .5f, (pointerPosition.Y / (float)image.Height) - .5f);
            _propertySet.InsertVector2("Translate", positionNormalized);
            _propertySet.InsertVector2("CenterPointOffset", new Vector2(128, 128));

            _transformExpression.SetReferenceParameter("props", _propertySet);

            image.Brush.StartAnimation("LightMapTransform.TransformMatrix", _transformExpression);
            _propertySet.StartAnimation("Scale", _enterAnimation);
        }