BsScriptVirtualInput.h 2.6 KB

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