Input.pkg 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. unsigned AddScreenJoystick(XMLFile* layoutFile = 0, XMLFile* styleFile = 0);
  31. bool RemoveScreenJoystick(unsigned index);
  32. void SetScreenKeyboardVisible(bool enable);
  33. bool RecordGesture();
  34. tolua_outside bool InputSaveGestures @ SaveGestures(File* dest);
  35. tolua_outside bool InputSaveGesture @ SaveGesture(File* dest, unsigned gestureID);
  36. tolua_outside unsigned InputLoadGestures @ LoadGestures(File* source);
  37. tolua_outside bool InputSaveGestures @ SaveGestures(const String fileName);
  38. tolua_outside bool InputSaveGesture @ SaveGesture(const String fileName, unsigned gestureID);
  39. tolua_outside unsigned InputLoadGestures @ LoadGestures(const String fileName);
  40. int GetKeyFromName(const String name) const;
  41. int GetKeyFromScancode(int scancode) const;
  42. String GetKeyName(int key) const;
  43. int GetScancodeFromKey(int key) const;
  44. int GetScancodeFromName(const String name) const;
  45. String GetScancodeName(int scancode) const;
  46. bool GetKeyDown(int key) const;
  47. bool GetKeyPress(int key) const;
  48. bool GetScancodeDown(int scancode) const;
  49. bool GetScancodePress(int scancode) const;
  50. bool GetMouseButtonDown(int button) const;
  51. bool GetMouseButtonPress(int button) const;
  52. bool GetQualifierDown(int qualifier) const;
  53. bool GetQualifierPress(int qualifier) const;
  54. int GetQualifiers() const;
  55. IntVector2 GetMousePosition() const;
  56. const IntVector2& GetMouseMove() const;
  57. int GetMouseMoveX() const;
  58. int GetMouseMoveY() const;
  59. int GetMouseMoveWheel() const;
  60. unsigned GetNumTouches() const;
  61. TouchState* GetTouch(unsigned index) const;
  62. unsigned GetNumJoysticks() const;
  63. const String GetJoystickName(unsigned index) const;
  64. JoystickState* GetJoystick(unsigned index);
  65. bool GetToggleFullscreen() const;
  66. bool GetScreenKeyboardSupport() const;
  67. bool IsScreenKeyboardVisible() const;
  68. bool IsMouseVisible() const;
  69. bool HasFocus();
  70. bool IsMinimized() const;
  71. tolua_readonly tolua_property__get_set int qualifiers;
  72. tolua_readonly tolua_property__get_set IntVector2 mousePosition;
  73. tolua_readonly tolua_property__get_set IntVector2& mouseMove;
  74. tolua_readonly tolua_property__get_set int mouseMoveX;
  75. tolua_readonly tolua_property__get_set int mouseMoveY;
  76. tolua_readonly tolua_property__get_set int mouseMoveWheel;
  77. tolua_readonly tolua_property__get_set unsigned numTouches;
  78. tolua_readonly tolua_property__get_set unsigned numJoysticks;
  79. tolua_readonly tolua_property__get_set bool toggleFullscreen;
  80. tolua_readonly tolua_property__get_set bool screenKeyboardSupport;
  81. tolua_property__is_set bool screenKeyboardVisible;
  82. tolua_property__is_set bool mouseVisible;
  83. tolua_readonly tolua_property__has_set bool focus;
  84. tolua_readonly tolua_property__is_set bool minimized;
  85. };
  86. Input* GetInput();
  87. tolua_readonly tolua_property__get_set Input* input;
  88. ${
  89. static bool InputSaveGestures(Input* input, File* file)
  90. {
  91. return file ? input->SaveGestures(*file) : false;
  92. }
  93. static bool InputSaveGesture(Input* input, File* file, unsigned gestureID)
  94. {
  95. return file ? input->SaveGesture(*file, gestureID) : false;
  96. }
  97. static unsigned InputLoadGestures(Input* input, File* file)
  98. {
  99. return file ? input->LoadGestures(*file) : 0;
  100. }
  101. static bool InputSaveGestures(Input* input, const String& fileName)
  102. {
  103. File file(input->GetContext(), fileName, FILE_WRITE);
  104. return file.IsOpen() ? input->SaveGestures(file) : false;
  105. }
  106. static bool InputSaveGesture(Input* input, const String& fileName, unsigned gestureID)
  107. {
  108. File file(input->GetContext(), fileName, FILE_WRITE);
  109. return file.IsOpen() ? input->SaveGesture(file, gestureID) : false;
  110. }
  111. static unsigned InputLoadGestures(Input* input, const String& fileName)
  112. {
  113. File file(input->GetContext(), fileName, FILE_READ);
  114. return file.IsOpen() ? input->LoadGestures(file) : 0;
  115. }
  116. #define TOLUA_DISABLE_tolua_InputLuaAPI_GetInput00
  117. static int tolua_InputLuaAPI_GetInput00(lua_State* tolua_S)
  118. {
  119. return ToluaGetSubsystem<Input>(tolua_S);
  120. }
  121. #define TOLUA_DISABLE_tolua_get_input_ptr
  122. #define tolua_get_input_ptr tolua_InputLuaAPI_GetInput00
  123. $}