BsGUITextureField.h 8.6 KB

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