BsScriptGUIElement.h 6.2 KB

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