BsScriptModalWindow.h 4.9 KB

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