/// <summary> /// Handles a particular touch by the user /// </summary> /// <param name='touch'>The position and type of gesture/touch made</param> /// <param name='touchPosition'>Touch position.</param> protected override void HandleTouch(ITouchPoint touchPosition) { var gaugeTouchPoint = touchPosition; if (this.boundsMiddleImage.Contains(touchPosition.Position)) { // if the user starts to press the gauge but slightly misses it (as it is quite small) and hence // their Y is just above/below the gauge then we alter the Y position to ensure that the touch // will get picked up on gaugeTouchPoint = new TouchPoint( new Vector2(touchPosition.Position.X, this.gaugeBounds.Y), touchPosition.TouchType); } else if (this.boundsLeftImage.Contains(touchPosition.Position)) { // if the user presses the 'slow icon' to the left of the gauge then treat this as pressing the // far left of the gauge - i.e. the slowest speed gaugeTouchPoint = new TouchPoint( new Vector2(this.boundsMiddleImage.X, this.gaugeBounds.Y), touchPosition.TouchType); } else if (this.boundsRightImage.Contains(touchPosition.Position)) { // if the user presses the 'fast icon' to the right of the gauge then treat this as pressing the // far right of the gauge - i.e. the fastest speed gaugeTouchPoint = new TouchPoint( new Vector2(this.boundsMiddleImage.X + this.boundsMiddleImage.Width - 1, this.gaugeBounds.Y), touchPosition.TouchType); } this.gauge.CheckTouchCollision(gaugeTouchPoint); }
/// <summary> /// Handles any user input. /// Collect all gestures made since the last 'update' - check if these need to be handled /// </summary> private void HandleInput() { while (TouchPanel.IsGestureAvailable) { // read the next gesture from the queue GestureSample gesture = TouchPanel.ReadGesture(); TouchType touchType = this.ConvertGestureType(gesture.GestureType); TouchPoint touchPoint = new TouchPoint(gesture.Position, touchType); this.CheckToolboxCollision(touchPoint); } }
/// <summary> /// Checks whether the user has touched inside the toolbox /// </summary> /// <returns> /// true if the touch is within the toolbox, false if not /// </returns> /// <param name='touchPoint' Where the user touched the screen /> protected bool CheckToolboxCollision(ITouchPoint touchPoint) { bool touchInToolbox = false; ITouchPoint offsetCollisionPoint = touchPoint; if (this.ToolBox.DockPosition == DockPosition.Bottom) { int toolboxPositionY = (this.ImageStateData.Height - this.ToolBox.ToolboxHeight); Vector2 offsetPosition = new Vector2(touchPoint.Position.X, touchPoint.Position.Y - toolboxPositionY); offsetCollisionPoint = new TouchPoint(offsetPosition, touchPoint.TouchType); if (touchPoint.Position.Y >= toolboxPositionY) { touchInToolbox = true; } } else { if (touchPoint.Position.Y <= this.ToolBox.ToolboxHeight) { touchInToolbox = true; } } if (touchInToolbox == false) { return false; } this.ToolBox.CheckTouchCollision(offsetCollisionPoint); return true; }