public override bool OnTouchEvent(MotionEvent e)
        {
            float currentX = e.GetX();
            float currentY = e.GetY();

            switch (e.Action)
            {
            case MotionEventActions.Down:
                path.MoveTo(currentX, currentY);

                previousX = currentX;
                previouxY = currentY;
                return(true);

            case MotionEventActions.Move:
            case MotionEventActions.Up:
                for (int i = 0; i < e.HistorySize; i++)
                {
                    float historicalX = e.GetHistoricalX(i);
                    float historicalY = e.GetHistoricalY(i);
                    path.LineTo(historicalX, historicalY);
                }
                path.LineTo(currentX, currentY);

                Invalidate();

                previousX = currentX;
                previouxY = currentY;
                return(true);

            default:
                return(false);
            }
        }
        //Iterate through the touch history since the last touch event and add them to the path and points list.
        void handleTouch(MotionEvent e)
        {
            float touchX = e.GetX();
            float touchY = e.GetY();

            System.Drawing.PointF touch = new System.Drawing.PointF(touchX, touchY);

            resetBounds(touchX, touchY);

            for (var i = 0; i < e.HistorySize; i++)
            {
                float historicalX = e.GetHistoricalX(i);
                float historicalY = e.GetHistoricalY(i);

                System.Drawing.PointF historical = new System.Drawing.PointF(historicalX, historicalY);

                updateBounds(historicalX, historicalY);

                currentPath.LineTo(historicalX, historicalY);
                currentPoints.Add(historical);
            }

            currentPath.LineTo(touchX, touchY);
            currentPoints.Add(touch);
        }
Пример #3
0
        private void TouchesMoved(MotionEvent e, bool update = true)
        {
            for (var i = 0; i < e.HistorySize; i++)
            {
                float historicalX = e.GetHistoricalX(i);
                float historicalY = e.GetHistoricalY(i);

                // update the dirty rectangle
                UpdateBounds(historicalX, historicalY);

                // add it to the current path
                currentPath.Path.LineTo(historicalX, historicalY);
                currentPath.GetPoints().Add(new System.Drawing.PointF(historicalX, historicalY));
            }

            float touchX = e.GetX();
            float touchY = e.GetY();

            // add it to the current path
            currentPath.Path.LineTo(touchX, touchY);
            currentPath.GetPoints().Add(new System.Drawing.PointF(touchX, touchY));

            // update the dirty rectangle
            UpdateBounds(touchX, touchY);
            if (update)
            {
                Invalidate(DirtyRect);
            }
        }
Пример #4
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            float x = ev.GetX();
            float y = ev.GetY();

            switch (ev.Action)
            {
            case MotionEventActions.Down:
                touch_start(x, y);
                Invalidate();
                break;

            case MotionEventActions.Move:
                for (int i = 0, n = ev.HistorySize; i < n; i++)
                {
                    touch_move(ev.GetHistoricalX(i), ev.GetHistoricalY(i));
                }
                touch_move(x, y);
                Invalidate();
                break;

            case MotionEventActions.Up:
                touch_up(x, y);
                Invalidate();
                break;
            }
            return(true);
        }
Пример #5
0
        private void handleMouseMoveRelativeEvent(MotionEvent evt)
        {
            for (int i = 0; i < evt.HistorySize; i++)
            {
                handleMouseMoveRelative(new Vector2(evt.GetHistoricalX(i), evt.GetHistoricalY(i)));
            }

            handleMouseMoveRelative(new Vector2(evt.GetX(), evt.GetY()));
        }
Пример #6
0
        private void TouchesMoved(MotionEvent e, bool update = true)
        {
            // something may have happened (clear) so start the stroke again
            if (currentPath == null)
            {
                TouchesBegan(e);
            }

            var hasMoved = false;

            for (var i = 0; i < e.HistorySize; i++)
            {
                float historicalX = e.GetHistoricalX(i);
                float historicalY = e.GetHistoricalY(i);

                if (HasMovedFarEnough(currentPath, historicalX, historicalY))
                {
                    // update the dirty rectangle
                    UpdateBounds(historicalX, historicalY);
                    hasMoved = true;

                    // add it to the current path
                    currentPath.Path.LineTo(historicalX, historicalY);
                }

                currentPath.GetPoints().Add(new InkPoint(
                                                new System.Drawing.PointF(historicalX, historicalY),
                                                e.GetHistoricalPressure(i),
                                                null,
                                                TimeSpan.FromMilliseconds(e.GetHistoricalEventTime(i))));
            }

            float touchX = e.GetX();
            float touchY = e.GetY();

            if (HasMovedFarEnough(currentPath, touchX, touchY))
            {
                // add it to the current path
                currentPath.Path.LineTo(touchX, touchY);

                // update the dirty rectangle
                UpdateBounds(touchX, touchY);
                hasMoved = true;
            }

            currentPath.GetPoints().Add(new InkPoint(
                                            new System.Drawing.PointF(touchX, touchY),
                                            e.Pressure,
                                            null,
                                            TimeSpan.FromMilliseconds(e.EventTime)));

            if (update && hasMoved)
            {
                Invalidate(DirtyRect);
            }
        }
