BsScriptGUIElement.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. protected:
  15. void initialize(GUIElementBase* element);
  16. bool mIsDestroyed;
  17. GUIElementBase* mElement;
  18. };
  19. template <class Type>
  20. class TScriptGUIElementBase : public ScriptObject<Type, ScriptGUIElementBaseTBase>
  21. {
  22. public:
  23. virtual ~TScriptGUIElementBase() {}
  24. protected:
  25. TScriptGUIElementBase(MonoObject* instance, GUIElementBase* element)
  26. :ScriptObject(instance)
  27. {
  28. initialize(element);
  29. }
  30. void _onManagedInstanceDeleted()
  31. {
  32. // Elements with a GUIWidget parent are destroyed automatically when widget is destroyed, but those without one
  33. // we need to destroy manually.
  34. if (getGUIElement()->_getParentWidget() == nullptr)
  35. destroy();
  36. ScriptObject::_onManagedInstanceDeleted();
  37. }
  38. };
  39. class BS_SCR_BE_EXPORT ScriptGUIElementTBase : public ScriptGUIElementBaseTBase
  40. {
  41. public:
  42. ScriptGUIElementTBase(MonoObject* instance);
  43. virtual ~ScriptGUIElementTBase() {}
  44. virtual void destroy();
  45. };
  46. template <class Type>
  47. class TScriptGUIElement : public ScriptObject<Type, ScriptGUIElementTBase>
  48. {
  49. public:
  50. virtual ~TScriptGUIElement() {}
  51. protected:
  52. TScriptGUIElement(MonoObject* instance, GUIElementBase* element)
  53. :ScriptObject(instance)
  54. {
  55. initialize(element);
  56. }
  57. void _onManagedInstanceDeleted()
  58. {
  59. // Elements with a GUIWidget parent are destroyed automatically when widget is destroyed, but those without one
  60. // we need to destroy manually.
  61. if (!mIsDestroyed && getGUIElement()->_getParentWidget() == nullptr)
  62. destroy();
  63. ScriptObject::_onManagedInstanceDeleted();
  64. }
  65. };
  66. class BS_SCR_BE_EXPORT ScriptGUIElement : public ScriptObject<ScriptGUIElement>
  67. {
  68. public:
  69. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "GUIElement")
  70. private:
  71. static void internal_destroy(ScriptGUIElementBaseTBase* nativeInstance);
  72. static void internal_setVisible(ScriptGUIElementBaseTBase* nativeInstance, bool visible);
  73. static Rect2I internal_getBounds(ScriptGUIElementBaseTBase* nativeInstance);
  74. static void internal_setBounds(ScriptGUIElementBaseTBase* nativeInstance, Rect2I bounds);
  75. static Rect2I internal_getVisibleBounds(ScriptGUIElementBaseTBase* nativeInstance);
  76. static void internal_SetPosition(ScriptGUIElementBaseTBase* nativeInstance, INT32 x, INT32 y);
  77. static void internal_SetWidth(ScriptGUIElementBaseTBase* nativeInstance, UINT32 width);
  78. static void internal_SetFlexibleWidth(ScriptGUIElementBaseTBase* nativeInstance, UINT32 minWidth, UINT32 maxWidth);
  79. static void internal_SetHeight(ScriptGUIElementBaseTBase* nativeInstance, UINT32 height);
  80. static void internal_SetFlexibleHeight(ScriptGUIElementBaseTBase* nativeInstance, UINT32 minHeight, UINT32 maxHeight);
  81. static void internal_ResetDimensions(ScriptGUIElementBaseTBase* nativeInstance);
  82. ScriptGUIElement(MonoObject* instance);
  83. };
  84. }