Input.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #ifndef INPUT_INPUT_H
  24. #define INPUT_INPUT_H
  25. #include "EventListener.h"
  26. #include "InputEvents.h"
  27. #include "SharedPtr.h"
  28. class Renderer;
  29. static const int MAX_KEYS = 256;
  30. //! Converts operating system window messages to input state and events
  31. class Input : public RefCounted, public EventListener
  32. {
  33. public:
  34. //! Construct with renderer subsystem pointer
  35. Input(Renderer* renderer);
  36. //! Destruct
  37. virtual ~Input();
  38. //! Poll for window messages through the Renderer
  39. void update();
  40. //! Set whether ALT-ENTER fullscreen toggle is enabled
  41. void setToggleFullscreen(bool enable);
  42. //! Suppress the next char message
  43. void suppressNextChar();
  44. //! Check if a key is held down
  45. bool getKeyDown(int key) const;
  46. //! Check if a key has been pressed on this frame
  47. bool getKeyPress(int key) const;
  48. //! Check if a mouse button is held down
  49. bool getMouseButtonDown(int button) const;
  50. //! Check if a mouse button has been pressed on this frame
  51. bool getMouseButtonPress(int button) const;
  52. //! Return horizontal mouse movement since last frame
  53. int getMouseMoveX() const { return mMouseMoveX; }
  54. //! Return vertical mouse movement since last frame
  55. int getMouseMoveY() const { return mMouseMoveY; }
  56. //! Return mouse wheel movement since last frame
  57. int getMouseMoveWheel() const { return mMouseMoveWheel; }
  58. //! Return whether fullscreen toggle is enabled
  59. bool getToggleFullscreen() const { return mToggleFullscreen; }
  60. //! Return whether application window is active
  61. bool isActive() { return mActive; }
  62. //! Return whether application window is minimized
  63. bool isMinimized() { return mMinimized; }
  64. private:
  65. //! Handle a window message event
  66. void handleWindowMessage(StringHash eventType, VariantMap& eventData);
  67. //! Activate the application
  68. void makeActive();
  69. //! Deactivate the application
  70. void makeInactive();
  71. //! Clear input state
  72. void clearState();
  73. //! Handle a mouse button change
  74. void mouseButtonChange(int button, bool newState);
  75. //! Handle a key change
  76. void keyChange(int key, bool newState);
  77. //! Renderer subsystem
  78. SharedPtr<Renderer> mRenderer;
  79. //! Key down state
  80. bool mKeyDown[MAX_KEYS];
  81. //! Key pressed state
  82. bool mKeyPress[MAX_KEYS];
  83. //! Mouse buttons' down state
  84. unsigned mMouseButtonDown;
  85. //! Mouse buttons' pressed state
  86. unsigned mMouseButtonPress;
  87. //! Horizontal mouse movement since last frame
  88. int mMouseMoveX;
  89. //! Vertical mouse movement since last frame
  90. int mMouseMoveY;
  91. //! Mouse wheel movement since last frame
  92. int mMouseMoveWheel;
  93. //! Fullscreen toggle flag
  94. bool mToggleFullscreen;
  95. //! Active flag
  96. bool mActive;
  97. //! Minimized flag
  98. bool mMinimized;
  99. //! Activated on this frame flag
  100. bool mActivated;
  101. //! Next char message suppress flag
  102. bool mSuppressNextChar;
  103. };
  104. #endif // INPUT_INPUT_H