Пример #7
0
        private void handleMouseMoveEvent(MotionEvent evt)
        {
            // https://developer.android.com/reference/android/View/MotionEvent#batching
            for (int i = 0; i < evt.HistorySize; i++)
            {
                handleMouseMove(new Vector2(evt.GetHistoricalX(i), evt.GetHistoricalY(i)));
            }

            handleMouseMove(new Vector2(evt.RawX, evt.RawY));
        }
        public override bool OnTouchEvent(MotionEvent e)
        {
            if (e.Action == MotionEventActions.Down)
            {
                CaptureMovementCheck(e);
                return(true);
            }
            if (!isTracking && !CaptureMovementCheck(e))
            {
                return(true);
            }

            if (e.Action != MotionEventActions.Move || MoveDirectionTest(e))
            {
                velocityTracker.AddMovement(e);
            }

            if (e.Action == MotionEventActions.Move)
            {
                var x = e.HistorySize > 0 ? e.GetHistoricalX(0) : e.GetX();
                var traveledDistance = (int)Math.Round(Math.Abs(x - (startX)));
                SetNewOffset(stateBeforeTracking ?
                             MaxOffset - Math.Min(MaxOffset, traveledDistance)
                              : Math.Max(0, traveledDistance));
            }
            else if (e.Action == MotionEventActions.Up &&
                     stateBeforeTracking == opened)
            {
                velocityTracker.ComputeCurrentVelocity(1000, maxFlingVelocity);
                if (Math.Abs(velocityTracker.XVelocity) > minFlingVelocity)
                {
                    SetOpened(!opened);
                }
                else if (!opened && contentOffsetX > MaxOffset / 2)
                {
                    SetOpened(true);
                }
                else if (opened && contentOffsetX < MaxOffset / 2)
                {
                    SetOpened(false);
                }
                else
                {
                    SetOpened(opened);
                }

                preTracking = isTracking = false;
            }

            return(true);
        }
Пример #9
0
        private void handleMouseMoveEvent(MotionEvent evt)
        {
            // https://developer.android.com/reference/android/View/MotionEvent#batching
            for (int i = 0; i < evt.HistorySize; i++)
            {
                handleMouseMove(new Vector2(evt.GetHistoricalX(i), evt.GetHistoricalY(i)));
            }

            handleMouseMove(new Vector2(evt.GetX(), evt.GetY()));

            absolutePositionReceived = true;

            // we may lose pointer capture if we lose focus / the app goes to the background,
            // so we use this opportunity to update capture if the user has requested it.
            updatePointerCapture();
        }
Пример #10
0
        private bool StartScroll(MotionEvent ev)
        {
            if (ev.HistorySize < 1)
            {
                return(false);
            }
            var historicalX = ev.GetHistoricalX(0);

            if (Math.Abs(historicalX - ev.GetX()) > m_scaledTouchSlop) // Increase value if we require a longer drag before scrolling starts.
            {
                m_isScrolling = true;
                m_elem?.SendPan(0, 0, GestureStatus.Started, m_pointerId);
                return(true);
            }

            return(false);
        }
Пример #11
0
        //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
        //ORIGINAL LINE: public float getHistoricalValue(@Nullable final android.view.MotionEvent event, final int index)
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        public float GetHistoricalValue(MotionEvent @event, int index)
        {
            if (@event != null)
            {
                switch (innerEnumValue)
                {
                case InnerEnum.X:
                    return(@event.GetHistoricalX(index));

                case InnerEnum.Y:
                    return(@event.GetHistoricalY(index));

                default:
                    return(0);
                }
            }

            return(0);
        }
Пример #12
0
        internal void TrackMotionDirections(MotionEvent e)
        {
            if (!_shouldRecalibrateFlingVelocity)
            {
                return;
            }

            switch (e.Action)
            {
            case MotionEventActions.Down:
                _deltaX = _deltaY = null;
                SaveCurrentCoordinates();
                break;

            case MotionEventActions.Move:
                ComputeMotionDirections();
                SaveCurrentCoordinates();
                break;

            case MotionEventActions.Up:
                // Note that ACTION_UP and ACTION_POINTER_UP always report the last known position
                // of the pointers that went up. -- VelocityTracker.cpp
                // Ignoring this one, since trying to compute directions here will always return 0s.
                break;

            case MotionEventActions.Cancel:
                _deltaX = _deltaY = null;
                break;
            }

            void SaveCurrentCoordinates()
            {
                _previousX = e.GetX();
                _previousY = e.GetY();
            }

            void ComputeMotionDirections()
            {
                _deltaX = e.GetX() - (e.HistorySize > 0 ? e.GetHistoricalX(e.HistorySize - 1) : _previousX);
                _deltaY = e.GetY() - (e.HistorySize > 0 ? e.GetHistoricalY(e.HistorySize - 1) : _previousY);
            }
        }
