Input.pkg 6.0 KB

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