BsGUITextureField.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEditorPrerequisites.h"
  5. #include "BsGUIElementContainer.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief GUI object that displays a field in which a Texture can be dragged and dropped.
  10. * The field accepts a Texture of a specific type and displays an optional label.
  11. * If texture is referenced its image is displayed in the field.
  12. */
  13. class BS_SCR_BED_EXPORT GUITextureField : public GUIElementContainer
  14. {
  15. struct PrivatelyConstruct {};
  16. public:
  17. /**
  18. * Returns type name of the GUI element used for finding GUI element styles.
  19. */
  20. static const String& getGUITypeName();
  21. /**
  22. * @brief Creates a new texture GUI editor field with a label.
  23. *
  24. * @param labelContent Content to display in the editor field label.
  25. * @param labelWidth Width of the label in pixels.
  26. * @param options Options that allow you to control how is the element positioned and sized.
  27. * This will override any similar options set by style.
  28. * @param style Optional style to use for the element. Style will be retrieved
  29. * from GUISkin of the GUIWidget the element is used on. If not specified
  30. * default style is used.
  31. */
  32. static GUITextureField* create(const GUIContent& labelContent, UINT32 labelWidth, const GUIOptions& options,
  33. const String& style = StringUtil::BLANK);
  34. /**
  35. * @brief Creates a new texture GUI editor field with a label.
  36. *
  37. * @param labelContent Content to display in the editor field label.
  38. * @param options Options that allow you to control how is the element positioned and sized.
  39. * This will override any similar options set by style.
  40. * @param style Optional style to use for the element. Style will be retrieved
  41. * from GUISkin of the GUIWidget the element is used on. If not specified
  42. * default style is used.
  43. */
  44. static GUITextureField* create(const GUIContent& labelContent, const GUIOptions& options,
  45. const String& style = StringUtil::BLANK);
  46. /**
  47. * @brief Creates a new texture GUI editor field with a label.
  48. *
  49. * @param labelText Text to display in the editor field label.
  50. * @param labelWidth Width of the label in pixels.
  51. * @param options Options that allow you to control how is the element positioned and sized.
  52. * This will override any similar options set by style.
  53. * @param style Optional style to use for the element. Style will be retrieved
  54. * from GUISkin of the GUIWidget the element is used on. If not specified
  55. * default style is used.
  56. */
  57. static GUITextureField* create(const HString& labelText, UINT32 labelWidth, const GUIOptions& options,
  58. const String& style = StringUtil::BLANK);
  59. /**
  60. * @brief Creates a new texture GUI editor field with a label.
  61. *
  62. * @param labelText Text to display in the editor field label.
  63. * @param options Options that allow you to control how is the element positioned and sized.
  64. * This will override any similar options set by style.
  65. * @param style Optional style to use for the element. Style will be retrieved
  66. * from GUISkin of the GUIWidget the element is used on. If not specified
  67. * default style is used.
  68. */
  69. static GUITextureField* create(const HString& labelText, const GUIOptions& options,
  70. const String& style = StringUtil::BLANK);
  71. /**
  72. * @brief Creates a new texture GUI editor field without a label.
  73. *
  74. * @param options Options that allow you to control how is the element positioned and sized.
  75. * This will override any similar options set by style.
  76. * @param style Optional style to use for the element. Style will be retrieved
  77. * from GUISkin of the GUIWidget the element is used on. If not specified
  78. * default style is used.
  79. */
  80. static GUITextureField* create(const GUIOptions& options, const String& style = StringUtil::BLANK);
  81. /**
  82. * @brief Creates a new texture GUI editor field with a label.
  83. *
  84. * @param labelContent Content to display in the editor field label.
  85. * @param labelWidth Width of the label in pixels.
  86. * @param style Optional style to use for the element. Style will be retrieved
  87. * from GUISkin of the GUIWidget the element is used on. If not specified
  88. * default style is used.
  89. */
  90. static GUITextureField* create(const GUIContent& labelContent, UINT32 labelWidth,
  91. const String& style = StringUtil::BLANK);
  92. /**
  93. * @brief Creates a new texture GUI editor field with a label.
  94. *
  95. * @param labelContent Content to display in the editor field label.
  96. * @param style Optional style to use for the element. Style will be retrieved
  97. * from GUISkin of the GUIWidget the element is used on. If not specified
  98. * default style is used.
  99. */
  100. static GUITextureField* create(const GUIContent& labelContent,
  101. const String& style = StringUtil::BLANK);
  102. /**
  103. * @brief Creates a new texture GUI editor field with a label.
  104. *
  105. * @param labelText Text to display in the editor field label.
  106. * @param labelWidth Width of the label in pixels.
  107. * @param style Optional style to use for the element. Style will be retrieved
  108. * from GUISkin of the GUIWidget the element is used on. If not specified
  109. * default style is used.
  110. */
  111. static GUITextureField* create(const HString& labelText, UINT32 labelWidth,
  112. const String& style = StringUtil::BLANK);
  113. /**
  114. * @brief Creates a new texture GUI editor field with a label.
  115. *
  116. * @param labelText Text to display in the editor field label.
  117. * @param style Optional style to use for the element. Style will be retrieved
  118. * from GUISkin of the GUIWidget the element is used on. If not specified
  119. * default style is used.
  120. */
  121. static GUITextureField* create(const HString& labelText,
  122. const String& style = StringUtil::BLANK);
  123. /**
  124. * @brief Creates a new texture GUI editor field without a label.
  125. *
  126. * @param style Optional style to use for the element. Style will be retrieved
  127. * from GUISkin of the GUIWidget the element is used on. If not specified
  128. * default style is used.
  129. */
  130. static GUITextureField* create(const String& style = StringUtil::BLANK);
  131. GUITextureField(const PrivatelyConstruct& dummy, const GUIContent& labelContent,
  132. UINT32 labelWidth, const String& style, const GUIDimensions& dimensions, bool withLabel);
  133. /**
  134. * @brief Returns the texture referenced by the field, if any. This will load the texture if it is not already
  135. * loaded.
  136. */
  137. HTexture getValue() const;
  138. /**
  139. * @brief Sets the texture referenced by the field.
  140. */
  141. void setValue(const HTexture& value);
  142. /**
  143. * @brief Returns a weak reference to the texture referenced by the field, if any.
  144. */
  145. WeakResourceHandle<Texture> getValueWeak() const;
  146. /**
  147. * @brief Sets a weak reference to the texture referenced by the field.
  148. */
  149. void setValueWeak(const WeakResourceHandle<Texture>& value);
  150. /**
  151. * @brief Returns the texture referenced by the field. Returns
  152. * empty string with no texture is referenced.
  153. */
  154. String getUUID() const { return mUUID; }
  155. /**
  156. * @copydoc GUIElement::setTint
  157. */
  158. virtual void setTint(const Color& color) override;
  159. /**
  160. * @copydoc GUIElement::_updateLayoutInternal
  161. */
  162. void _updateLayoutInternal(const GUILayoutData& data) override;
  163. /**
  164. * @copydoc GUIElement::_getOptimalSize
  165. */
  166. Vector2I _getOptimalSize() const override;
  167. /**
  168. * @brief Triggered whenever the referenced texture changes. Provides
  169. * a weak handle to the resource, or empty handle if no texture is referenced.
  170. */
  171. Event<void(const WeakResourceHandle<Texture>&)> onValueChanged;
  172. private:
  173. virtual ~GUITextureField();
  174. /**
  175. * @copydoc GUIElement::styleUpdated
  176. */
  177. void styleUpdated() override;
  178. /**
  179. * @brief Sets the texture referenced by the field by finding
  180. * the texture with the provided UUID.
  181. *
  182. * @param uuid Unique resource identifier of the texture to show, or empty string if no texture.
  183. * @param triggerEvent Determines should the ::onValueChanged event be triggered if the new UUID is different
  184. * from the previous one.
  185. */
  186. void setUUID(const String& uuid, bool triggerEvent = true);
  187. /**
  188. * @brief Triggered when a drag and drop operation finishes over this element.
  189. */
  190. void dataDropped(void* data);
  191. /**
  192. * @brief Triggered when the drop button that displays the game object label is clicked.
  193. */
  194. void onDropButtonClicked();
  195. /**
  196. * @brief Triggered when the clear button is clicked.
  197. */
  198. void onClearButtonClicked();
  199. private:
  200. static const UINT32 DEFAULT_LABEL_WIDTH;
  201. GUILayout* mLayout;
  202. GUILabel* mLabel;
  203. GUIDropButton* mDropButton;
  204. GUIButton* mClearButton;
  205. String mUUID;
  206. };
  207. }