BsScriptGUIElement.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. static void onFocusChanged(MonoObject* instance, bool focus);
  18. bool mIsDestroyed;
  19. GUIElementBase* mElement;
  20. };
  21. template <class Type>
  22. class TScriptGUIElementBase : public ScriptObject<Type, ScriptGUIElementBaseTBase>
  23. {
  24. public:
  25. virtual ~TScriptGUIElementBase() {}
  26. protected:
  27. TScriptGUIElementBase(MonoObject* instance, GUIElementBase* element)
  28. :ScriptObject(instance)
  29. {
  30. initialize(element);
  31. }
  32. void _onManagedInstanceDeleted()
  33. {
  34. // Elements with a GUIWidget parent are destroyed automatically when widget is destroyed, but those without one
  35. // we need to destroy manually.
  36. if (getGUIElement()->_getParentWidget() == nullptr)
  37. destroy();
  38. ScriptObject::_onManagedInstanceDeleted();
  39. }
  40. };
  41. class BS_SCR_BE_EXPORT ScriptGUIElementTBase : public ScriptGUIElementBaseTBase
  42. {
  43. public:
  44. ScriptGUIElementTBase(MonoObject* instance);
  45. virtual ~ScriptGUIElementTBase() {}
  46. virtual void destroy();
  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. typedef void(__stdcall *OnFocusChangedThunkDef) (MonoObject*, bool, MonoException**);
  73. static OnFocusChangedThunkDef onFocusChangedThunk;
  74. private:
  75. static void internal_destroy(ScriptGUIElementBaseTBase* nativeInstance);
  76. static void internal_setVisible(ScriptGUIElementBaseTBase* nativeInstance, bool visible);
  77. static Rect2I internal_getBounds(ScriptGUIElementBaseTBase* nativeInstance);
  78. static void internal_setBounds(ScriptGUIElementBaseTBase* nativeInstance, Rect2I bounds);
  79. static Rect2I internal_getVisibleBounds(ScriptGUIElementBaseTBase* nativeInstance);
  80. static void internal_SetPosition(ScriptGUIElementBaseTBase* nativeInstance, INT32 x, INT32 y);
  81. static void internal_SetWidth(ScriptGUIElementBaseTBase* nativeInstance, UINT32 width);
  82. static void internal_SetFlexibleWidth(ScriptGUIElementBaseTBase* nativeInstance, UINT32 minWidth, UINT32 maxWidth);
  83. static void internal_SetHeight(ScriptGUIElementBaseTBase* nativeInstance, UINT32 height);
  84. static void internal_SetFlexibleHeight(ScriptGUIElementBaseTBase* nativeInstance, UINT32 minHeight, UINT32 maxHeight);
  85. static void internal_SetContextMenu(ScriptGUIElementBaseTBase* nativeInstance, ScriptContextMenu* contextMenu);
  86. static void internal_ResetDimensions(ScriptGUIElementBaseTBase* nativeInstance);
  87. ScriptGUIElement(MonoObject* instance);
  88. };
  89. }