platformInput.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 "console/simBase.h"
  26. #endif
  27. #include "platform/input/event.h"
  28. //------------------------------------------------------------------------------
  29. U8 TranslateOSKeyCode( U8 vcode );
  30. U8 TranslateKeyCodeToOS(U8 keycode);
  31. //------------------------------------------------------------------------------
  32. //------------------------------------------------------------------------------
  33. class InputDevice : public SimObject
  34. {
  35. protected:
  36. char mName[30];
  37. public:
  38. struct ObjInfo
  39. {
  40. InputEventType mType;
  41. InputObjectInstances mInst;
  42. S32 mMin, mMax;
  43. };
  44. inline const char* getDeviceName()
  45. {
  46. return mName;
  47. }
  48. virtual bool process() = 0;
  49. };
  50. //------------------------------------------------------------------------------
  51. class InputManager : public SimGroup
  52. {
  53. protected:
  54. bool mEnabled;
  55. public:
  56. inline bool isEnabled()
  57. {
  58. return mEnabled;
  59. }
  60. virtual bool enable() = 0;
  61. virtual void disable() = 0;
  62. virtual void process() = 0;
  63. };
  64. enum KEY_STATE
  65. {
  66. STATE_LOWER,
  67. STATE_UPPER,
  68. STATE_GOOFY
  69. };
  70. //------------------------------------------------------------------------------
  71. class Input
  72. {
  73. protected:
  74. static InputManager* smManager;
  75. static bool smActive;
  76. /// Current modifier keys.
  77. static U8 smModifierKeys;
  78. static bool smLastKeyboardActivated;
  79. static bool smLastMouseActivated;
  80. static bool smLastJoystickActivated;
  81. public:
  82. static void init();
  83. static void destroy();
  84. static bool enable();
  85. static void disable();
  86. static void activate();
  87. static void deactivate();
  88. static U16 getAscii( U16 keyCode, KEY_STATE keyState );
  89. static U16 getKeyCode( U16 asciiCode );
  90. static bool isEnabled();
  91. static bool isActive();
  92. static void process();
  93. static InputManager* getManager();
  94. static U8 getModifierKeys() {return smModifierKeys;}
  95. static void setModifierKeys(U8 mod) {smModifierKeys = mod;}
  96. #ifdef LOG_INPUT
  97. static void log( const char* format, ... );
  98. #endif
  99. /// Global input routing JournaledSignal; post input events here for
  100. /// processing.
  101. static InputEvent smInputEvent;
  102. };
  103. #endif // _H_PLATFORMINPUT_