BsScriptGUILayout.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsScriptGUIElement.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Interop class between C++ & CLR for GUILayout derived classes.
  8. */
  9. class BS_SCR_BE_EXPORT ScriptGUILayout : public TScriptGUIElementBase<ScriptGUILayout>
  10. {
  11. protected:
  12. /**
  13. * @brief Contains information about an interop object that represents
  14. * a child of the layout.
  15. */
  16. struct ChildInfo
  17. {
  18. ScriptGUIElementBaseTBase* element;
  19. uint32_t gcHandle;
  20. };
  21. public:
  22. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "GUILayout")
  23. virtual ~ScriptGUILayout() { }
  24. /**
  25. * @brief Returns the internal wrapped GUILayout object.
  26. */
  27. GUILayout* getInternalValue() const { return mLayout; }
  28. /**
  29. * @brief Registers a new managed child GUI element and inserts it at
  30. * the end of the layout.
  31. */
  32. void addChild(ScriptGUIElementBaseTBase* element);
  33. /**
  34. * @brief Registers a new managed child GUI element and inserts it at a specific
  35. * location in the layout.
  36. */
  37. void insertChild(UINT32 index, ScriptGUIElementBaseTBase* element);
  38. /**
  39. * @brief Removes a managed GUI element from the layout.
  40. */
  41. void removeChild(ScriptGUIElementBaseTBase* element);
  42. /**
  43. * @copydoc ScriptGUIElementBaseTBase::destroy
  44. *
  45. * Destroys the layout and all of its managed children.
  46. */
  47. void destroy() override;
  48. protected:
  49. friend class ScriptGUIPanel;
  50. /**
  51. * @brief Constructor.
  52. *
  53. * @param instance Managed GUILayout instance.
  54. * @param layout Native GUILayout instance.
  55. * @param ownsNative Does this object own the native instance. If it does it will destroy the
  56. * object when ::destroy() is called, otherwise it is up to the caller to destroy it.
  57. */
  58. ScriptGUILayout(MonoObject* instance, GUILayout* layout, bool ownsNative = true);
  59. GUILayout* mLayout;
  60. Vector<ChildInfo> mChildren;
  61. bool mIsDestroyed;
  62. bool mOwnsNative;
  63. private:
  64. /************************************************************************/
  65. /* CLR HOOKS */
  66. /************************************************************************/
  67. static void internal_createInstanceX(MonoObject* instance, MonoArray* guiOptions);
  68. static void internal_createInstanceY(MonoObject* instance, MonoArray* guiOptions);
  69. static void internal_createInstancePanel(MonoObject* instance, INT16 depth, UINT16 depthRangeMin, UINT32 depthRangeMax, MonoArray* guiOptions);
  70. static void internal_addElement(ScriptGUILayout* instance, ScriptGUIElementBaseTBase* element);
  71. static void internal_insertElement(ScriptGUILayout* instance, UINT32 index, ScriptGUIElementBaseTBase* element);
  72. static UINT32 internal_getChildCount(ScriptGUILayout* instance);
  73. static MonoObject* internal_getChild(ScriptGUILayout* instance, UINT32 index);
  74. static void internal_clear(ScriptGUILayout* instance);
  75. static void internal_createInstanceYFromScrollArea(MonoObject* instance, MonoObject* parentScrollArea);
  76. };
  77. /**
  78. * @brief Interop class between C++ & CLR for GUIPanel.
  79. */
  80. class BS_SCR_BE_EXPORT ScriptGUIPanel : public ScriptObject<ScriptGUIPanel>
  81. {
  82. public:
  83. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "GUIPanel")
  84. /**
  85. * @brief Creates a new managed GUIPanel that wraps the provided native GUIPanel.
  86. */
  87. static MonoObject* createFromExisting(GUIPanel* panel);
  88. private:
  89. ScriptGUIPanel(MonoObject* instance);
  90. };
  91. /**
  92. * @brief Specialized ScriptGUILayout that is used only in GUI scroll areas.
  93. */
  94. class BS_SCR_BE_EXPORT ScriptGUIScrollAreaLayout : public ScriptGUILayout
  95. {
  96. public:
  97. /**
  98. * @brief Constructor.
  99. *
  100. * @param instance Managed GUILayout instance.
  101. * @param layout Native GUILayout instance.
  102. */
  103. ScriptGUIScrollAreaLayout(MonoObject* instance, GUILayout* layout);
  104. /**
  105. * @copydoc ScriptGUILayout::destroy
  106. */
  107. void destroy() override;
  108. private:
  109. friend class ScriptGUIScrollArea;
  110. ScriptGUIScrollArea* mParentScrollArea;
  111. };
  112. }