BsScriptGUILayout.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /** @addtogroup ScriptInteropEngine
  9. * @{
  10. */
  11. /** Interop class between C++ & CLR for GUILayout derived classes. */
  12. class BS_SCR_BE_EXPORT ScriptGUILayout : public TScriptGUIElementBase<ScriptGUILayout>
  13. {
  14. protected:
  15. /** Contains information about an interop object that represents a child of the layout. */
  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. /** Returns the internal wrapped GUILayout object. */
  25. GUILayout* getInternalValue() const { return mLayout; }
  26. /** Registers a new managed child GUI element and inserts it at the end of the layout. */
  27. void addChild(ScriptGUIElementBaseTBase* element);
  28. /** Registers a new managed child GUI element and inserts it at a specific location in the layout. */
  29. void insertChild(UINT32 index, ScriptGUIElementBaseTBase* element);
  30. /** Removes a managed GUI element from the layout. */
  31. void removeChild(ScriptGUIElementBaseTBase* element);
  32. /**
  33. * @copydoc ScriptGUIElementBaseTBase::destroy
  34. *
  35. * Destroys the layout and all of its managed children.
  36. */
  37. void destroy() override;
  38. protected:
  39. friend class ScriptGUIPanel;
  40. /**
  41. * Constructor.
  42. *
  43. * @param[in] instance Managed GUILayout instance.
  44. * @param[in] layout Native GUILayout instance.
  45. * @param[in] ownsNative Does this object own the native instance. If it does it will destroy the
  46. * object when destroy() is called, otherwise it is up to the caller to destroy it.
  47. */
  48. ScriptGUILayout(MonoObject* instance, GUILayout* layout, bool ownsNative = true);
  49. GUILayout* mLayout;
  50. Vector<ChildInfo> mChildren;
  51. bool mIsDestroyed;
  52. bool mOwnsNative;
  53. private:
  54. /************************************************************************/
  55. /* CLR HOOKS */
  56. /************************************************************************/
  57. static void internal_createInstanceX(MonoObject* instance, MonoArray* guiOptions);
  58. static void internal_createInstanceY(MonoObject* instance, MonoArray* guiOptions);
  59. static void internal_createInstancePanel(MonoObject* instance, INT16 depth, UINT16 depthRangeMin, UINT32 depthRangeMax, MonoArray* guiOptions);
  60. static void internal_addElement(ScriptGUILayout* instance, ScriptGUIElementBaseTBase* element);
  61. static void internal_insertElement(ScriptGUILayout* instance, UINT32 index, ScriptGUIElementBaseTBase* element);
  62. static UINT32 internal_getChildCount(ScriptGUILayout* instance);
  63. static MonoObject* internal_getChild(ScriptGUILayout* instance, UINT32 index);
  64. static void internal_clear(ScriptGUILayout* instance);
  65. static void internal_createInstanceYFromScrollArea(MonoObject* instance, MonoObject* parentScrollArea);
  66. };
  67. /** Interop class between C++ & CLR for GUIPanel. */
  68. class BS_SCR_BE_EXPORT ScriptGUIPanel : public ScriptObject<ScriptGUIPanel>
  69. {
  70. public:
  71. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "GUIPanel")
  72. /** Creates a new managed GUIPanel that wraps the provided native GUIPanel. */
  73. static MonoObject* createFromExisting(GUIPanel* panel);
  74. private:
  75. ScriptGUIPanel(MonoObject* instance);
  76. };
  77. /** Specialized ScriptGUILayout that is used only in GUI scroll areas. */
  78. class BS_SCR_BE_EXPORT ScriptGUIScrollAreaLayout : public ScriptGUILayout
  79. {
  80. public:
  81. /**
  82. * Constructor.
  83. *
  84. * @param[in] instance Managed GUILayout instance.
  85. * @param[in] layout Native GUILayout instance.
  86. */
  87. ScriptGUIScrollAreaLayout(MonoObject* instance, GUILayout* layout);
  88. /** @copydoc ScriptGUILayout::destroy */
  89. void destroy() override;
  90. private:
  91. friend class ScriptGUIScrollArea;
  92. ScriptGUIScrollArea* mParentScrollArea;
  93. };
  94. /** @} */
  95. }