BsScriptModalWindow.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEditorPrerequisites.h"
  5. #include "BsScriptObject.h"
  6. #include "EditorWindow/BsModalWindow.h"
  7. #include "Math/BsVector2I.h"
  8. namespace bs
  9. {
  10. /** @addtogroup ScriptInteropEditor
  11. * @{
  12. */
  13. class ManagedModalWindow;
  14. /** Interop class between C++ & CLR for ManagedModalWindow. */
  15. class BS_SCR_BED_EXPORT ScriptModalWindow : public ScriptObject <ScriptModalWindow>
  16. {
  17. /** Contains data about the managed handle to a modal window. */
  18. struct ModalWindowHandle
  19. {
  20. uint32_t gcHandle;
  21. ManagedModalWindow* nativeObj;
  22. };
  23. public:
  24. SCRIPT_OBJ(EDITOR_ASSEMBLY, EDITOR_NS, "ModalWindow")
  25. ~ScriptModalWindow();
  26. private:
  27. friend class ManagedModalWindow;
  28. ScriptModalWindow(ManagedModalWindow* editorWidget);
  29. /** Triggered when assembly refresh has started. */
  30. void onAssemblyRefreshStarted();
  31. /** Triggered when the native modal window is closed. */
  32. void notifyWindowDestroyed();
  33. ManagedModalWindow* mModalWindow;
  34. HEvent mOnAssemblyRefreshStartedConn;
  35. static MonoField* guiPanelField;
  36. /************************************************************************/
  37. /* CLR HOOKS */
  38. /************************************************************************/
  39. static void internal_createInstance(MonoObject* instance, bool allowCloseButton);
  40. static void internal_close(ScriptModalWindow* thisPtr);
  41. static UINT32 internal_getWidth(ScriptModalWindow* thisPtr);
  42. static UINT32 internal_getHeight(ScriptModalWindow* thisPtr);
  43. static void internal_setWidth(ScriptModalWindow* thisPtr, UINT32 value);
  44. static void internal_setHeight(ScriptModalWindow* thisPtr, UINT32 value);
  45. static UINT32 internal_getContentWidth(ScriptModalWindow* thisPtr);
  46. static UINT32 internal_getContentHeight(ScriptModalWindow* thisPtr);
  47. static void internal_setContentWidth(ScriptModalWindow* thisPtr, UINT32 value);
  48. static void internal_setContentHeight(ScriptModalWindow* thisPtr, UINT32 value);
  49. static void internal_setTitle(ScriptModalWindow* thisPtr, MonoObject* title);
  50. static void internal_screenToWindowPos(ScriptModalWindow* thisPtr, Vector2I* screenPos, Vector2I* windowPos);
  51. static void internal_windowToScreenPos(ScriptModalWindow* thisPtr, Vector2I* windowPos, Vector2I* screenPos);
  52. };
  53. /** @} */
  54. /** @addtogroup EditorScript
  55. * @{
  56. */
  57. /**
  58. * Modal window implementation that handles managed modal window implementations. Each implementation is wrapped in this
  59. * object and then managed by its parent interop object of ScriptModalWindow type.
  60. */
  61. class BS_SCR_BED_EXPORT ManagedModalWindow : public ModalWindow
  62. {
  63. public:
  64. ManagedModalWindow(bool allowCloseButton, UINT32 width, UINT32 height, MonoObject* managedInstance);
  65. ~ManagedModalWindow();
  66. /**
  67. * Attempts to create a managed instance for the modal window described by the type provided upon construction.
  68. *
  69. * @return True if the managed instance was created.
  70. */
  71. bool createManagedInstance();
  72. /**
  73. * Releases the internally held handle to the managed instance. This will cause managed instance to be destroyed if
  74. * no other references are being held.
  75. */
  76. void releaseManagedInstance();
  77. /**
  78. * Sets the parent interop object that handles part of the communication between this object and the managed
  79. * instance.
  80. */
  81. void setParent(ScriptModalWindow* parent);
  82. /** @copydoc ModalWindow::update */
  83. void update() override;
  84. /**
  85. * Loads all required mono methods, fields and types required for operation of this object. Must be called after
  86. * construction and after assembly refresh.
  87. *
  88. * @param[in] windowClass Mono class to load the types from.
  89. */
  90. void reloadMonoTypes(MonoClass* windowClass);
  91. /** Triggers OnInitialize callbacks on the managed instance. */
  92. void triggerOnInitialize();
  93. /** Triggers OnDestroy callbacks on the managed instance. */
  94. void triggerOnDestroy();
  95. /** Returns the managed instance for the modal window represented by this object. */
  96. MonoObject* getManagedInstance() const { return mManagedInstance; }
  97. protected:
  98. /** @copydoc ModalWindow::resized */
  99. void resized() override;
  100. /** @copydoc ModalWindow::close */
  101. void close() override;
  102. private:
  103. friend class ScriptModalWindow;
  104. typedef void(BS_THUNKCALL *OnInitializeThunkDef) (MonoObject*, MonoException**);
  105. typedef void(BS_THUNKCALL *OnDestroyThunkDef) (MonoObject*, MonoException**);
  106. typedef void(BS_THUNKCALL *UpdateThunkDef) (MonoObject*, MonoException**);
  107. String mNamespace;
  108. String mTypename;
  109. OnInitializeThunkDef mOnInitializeThunk = nullptr;
  110. OnDestroyThunkDef mOnDestroyThunk = nullptr;
  111. UpdateThunkDef mUpdateThunk = nullptr;
  112. MonoMethod* mOnWindowResizedMethod = nullptr;
  113. bool mIsInitialized = false;
  114. MonoObject* mManagedInstance;
  115. uint32_t mGCHandle = 0;
  116. ScriptModalWindow* mScriptParent = nullptr;
  117. ScriptGUILayout* mContentsPanel = nullptr;
  118. };
  119. /** @} */
  120. }