2
0

BsScriptModalWindow.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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>
  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. * @brief Triggered when assembly refresh has started.
  30. */
  31. void onAssemblyRefreshStarted();
  32. /**
  33. * @brief Triggered when the native modal window is closed.
  34. */
  35. void notifyWindowDestroyed();
  36. ManagedModalWindow* mModalWindow;
  37. HEvent mOnAssemblyRefreshStartedConn;
  38. static MonoField* guiPanelField;
  39. /************************************************************************/
  40. /* CLR HOOKS */
  41. /************************************************************************/
  42. static void internal_createInstance(MonoObject* instance, bool allowCloseButton);
  43. static void internal_close(ScriptModalWindow* thisPtr);
  44. static UINT32 internal_getWidth(ScriptModalWindow* thisPtr);
  45. static UINT32 internal_getHeight(ScriptModalWindow* thisPtr);
  46. static void internal_setWidth(ScriptModalWindow* thisPtr, UINT32 value);
  47. static void internal_setHeight(ScriptModalWindow* thisPtr, UINT32 value);
  48. static void internal_setTitle(ScriptModalWindow* thisPtr, MonoObject* title);
  49. static void internal_screenToWindowPos(ScriptModalWindow* thisPtr, Vector2I screenPos, Vector2I* windowPos);
  50. static void internal_windowToScreenPos(ScriptModalWindow* thisPtr, Vector2I windowPos, Vector2I* screenPos);
  51. };
  52. /**
  53. * @brief Modal window implementation that handles managed modal window implementations.
  54. * Each implementation is wrapped in this object and then managed by its parent interop
  55. * object of ScriptModalWindow type.
  56. */
  57. class BS_SCR_BED_EXPORT ManagedModalWindow : public ModalWindow
  58. {
  59. public:
  60. ManagedModalWindow(bool allowCloseButton, MonoObject* managedInstance);
  61. ~ManagedModalWindow();
  62. /**
  63. * @brief Attempts to create a managed instance for the modal window described by the
  64. * type provided upon construction.
  65. *
  66. * @return True if the managed instance was created.
  67. */
  68. bool createManagedInstance();
  69. /**
  70. * @brief Releases the internally held handle to the managed instance. This will cause
  71. * managed instance to be destroyed if no other references are being held.
  72. */
  73. void releaseManagedInstance();
  74. /**
  75. * @brief Sets the parent interop object that handles part of the communication
  76. * between this object and the managed instance.
  77. */
  78. void setParent(ScriptModalWindow* parent);
  79. /**
  80. * @copydoc ModalWindow::update
  81. */
  82. void update() override;
  83. /**
  84. * @brief Loads all required mono methods, fields and types required
  85. * for operation of this object. Must be called after construction
  86. * and after assembly refresh.
  87. *
  88. * @param windowClass Mono class to load the types from.
  89. */
  90. void reloadMonoTypes(MonoClass* windowClass);
  91. /**
  92. * @brief Triggers OnInitialize callbacks on the managed instance.
  93. */
  94. void triggerOnInitialize();
  95. /**
  96. * @brief Triggers OnDestroy callbacks on the managed instance.
  97. */
  98. void triggerOnDestroy();
  99. /**
  100. * @brief Returns the managed instance for the modal window
  101. * represented by this object.
  102. */
  103. MonoObject* getManagedInstance() const { return mManagedInstance; }
  104. protected:
  105. /**
  106. * @copydoc ModalWindow::resized
  107. */
  108. virtual void resized() override;
  109. /**
  110. * @copydoc ModalWindow::close
  111. */
  112. virtual void close() override;
  113. private:
  114. friend class ScriptModalWindow;
  115. typedef void(__stdcall *OnInitializeThunkDef) (MonoObject*, MonoException**);
  116. typedef void(__stdcall *OnDestroyThunkDef) (MonoObject*, MonoException**);
  117. typedef void(__stdcall *UpdateThunkDef) (MonoObject*, MonoException**);
  118. String mNamespace;
  119. String mTypename;
  120. OnInitializeThunkDef mOnInitializeThunk;
  121. OnDestroyThunkDef mOnDestroyThunk;
  122. UpdateThunkDef mUpdateThunk;
  123. MonoMethod* mOnWindowResizedMethod;
  124. MonoObject* mManagedInstance;
  125. uint32_t mGCHandle;
  126. ScriptModalWindow* mScriptParent;
  127. ScriptGUILayout* mContentsPanel;
  128. };
  129. }