BsGUITextureField.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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.
  133. */
  134. HTexture getValue() const;
  135. /**
  136. * @brief Sets the texture referenced by the field.
  137. */
  138. void setValue(const HTexture& value);
  139. /**
  140. * @brief Returns the texture referenced by the field. Returns
  141. * empty string with no texture is referenced.
  142. */
  143. String getUUID() const { return mUUID; }
  144. /**
  145. * @copydoc GUIElement::setTint
  146. */
  147. virtual void setTint(const Color& color) override;
  148. /**
  149. * @copydoc GUIElement::_updateLayoutInternal
  150. */
  151. void _updateLayoutInternal(const GUILayoutData& data) override;
  152. /**
  153. * @copydoc GUIElement::_getOptimalSize
  154. */
  155. Vector2I _getOptimalSize() const override;
  156. /**
  157. * @brief Triggered whenever the referenced texture changes. Provides
  158. * the UUID of the resource, or empty string if no texture is referenced.
  159. */
  160. Event<void(const String&)> onValueChanged;
  161. private:
  162. virtual ~GUITextureField();
  163. /**
  164. * @copydoc GUIElement::styleUpdated
  165. */
  166. void styleUpdated() override;
  167. /**
  168. * @brief Sets the texture referenced by the field by finding
  169. * the texture with the provided UUID.
  170. *
  171. * @param uuid Unique resource identifier of the texture to show, or empty string if no texture.
  172. * @param triggerEvent Determines should the ::onValueChanged event be triggered if the new UUID is different
  173. * from the previous one.
  174. */
  175. void setUUID(const String& uuid, bool triggerEvent = true);
  176. /**
  177. * @brief Triggered when a drag and drop operation finishes over this element.
  178. */
  179. void dataDropped(void* data);
  180. /**
  181. * @brief Triggered when the drop button that displays the game object label is clicked.
  182. */
  183. void onDropButtonClicked();
  184. /**
  185. * @brief Triggered when the clear button is clicked.
  186. */
  187. void onClearButtonClicked();
  188. private:
  189. static const UINT32 DEFAULT_LABEL_WIDTH;
  190. GUILayout* mLayout;
  191. GUILabel* mLabel;
  192. GUIDropButton* mDropButton;
  193. GUIButton* mClearButton;
  194. String mUUID;
  195. };
  196. }