BsGUITextureField.h 8.6 KB

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