BsScriptDropDownWindow.h 4.0 KB

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