Пример #1
0
		//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);
		}
Пример #2
0
        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;
        }
Пример #3
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;
        }
Пример #4
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;
			}
Пример #5
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;
			}
Пример #6
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;
		}