BsScriptGUILayout.h 4.2 KB

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