Input.pkg 5.2 KB

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