BsScriptVirtualInput.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsScriptObject.h"
  4. #include "BsInputConfiguration.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Interop class between C++ & CLR for VirtualInput.
  9. */
  10. class BS_SCR_BE_EXPORT ScriptVirtualInput : public ScriptObject<ScriptVirtualInput>
  11. {
  12. public:
  13. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "VirtualInput")
  14. /**
  15. * @brief Must be called on library load. Hooks up necessary callbacks.
  16. */
  17. static void startUp();
  18. /**
  19. * @brief Must be called before library shutdown. Releases previously hooked callbacks.
  20. */
  21. static void shutDown();
  22. private:
  23. /**
  24. * @brief Triggered whenever a virtual button is pressed.
  25. *
  26. * @param btn Virtual button that was pressed.
  27. * @param deviceIdx Index of the device the button was pressed on.
  28. */
  29. static void onButtonDown(const VirtualButton& btn, UINT32 deviceIdx);
  30. /**
  31. * @brief Triggered whenever a virtual button is released.
  32. *
  33. * @param btn Virtual button that was released.
  34. * @param deviceIdx Index of the device the button was released on.
  35. */
  36. static void onButtonUp(const VirtualButton& btn, UINT32 deviceIdx);
  37. /**
  38. * @brief Triggered every frame while a virtual button is held down.
  39. *
  40. * @param btn Virtual button that is being held.
  41. * @param deviceIdx Index of the device the button is held.
  42. */
  43. static void onButtonHeld(const VirtualButton& btn, UINT32 deviceIdx);
  44. static HEvent OnButtonPressedConn;
  45. static HEvent OnButtonReleasedConn;
  46. static HEvent OnButtonHeldConn;
  47. ScriptVirtualInput(MonoObject* instance);
  48. /************************************************************************/
  49. /* CLR HOOKS */
  50. /************************************************************************/
  51. static MonoObject* internal_getKeyConfig();
  52. static void internal_setKeyConfig(MonoObject* keyConfig);
  53. static bool internal_isButtonHeld(VirtualButton btn, UINT32 deviceIdx);
  54. static bool internal_isButtonDown(VirtualButton btn, UINT32 deviceIdx);
  55. static bool internal_isButtonUp(VirtualButton btn, UINT32 deviceIdx);
  56. static float internal_getAxisValue(VirtualAxis axis, UINT32 deviceIdx);
  57. typedef void(__stdcall *OnButtonEventThunkDef) (MonoObject*, UINT32, MonoException**);
  58. static OnButtonEventThunkDef OnButtonUpThunk;
  59. static OnButtonEventThunkDef OnButtonDownThunk;
  60. static OnButtonEventThunkDef OnButtonHeldThunk;
  61. };
  62. }