BsScriptGUIElement.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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(bool assemblyRefresh) override;
  39. /** @copydoc ScriptObjectBase::_clearManagedInstance */
  40. void _clearManagedInstance() override;
  41. /** Triggered when the focus changes for the underlying GUIElementBase. */
  42. static void onFocusChanged(ScriptGUIElementBaseTBase* thisPtr, bool focus);
  43. bool mIsDestroyed = false;
  44. GUIElementBase* mElement = nullptr;
  45. ScriptGUILayout* mParent = nullptr;
  46. UINT32 mGCHandle = 0;
  47. };
  48. /**
  49. * A more specialized implementation of ScriptGUIElementBaseTBase that references a specific GUI element type instead
  50. * of the generic GUIElementBase.
  51. */
  52. template <class Type>
  53. class TScriptGUIElementBase : public ScriptObject<Type, ScriptGUIElementBaseTBase>
  54. {
  55. public:
  56. virtual ~TScriptGUIElementBase() {}
  57. protected:
  58. TScriptGUIElementBase(MonoObject* instance, GUIElementBase* element)
  59. :ScriptObject<Type, ScriptGUIElementBaseTBase>(instance)
  60. {
  61. this->initialize(element);
  62. }
  63. };
  64. /** Interop class between C++ & CLR for all elements inheriting from GUIElement. */
  65. class BS_SCR_BE_EXPORT ScriptGUIElementTBase : public ScriptGUIElementBaseTBase
  66. {
  67. public:
  68. ScriptGUIElementTBase(MonoObject* instance);
  69. virtual ~ScriptGUIElementTBase() {}
  70. /** @copydoc ScriptGUIElementBaseTBase::destroy */
  71. void destroy() override;
  72. };
  73. /**
  74. * A more specialized implementation of ScriptGUIElementTBase that references a specific GUI element type instead of
  75. * the generic GUIElement.
  76. */
  77. template <class Type>
  78. class TScriptGUIElement : public ScriptObject<Type, ScriptGUIElementTBase>
  79. {
  80. public:
  81. virtual ~TScriptGUIElement() {}
  82. protected:
  83. TScriptGUIElement(MonoObject* instance, GUIElementBase* element)
  84. :ScriptObject<Type, ScriptGUIElementTBase>(instance)
  85. {
  86. this->initialize(element);
  87. }
  88. };
  89. /** @} */
  90. /** @addtogroup ScriptInteropEngine
  91. * @{
  92. */
  93. /**
  94. * Interop class between C++ & CLR for GUIElement. This includes only base methods belonging directly to GUIElement
  95. * while specific GUI element implementations have their own interop classes.
  96. */
  97. class BS_SCR_BE_EXPORT ScriptGUIElement : public ScriptObject<ScriptGUIElement>
  98. {
  99. public:
  100. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "GUIElement")
  101. private:
  102. ScriptGUIElement(MonoObject* instance);
  103. /************************************************************************/
  104. /* CLR HOOKS */
  105. /************************************************************************/
  106. static void internal_destroy(ScriptGUIElementBaseTBase* nativeInstance);
  107. static void internal_setVisible(ScriptGUIElementBaseTBase* nativeInstance, bool visible);
  108. static void internal_setActive(ScriptGUIElementBaseTBase* nativeInstance, bool active);
  109. static void internal_setDisabled(ScriptGUIElementBaseTBase* nativeInstance, bool disabled);
  110. static void internal_setFocus(ScriptGUIElementBaseTBase* nativeInstance, bool focus);
  111. static void internal_setBlocking(ScriptGUIElementBaseTBase* nativeInstance, bool blocking);
  112. static void internal_setAcceptsKeyFocus(ScriptGUIElementBaseTBase* nativeInstance, bool accepts);
  113. static bool internal_getVisible(ScriptGUIElementBaseTBase* nativeInstance);
  114. static bool internal_getActive(ScriptGUIElementBaseTBase* nativeInstance);
  115. static bool internal_getDisabled(ScriptGUIElementBaseTBase* nativeInstance);
  116. static bool internal_getBlocking(ScriptGUIElementBaseTBase* nativeInstance);
  117. static bool internal_getAcceptsKeyFocus(ScriptGUIElementBaseTBase* nativeInstance);
  118. static MonoObject* internal_getParent(ScriptGUIElementBaseTBase* nativeInstance);
  119. static void internal_getBounds(ScriptGUIElementBaseTBase* nativeInstance, Rect2I* bounds);
  120. static void internal_setBounds(ScriptGUIElementBaseTBase* nativeInstance, Rect2I* bounds);
  121. static void internal_getVisibleBounds(ScriptGUIElementBaseTBase* nativeInstance, Rect2I* bounds);
  122. static void internal_SetPosition(ScriptGUIElementBaseTBase* nativeInstance, INT32 x, INT32 y);
  123. static void internal_SetWidth(ScriptGUIElementBaseTBase* nativeInstance, UINT32 width);
  124. static void internal_SetFlexibleWidth(ScriptGUIElementBaseTBase* nativeInstance, UINT32 minWidth, UINT32 maxWidth);
  125. static void internal_SetHeight(ScriptGUIElementBaseTBase* nativeInstance, UINT32 height);
  126. static void internal_SetFlexibleHeight(ScriptGUIElementBaseTBase* nativeInstance, UINT32 minHeight, UINT32 maxHeight);
  127. static void internal_SetContextMenu(ScriptGUIElementBaseTBase* nativeInstance, ScriptContextMenu* contextMenu);
  128. static void internal_ResetDimensions(ScriptGUIElementBaseTBase* nativeInstance);
  129. static MonoString* internal_GetStyle(ScriptGUIElementBaseTBase* nativeInstance);
  130. static void internal_SetStyle(ScriptGUIElementBaseTBase* nativeInstance, MonoString* style);
  131. typedef void(BS_THUNKCALL *OnFocusChangedThunkDef) (MonoObject*, MonoException**);
  132. public:
  133. static OnFocusChangedThunkDef onFocusGainedThunk;
  134. static OnFocusChangedThunkDef onFocusLostThunk;
  135. };
  136. /** @} */
  137. }