Пример #13
0
        private void TouchesMoved(MotionEvent e, bool update = true)
        {
            // something may have happened (clear) so start the stroke again
            if (currentPath == null)
            {
                TouchesBegan(e);
            }

            for (var i = 0; i < e.HistorySize; i++)
            {
                float historicalX = e.GetHistoricalX(i);
                float historicalY = e.GetHistoricalY(i);

                if (HasMovedFarEnough(currentPath, historicalX, historicalY))
                {
                    // update the dirty rectangle
                    UpdateBounds(historicalX, historicalY);

                    // add it to the current path
                    currentPath.Path.LineTo(historicalX, historicalY);
                    currentPath.GetPoints().Add(new System.Drawing.PointF(historicalX, historicalY));
                }
            }

            float touchX = e.GetX();
            float touchY = e.GetY();

            if (HasMovedFarEnough(currentPath, touchX, touchY))
            {
                // add it to the current path
                currentPath.Path.LineTo(touchX, touchY);
                currentPath.GetPoints().Add(new System.Drawing.PointF(touchX, touchY));

                // update the dirty rectangle
                UpdateBounds(touchX, touchY);
                if (update)
                {
                    Invalidate(DirtyRect);
                }
            }
        }
Пример #14
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            var spos = new Vector2(e.GetX(), _size.Y - e.GetY());
            var pos  = this.NormalizeToViewport(spos);

            switch (e.Action)
            {
            case MotionEventActions.Down:
                _queue.Enqueue(new Touch(TouchState.Start, pos, spos));
                break;

            case MotionEventActions.Up:
                _queue.Enqueue(new Touch(TouchState.End, pos, spos));
                break;

            case MotionEventActions.Move:
                for (var i = 0; i < e.HistorySize; i++)
                {
                    var shpos = new Vector2(e.GetHistoricalX(i), _size.Y - e.GetHistoricalY(i));
                    var hpos  = this.NormalizeToViewport(shpos);
                    _queue.Enqueue(new Touch(TouchState.Move, hpos, shpos));
                }
                _queue.Enqueue(new Touch(TouchState.Move, pos, spos));
                break;

            case MotionEventActions.Cancel:
                _queue.Enqueue(new Touch(TouchState.Cancel, pos, spos));
                break;

            default:
                break;
            }
            if (_gestureDetector != null)
            {
                _gestureDetector.OnTouchEvent(e);
            }
            return(true);
        }
Пример #15
0
            public override bool OnTrackballEvent(MotionEvent e)
            {
                MotionEventActions action = e.ActionMasked;

                if (action == MotionEventActions.Down)
                {
                    // Advance color when the trackball button is pressed.
                    AdvanceColor();
                }

                if (action == MotionEventActions.Down || action == MotionEventActions.Move)
                {
                    int   N      = e.HistorySize;
                    float scaleX = e.XPrecision * TRACKBALL_SCALE;
                    float scaleY = e.YPrecision * TRACKBALL_SCALE;
                    for (int i = 0; i < N; i++)
                    {
                        MoveTrackball(e.GetHistoricalX(i) * scaleX,
                                      e.GetHistoricalY(i) * scaleY);
                    }
                    MoveTrackball(e.GetX() * scaleX, e.GetY() * scaleY);
                }
                return(true);
            }
