BsScriptGUIElement.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsScriptObject.h"
  4. #include "BsGUIOptions.h"
  5. #include "BsGUIElementBase.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Interop class between C++ & CLR for all elements inheriting from
  10. * GUIElementBase.
  11. */
  12. class BS_SCR_BE_EXPORT ScriptGUIElementBaseTBase : public ScriptObjectBase
  13. {
  14. public:
  15. ScriptGUIElementBaseTBase(MonoObject* instance);
  16. virtual ~ScriptGUIElementBaseTBase() {}
  17. /**
  18. * @brief Returns the underlying GUIElementBase wrapped by this object.
  19. */
  20. GUIElementBase* getGUIElement() const { return (GUIElementBase*)mElement; }
  21. /**
  22. * @brief Destroys the underlying GUIElementBase.
  23. */
  24. virtual void destroy() = 0;
  25. /**
  26. * @brief Checks have we destroyed the underlying GUIElementBase.
  27. */
  28. bool isDestroyed() const { return mIsDestroyed; }
  29. /**
  30. * @brief Returns the parent interop object for a GUI layout or a GUI panel.
  31. */
  32. ScriptGUILayout* getParent() const { return mParent; }
  33. /**
  34. * @brief Sets an interop object for a GUI layout or a panel as this object's parent.
  35. */
  36. void setParent(ScriptGUILayout* parent) { mParent = parent; }
  37. protected:
  38. /**
  39. * @brief Initializes the interop object with a previously initialized GUI
  40. * element. You must call this before using this object.
  41. */
  42. void initialize(GUIElementBase* element);
  43. /**
  44. * @copydoc ScriptObjectBase::_onManagedInstanceDeleted
  45. */
  46. virtual void _onManagedInstanceDeleted() override;
  47. /**
  48. * @brief Triggered when the focus changes for the underlying GUIElementBase.
  49. */
  50. static void onFocusChanged(MonoObject* instance, bool focus);
  51. bool mIsDestroyed;
  52. GUIElementBase* mElement;
  53. ScriptGUILayout* mParent;
  54. };
  55. /**
  56. * @brief A more specialized implementation of ScriptGUIElementBaseTBase that
  57. * references a specific GUI element type instead of the generic GUIElementBase.
  58. */
  59. template <class Type>
  60. class TScriptGUIElementBase : public ScriptObject<Type, ScriptGUIElementBaseTBase>
  61. {
  62. public:
  63. virtual ~TScriptGUIElementBase() {}
  64. protected:
  65. TScriptGUIElementBase(MonoObject* instance, GUIElementBase* element)
  66. :ScriptObject(instance)
  67. {
  68. initialize(element);
  69. }
  70. };
  71. /**
  72. * @brief Interop class between C++ & CLR for all elements inheriting from
  73. * GUIElement.
  74. */
  75. class BS_SCR_BE_EXPORT ScriptGUIElementTBase : public ScriptGUIElementBaseTBase
  76. {
  77. public:
  78. ScriptGUIElementTBase(MonoObject* instance);
  79. virtual ~ScriptGUIElementTBase() {}
  80. /**
  81. * @copydoc ScriptGUIElementBaseTBase::destroy
  82. */
  83. virtual void destroy() override;
  84. };
  85. /**
  86. * @brief A more specialized implementation of ScriptGUIElementTBase that
  87. * references a specific GUI element type instead of the generic GUIElement.
  88. */
  89. template <class Type>
  90. class TScriptGUIElement : public ScriptObject<Type, ScriptGUIElementTBase>
  91. {
  92. public:
  93. virtual ~TScriptGUIElement() {}
  94. protected:
  95. TScriptGUIElement(MonoObject* instance, GUIElementBase* element)
  96. :ScriptObject(instance)
  97. {
  98. initialize(element);
  99. }
  100. };
  101. /**
  102. * @brief Interop class between C++ & CLR for GUIElement. This includes only base
  103. * methods belonging directly to GUIElement while specific GUI element
  104. * implementations have their own interop classes.
  105. */
  106. class BS_SCR_BE_EXPORT ScriptGUIElement : public ScriptObject<ScriptGUIElement>
  107. {
  108. public:
  109. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "GUIElement")
  110. typedef void(__stdcall *OnFocusChangedThunkDef) (MonoObject*, bool, MonoException**);
  111. static OnFocusChangedThunkDef onFocusChangedThunk;
  112. private:
  113. ScriptGUIElement(MonoObject* instance);
  114. /************************************************************************/
  115. /* CLR HOOKS */
  116. /************************************************************************/
  117. static void internal_destroy(ScriptGUIElementBaseTBase* nativeInstance);
  118. static void internal_setVisible(ScriptGUIElementBaseTBase* nativeInstance, bool visible);
  119. static void internal_setFocus(ScriptGUIElementBaseTBase* nativeInstance, bool focus);
  120. static Rect2I internal_getBounds(ScriptGUIElementBaseTBase* nativeInstance);
  121. static void internal_setBounds(ScriptGUIElementBaseTBase* nativeInstance, Rect2I bounds);
  122. static Rect2I internal_getVisibleBounds(ScriptGUIElementBaseTBase* nativeInstance);
  123. static void internal_SetPosition(ScriptGUIElementBaseTBase* nativeInstance, INT32 x, INT32 y);
  124. static void internal_SetWidth(ScriptGUIElementBaseTBase* nativeInstance, UINT32 width);
  125. static void internal_SetFlexibleWidth(ScriptGUIElementBaseTBase* nativeInstance, UINT32 minWidth, UINT32 maxWidth);
  126. static void internal_SetHeight(ScriptGUIElementBaseTBase* nativeInstance, UINT32 height);
  127. static void internal_SetFlexibleHeight(ScriptGUIElementBaseTBase* nativeInstance, UINT32 minHeight, UINT32 maxHeight);
  128. static void internal_SetContextMenu(ScriptGUIElementBaseTBase* nativeInstance, ScriptContextMenu* contextMenu);
  129. static void internal_ResetDimensions(ScriptGUIElementBaseTBase* nativeInstance);
  130. };
  131. }