BsScriptGUIElement.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsScriptObject.h"
  4. #include "BsGUIOptions.h"
  5. #include "BsGUIElementBase.h"
  6. namespace BansheeEngine
  7. {
  8. class BS_SCR_BE_EXPORT ScriptGUIElementBaseTBase : public ScriptObjectBase
  9. {
  10. public:
  11. ScriptGUIElementBaseTBase(MonoObject* instance);
  12. virtual ~ScriptGUIElementBaseTBase() {}
  13. GUIElementBase* getGUIElement() const { return (GUIElementBase*)mElement; }
  14. virtual void destroy() = 0;
  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. };
  47. template <class Type>
  48. class TScriptGUIElement : public ScriptObject<Type, ScriptGUIElementTBase>
  49. {
  50. public:
  51. virtual ~TScriptGUIElement() {}
  52. protected:
  53. TScriptGUIElement(MonoObject* instance, GUIElementBase* element)
  54. :ScriptObject(instance)
  55. {
  56. initialize(element);
  57. }
  58. void _onManagedInstanceDeleted()
  59. {
  60. // Elements with a GUIWidget parent are destroyed automatically when widget is destroyed, but those without one
  61. // we need to destroy manually.
  62. if (!mIsDestroyed && getGUIElement()->_getParentWidget() == nullptr)
  63. destroy();
  64. ScriptObject::_onManagedInstanceDeleted();
  65. }
  66. };
  67. class BS_SCR_BE_EXPORT ScriptGUIElement : public ScriptObject<ScriptGUIElement>
  68. {
  69. public:
  70. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "GUIElement")
  71. private:
  72. static void internal_destroy(ScriptGUIElementBaseTBase* nativeInstance);
  73. static void internal_setVisible(ScriptGUIElementBaseTBase* nativeInstance, bool visible);
  74. static Rect2I internal_getBounds(ScriptGUIElementBaseTBase* nativeInstance);
  75. static void internal_setBounds(ScriptGUIElementBaseTBase* nativeInstance, Rect2I bounds);
  76. static Rect2I internal_getVisibleBounds(ScriptGUIElementBaseTBase* nativeInstance);
  77. static void internal_SetPosition(ScriptGUIElementBaseTBase* nativeInstance, INT32 x, INT32 y);
  78. static void internal_SetWidth(ScriptGUIElementBaseTBase* nativeInstance, UINT32 width);
  79. static void internal_SetFlexibleWidth(ScriptGUIElementBaseTBase* nativeInstance, UINT32 minWidth, UINT32 maxWidth);
  80. static void internal_SetHeight(ScriptGUIElementBaseTBase* nativeInstance, UINT32 height);
  81. static void internal_SetFlexibleHeight(ScriptGUIElementBaseTBase* nativeInstance, UINT32 minHeight, UINT32 maxHeight);
  82. static void internal_SetContextMenu(ScriptGUIElementBaseTBase* nativeInstance, ScriptContextMenu* contextMenu);
  83. static void internal_ResetDimensions(ScriptGUIElementBaseTBase* nativeInstance);
  84. ScriptGUIElement(MonoObject* instance);
  85. };
  86. }