/// <summary> /// Add an amount to the command menu button vertical offsets. /// </summary> /// <param name="off"></param> private void OffsetMenuButtons(int off) { MenuButtonVerticalOffset += off; if (MenuButtonVerticalOffset < MENU_BUTTON_OFFSET_MIN) { MenuButtonVerticalOffset = MENU_BUTTON_OFFSET_MIN; currentAnimationType = CommandMenuButtonScrollAnimationType.None; } if (MenuButtonVerticalOffset > MENU_BUTTON_OFFSET_MAX) { MenuButtonVerticalOffset = MENU_BUTTON_OFFSET_MAX; currentAnimationType = CommandMenuButtonScrollAnimationType.None; } }
/// <summary> /// Handles the touch gesture. Returns a response based on what we did with the touch. /// </summary> /// <param name="gesture"></param> /// <returns>Whether or not this object handled the touch.</returns> public bool ProcessTouch(GestureSample gesture, LinkedList<Platform> listOfWorldPlatforms) { Point hit = new Point((int)gesture.Position.X, (int)gesture.Position.Y); Point worldHit = Spotlight.TranslateScreenPointToWorldPoint(hit); #region Menu Touches if (drawRect.Contains(hit) && CanRespond()) { if (selectedCommand == CommandType.NumCommands) { Point adjustedHit = new Point(hit.X, hit.Y - MenuButtonVerticalOffset); foreach (CommandButton cb in commandButtons) { if (cb.Contains(adjustedHit)) { selectedCommand = cb.getData().getCommandType(); break; } } } switch (gesture.GestureType) { case GestureType.FreeDrag: OffsetMenuButtons((int)gesture.Delta.Y); BecomeFirstResponder(); return true; } return true; // Eat all touches in this draw frame } else if (IsFirstResponder()) { switch (gesture.GestureType) { case GestureType.FreeDrag: ResignFirstResponder(); if (selectedCommand == CommandType.NumCommands || commandlimits[(int)selectedCommand] == 0) return false; // earlier touch wasnt on a button. Command created = new Command(worldHit, selectedCommand); created.ProcessTouch(gesture); Hide(); listOfWorldCommands.AddLast(created); if (commandlimits[(int)selectedCommand] != -1) commandlimits[(int)selectedCommand]--; selectedCommand = CommandType.NumCommands; return true; case GestureType.DragComplete: ResignFirstResponder(); selectedCommand = CommandType.NumCommands; return false; case GestureType.Flick: if (gesture.Delta.Y > 0) { currentAnimationType = CommandMenuButtonScrollAnimationType.ToTop; } else { currentAnimationType = CommandMenuButtonScrollAnimationType.ToBottom; } ResignFirstResponder(); selectedCommand = CommandType.NumCommands; return true; } } #endregion #region Toggle Touches if (toggle.ProcessTouch(gesture)) { if (show) Hide(); else Show(); return true; } #endregion #region Command Touches foreach (Command c in listOfWorldCommands) { if (c.ProcessTouch(gesture, listOfWorldPlatforms)) { if (gesture.GestureType == GestureType.DragComplete) { if (drawRect.Contains(Spotlight.TranslateWorldPointToScreenPoint(c.drawRect.Location))) { listOfWorldCommands.Remove(c); if (commandlimits[(int)c.getCommandType()] != -1) commandlimits[(int)c.getCommandType()] += 1; } if (c.newlyCreated) { Show(); c.newlyCreated = false; } } return true; } } #endregion return false; }