InputAPI.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Precompiled.h"
  24. #include "APITemplates.h"
  25. #include "Input.h"
  26. static void RegisterInputConstants(asIScriptEngine* engine)
  27. {
  28. engine->RegisterGlobalProperty("const int MOUSEB_LEFT", (void*)&MOUSEB_LEFT);
  29. engine->RegisterGlobalProperty("const int MOUSEB_RIGHT", (void*)&MOUSEB_RIGHT);
  30. engine->RegisterGlobalProperty("const int MOUSEB_MIDDLE", (void*)&MOUSEB_MIDDLE);
  31. engine->RegisterGlobalProperty("const int QUAL_SHIFT", (void*)&QUAL_SHIFT);
  32. engine->RegisterGlobalProperty("const int QUAL_CTRL", (void*)&QUAL_CTRL);
  33. engine->RegisterGlobalProperty("const int QUAL_ALT", (void*)&QUAL_ALT);
  34. engine->RegisterGlobalProperty("const int QUAL_ANY", (void*)&QUAL_ANY);
  35. engine->RegisterGlobalProperty("const int KEY_BACKSPACE", (void*)&KEY_BACKSPACE);
  36. engine->RegisterGlobalProperty("const int KEY_TAB", (void*)&KEY_TAB);
  37. engine->RegisterGlobalProperty("const int KEY_RETURN", (void*)&KEY_RETURN);
  38. engine->RegisterGlobalProperty("const int KEY_PAUSE", (void*)&KEY_PAUSE);
  39. engine->RegisterGlobalProperty("const int KEY_CAPSLOCK", (void*)&KEY_CAPSLOCK);
  40. engine->RegisterGlobalProperty("const int KEY_ESC", (void*)&KEY_ESC);
  41. engine->RegisterGlobalProperty("const int KEY_SPACE", (void*)&KEY_SPACE);
  42. engine->RegisterGlobalProperty("const int KEY_PAGEUP", (void*)&KEY_PAGEUP);
  43. engine->RegisterGlobalProperty("const int KEY_PAGEDOWN", (void*)&KEY_PAGEDOWN);
  44. engine->RegisterGlobalProperty("const int KEY_END", (void*)&KEY_END);
  45. engine->RegisterGlobalProperty("const int KEY_HOME", (void*)&KEY_HOME);
  46. engine->RegisterGlobalProperty("const int KEY_LEFT", (void*)&KEY_LEFT);
  47. engine->RegisterGlobalProperty("const int KEY_UP", (void*)&KEY_UP);
  48. engine->RegisterGlobalProperty("const int KEY_RIGHT", (void*)&KEY_RIGHT);
  49. engine->RegisterGlobalProperty("const int KEY_DOWN", (void*)&KEY_DOWN);
  50. engine->RegisterGlobalProperty("const int KEY_INSERT", (void*)&KEY_INSERT);
  51. engine->RegisterGlobalProperty("const int KEY_DELETE", (void*)&KEY_DELETE);
  52. engine->RegisterGlobalProperty("const int KEY_LWIN", (void*)&KEY_LWIN);
  53. engine->RegisterGlobalProperty("const int KEY_RWIN", (void*)&KEY_RWIN);
  54. engine->RegisterGlobalProperty("const int KEY_APPS", (void*)&KEY_APPS);
  55. engine->RegisterGlobalProperty("const int KEY_NUMPAD0", (void*)&KEY_NUMPAD0);
  56. engine->RegisterGlobalProperty("const int KEY_NUMPAD1", (void*)&KEY_NUMPAD1);
  57. engine->RegisterGlobalProperty("const int KEY_NUMPAD2", (void*)&KEY_NUMPAD2);
  58. engine->RegisterGlobalProperty("const int KEY_NUMPAD3", (void*)&KEY_NUMPAD3);
  59. engine->RegisterGlobalProperty("const int KEY_NUMPAD4", (void*)&KEY_NUMPAD4);
  60. engine->RegisterGlobalProperty("const int KEY_NUMPAD5", (void*)&KEY_NUMPAD5);
  61. engine->RegisterGlobalProperty("const int KEY_NUMPAD6", (void*)&KEY_NUMPAD6);
  62. engine->RegisterGlobalProperty("const int KEY_NUMPAD7", (void*)&KEY_NUMPAD7);
  63. engine->RegisterGlobalProperty("const int KEY_NUMPAD8", (void*)&KEY_NUMPAD8);
  64. engine->RegisterGlobalProperty("const int KEY_NUMPAD9", (void*)&KEY_NUMPAD9);
  65. engine->RegisterGlobalProperty("const int KEY_MULTIPLY", (void*)&KEY_MULTIPLY);
  66. engine->RegisterGlobalProperty("const int KEY_ADD", (void*)&KEY_ADD);
  67. engine->RegisterGlobalProperty("const int KEY_SUBTRACT", (void*)&KEY_SUBTRACT);
  68. engine->RegisterGlobalProperty("const int KEY_DECIMAL", (void*)&KEY_DECIMAL);
  69. engine->RegisterGlobalProperty("const int KEY_DIVIDE", (void*)&KEY_DIVIDE);
  70. engine->RegisterGlobalProperty("const int KEY_F1", (void*)&KEY_F1);
  71. engine->RegisterGlobalProperty("const int KEY_F2", (void*)&KEY_F2);
  72. engine->RegisterGlobalProperty("const int KEY_F3", (void*)&KEY_F3);
  73. engine->RegisterGlobalProperty("const int KEY_F4", (void*)&KEY_F4);
  74. engine->RegisterGlobalProperty("const int KEY_F5", (void*)&KEY_F5);
  75. engine->RegisterGlobalProperty("const int KEY_F6", (void*)&KEY_F6);
  76. engine->RegisterGlobalProperty("const int KEY_F7", (void*)&KEY_F7);
  77. engine->RegisterGlobalProperty("const int KEY_F8", (void*)&KEY_F8);
  78. engine->RegisterGlobalProperty("const int KEY_F9", (void*)&KEY_F9);
  79. engine->RegisterGlobalProperty("const int KEY_F10", (void*)&KEY_F10);
  80. engine->RegisterGlobalProperty("const int KEY_F11", (void*)&KEY_F11);
  81. engine->RegisterGlobalProperty("const int KEY_F12", (void*)&KEY_F12);
  82. engine->RegisterGlobalProperty("const int KEY_F13", (void*)&KEY_F13);
  83. engine->RegisterGlobalProperty("const int KEY_F14", (void*)&KEY_F14);
  84. engine->RegisterGlobalProperty("const int KEY_F15", (void*)&KEY_F15);
  85. engine->RegisterGlobalProperty("const int KEY_F16", (void*)&KEY_F16);
  86. engine->RegisterGlobalProperty("const int KEY_F17", (void*)&KEY_F17);
  87. engine->RegisterGlobalProperty("const int KEY_F18", (void*)&KEY_F18);
  88. engine->RegisterGlobalProperty("const int KEY_F19", (void*)&KEY_F19);
  89. engine->RegisterGlobalProperty("const int KEY_F20", (void*)&KEY_F20);
  90. engine->RegisterGlobalProperty("const int KEY_F21", (void*)&KEY_F21);
  91. engine->RegisterGlobalProperty("const int KEY_F22", (void*)&KEY_F22);
  92. engine->RegisterGlobalProperty("const int KEY_F23", (void*)&KEY_F23);
  93. engine->RegisterGlobalProperty("const int KEY_F24", (void*)&KEY_F24);
  94. engine->RegisterGlobalProperty("const int KEY_NUMLOCK", (void*)&KEY_NUMLOCK);
  95. engine->RegisterGlobalProperty("const int KEY_SCROLLLOCK", (void*)&KEY_SCROLLLOCK);
  96. engine->RegisterGlobalProperty("const int KEY_LSHIFT", (void*)&KEY_LSHIFT);
  97. engine->RegisterGlobalProperty("const int KEY_RSHIFT", (void*)&KEY_RSHIFT);
  98. engine->RegisterGlobalProperty("const int KEY_LCTRL", (void*)&KEY_LCTRL);
  99. engine->RegisterGlobalProperty("const int KEY_RCTRL", (void*)&KEY_RCTRL);
  100. engine->RegisterGlobalProperty("const int KEY_LALT", (void*)&KEY_LALT);
  101. engine->RegisterGlobalProperty("const int KEY_RALT", (void*)&KEY_RALT);
  102. }
  103. static Input* GetInput()
  104. {
  105. return GetScriptContext()->GetSubsystem<Input>();
  106. }
  107. static void ConstructTouchState(TouchState* ptr)
  108. {
  109. new(ptr) TouchState();
  110. }
  111. static void RegisterInput(asIScriptEngine* engine)
  112. {
  113. engine->RegisterObjectType("TouchState", sizeof(TouchState), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS);
  114. engine->RegisterObjectBehaviour("TouchState", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructTouchState), asCALL_CDECL_OBJLAST);
  115. engine->RegisterObjectProperty("TouchState", "int touchID", offsetof(TouchState, touchID_));
  116. engine->RegisterObjectProperty("TouchState", "IntVector2 position", offsetof(TouchState, position_));
  117. engine->RegisterObjectProperty("TouchState", "IntVector2 delta", offsetof(TouchState, delta_));
  118. engine->RegisterObjectProperty("TouchState", "int pressure", offsetof(TouchState, pressure_));
  119. RegisterObject<Input>(engine, "Input");
  120. engine->RegisterObjectMethod("Input", "void set_toggleFullscreen(bool)", asMETHOD(Input, SetToggleFullscreen), asCALL_THISCALL);
  121. engine->RegisterObjectMethod("Input", "bool get_toggleFullscreen() const", asMETHOD(Input, GetToggleFullscreen), asCALL_THISCALL);
  122. engine->RegisterObjectMethod("Input", "bool get_keyDown(int) const", asMETHOD(Input, GetKeyDown), asCALL_THISCALL);
  123. engine->RegisterObjectMethod("Input", "bool get_keyPress(int) const", asMETHOD(Input, GetKeyPress), asCALL_THISCALL);
  124. engine->RegisterObjectMethod("Input", "bool get_mouseButtonDown(int) const", asMETHOD(Input, GetMouseButtonDown), asCALL_THISCALL);
  125. engine->RegisterObjectMethod("Input", "bool get_mouseButtonPress(int) const", asMETHOD(Input, GetMouseButtonPress), asCALL_THISCALL);
  126. engine->RegisterObjectMethod("Input", "bool get_qualifierDown(int) const", asMETHOD(Input, GetQualifierDown), asCALL_THISCALL);
  127. engine->RegisterObjectMethod("Input", "bool get_qualifierPress(int) const", asMETHOD(Input, GetQualifierPress), asCALL_THISCALL);
  128. engine->RegisterObjectMethod("Input", "int get_qualifiers() const", asMETHOD(Input, GetQualifiers), asCALL_THISCALL);
  129. engine->RegisterObjectMethod("Input", "const IntVector2& get_mouseMove() const", asMETHOD(Input, GetMouseMove), asCALL_THISCALL);
  130. engine->RegisterObjectMethod("Input", "int get_mouseMoveX() const", asMETHOD(Input, GetMouseMoveX), asCALL_THISCALL);
  131. engine->RegisterObjectMethod("Input", "int get_mouseMoveY() const", asMETHOD(Input, GetMouseMoveY), asCALL_THISCALL);
  132. engine->RegisterObjectMethod("Input", "int get_mouseMoveWheel() const", asMETHOD(Input, GetMouseMoveWheel), asCALL_THISCALL);
  133. engine->RegisterObjectMethod("Input", "uint get_numTouches() const", asMETHOD(Input, GetNumTouches), asCALL_THISCALL);
  134. engine->RegisterObjectMethod("Input", "TouchState get_touches(uint) const", asMETHOD(Input, GetTouch), asCALL_THISCALL);
  135. engine->RegisterObjectMethod("Input", "bool get_active() const", asMETHOD(Input, IsActive), asCALL_THISCALL);
  136. engine->RegisterObjectMethod("Input", "bool get_minimized() const", asMETHOD(Input, IsMinimized), asCALL_THISCALL);
  137. engine->RegisterGlobalFunction("Input@+ get_input()", asFUNCTION(GetInput), asCALL_CDECL);
  138. }
  139. void RegisterInputAPI(asIScriptEngine* engine)
  140. {
  141. RegisterInputConstants(engine);
  142. RegisterInput(engine);
  143. }