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