Input.pkg 5.9 KB

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