Input.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. //! Check if a qualifier key is held down
  53. bool getQualifierDown(int qualifier) const;
  54. //! Check if a qualifier key has been pressed on this frame
  55. bool getQualifierPress(int qualifier) const;
  56. //! Return the currently held down qualifiers
  57. int getQualifiers() const;
  58. //! Return horizontal mouse movement since last frame
  59. int getMouseMoveX() const { return mMouseMoveX; }
  60. //! Return vertical mouse movement since last frame
  61. int getMouseMoveY() const { return mMouseMoveY; }
  62. //! Return mouse wheel movement since last frame
  63. int getMouseMoveWheel() const { return mMouseMoveWheel; }
  64. //! Return whether fullscreen toggle is enabled
  65. bool getToggleFullscreen() const { return mToggleFullscreen; }
  66. //! Return whether application window is active
  67. bool isActive() { return mActive; }
  68. //! Return whether application window is minimized
  69. bool isMinimized() { return mMinimized; }
  70. private:
  71. //! Handle a window message event
  72. void handleWindowMessage(StringHash eventType, VariantMap& eventData);
  73. //! Activate the application
  74. void makeActive();
  75. //! Deactivate the application
  76. void makeInactive();
  77. //! Clear input state
  78. void clearState();
  79. //! Handle a mouse button change
  80. void mouseButtonChange(int button, bool newState);
  81. //! Handle a key change
  82. void keyChange(int key, bool newState);
  83. //! Renderer subsystem
  84. SharedPtr<Renderer> mRenderer;
  85. //! Key down state
  86. bool mKeyDown[MAX_KEYS];
  87. //! Key pressed state
  88. bool mKeyPress[MAX_KEYS];
  89. //! Mouse buttons' down state
  90. unsigned mMouseButtonDown;
  91. //! Mouse buttons' pressed state
  92. unsigned mMouseButtonPress;
  93. //! Horizontal mouse movement since last frame
  94. int mMouseMoveX;
  95. //! Vertical mouse movement since last frame
  96. int mMouseMoveY;
  97. //! Mouse wheel movement since last frame
  98. int mMouseMoveWheel;
  99. //! Fullscreen toggle flag
  100. bool mToggleFullscreen;
  101. //! Active flag
  102. bool mActive;
  103. //! Minimized flag
  104. bool mMinimized;
  105. //! Activated on this frame flag
  106. bool mActivated;
  107. //! Next char message suppress flag
  108. bool mSuppressNextChar;
  109. };
  110. #endif // INPUT_INPUT_H