BsGUITextureField.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. /**
  124. * Returns the texture referenced by the field, if any. Note that this will not load the texture in case it's not
  125. * already loaded.
  126. */
  127. HTexture getValue() const;
  128. /** Sets the texture referenced by the field. */
  129. void setValue(const HTexture& value);
  130. /** Returns the texture referenced by the field. Returns empty string with no texture is referenced. */
  131. UUID getUUID() const { return mUUID; }
  132. /** @copydoc GUIElement::setTint */
  133. void setTint(const Color& color) override;
  134. /** @copydoc GUIElement::_updateLayoutInternal */
  135. void _updateLayoutInternal(const GUILayoutData& data) override;
  136. /** @copydoc GUIElement::_getOptimalSize */
  137. Vector2I _getOptimalSize() const override;
  138. /**
  139. * Triggered whenever the referenced texture changes. Provides a weak handle to the resource, or empty handle if no
  140. * texture is referenced.
  141. */
  142. Event<void(const HTexture&)> onValueChanged;
  143. private:
  144. virtual ~GUITextureField();
  145. /** @copydoc GUIElement::styleUpdated */
  146. void styleUpdated() override;
  147. /**
  148. * Sets the texture referenced by the field by finding the texture with the provided UUID.
  149. *
  150. * @param[in] uuid Unique resource identifier of the texture to show, or empty string if no texture.
  151. * @param[in] triggerEvent Determines should the onValueChanged() event be triggered if the new UUID is
  152. * different from the previous one.
  153. */
  154. void setUUID(const UUID& uuid, bool triggerEvent = true);
  155. /** Triggered when a drag and drop operation finishes over this element. */
  156. void dataDropped(void* data);
  157. /** Triggered when the drop button that displays the game object label is clicked. */
  158. void onDropButtonClicked();
  159. /** Triggered when the clear button is clicked. */
  160. void onClearButtonClicked();
  161. private:
  162. static const UINT32 DEFAULT_LABEL_WIDTH;
  163. GUILayout* mLayout;
  164. GUILabel* mLabel;
  165. GUIDropButton* mDropButton;
  166. GUIButton* mClearButton;
  167. UUID mUUID;
  168. };
  169. /** @} */
  170. }