BsScriptModalWindow.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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, "BansheeEditor", "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 void internal_setTitle(ScriptModalWindow* thisPtr, MonoObject* title);
  46. static void internal_screenToWindowPos(ScriptModalWindow* thisPtr, Vector2I* screenPos, Vector2I* windowPos);
  47. static void internal_windowToScreenPos(ScriptModalWindow* thisPtr, Vector2I* windowPos, Vector2I* screenPos);
  48. };
  49. /** @} */
  50. /** @addtogroup EditorScript
  51. * @{
  52. */
  53. /**
  54. * Modal window implementation that handles managed modal window implementations. Each implementation is wrapped in this
  55. * object and then managed by its parent interop 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. * Attempts to create a managed instance for the modal window described by the type provided upon construction.
  64. *
  65. * @return True if the managed instance was created.
  66. */
  67. bool createManagedInstance();
  68. /**
  69. * Releases the internally held handle to the managed instance. This will cause managed instance to be destroyed if
  70. * no other references are being held.
  71. */
  72. void releaseManagedInstance();
  73. /**
  74. * Sets the parent interop object that handles part of the communication between this object and the managed
  75. * instance.
  76. */
  77. void setParent(ScriptModalWindow* parent);
  78. /** @copydoc ModalWindow::update */
  79. void update() override;
  80. /**
  81. * Loads all required mono methods, fields and types required for operation of this object. Must be called after
  82. * construction and after assembly refresh.
  83. *
  84. * @param[in] windowClass Mono class to load the types from.
  85. */
  86. void reloadMonoTypes(MonoClass* windowClass);
  87. /** Triggers OnInitialize callbacks on the managed instance. */
  88. void triggerOnInitialize();
  89. /** Triggers OnDestroy callbacks on the managed instance. */
  90. void triggerOnDestroy();
  91. /** Returns the managed instance for the modal window represented by this object. */
  92. MonoObject* getManagedInstance() const { return mManagedInstance; }
  93. protected:
  94. /** @copydoc ModalWindow::resized */
  95. virtual void resized() override;
  96. /** @copydoc ModalWindow::close */
  97. virtual void close() override;
  98. private:
  99. friend class ScriptModalWindow;
  100. typedef void(BS_THUNKCALL *OnInitializeThunkDef) (MonoObject*, MonoException**);
  101. typedef void(BS_THUNKCALL *OnDestroyThunkDef) (MonoObject*, MonoException**);
  102. typedef void(BS_THUNKCALL *UpdateThunkDef) (MonoObject*, MonoException**);
  103. String mNamespace;
  104. String mTypename;
  105. OnInitializeThunkDef mOnInitializeThunk;
  106. OnDestroyThunkDef mOnDestroyThunk;
  107. UpdateThunkDef mUpdateThunk;
  108. MonoMethod* mOnWindowResizedMethod;
  109. bool mIsInitialized;
  110. MonoObject* mManagedInstance;
  111. uint32_t mGCHandle;
  112. ScriptModalWindow* mScriptParent;
  113. ScriptGUILayout* mContentsPanel;
  114. };
  115. /** @} */
  116. }