Пример #16
0
            bool OnTouchOrHoverEvent(MotionEvent e, bool isTouch)
            {
                MotionEventButtonState buttonState    = e.ButtonState;
                MotionEventButtonState pressedButtons = buttonState & ~mOldButtonState;

                mOldButtonState = buttonState;

                if ((pressedButtons & MotionEventButtonState.Secondary) != 0)
                {
                    // Advance color when the right mouse button or first stylus button
                    // is pressed.
                    AdvanceColor();
                }

                PaintMode mode;

                if ((buttonState & MotionEventButtonState.Tertiary) != 0)
                {
                    // Splat paint when the middle mouse button or second stylus button is pressed.
                    mode = PaintMode.Splat;
                }
                else if (isTouch || (buttonState & MotionEventButtonState.Primary) != 0)
                {
                    // Draw paint when touching or if the primary button is pressed.
                    mode = PaintMode.Draw;
                }
                else
                {
                    // Otherwise, do not paint anything.
                    return(false);
                }

                MotionEventActions action = e.ActionMasked;

                if (action == MotionEventActions.Down || action == MotionEventActions.Move ||
                    action == MotionEventActions.HoverMove)
                {
                    int N = e.HistorySize;
                    int P = e.PointerCount;
                    for (int i = 0; i < N; i++)
                    {
                        for (int j = 0; j < P; j++)
                        {
                            Paint(GetPaintModeForTool(e.GetToolType(j), mode),
                                  e.GetHistoricalX(j, i),
                                  e.GetHistoricalY(j, i),
                                  e.GetHistoricalPressure(j, i),
                                  e.GetHistoricalTouchMajor(j, i),
                                  e.GetHistoricalTouchMinor(j, i),
                                  e.GetHistoricalOrientation(j, i),
                                  e.GetHistoricalAxisValue(Axis.Distance, j, i),
                                  e.GetHistoricalAxisValue(Axis.Tilt, j, i));
                        }
                    }
                    for (int j = 0; j < P; j++)
                    {
                        Paint(GetPaintModeForTool(e.GetToolType(j), mode),
                              e.GetX(j),
                              e.GetY(j),
                              e.GetPressure(j),
                              e.GetTouchMajor(j),
                              e.GetTouchMinor(j),
                              e.GetOrientation(j),
                              e.GetAxisValue(Axis.Distance, j),
                              e.GetAxisValue(Axis.Tilt, j));
                    }
                    mCurX = e.GetX();
                    mCurY = e.GetY();
                }
                return(true);
            }
Пример #17
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            _touchReleased = false;
            float eventX;
            float eventY;

            if (_previousWidth != 0.0)
            {
                _widthRatio = _screenWidth / _previousWidth;
            }

            if (Resources.Configuration.Orientation == Orientation.Landscape)
            {
                var x = e.GetX() / _widthRatio;
                var y = e.GetY() / _widthRatio;
                eventX = x - _newPositionOfX;
                eventY = y - newPositionOfY;
            }
            else
            {
                eventX = e.GetX();
                eventY = e.GetY();
            }

            _pathContainerOpen = true;

            if (!_autoTouchtriggered)
            {
                switch (e.Action)
                {
                case MotionEventActions.Down:
                    _path.MoveTo(eventX, eventY);
                    if (!_autoTouchtriggered)
                    {
                        if (_vectorStringData.Contains("M"))
                        {
                            _vectorStringData +=
                                " \" fill=\"none\" stroke=\"black\" stroke-width=\"1\"/>\n\"  <path d=\"";
                            _vectorStringData += $"M {eventX} {eventY}";
                        }
                        else
                        {
                            if (_vectorStringData.Contains(SvgEnd))
                            {
                                _vectorStringData = _vectorStringData.Replace(SvgEnd, "");
                            }
                            _vectorStringData = $"M {eventX} {eventY}";
                        }
                    }
                    _lastTouchX = eventX;
                    _lastTouchY = eventY;
                    return(true);

                case MotionEventActions.Move:

                case MotionEventActions.Up:
                    ResetSignatureBoundRect(eventX, eventY);
                    var historySize = e.HistorySize;

                    for (var i = 0; i < historySize; i++)
                    {
                        float historicalX;
                        float historicalY;
                        if (Resources.Configuration.Orientation == Orientation.Landscape)
                        {
                            historicalX = e.
                                          GetHistoricalX(i) / _widthRatio
                                          - _newPositionOfX;
                            historicalY        = e.GetHistoricalY(i) / _widthRatio - newPositionOfY;
                            _vectorStringData += $" L {e.GetHistoricalX(i) / _widthRatio} {e.GetHistoricalY(i) / _widthRatio}";
                        }
                        else
                        {
                            historicalX = e.
                                          GetHistoricalX(i)
                                          - _newPositionOfX;
                            historicalY = e.
                                          GetHistoricalY(i)
                                          - newPositionOfY;
                            _vectorStringData += $" L {e.GetHistoricalX(i)} {e.GetHistoricalY(i)}";
                        }
                        ExpandSignatureBoundRect(historicalX, historicalY);
                        _path.LineTo(historicalX, historicalY);
                    }

                    _path.LineTo(eventX, eventY);
                    _vectorStringData += $" L {eventX} {eventY}";
                    break;

                default:
                    return(false);
                }
            }
            else
            {
                _autoTouchtriggered = false;
            }

            _touchReleased = true;

            Invalidate((int)(_signatureBoundRect.Left - _strokeWidth / 2),
                       (int)(_signatureBoundRect.Top - _strokeWidth / 2),
                       (int)(_signatureBoundRect.Right + _strokeWidth / 2),
                       (int)(_signatureBoundRect.Bottom + _strokeWidth / 2));

            _lastTouchX = eventX;
            _lastTouchY = eventY;

            return(true);
        }