Input.pkg 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. $#include "IO/File.h"
  2. $#include "Input/Input.h"
  3. enum MouseMode
  4. {
  5. MM_ABSOLUTE = 0,
  6. MM_RELATIVE,
  7. MM_WRAP,
  8. MM_FREE
  9. };
  10. struct TouchState
  11. {
  12. UIElement* GetTouchedElement();
  13. int touchID_ @ touchID;
  14. IntVector2 position_ @ position;
  15. IntVector2 lastPosition_ @ lastPosition;
  16. IntVector2 delta_ @ delta;
  17. float pressure_ @ pressure;
  18. tolua_readonly tolua_property__get_set UIElement* touchedElement;
  19. };
  20. struct JoystickState
  21. {
  22. const String name_ @ name;
  23. const int joystickID_ @ joystickID;
  24. bool IsController() const;
  25. unsigned GetNumButtons() const;
  26. unsigned GetNumAxes() const;
  27. unsigned GetNumHats() const;
  28. bool GetButtonDown(unsigned index) const;
  29. bool GetButtonPress(unsigned index) const;
  30. float GetAxisPosition(unsigned index) const;
  31. int GetHatPosition(unsigned index) const;
  32. tolua_readonly tolua_property__is_set bool controller;
  33. tolua_readonly tolua_property__get_set unsigned numButtons;
  34. tolua_readonly tolua_property__get_set unsigned numAxes;
  35. tolua_readonly tolua_property__get_set unsigned numHats;
  36. };
  37. class Input : public Object
  38. {
  39. void SetToggleFullscreen(bool enable);
  40. void SetMouseVisible(bool enable, bool suppressEvent = false);
  41. void SetMouseGrabbed(bool grab, bool suppressEvent = false);
  42. void SetMouseMode(MouseMode mode, bool suppressEvent = false);
  43. bool IsMouseLocked();
  44. int AddScreenJoystick(XMLFile* layoutFile = 0, XMLFile* styleFile = 0);
  45. bool RemoveScreenJoystick(int id);
  46. void SetScreenJoystickVisible(int id, bool enable);
  47. void SetScreenKeyboardVisible(bool enable);
  48. void SetTouchEmulation(bool enable);
  49. bool RecordGesture();
  50. tolua_outside bool InputSaveGestures @ SaveGestures(File* dest);
  51. tolua_outside bool InputSaveGesture @ SaveGesture(File* dest, unsigned gestureID);
  52. tolua_outside unsigned InputLoadGestures @ LoadGestures(File* source);
  53. tolua_outside bool InputSaveGestures @ SaveGestures(const String fileName);
  54. tolua_outside bool InputSaveGesture @ SaveGesture(const String fileName, unsigned gestureID);
  55. tolua_outside unsigned InputLoadGestures @ LoadGestures(const String fileName);
  56. bool RemoveGesture(unsigned gestureID);
  57. void RemoveAllGestures();
  58. int GetKeyFromName(const String name) const;
  59. int GetKeyFromScancode(int scancode) const;
  60. String GetKeyName(int key) const;
  61. int GetScancodeFromKey(int key) const;
  62. int GetScancodeFromName(const String name) const;
  63. String GetScancodeName(int scancode) const;
  64. bool GetKeyDown(int key) const;
  65. bool GetKeyPress(int key) const;
  66. bool GetScancodeDown(int scancode) const;
  67. bool GetScancodePress(int scancode) const;
  68. bool GetMouseButtonDown(int button) const;
  69. bool GetMouseButtonPress(int button) const;
  70. bool GetQualifierDown(int qualifier) const;
  71. bool GetQualifierPress(int qualifier) const;
  72. int GetQualifiers() const;
  73. IntVector2 GetMousePosition() const;
  74. const IntVector2& GetMouseMove() const;
  75. int GetMouseMoveX() const;
  76. int GetMouseMoveY() const;
  77. int GetMouseMoveWheel() const;
  78. unsigned GetNumTouches() const;
  79. TouchState* GetTouch(unsigned index) const;
  80. unsigned GetNumJoysticks() const;
  81. JoystickState* GetJoystick(int id);
  82. JoystickState* GetJoystickByIndex(unsigned index);
  83. bool GetToggleFullscreen() const;
  84. bool GetScreenKeyboardSupport() const;
  85. bool IsScreenJoystickVisible(int id) const;
  86. bool IsScreenKeyboardVisible() const;
  87. bool GetTouchEmulation() const;
  88. bool IsMouseVisible() const;
  89. bool IsMouseGrabbed() const;
  90. MouseMode GetMouseMode() const;
  91. bool HasFocus();
  92. bool IsMinimized() const;
  93. tolua_readonly tolua_property__get_set int qualifiers;
  94. tolua_readonly tolua_property__get_set IntVector2 mousePosition;
  95. tolua_readonly tolua_property__get_set IntVector2& mouseMove;
  96. tolua_readonly tolua_property__get_set int mouseMoveX;
  97. tolua_readonly tolua_property__get_set int mouseMoveY;
  98. tolua_readonly tolua_property__get_set int mouseMoveWheel;
  99. tolua_readonly tolua_property__get_set unsigned numTouches;
  100. tolua_readonly tolua_property__get_set unsigned numJoysticks;
  101. tolua_readonly tolua_property__get_set bool toggleFullscreen;
  102. tolua_readonly tolua_property__get_set bool screenKeyboardSupport;
  103. tolua_property__get_set MouseMode mouseMode;
  104. tolua_property__is_set bool screenKeyboardVisible;
  105. tolua_property__get_set bool touchEmulation;
  106. tolua_property__is_set bool mouseVisible;
  107. tolua_property__is_set bool mouseGrabbed;
  108. tolua_readonly tolua_property__is_set bool mouseLocked;
  109. tolua_readonly tolua_property__has_set bool focus;
  110. tolua_readonly tolua_property__is_set bool minimized;
  111. };
  112. Input* GetInput();
  113. tolua_readonly tolua_property__get_set Input* input;
  114. ${
  115. static bool InputSaveGestures(Input* input, File* file)
  116. {
  117. return file ? input->SaveGestures(*file) : false;
  118. }
  119. static bool InputSaveGesture(Input* input, File* file, unsigned gestureID)
  120. {
  121. return file ? input->SaveGesture(*file, gestureID) : false;
  122. }
  123. static unsigned InputLoadGestures(Input* input, File* file)
  124. {
  125. return file ? input->LoadGestures(*file) : 0;
  126. }
  127. static bool InputSaveGestures(Input* input, const String& fileName)
  128. {
  129. File file(input->GetContext(), fileName, FILE_WRITE);
  130. return file.IsOpen() ? input->SaveGestures(file) : false;
  131. }
  132. static bool InputSaveGesture(Input* input, const String& fileName, unsigned gestureID)
  133. {
  134. File file(input->GetContext(), fileName, FILE_WRITE);
  135. return file.IsOpen() ? input->SaveGesture(file, gestureID) : false;
  136. }
  137. static unsigned InputLoadGestures(Input* input, const String& fileName)
  138. {
  139. File file(input->GetContext(), fileName, FILE_READ);
  140. return file.IsOpen() ? input->LoadGestures(file) : 0;
  141. }
  142. #define TOLUA_DISABLE_tolua_InputLuaAPI_GetInput00
  143. static int tolua_InputLuaAPI_GetInput00(lua_State* tolua_S)
  144. {
  145. return ToluaGetSubsystem<Input>(tolua_S);
  146. }
  147. #define TOLUA_DISABLE_tolua_get_input_ptr
  148. #define tolua_get_input_ptr tolua_InputLuaAPI_GetInput00
  149. $}