public void Enqueue(int id, TouchLocationState state, Vector2 pos, bool isMouse = false) { lock (_queue) { _queue.Add(new TouchEvent(id, state, pos, isMouse)); } }
public void Update(TouchCollection NewCollection) { this.touchCollection = NewCollection; Touch = touchCollection[0]; prevTouchState = curTouchState; curTouchState = Touch.State; }
public TouchEvent(int id, TouchLocationState state, Vector2 pos, bool isMouse) { Id = id; State = state; Pos = pos; IsMouse = isMouse; }
public void NonPressedDoesntStartATouch(TouchLocationState providedState) { _tps.AddEvent(1, providedState, new Vector2(100, 50)); var state = _tps.GetState(); Assert.AreEqual(0, state.Count); }
/// <summary> /// Constructor. /// </summary> public FlxMouse() { screenX = 0; screenY = 0; cursor = new FlxSprite(); cursor.Visible = false; lastTouchEvent = false; _lastTouch = TouchLocationState.Released; }
public static void HandleTouchScreenInputs() { TouchCollection touchCollection = TouchPanel.GetState(); foreach (TouchLocation touchLoc in touchCollection) { if ((touchLoc.State == TouchLocationState.Pressed) || (touchLoc.State == TouchLocationState.Moved)) { touchPosition = touchLoc.Position; } TouchState = touchLoc.State; } }
public static TouchPhase PhaseFromState(TouchLocationState touchState) { switch (touchState) { case TouchLocationState.Moved: return TouchPhase.Moved; case TouchLocationState.Pressed: return TouchPhase.Began; case TouchLocationState.Released: return TouchPhase.Ended; case TouchLocationState.Invalid: return TouchPhase.Canceled; } // can't get here but must satisfy the compiler return TouchPhase.Canceled; }
public bool IsTouchAt(Rectangle screenArea, TouchLocationState state) { TouchLocation touchLocation; return this.IsTouchAt(screenArea, state, out touchLocation); }
public TouchLocation(int id, TouchLocationState state, Vector2 position, TouchLocationState previousState, Vector2 previousPosition) : this(id, state, position, previousState, previousPosition, TimeSpan.Zero) { }
public TouchInfo(Vector2 position, float pressure, TouchLocationState state) { Position = position; Pressure = pressure; State = state; }
/// <summary> /// Is the given touch state "down" (pressed or moved)? /// </summary> public static bool IsDown(this TouchLocationState state) => state == TouchLocationState.Pressed || state == TouchLocationState.Moved;
public void Update(GameTime gameTime) { if (game1.gamePadState.Buttons.Back == ButtonState.Pressed) { switch (game1.Stat_Curent) { case GameStat.Pause: game1.Stat_Next = GameStat.Resume; break; case GameStat.Lose: game1.Stat_Next = GameStat.MenuMain; break; case GameStat.Win: game1.Stat_Next = GameStat.MenuMain; break; } } if (Enable) { foreach (TouchLocation tl in game1.touchState) { Touch_State = tl.State; Touch_Position = tl.Position; if (Touch_State == TouchLocationState.Pressed) { switch (game1.Stat_Curent) { case GameStat.Pause: if (Button_Restart.touched(Touch_Position, game1)) { Timer_MenuGame.Set(gameTime.TotalGameTime, Actions.Restart, 250); } else if (Button_MenuMain.touched(Touch_Position, game1)) { Timer_MenuGame.Set(gameTime.TotalGameTime, Actions.MainMenu, 250); } else if (Button_Resume.touched(Touch_Position, game1)) { Timer_MenuGame.Set(gameTime.TotalGameTime, Actions.Resume, 250); } break; case GameStat.Lose: if (Button_Restart.touched(Touch_Position, game1)) { Timer_MenuGame.Set(gameTime.TotalGameTime, Actions.Restart, 250); } else if (Button_MenuMain.touched(Touch_Position, game1)) { Timer_MenuGame.Set(gameTime.TotalGameTime, Actions.MainMenu, 250); } break; case GameStat.Win: if ((game1.Level + 1) < game1.Level_Count) { if (game1.Level_Data[game1.Level + 1].Enable) { if (Button_Next.touched(Touch_Position, game1)) { Timer_MenuGame.Set(gameTime.TotalGameTime, Actions.Next, 250); } } } if (Button_Restart.touched(Touch_Position, game1)) { Timer_MenuGame.Set(gameTime.TotalGameTime, Actions.Restart, 250); } else if (Button_MenuMain.touched(Touch_Position, game1)) { Timer_MenuGame.Set(gameTime.TotalGameTime, Actions.MainMenu, 250); } break; } } break; } } else if (Timer_Start < 0) { Timer_Start = (long)gameTime.TotalGameTime.TotalMilliseconds; } else { TranslationVector.Y = Position_Start - ((float)((long)gameTime.TotalGameTime.TotalMilliseconds - Timer_Start) / Time_Raise) * Position_Start; if (TranslationVector.Y >= 0) { TranslationVector.Y = 0; Enable = true; } Translation = Matrix.CreateTranslation(TranslationVector); } if (Timer_MenuGame.Get(gameTime.TotalGameTime)) { switch (Timer_MenuGame.Action) { case Actions.Restart: game1.Stat_Next = GameStat.Start; break; case Actions.MainMenu: game1.Stat_Next = GameStat.MenuMain; break; case Actions.Resume: game1.Stat_Next = GameStat.Resume; break; case Actions.Next: game1.Stat_Next = GameStat.Next; break; case Actions.MenuGameEnable: Enable = true; break; } Timer_MenuGame.Action = Actions.Null; } }
private void UpdateGameWon(GameTime gameTime) { // Remove savegame on game end if (gameLoaded) { IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication(); if (myStore.FileExists("maze.lvl")) { myStore.DeleteFile("maze.lvl"); } if (myStore.FileExists("savegame.sav")) { myStore.DeleteFile("savegame.sav"); } gameLoaded = false; saveGameAvailable = false; } if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { if (gameState == GameState.Instructions) { instructionsPage = 1; } gameState = GameState.Menu; } tapScreen.Update(gameTime); TouchCollection touchCollection = TouchPanel.GetState(); if (touchCollection.Count > 0) { TouchLocation touchLocation = touchCollection[0]; Vector2 touchPosition = touchLocation.Position; switch (touchLocation.State) { case TouchLocationState.Pressed: { previousTouchState = TouchLocationState.Pressed; } break; case TouchLocationState.Released: { if (previousTouchState == TouchLocationState.Pressed) { gameState = GameState.Menu; } previousTouchState = TouchLocationState.Released; } break; default: break; } } actualMoves = player.Steps; finalScore = (int)Math.Round(player.Score * ((minimumMoves / actualMoves) + 1)); if (finalScore > highscore) { highscore = finalScore; } }
public TouchLocation(Vector2 position, TouchLocationState state) { this.Position = position; this.State = state; this.Pressure = 1; this.Id = -1; }
public override void ProcessTouchEvents(int x, int y, TouchLocationState tlState) { mainMenuButton.ProcessTouchEvent(x, y, tlState); }
internal void AddEvent(int id, TouchLocationState state, Vector2 position, bool isMouse) { // Different platforms return different touch identifiers // based on the specifics of their implementation and the // system drivers. // // Sometimes these ids are suitable for our use, but other // times it can recycle ids or do cute things like return // the same id for double tap events. // // We instead provide consistent ids by generating them // ourselves on the press and looking them up on move // and release events. // if (state == TouchLocationState.Pressed) { if (isMouse) { // Mouse pointing devices always use a reserved Id _touchIds[id] = MouseTouchId; } else { _touchIds[id] = _nextTouchId++; } } // Try to find the touch id. int touchId; if (!_touchIds.TryGetValue(id, out touchId)) { // If we got here that means either the device is sending // us bad, out of order, or old touch events. In any case // just ignore them. return; } if (!isMouse || EnableMouseTouchPoint || EnableMouseGestures) { // Add the new touch event keeping the list from getting // too large if no one happens to be requesting the state. var evt = new TouchLocation(touchId, state, position * _touchScale, CurrentTimestamp); if (!isMouse || EnableMouseTouchPoint) { ApplyTouch(_touchState, evt); } //If we have gestures enabled then collect events for those too. //We also have to keep tracking any touches while we know about touches so we don't miss releases even if gesture recognition is disabled if ((EnabledGestures != GestureType.None || _gestureState.Count > 0) && (!isMouse || EnableMouseGestures)) { ApplyTouch(_gestureState, evt); if (EnabledGestures != GestureType.None) { UpdateGestures(true); } AgeTouches(_gestureState); } } // If this is a release unmap the hardware id. if (state == TouchLocationState.Released) { _touchIds.Remove(id); } }
public TouchChangedState(TouchLocationState state) : base(false) { this.State = state; base.BlockedInputs.Add(0); }
internal static void AddEvent(int id, TouchLocationState state, Vector2 position, bool isMouse) { PrimaryWindow.TouchPanelState.AddEvent(id, state, position, isMouse); }
public override void Update(GameTime gameTime) { Matrix Scale = Matrix.CreateScale(1, 1, 1); OldMouseState = MouseState; MouseState = Mouse.GetState(); var touch = TouchPanel.GetState().FirstOrDefault(); if (touch != null) { OldTouchState = TouchState; TouchState = touch.State; } Vector2 pos = new Vector2(); if (InputObserver.IsUsingTouchScreen) { if (touch.State != TouchLocationState.Invalid) { //Position = Vector2.Transform(touch.Position - new Vector2(Game.GraphicsDevice.Viewport.X, Game.GraphicsDevice.Viewport.Y), Matrix.Invert(Resolution.getTransformationMatrix())); pos = touch.Position; } } else { pos = new Vector2(MouseState.X, MouseState.Y); //Position = Vector2.Transform(new Vector2(MouseState.X, MouseState.Y) - new Vector2(Game.GraphicsDevice.Viewport.X, Game.GraphicsDevice.Viewport.Y), Matrix.Invert(Resolution.getTransformationMatrix())); } this.Position = Vector2.Transform(pos, Scale); X = Position.X; Y = Position.Y; // this.HandClosed = MouseState.LeftButton == ButtonState.Pressed; }
// GAMESTATE UPDATE FUNCTIONS private void UpdateMenu(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { ExitGame(); } if (gameIsLaunched) { gamesLaunched++; if (!gameIsReviewed) { if (gamesLaunched == 2 || gamesLaunched == 5 || gamesLaunched == 10) { if (!Guide.IsVisible) { List<string> buttons = new List<string>(); buttons.Add("Yes"); buttons.Add("No"); Guide.BeginShowMessageBox("Review", "Would you like to review this game?", buttons, 0, MessageBoxIcon.Alert, DoReview, null); } } } // Get anonymous user ID bool networkAvailable; string anid; string anonymousUserId; string parameters; Uri uri; anid = UserExtendedProperties.GetValue("ANID") as string; networkAvailable = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable(); if (anid != null && networkAvailable) { anonymousUserId = anid.Substring(2, 32); uri = new Uri("http://my89.nl/analytics/update.php"); parameters = string.Format("app={0}&version={1}&id={2}", GameSettings.GameName, GameSettings.GameVersion, anonymousUserId); WebClient webClient = new WebClient(); webClient.Headers["Content-type"] = "application/x-www-form-urlencoded"; webClient.UploadStringAsync(uri, parameters); } gameIsLaunched = false; } TouchCollection touchCollection = TouchPanel.GetState(); if (touchCollection.Count > 0) { TouchLocation touchLocation = touchCollection[0]; Vector2 touchPosition = touchLocation.Position; Rectangle rectangleInput = new Rectangle((int)touchLocation.Position.X, (int)touchLocation.Position.Y, 0, 0); Rectangle resumeRectangle = new Rectangle(0, 394, 480, 60); Rectangle startRectangle = new Rectangle(0, 464, 480, 60); Rectangle howtoRectangle = new Rectangle(0, 534, 480, 60); Rectangle aboutRectangle = new Rectangle(0, 604, 480, 60); Rectangle exitRectangle = new Rectangle(0, 674, 480, 60); switch (touchLocation.State) { case TouchLocationState.Pressed: { previousTouchState = TouchLocationState.Pressed; } break; case TouchLocationState.Released: { if (previousTouchState == TouchLocationState.Pressed) { if (rectangleInput.Intersects(resumeRectangle) && (saveGameAvailable == true || gameLoaded == true)) { loadSaveGame = true; gameState = GameState.Resume; } if (rectangleInput.Intersects(startRectangle)) { gameState = GameState.GameSettings; } if (rectangleInput.Intersects(howtoRectangle)) { gameState = GameState.Instructions; } if (rectangleInput.Intersects(aboutRectangle)) { gameState = GameState.About; } if (rectangleInput.Intersects(exitRectangle)) { ExitGame(); } } previousTouchState = TouchLocationState.Released; } break; default: break; } } }
public void Update(GameTime gameTime) { if (game1.gamePadState.Buttons.Back == ButtonState.Pressed) { switch (game1.Stat_Curent) { case GameStat.MenuMain: game1.Exit(); break; case GameStat.MenuSettings: game1.Stat_Next = GameStat.MenuMain; break; case GameStat.Help: game1.Stat_Next = GameStat.MenuMain; break; } } foreach (TouchLocation tl in game1.touchState) { Touch_State = tl.State; Touch_Position = tl.Position; if (Touch_State == TouchLocationState.Pressed) { switch (game1.Stat_Curent) { case GameStat.MenuMain: if (Button_Play.touched(Touch_Position, game1)) { Timer_Menu.Set(gameTime.TotalGameTime, Actions.Select, 250); } else if (Button_Settings.touched(Touch_Position, game1)) { Timer_Menu.Set(gameTime.TotalGameTime, Actions.Settings, 250); } else if (Button_Help.touched(Touch_Position, game1)) { Timer_Menu.Set(gameTime.TotalGameTime, Actions.Help, 250); } else if (Button_Exit.touched(Touch_Position, game1)) { Timer_Menu.Set(gameTime.TotalGameTime, Actions.Exit, 250); } break; case GameStat.Help: if (Button_Back.touched(Touch_Position, game1)) { game1.Stat_Next = GameStat.MenuMain; } break; case GameStat.MenuSettings: if (game1.Sound) { if (Button_Sound_On.touched(Touch_Position, game1)) { Timer_Menu.Set(gameTime.TotalGameTime, Actions.Sound, 250); } } else { if (Button_Sound_Off.touched(Touch_Position, game1)) { Timer_Menu.Set(gameTime.TotalGameTime, Actions.Sound, 250); } } if (Button_Reset.touched(Touch_Position, game1)) { game1.ResetData(); Timer_Menu.Set(gameTime.TotalGameTime, Actions.MainMenu, 500); } else if (Button_Back.touched(Touch_Position, game1)) { game1.Stat_Next = GameStat.MenuMain; } break; } } break; } if (Timer_Menu.Get(gameTime.TotalGameTime)) { switch (Timer_Menu.Action) { case Actions.Select: game1.Stat_Next = GameStat.MenuSelect; break; case Actions.Settings: game1.Stat_Next = GameStat.MenuSettings; break; case Actions.Exit: game1.Exit(); break; case Actions.MainMenu: game1.Stat_Next = GameStat.MenuMain; break; case Actions.Sound: if (game1.Sound) { game1.Sound = false; } else { game1.Sound = true; } Button_Sound_Off.touch = false; Button_Sound_On.touch = false; break; case Actions.Help: game1.Stat_Next = GameStat.Help; break; } Timer_Menu.Action = Actions.Null; } }
abstract public void ProcessTouchEvents(int x, int y, TouchLocationState state);
internal static TouchLocation AdvanceTouchLocation(TouchLocation original, TouchLocationState newState) { return new TouchLocation(original.Id, newState, original.Position, original.State, original.Position); }
internal void AddEvent( int id, TouchLocationState state, Vector2 position, bool isMouse ) { #if JSIL // HACK: IsConnected is determined statically, but in browsers // you can't physically detect a touch panel and need to respond // to the first tap you get instead. capabilities.isConnected = true; #endif /* Different platforms return different touch identifiers * based on the specifics of their implementation and the * system drivers. * * Sometimes these ids are suitable for our use, but other * times it can recycle ids or do cute things like return * the same id for double tap events. * * We instead provide consistent ids by generating them * ourselves on the press and looking them up on move * and release events. */ if (state == TouchLocationState.Pressed) { if (isMouse) { // Mouse pointing devices always use a reserved Id touchIds[id] = MouseTouchId; } else { touchIds[id] = nextTouchId += 1; } } // Try to find the touch id. int touchId; if (!touchIds.TryGetValue(id, out touchId)) { /* If we got here that means either the device is sending * us bad, out of order, or old touch events. * In any case, just ignore them. */ return; } if (!isMouse || EnableMouseTouchPoint || EnableMouseGestures) { /* Add the new touch event keeping the list from getting * too large if no one happens to be requesting the state. */ TouchLocation evt = new TouchLocation( touchId, state, position * touchScale, CurrentTimestamp ); if (!isMouse || EnableMouseTouchPoint) { ApplyTouch(touchState, evt); } /* If we have gestures enabled then start to collect * events for those too. * We also have to keep tracking any touches while * we know about touches so we don't miss releases * even if gesture recognition is disabled. */ if ((EnabledGestures != GestureType.None || gestureState.Count > 0) && (!isMouse || EnableMouseGestures)) { ApplyTouch(gestureState, evt); if (EnabledGestures != GestureType.None) { UpdateGestures(true); } AgeTouches(gestureState); } } // If this is a release unmap the hardware id. if (state == TouchLocationState.Released) { touchIds.Remove(id); } }
/// <summary> /// Initializes a new instance of the <see cref="TouchLocation"/> struct. /// </summary> public TouchLocation(int id, TouchLocationState state, Vector2 position) { this.Id = id; this.State = state; this.Position = position; }
private TouchPointState ConvertState(TouchLocationState state) { // a simple mapping between the built-in types and our own ones switch (state) { case TouchLocationState.Invalid: return TouchPointState.Invalid; case TouchLocationState.Moved: return TouchPointState.Moved; case TouchLocationState.Pressed: return TouchPointState.Pressed; case TouchLocationState.Released: return TouchPointState.Released; default: return TouchPointState.Invalid; } }
public Touch(Vector2 APos, TouchLocationState AState) { Position = APos; State = AState; }
public override bool OnTouchEvent(MotionEvent e) { TouchLocationState state = TouchLocationState.Invalid; if (e.Action == MotionEventActions.Cancel) { state = TouchLocationState.Invalid; } if (e.Action == MotionEventActions.Up) { state = TouchLocationState.Released; } if (e.Action == MotionEventActions.Move) { state = TouchLocationState.Moved; Mouse.SetPosition((int)e.GetX(), (int)e.GetY()); } if (e.Action == MotionEventActions.Down) { state = TouchLocationState.Pressed; Mouse.SetPosition((int)e.GetX(), (int)e.GetY()); } TouchLocation tprevious; TouchLocation tlocation; Vector2 position = new Vector2(e.GetX(), e.GetY()); Vector2 translatedPosition = position; switch (CurrentOrientation) { case DisplayOrientation.Portrait: break; case DisplayOrientation.LandscapeRight: translatedPosition = new Vector2(ClientBounds.Height - position.Y, position.X); break; case DisplayOrientation.LandscapeLeft: translatedPosition = new Vector2(position.Y, ClientBounds.Width - position.X); break; case DisplayOrientation.PortraitUpsideDown: translatedPosition = new Vector2(ClientBounds.Width - position.X, ClientBounds.Height - position.Y); break; } if (state != TouchLocationState.Pressed && _previousTouches.TryGetValue(e.Handle, out tprevious)) { tlocation = new TouchLocation(e.Handle.ToInt32(), state, translatedPosition, e.Pressure, tprevious.State, tprevious.Position, tprevious.Pressure); } else { tlocation = new TouchLocation(e.Handle.ToInt32(), state, translatedPosition, e.Pressure); } TouchPanel.Collection.Clear(); TouchPanel.Collection.Add(tlocation); if (state != TouchLocationState.Released) { _previousTouches[e.Handle] = tlocation; } else { _previousTouches.Remove(e.Handle); } GamePad.Instance.Update(e); return(true); }
public TouchHelper() { prevTouchState = TouchLocationState.Invalid; curTouchState = TouchLocationState.Invalid; }
/// <summary> /// Is the given touch state "up" (released or invalid)? /// </summary> public static bool IsUp(this TouchLocationState state) => state == TouchLocationState.Released || state == TouchLocationState.Invalid;
public void Update(List<Player> players, Board board) { touchCollection = TouchPanel.GetState(); if (touchCollection.Count > 0) { touchState = touchCollection[0].State; if(touchState == TouchLocationState.Pressed) { touchPosition = touchCollection[0].Position; HandleTouch(new Rectangle((int)touchPosition.X - 16, (int)touchPosition.Y - 16, 32, 32), players, board); } } }
public TouchLocation(int id, TouchLocationState state, Vector2 position) : this(id, state, position, TouchLocationState.Invalid, Vector2.Zero) { }
public void Enqueue(int id, TouchLocationState state, Vector2 pos, bool isMouse = false) { _queue.Enqueue(new TouchEvent(id, state, pos, isMouse)); }
internal TouchLocation(int id, TouchLocationState state, Vector2 position, TimeSpan timestamp) : this(id, state, position, TouchLocationState.Invalid, Vector2.Zero, timestamp) { }
internal void AddEvent(int id, TouchLocationState state, Vector2 position, bool isMouse) { // Different platforms return different touch identifiers // based on the specifics of their implementation and the // system drivers. // // Sometimes these ids are suitable for our use, but other // times it can recycle ids or do cute things like return // the same id for double tap events. // // We instead provide consistent ids by generating them // ourselves on the press and looking them up on move // and release events. // if (state == TouchLocationState.Pressed) { if (isMouse) { // Mouse pointing devices always use a reserved Id _touchIds[id] = MouseTouchId; } else { _touchIds[id] = _nextTouchId++; } } // Try to find the touch id. int touchId; if (!_touchIds.TryGetValue(id, out touchId)) { // If we got here that means either the device is sending // us bad, out of order, or old touch events. In any case // just ignore them. return; } if (!isMouse || EnableMouseTouchPoint || EnableMouseGestures) { // Add the new touch event keeping the list from getting // too large if no one happens to be requesting the state. var evt = new TouchLocation(touchId, state, position * _touchScale, _currentTimestamp); if (!isMouse || EnableMouseTouchPoint) { ApplyTouch(_touchState, evt); } //If we have gestures enabled then collect events for those too. //We also have to keep tracking any touches while we know about touches so we don't miss releases even if gesture recognition is disabled if ((EnabledGestures != GestureType.None || _gestureState.Count > 0) && (!isMouse || EnableMouseGestures)) { ApplyTouch(_gestureState, evt); if (EnabledGestures != GestureType.None) UpdateGestures(true); AgeTouches(_gestureState); } } // If this is a release unmap the hardware id. if (state == TouchLocationState.Released) _touchIds.Remove(id); }
public bool IsTouchAt(Rectangle screenArea, TouchLocationState state, out TouchLocation touchLocation) { for (int i = 0; i < _touchLocations.Count; i++) { if (_touchLocations[i].State == state && screenArea.Contains(_touchLocations[i].Position)) { touchLocation = _touchLocations[i]; return true; } } touchLocation = default(TouchLocation); return false; }
private void UpdatePaused(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { gameState = previousGameState; } TouchCollection touchCollection = TouchPanel.GetState(); if (touchCollection.Count > 0) { TouchLocation touchLocation = touchCollection[0]; Vector2 touchPosition = touchLocation.Position; Rectangle rectangleInput = new Rectangle((int)touchLocation.Position.X, (int)touchLocation.Position.Y, 0, 0); Rectangle continueRectangle = new Rectangle(0, 464, 480, 60); Rectangle restartRectangle = new Rectangle(0, 534, 480, 60); Rectangle soundRectnalge = new Rectangle(0, 604, 480, 60); Rectangle quitRectangle = new Rectangle(0, 674, 480, 60); switch (touchLocation.State) { case TouchLocationState.Pressed: { previousTouchState = TouchLocationState.Pressed; } break; case TouchLocationState.Released: { if (previousTouchState == TouchLocationState.Pressed) { if (rectangleInput.Intersects(continueRectangle)) { gameState = previousGameState; } if (rectangleInput.Intersects(restartRectangle)) { gameState = GameState.Loading; } if (rectangleInput.Intersects(soundRectnalge)) { if (soundEnabled == true) { soundEnabled = false; } else { soundEnabled = true; } } if (rectangleInput.Intersects(quitRectangle)) { gameState = GameState.Menu; } } previousTouchState = TouchLocationState.Released; } break; default: break; } } }
private void UpdateInstructions(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { if (gameState == GameState.Instructions) { instructionsPage = 1; } gameState = GameState.Menu; } tapScreen.Update(gameTime); TouchCollection touchCollection = TouchPanel.GetState(); if (touchCollection.Count > 0) { TouchLocation touchLocation = touchCollection[0]; Vector2 touchPosition = touchLocation.Position; switch (touchLocation.State) { case TouchLocationState.Pressed: { previousTouchState = TouchLocationState.Pressed; } break; case TouchLocationState.Released: { if (previousTouchState == TouchLocationState.Pressed) { switch (instructionsPage) { case 1: instructionsPage = 2; break; case 2: instructionsPage = 1; gameState = GameState.Menu; break; } } previousTouchState = TouchLocationState.Released; } break; default: break; } } }
internal static void AddEvent( int id, TouchLocationState state, Vector2 position, float pressure ) { AddEvent(id, state, position, pressure, false); }
internal static void AddEvent(int id, TouchLocationState state, Vector2 position, bool isMouse) { if (state == TouchLocationState.Pressed) TouchPanel._touchIds[id] = !isMouse ? TouchPanel._nextTouchId++ : 1; int id1; if (!TouchPanel._touchIds.TryGetValue(id, out id1)) return; if (!isMouse || TouchPanel.EnableMouseTouchPoint || TouchPanel.EnableMouseGestures) { TouchLocation touchLocation = new TouchLocation(id1, state, position * TouchPanel._touchScale); if (!isMouse || TouchPanel.EnableMouseTouchPoint) { TouchPanel._touchEvents.Add(touchLocation); if (TouchPanel._touchEvents.Count > 100) TouchPanel._touchEvents.RemoveRange(0, TouchPanel._touchEvents.Count - 100); } if (TouchPanel.EnabledGestures != GestureType.None && (!isMouse || TouchPanel.EnableMouseGestures)) { TouchPanel._gestureEvents.Add(touchLocation); if (TouchPanel._gestureEvents.Count > 100) TouchPanel._gestureEvents.RemoveRange(0, TouchPanel._gestureEvents.Count - 100); } } if (state != TouchLocationState.Released) return; TouchPanel._touchIds.Remove(id); }
internal static void AddEvent( int id, TouchLocationState state, Vector2 position, float pressure, bool isMouse ) { PrimaryWindow.TouchPanelState.AddEvent( id, state, position, pressure, isMouse ); }
private static TouchPhase ToPhase(TouchLocationState touchLocationState) { switch (touchLocationState) { case TouchLocationState.Invalid: return TouchPhase.Canceled; case TouchLocationState.Moved: return TouchPhase.Moved; case TouchLocationState.Pressed: return TouchPhase.Began; case TouchLocationState.Released: return TouchPhase.Ended; default: throw new InvalidOperationException("The touch state " + touchLocationState + " does not exist!"); } }
private static TouchCollection MakeTouchCollectionFromMouse() { var mouseState = Mouse.GetState (); var touchState = TouchLocationState.Invalid; if (mouseState.LeftButton == ButtonState.Pressed) { switch (previousTouchState) { case TouchLocationState.Invalid: case TouchLocationState.Released: touchState = TouchLocationState.Pressed; break; default: touchState = TouchLocationState.Moved; break; } } else { switch (previousTouchState) { case TouchLocationState.Pressed: case TouchLocationState.Moved: touchState = TouchLocationState.Released; break; default: touchState = TouchLocationState.Invalid; break; } } var isValid = mouseState.LeftButton == ButtonState.Pressed || touchState == TouchLocationState.Released; var result = new List<TouchLocation>(); if (isValid) { result.Add( new TouchLocation ( 0, touchState, new Vector2 (mouseState.Position.X, mouseState.Position.Y), previousTouchState, previousLocation.HasValue ? previousLocation.Value : Vector2.Zero)); } previousLocation = new Vector2 (mouseState.Position.X, mouseState.Position.Y); previousTouchState = touchState; return new TouchCollection(result.ToArray()); }
internal void AddEvent( int id, TouchLocationState state, Vector2 position, float pressure, bool isMouse ) { /* Different platforms return different touch identifiers * based on the specifics of their implementation and the * system drivers. * * Sometimes these ids are suitable for our use, but other * times it can recycle ids or do cute things like return * the same id for double tap events. * * We instead provide consistent ids by generating them * ourselves on the press and looking them up on move * and release events. */ if (state == TouchLocationState.Pressed) { if (isMouse) { // Mouse pointing devices always use a reserved Id touchIds[id] = MouseTouchId; } else { touchIds[id] = nextTouchId += 1; } } // Try to find the touch id. int touchId; if (!touchIds.TryGetValue(id, out touchId)) { /* If we got here that means either the device is sending * us bad, out of order, or old touch events. * In any case, just ignore them. */ return; } if (!isMouse || EnableMouseTouchPoint || EnableMouseGestures) { /* Add the new touch event keeping the list from getting * too large if no one happens to be requesting the state. */ TouchLocation evt = new TouchLocation( touchId, state, position * touchScale, pressure, CurrentTimestamp ); if (!isMouse || EnableMouseTouchPoint) { ApplyTouch(touchState, evt); } /* If we have gestures enabled then start to collect * events for those too. * We also have to keep tracking any touches while * we know about touches so we don't miss releases * even if gesture recognition is disabled. */ if ( (EnabledGestures != GestureType.None || gestureState.Count > 0) && (!isMouse || EnableMouseGestures) ) { ApplyTouch(gestureState, evt); if (EnabledGestures != GestureType.None) { UpdateGestures(true); } AgeTouches(gestureState); } } // If this is a release unmap the hardware id. if (state == TouchLocationState.Released) { touchIds.Remove(id); } }
internal void AddEvent(int id, TouchLocationState state, Vector2 position) { AddEvent(id, state, position, false); }
internal static void AddEvent( int id, TouchLocationState state, Vector2 position ) { AddEvent(id, state, position, false); }
internal void AddEvent(int id, TouchLocationState state, Vector2 position, bool isMouse) { /* Different platforms return different touch identifiers * based on the specifics of their implementation and the * system drivers. * * Sometimes these ids are suitable for our use, but other * times it can recycle ids or do cute things like return * the same id for double tap events. * * We instead provide consistent ids by generating them * ourselves on the press and looking them up on move * and release events. */ if (state == TouchLocationState.Pressed) { if (isMouse) { // Mouse pointing devices always use a reserved Id touchIds[id] = MouseTouchId; } else { touchIds[id] = nextTouchId += 1; } } // Try to find the touch id. int touchId; if (!touchIds.TryGetValue(id, out touchId)) { /* If we got here that means either the device is sending * us bad, out of order, or old touch events. In any case * just ignore them. */ return; } if (!isMouse || EnableMouseTouchPoint || EnableMouseGestures) { /* Add the new touch event keeping the list from getting * too large if no one happens to be requesting the state. */ TouchLocation evt = new TouchLocation(touchId, state, position * touchScale); if (!isMouse || EnableMouseTouchPoint) { touchEvents.Add(evt); if (touchEvents.Count > MaxEvents) { touchEvents.RemoveRange( 0, touchEvents.Count - MaxEvents ); } } /* If we have gestures enabled then start to collect * events for those too. */ if (EnabledGestures != GestureType.None && (!isMouse || EnableMouseGestures)) { gestureEvents.Add(evt); if (gestureEvents.Count > MaxEvents) { gestureEvents.RemoveRange( 0, gestureEvents.Count - MaxEvents ); } } } // If this is a release unmap the hardware id. if (state == TouchLocationState.Released) { touchIds.Remove(id); } }
internal static void AddEvent( int id, TouchLocationState state, Vector2 position, bool isMouse ) { AddEvent(id, state, position, 1f, isMouse); }
public override void Update(GameTime gameTime, Matrix?parentTransform) { base.Update(gameTime, parentTransform); Matrix.CreateTranslation(ContentsOffset.X, ContentsOffset.Y, 0f, out ContentsTransform); if (UserInputEnabled) { TouchCollection touches = SpartaTouch.TouchCollection; if (touches.Count > 0) { TouchLocation touch = touches[0]; TouchLocationState touchState = touch.State; Vector2 touchPosition = touch.Position; if (parentTransform.HasValue) { Matrix inverse = Matrix.Invert(parentTransform.Value); Vector2.Transform(ref touchPosition, ref inverse, out touchPosition); } bool boundingBoxContainsPoint = BoundingBox.Contains((int)touchPosition.X, (int)touchPosition.Y); switch (touchState) { case TouchLocationState.Pressed: if (boundingBoxContainsPoint) { deltas.Clear(); if (State == FlickableState.Steady) { State = FlickableState.Pressed; previousPoint = touchPosition; } else if (State == FlickableState.AutoScroll) { State = FlickableState.Stop; ScrollVelocity = DefaultScrollVelocity; previousPoint = touchPosition; Slowing = false; } SpartaTouch.Accept(); } break; case TouchLocationState.Moved: if (boundingBoxContainsPoint && (State == FlickableState.Pressed || State == FlickableState.Stop)) { ScrollVelocity = DefaultScrollVelocity; Vector2 delta = touchPosition - previousPoint; if (delta.X > Threshold || delta.X < -Threshold || delta.Y > Threshold || delta.Y < -Threshold) { State = FlickableState.ManualScroll; previousPoint = touchPosition; } } else if (State == FlickableState.ManualScroll) { Vector2 delta = touchPosition - previousPoint; float value = ScrollMode == FlickableScrollMode.Horizontally ? delta.X : delta.Y; deltas.Add(value); ScrollVelocity = value; previousPoint = touchPosition; } break; case TouchLocationState.Released: case TouchLocationState.Invalid: if (State == FlickableState.Pressed || State == FlickableState.Stop) { State = FlickableState.Steady; ScrollVelocity = DefaultScrollVelocity; } else if (State == FlickableState.ManualScroll) { ScrollVelocity = deltas.Sum() / deltas.Count; previousPoint = touchPosition; if (ScrollVelocity == 0f) { State = FlickableState.Steady; ScrollVelocity = DefaultScrollVelocity; } else { State = FlickableState.AutoScroll; Slowing = true; } } break; } } } if (Slowing) { ScrollVelocity = Deaccelerate(ScrollVelocity, 1, MaximumScrollVelocity); if (ScrollVelocity == 0f) { State = FlickableState.Steady; ScrollVelocity = DefaultScrollVelocity; Slowing = false; } } if (!float.IsNaN(ScrollVelocity)) { if (ScrollMode == FlickableScrollMode.Horizontally) { contentsOffset.X += ScrollVelocity; } else { contentsOffset.Y += ScrollVelocity; } } else { ScrollVelocity = DefaultScrollVelocity; } if (LoopingMode) { if (contentsOffset.X < -ContentsWidth) { contentsOffset.X = Width + (contentsOffset.X + ContentsWidth); } else if (contentsOffset.X > Width) { contentsOffset.X = -ContentsWidth + (contentsOffset.X - Width); } if (contentsOffset.Y < -ContentsHeight) { contentsOffset.Y = Height + (contentsOffset.Y + ContentsHeight); } else if (contentsOffset.Y > Height) { contentsOffset.Y = -ContentsHeight + (contentsOffset.Y - Height); } } else { if (contentsOffset.X < -ContentsWidth + Width) { contentsOffset.X = -ContentsWidth + Width; } else if (contentsOffset.X > 0f) { contentsOffset.X = 0f; } if (contentsOffset.Y < -ContentsHeight + Height) { contentsOffset.Y = -ContentsHeight + Height; } else if (contentsOffset.Y > 0f) { contentsOffset.Y = 0f; } } }
internal void UpdateTouchState(int touchIndex, TouchLocationState state) { bool isTouchDown = state == TouchLocationState.Pressed || state == TouchLocationState.Moved; states[touchIndex] = states[touchIndex].UpdateOnNativePressing(isTouchDown); }
private void UpdateGameSettings(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { gameState = GameState.Menu; } TouchCollection touchCollection = TouchPanel.GetState(); if (touchCollection.Count > 0) { TouchLocation touchLocation = touchCollection[0]; Vector2 touchPosition = touchLocation.Position; Rectangle rectangleInput = new Rectangle((int)touchLocation.Position.X, (int)touchLocation.Position.Y, 0, 0); Rectangle startRectangle = new Rectangle(0, 464, 480, 60); Rectangle howtoRectangle = new Rectangle(0, 534, 480, 60); Rectangle aboutRectangle = new Rectangle(0, 604, 480, 60); Rectangle exitRectangle = new Rectangle(0, 674, 480, 60); switch (touchLocation.State) { case TouchLocationState.Pressed: { previousTouchState = TouchLocationState.Pressed; } break; case TouchLocationState.Released: { if (previousTouchState == TouchLocationState.Pressed) { if (rectangleInput.Intersects(startRectangle)) { gameState = GameState.Loading; } if (rectangleInput.Intersects(howtoRectangle)) { switch (difficulty) { case 0: difficulty = 1; break; case 1: difficulty = 2; break; case 2: difficulty = 0; break; } } if (rectangleInput.Intersects(aboutRectangle)) { if (soundEnabled == true) { soundEnabled = false; } else { soundEnabled = true; } } if (rectangleInput.Intersects(exitRectangle)) { gameState = GameState.Menu; } } previousTouchState = TouchLocationState.Released; } break; default: break; } } }