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