/// <summary>
        /// ダウン時動作
        /// </summary>
        /// <param name="e"></param>
        private void OnDown(PointerTapEventArgs e, UIElement target)
        {
            // マウスムーブをマウスダウンまでスキップ。マウスダウン時にマウスをキャプチャ

            if (this.isMouseCapturing)
            {
                return;
            }

            this.StopAnimation();
            //this.story?.Pause();

            var position = (Vector)e.GetPosition(this.AssociatedObject);

            this.startPosition = position;

            this.positionHistory.Clear();
            this.intervalMilliSecHistory.Clear();


            this.startOffset = new Vector
                                   (this.AssociatedObject.HorizontalOffset, this.AssociatedObject.VerticalOffset);

            this.isTouch = e.IsTouch;

            //this.isInartiaMoving = false;
            //this.isMouseCapturing = false;

            //if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
            {
                target.CaptureMouse();//.CapturePointer(e.Pointer);
                this.isMouseCapturing = true;
            }
        }
Example #2
0
        /// <summary>
        /// ダウン時動作
        /// </summary>
        /// <param name="e"></param>
        private void OnDown(PointerTapEventArgs e, UIElement target)
        {
            var position = (Vector)e.GetPosition(this.AssociatedObject);

            this.startPosition = position;
            this.startTime     = DateTime.Now;
            this.moved         = false;
        }
Example #3
0
        /// <summary>
        /// 移動中動作
        /// </summary>
        /// <param name="e"></param>
        private void OnMove(PointerTapEventArgs e, UIElement target)
        {
            var point = (Vector)e.GetPosition(this.AssociatedObject);


            if ((point - this.startPosition).LengthSquared > 800)
            {
                this.moved = true;
            }
        }
        /// <summary>
        /// 移動中動作
        /// </summary>
        /// <param name="e"></param>
        private void OnMove(PointerTapEventArgs e, UIElement target)
        {
            //this.isInartiaMoving = false;

            if (!this.isMouseCapturing)
            {
                return;
            }

            var point = (Vector)e.GetPosition(this.AssociatedObject);

            this.positionHistory.Push(point);

            this.CurrentOffset = (Point)(this.startOffset - point + this.startPosition);
        }
Example #5
0
        /// <summary>
        /// アップ時動作
        /// </summary>
        /// <param name="e"></param>
        private void OnUp(PointerTapEventArgs e, UIElement target)
        {
            var timeSpan = DateTime.Now - this.startTime;

            if (!this.moved)
            {
                var args = e.Clone();

                args.Span          = timeSpan;
                args.StartPosition = this.startPosition;
                args.EndPosition   = (Vector)e.GetPosition(this.AssociatedObject);
                args.SenderHeight  = this.AssociatedObject.ActualHeight;
                args.SenderWidth   = this.AssociatedObject.ActualWidth;

                this.TapSubject.OnNext(args);
            }
        }
        /// <summary>
        /// アップ時動作
        /// </summary>
        /// <param name="e"></param>
        private void OnUp(PointerTapEventArgs e, UIElement target)
        {
            if (target?.IsMouseCaptured == true)
            {
                target.ReleaseMouseCapture();
            }


            this.StopAnimation();

            if (!this.isMouseCapturing)
            {
                return;
            }
            var pc = this.positionHistory.Count;
            var tc = this.intervalMilliSecHistory.Count;

            if (tc < 2)
            {
                return;
            }

            var positionZ1 = this.positionHistory.Pop();

            var lastPosition         = positionZ1;
            var prevPosition         = positionZ1;
            var lastIntervalMilliSec = this.intervalMilliSecHistory.Pop();

            while (this.positionHistory.Count > 0 && this.intervalMilliSecHistory.Count > 0)
            {
                prevPosition = this.positionHistory.Pop();
                if (lastPosition != prevPosition)
                {
                    break;
                }
                lastIntervalMilliSec = this.intervalMilliSecHistory.Pop();
            }

            this.positionHistory.Clear();
            this.intervalMilliSecHistory.Clear();


            if (lastIntervalMilliSec <= 0)
            {
                return;
            }

            var velocity = (lastPosition - prevPosition) / lastIntervalMilliSec;


            var displacement = this.startPosition - positionZ1;
            var vo           = velocity.Length;

            if (vo > this.scrollableVelocityThreshold &&
                displacement.Length > scrollableDisplacementThreshold)
            {
                var a = -Math.Log(vo / this.endVelocity);

                var damping = this.CalcDamping(vo);

                var time = Math.Min(-a / damping * vo / (vo - this.endVelocity), maxTime);

                var start = this.startOffset + displacement;
                var goal  = start - velocity / damping;


                // 慣性スクロールアニメーション開始
                //var storyboard = new Storyboard();
                var animation = new PointAnimation()
                {
                    From           = (Point)start,
                    To             = new Point(Math.Round(goal.X), Math.Round(goal.Y)),// (Point)goal,
                    Duration       = new Duration(TimeSpan.FromMilliseconds(time)),
                    EasingFunction = new ExponentialEase()
                    {
                        Exponent   = a,
                        EasingMode = EasingMode.EaseIn
                    },
                    //EnableDependentAnimation = true,
                };
                Storyboard.SetTarget(animation, this);
                Storyboard.SetTargetProperty(animation, new PropertyPath(CurrentOffsetProperty));

                //new PropertyPath($"({nameof(InertiaScrollViewerBehaviour)}.{nameof(CurrentOffset)})"));

                this.BeginAnimation(CurrentOffsetProperty, animation);

                //storyboard.Children.Add(animation);

                //this.story = storyboard;

                //storyboard.Begin();
            }

            this.isMouseCapturing = false;
        }