BsScriptGUIElement.h 6.2 KB

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