InputSample.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef INPUTSAMPLE_H_
  2. #define INPUTSAMPLE_H_
  3. #include "gameplay.h"
  4. #include "Sample.h"
  5. using namespace gameplay;
  6. /**
  7. * Samples basic input for keyboard, mouse, touch and accelerometer.
  8. */
  9. class InputSample : public Sample, Control::Listener
  10. {
  11. public:
  12. InputSample();
  13. void touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
  14. void keyEvent(Keyboard::KeyEvent evt, int key);
  15. bool mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta);
  16. void controlEvent(Control* control, EventType evt);
  17. protected:
  18. void initialize();
  19. void finalize();
  20. void update(float elapsedTime);
  21. void render(float elapsedTime);
  22. private:
  23. bool drawScene(Node* node);
  24. void setCaptured(bool captured);
  25. private:
  26. class TouchPoint
  27. {
  28. public:
  29. unsigned int _id;
  30. Vector2 _coord;
  31. bool _isStale;
  32. };
  33. std::list<TouchPoint> _touchPoints;
  34. std::set<int> _downKeys;
  35. Vector2 _mousePoint;
  36. Vector2 _mouseWheelPoint;
  37. std::string _keyboardString;
  38. std::string _symbolsString;
  39. std::string _mouseString;
  40. Font* _font;
  41. Form* _inputSampleControls;
  42. int _mouseWheel;
  43. bool _keyboardState;
  44. SpriteBatch* _crosshair;
  45. Rectangle _crosshairDstRect;
  46. Rectangle _crosshairSrcRect;
  47. Vector2 _crosshairLowerLimit;
  48. Vector2 _crosshairUpperLimit;
  49. Scene* _scene;
  50. Node* _formNode;
  51. Node* _formNodeParent;
  52. Vector3 _formNodeRestPosition;
  53. };
  54. #endif