platformInput.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _PLATFORMINPUT_H_
  23. #define _PLATFORMINPUT_H_
  24. #ifndef _SIMBASE_H_
  25. #include "sim/simBase.h"
  26. #endif
  27. //------------------------------------------------------------------------------
  28. U8 TranslateOSKeyCode( U8 vcode );
  29. //------------------------------------------------------------------------------
  30. class InputDevice : public SimObject
  31. {
  32. public:
  33. struct ObjInfo
  34. {
  35. U16 mType;
  36. U16 mInst;
  37. S32 mMin, mMax;
  38. };
  39. protected:
  40. char mName[30];
  41. public:
  42. const char* getDeviceName();
  43. virtual bool process() = 0;
  44. };
  45. //------------------------------------------------------------------------------
  46. inline const char* InputDevice::getDeviceName()
  47. {
  48. return mName;
  49. }
  50. //------------------------------------------------------------------------------
  51. class InputManager : public SimGroup
  52. {
  53. protected:
  54. bool mEnabled;
  55. public:
  56. bool isEnabled();
  57. virtual bool enable() = 0;
  58. virtual void disable() = 0;
  59. virtual void process() = 0;
  60. };
  61. //------------------------------------------------------------------------------
  62. inline bool InputManager::isEnabled()
  63. {
  64. return mEnabled;
  65. }
  66. enum KEY_STATE
  67. {
  68. STATE_LOWER,
  69. STATE_UPPER,
  70. STATE_GOOFY
  71. };
  72. //------------------------------------------------------------------------------
  73. /// A Singleton LIFO stack of platform cursor shapes
  74. ///
  75. /// The CursorManager class manages a LIFO stack of platform cursor shapes
  76. /// with a standard platform cursor at the bottom, usually an Arrow Cursor.
  77. class CursorManager
  78. {
  79. // todo: paxorr: make cursor manager a singleton, store in cursormanager.cc
  80. protected:
  81. struct cursors
  82. {
  83. S32 mCursorID; ///< Points to a platform specific cursor ID
  84. };
  85. Vector<cursors> mCursors; ///< A Vector of Platform Cursors
  86. void changeCursorShape(S32 cursorID);///< Change the Current Cursor Shape
  87. public:
  88. enum
  89. {
  90. curArrow = 0, ///< Default Cursor
  91. curWait, ///< Hourglass Cursor
  92. curPlus, ///< Arrow Plus
  93. curResizeVert, ///< Resize Vertical
  94. curResizeHorz, ///< Resize Horizontal
  95. curResizeAll, ///< Resize All
  96. curIBeam, ///< IBeam Used for Text Entry
  97. curResizeNESW, ///< Resize NESW
  98. curResizeNWSE, ///< Resize NWSE
  99. };
  100. public:
  101. /// Push a Cursor onto the Stack
  102. /// @param cursorID The Cursor ID to use
  103. void pushCursor(S32 cursorID);
  104. /// Pop a Cursor from the Stack
  105. void popCursor();
  106. /// Refresh the Cursor
  107. void refreshCursor();
  108. };
  109. //------------------------------------------------------------------------------
  110. class Input
  111. {
  112. protected:
  113. static InputManager* smManager; ///< Input Manager Singleton
  114. static CursorManager* smCursorManager; ///< Cursor Manager Singleton
  115. static bool smActive; ///< Is Input Active
  116. static bool smLastKeyboardActivated;
  117. static U8 smModifierKeys; ///< Current Modifier Keys Pressed
  118. static bool smLastMouseActivated;
  119. static bool smLastJoystickActivated;
  120. static bool smCursorGuard; ///< Used by Mac to prevent over hiding the cursor
  121. public:
  122. static void init();
  123. static void destroy();
  124. static bool enable();
  125. static void disable();
  126. static void activate();
  127. static void deactivate();
  128. static void reactivate();
  129. static void enableMouse();
  130. static void disableMouse();
  131. static void enableKeyboard();
  132. static void disableKeyboard();
  133. static bool activateKeyboard();
  134. static void deactivateKeyboard();
  135. static bool enableJoystick();
  136. static void disableJoystick();
  137. static void echoInputState();
  138. static U16 getAscii( U16 keyCode, KEY_STATE keyState );
  139. static U16 getKeyCode( U16 asciiCode );
  140. static bool isEnabled();
  141. static bool isActive();
  142. static bool isMouseEnabled();
  143. static bool isKeyboardEnabled();
  144. static void process();
  145. static void setCursorPos(S32 x, S32 y);
  146. static void setCursorState(bool on); ///< If True, turns off the platform cursor
  147. static void setCursorShape(U32 cursorID);
  148. static void pushCursor(S32 cursorID); ///< Push a cursor shape using the Cursor Manager
  149. static void popCursor(); ///< Pop the current cursor off of the Cursor Manager stack
  150. static void refreshCursor(); ///< Refresh the current cursor's shape.
  151. static U32 getDoubleClickTime();
  152. static S32 getDoubleClickWidth();
  153. static S32 getDoubleClickHeight();
  154. static InputManager* getManager(); ///< Return InputManager Singleton
  155. static CursorManager* getCursorManager(); ///< Return CursorManager Singleton
  156. static U8 getModifierKeys() {return smModifierKeys;}
  157. static void setModifierKeys(U8 mod) {smModifierKeys = mod;}
  158. };
  159. #endif // _H_PLATFORMINPUT_