BsScriptDropDownWindow.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #pragma once
  2. #include "BsScriptEditorPrerequisites.h"
  3. #include "BsScriptObject.h"
  4. #include "BsDropDownWindow.h"
  5. #include "BsVector2I.h"
  6. namespace BansheeEngine
  7. {
  8. class ManagedDropDownWindow;
  9. /**
  10. * @brief Interop class between C++ & CLR for types deriving from DropDownWindow.
  11. */
  12. class BS_SCR_BED_EXPORT ScriptDropDownWindow : public ScriptObject <ScriptDropDownWindow>
  13. {
  14. public:
  15. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "DropDownWindow")
  16. ~ScriptDropDownWindow();
  17. private:
  18. friend class ManagedDropDownWindow;
  19. ScriptDropDownWindow(ManagedDropDownWindow* window);
  20. /**
  21. * @brief Triggered when the assembly refresh starts.
  22. */
  23. void onAssemblyRefreshStarted();
  24. /**
  25. * @brief Triggered when the native DropDownWindow wrapped by this object
  26. * gets closed.
  27. */
  28. void notifyWindowClosed();
  29. ManagedDropDownWindow* mDropDownWindow;
  30. HEvent mOnAssemblyRefreshStartedConn;
  31. static MonoField* guiPanelField;
  32. /************************************************************************/
  33. /* CLR HOOKS */
  34. /************************************************************************/
  35. static void internal_CreateInstance(MonoObject* instance, ScriptEditorWindow* parentWindow, Vector2I position, int width, int height);
  36. static void internal_Close(ScriptDropDownWindow* nativeInstance);
  37. static void internal_SetWidth(ScriptDropDownWindow* nativeInstance, UINT32 value);
  38. static void internal_SetHeight(ScriptDropDownWindow* nativeInstance, UINT32 value);
  39. static void internal_ScreenToWindowPos(ScriptDropDownWindow* nativeInstance, Vector2I position, Vector2I* windowPos);
  40. static void internal_WindowToScreenPos(ScriptDropDownWindow* nativeInstance, Vector2I position, Vector2I* screenPos);
  41. };
  42. /**
  43. * @brief Managed implementation of a DropDownWindow. All managed drop down windows
  44. * are implemented using this class, and the managed instance contains the
  45. * specifics of each implementation.
  46. */
  47. class BS_SCR_BED_EXPORT ManagedDropDownWindow : public DropDownWindow
  48. {
  49. public:
  50. ManagedDropDownWindow(const RenderWindowPtr& parent, const CameraPtr& camera,
  51. const Vector2I& position, MonoObject* managedInstance, UINT32 width, UINT32 height);
  52. ~ManagedDropDownWindow();
  53. /**
  54. * @brief Initializes the drop down window with the interop object that owns
  55. * the managed instance of this window
  56. */
  57. void initialize(ScriptDropDownWindow* parent);
  58. /**
  59. * @brief Called every frame. Triggers OnEditorUpdate method on the managed object.
  60. */
  61. void update() override;
  62. /**
  63. * @brief Trigger the OnInitialize method on the managed object.
  64. */
  65. void triggerOnInitialize();
  66. /**
  67. * @brief Trigger the OnDestroy method on the managed object.
  68. */
  69. void triggerOnDestroy();
  70. /**
  71. * @brief Returns the managed instance of the drop down window implementation.
  72. */
  73. MonoObject* getManagedInstance() const { return mManagedInstance; }
  74. /**
  75. * @brief Reloads all the managed types and methods. Usually called right after
  76. * construction or after assembly reload.
  77. *
  78. * @param windowClass Managed class of the drop down window to retrieve the data for.
  79. */
  80. void reloadMonoTypes(MonoClass* windowClass);
  81. private:
  82. friend class ScriptModalWindow;
  83. typedef void(__stdcall *OnInitializeThunkDef) (MonoObject*, MonoException**);
  84. typedef void(__stdcall *OnDestroyThunkDef) (MonoObject*, MonoException**);
  85. typedef void(__stdcall *UpdateThunkDef) (MonoObject*, MonoException**);
  86. String mNamespace;
  87. String mTypename;
  88. OnInitializeThunkDef mOnInitializeThunk;
  89. OnDestroyThunkDef mOnDestroyThunk;
  90. UpdateThunkDef mUpdateThunk;
  91. bool mIsInitialized;
  92. MonoObject* mManagedInstance;
  93. uint32_t mGCHandle;
  94. ScriptDropDownWindow* mScriptParent;
  95. ScriptGUILayout* mContentsPanel;
  96. };
  97. }