Input.pkg 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. void SetMousePosition(const IntVector2& position);
  59. void CenterMousePosition();
  60. int GetKeyFromName(const String name) const;
  61. int GetKeyFromScancode(int scancode) const;
  62. String GetKeyName(int key) const;
  63. int GetScancodeFromKey(int key) const;
  64. int GetScancodeFromName(const String name) const;
  65. String GetScancodeName(int scancode) const;
  66. bool GetKeyDown(int key) const;
  67. bool GetKeyPress(int key) const;
  68. bool GetScancodeDown(int scancode) const;
  69. bool GetScancodePress(int scancode) const;
  70. bool GetMouseButtonDown(int button) const;
  71. bool GetMouseButtonPress(int button) const;
  72. bool GetQualifierDown(int qualifier) const;
  73. bool GetQualifierPress(int qualifier) const;
  74. int GetQualifiers() const;
  75. IntVector2 GetMousePosition() const;
  76. IntVector2 GetMouseMove() const;
  77. int GetMouseMoveX() const;
  78. int GetMouseMoveY() const;
  79. int GetMouseMoveWheel() const;
  80. Vector2 GetInputScale() const;
  81. unsigned GetNumTouches() const;
  82. TouchState* GetTouch(unsigned index) const;
  83. unsigned GetNumJoysticks() const;
  84. JoystickState* GetJoystick(int id);
  85. JoystickState* GetJoystickByIndex(unsigned index);
  86. JoystickState* GetJoystickByName(const String name);
  87. bool GetToggleFullscreen() const;
  88. bool GetScreenKeyboardSupport() const;
  89. bool IsScreenJoystickVisible(int id) const;
  90. bool IsScreenKeyboardVisible() const;
  91. bool GetTouchEmulation() const;
  92. bool IsMouseVisible() const;
  93. bool IsMouseGrabbed() const;
  94. MouseMode GetMouseMode() const;
  95. bool HasFocus();
  96. bool IsMinimized() const;
  97. tolua_readonly tolua_property__get_set int qualifiers;
  98. tolua_property__get_set IntVector2 mousePosition;
  99. tolua_readonly tolua_property__get_set IntVector2 mouseMove;
  100. tolua_readonly tolua_property__get_set int mouseMoveX;
  101. tolua_readonly tolua_property__get_set int mouseMoveY;
  102. tolua_readonly tolua_property__get_set int mouseMoveWheel;
  103. tolua_readonly tolua_property__get_set Vector2 inputScale;
  104. tolua_readonly tolua_property__get_set unsigned numTouches;
  105. tolua_readonly tolua_property__get_set unsigned numJoysticks;
  106. tolua_readonly tolua_property__get_set bool toggleFullscreen;
  107. tolua_readonly tolua_property__get_set bool screenKeyboardSupport;
  108. tolua_property__get_set MouseMode mouseMode;
  109. tolua_property__is_set bool screenKeyboardVisible;
  110. tolua_property__get_set bool touchEmulation;
  111. tolua_property__is_set bool mouseVisible;
  112. tolua_property__is_set bool mouseGrabbed;
  113. tolua_readonly tolua_property__is_set bool mouseLocked;
  114. tolua_readonly tolua_property__has_set bool focus;
  115. tolua_readonly tolua_property__is_set bool minimized;
  116. };
  117. Input* GetInput();
  118. tolua_readonly tolua_property__get_set Input* input;
  119. ${
  120. static bool InputSaveGestures(Input* input, File* file)
  121. {
  122. return file ? input->SaveGestures(*file) : false;
  123. }
  124. static bool InputSaveGesture(Input* input, File* file, unsigned gestureID)
  125. {
  126. return file ? input->SaveGesture(*file, gestureID) : false;
  127. }
  128. static unsigned InputLoadGestures(Input* input, File* file)
  129. {
  130. return file ? input->LoadGestures(*file) : 0;
  131. }
  132. static bool InputSaveGestures(Input* input, const String& fileName)
  133. {
  134. File file(input->GetContext(), fileName, FILE_WRITE);
  135. return file.IsOpen() ? input->SaveGestures(file) : false;
  136. }
  137. static bool InputSaveGesture(Input* input, const String& fileName, unsigned gestureID)
  138. {
  139. File file(input->GetContext(), fileName, FILE_WRITE);
  140. return file.IsOpen() ? input->SaveGesture(file, gestureID) : false;
  141. }
  142. static unsigned InputLoadGestures(Input* input, const String& fileName)
  143. {
  144. File file(input->GetContext(), fileName, FILE_READ);
  145. return file.IsOpen() ? input->LoadGestures(file) : 0;
  146. }
  147. #define TOLUA_DISABLE_tolua_InputLuaAPI_GetInput00
  148. static int tolua_InputLuaAPI_GetInput00(lua_State* tolua_S)
  149. {
  150. return ToluaGetSubsystem<Input>(tolua_S);
  151. }
  152. #define TOLUA_DISABLE_tolua_get_input_ptr
  153. #define tolua_get_input_ptr tolua_InputLuaAPI_GetInput00
  154. $}