BsScriptGUIElement.h 3.7 KB

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