BsScriptModalWindow.h 5.0 KB

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