Input.pkg 5.6 KB

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