Input.pkg 5.7 KB

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