BsScriptGUIElement.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsScriptObject.h"
  4. #include "BsGUIOptions.h"
  5. namespace BansheeEngine
  6. {
  7. class BS_SCR_BE_EXPORT ScriptGUIElementBaseTBase : public ScriptObjectBase
  8. {
  9. public:
  10. ScriptGUIElementBaseTBase(MonoObject* instance);
  11. virtual ~ScriptGUIElementBaseTBase() {}
  12. GUIElementBase* getGUIElement() const { return (GUIElementBase*)mElement; }
  13. virtual void destroy() = 0;
  14. virtual void setLayoutOptions(GUIOptions options) { }
  15. protected:
  16. void initialize(GUIElementBase* element);
  17. bool mIsDestroyed;
  18. GUIElementBase* mElement;
  19. };
  20. template <class Type>
  21. class TScriptGUIElementBase : public ScriptObject<Type, ScriptGUIElementBaseTBase>
  22. {
  23. public:
  24. virtual ~TScriptGUIElementBase() {}
  25. protected:
  26. TScriptGUIElementBase(MonoObject* instance, GUIElementBase* element)
  27. :ScriptObject(instance)
  28. {
  29. initialize(element);
  30. }
  31. void _onManagedInstanceDeleted()
  32. {
  33. // Elements with a GUIWidget parent are destroyed automatically when widget is destroyed, but those without one
  34. // we need to destroy manually.
  35. if (getGUIElement()->_getParentWidget() == nullptr)
  36. destroy();
  37. ScriptObject::_onManagedInstanceDeleted();
  38. }
  39. };
  40. class BS_SCR_BE_EXPORT ScriptGUIElementTBase : public ScriptGUIElementBaseTBase
  41. {
  42. public:
  43. ScriptGUIElementTBase(MonoObject* instance);
  44. virtual ~ScriptGUIElementTBase() {}
  45. virtual void destroy();
  46. virtual void setLayoutOptions(GUIOptions options);
  47. };
  48. template <class Type>
  49. class TScriptGUIElement : public ScriptObject<Type, ScriptGUIElementTBase>
  50. {
  51. public:
  52. virtual ~TScriptGUIElement() {}
  53. protected:
  54. TScriptGUIElement(MonoObject* instance, GUIElementBase* element)
  55. :ScriptObject(instance)
  56. {
  57. initialize(element);
  58. }
  59. void _onManagedInstanceDeleted()
  60. {
  61. // Elements with a GUIWidget parent are destroyed automatically when widget is destroyed, but those without one
  62. // we need to destroy manually.
  63. if (!mIsDestroyed && getGUIElement()->_getParentWidget() == nullptr)
  64. destroy();
  65. ScriptObject::_onManagedInstanceDeleted();
  66. }
  67. };
  68. class BS_SCR_BE_EXPORT ScriptGUIElement : public ScriptObject<ScriptGUIElement>
  69. {
  70. public:
  71. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "GUIElement")
  72. private:
  73. static void internal_destroy(ScriptGUIElementBaseTBase* nativeInstance);
  74. static void internal_setVisible(ScriptGUIElementBaseTBase* nativeInstance, bool visible);
  75. static Rect2I internal_getBounds(ScriptGUIElementBaseTBase* nativeInstance);
  76. static void internal_setBounds(ScriptGUIElementBaseTBase* nativeInstance, Rect2I bounds);
  77. static Rect2I internal_getVisibleBounds(ScriptGUIElementBaseTBase* nativeInstance);
  78. static void internal_setLayoutOptions(ScriptGUIElementBaseTBase* nativeInstance, MonoArray* guiOptions);
  79. ScriptGUIElement(MonoObject* instance);
  80. };
  81. }