BsGUITextureField.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #include "GUI/BsGUIFieldOptions.h"
  7. namespace bs
  8. {
  9. /** @addtogroup EditorScript
  10. * @{
  11. */
  12. /** Type that control what type of texture does a GUITexture field accept. */
  13. enum class BS_SCRIPT_EXPORT(m:GUI-Editor,api:bed) GUITextureFieldType
  14. {
  15. Texture = 1,
  16. SpriteTexture = 2,
  17. TextureOrSpriteTexture = 3,
  18. };
  19. /**
  20. * GUI object that displays a field in which a Texture or a SpriteTexture can be dragged and dropped. It also displays
  21. * an optional label field. When a texture is referenced its image is displayed in the field.
  22. */
  23. class BS_SCR_BED_EXPORT GUITextureField : public GUIElementContainer
  24. {
  25. struct PrivatelyConstruct {};
  26. public:
  27. GUITextureField(const PrivatelyConstruct& dummy, GUITextureFieldType type, const GUIContent& labelContent,
  28. UINT32 labelWidth, const String& style, const GUIDimensions& dimensions, bool withLabel);
  29. /** Returns type name of the GUI element used for finding GUI element styles. */
  30. static const String& getGUITypeName();
  31. /**
  32. * Creates a new texture GUI editor field.
  33. *
  34. * @param[in] type Determines the type of texture the field should accept.
  35. * @param[in] options Options controlling the label, style and layout of the field.
  36. */
  37. static GUITextureField* create(GUITextureFieldType type, const GUIFieldOptions& options = GUIFieldOptions());
  38. /**
  39. * Creates a new texture GUI editor field that accepts a Texture.
  40. *
  41. * @param[in] options Options controlling the label, style and layout of the field.
  42. */
  43. static GUITextureField* create(const GUIFieldOptions& options = GUIFieldOptions());
  44. /**
  45. * Returns the texture referenced by the field, if any. Returns null if no texture is assigned, or if sprite
  46. * texture is assigned.
  47. */
  48. HTexture getTexture() const;
  49. /** Sets the texture referenced by the field. */
  50. void setTexture(const HTexture& value);
  51. /**
  52. * Returns the sprite texture referenced by the field, if any. Returns null if no sprite texture is assigned, or
  53. * if non-sprite texture is assigned.
  54. */
  55. HSpriteTexture getSpriteTexture() const;
  56. /** Sets the sprite texture referenced by the field. */
  57. void setSpriteTexture(const HSpriteTexture& value);
  58. /** Returns the normal or sprite texture referenced by the field, as a generic resource handle. */
  59. HResource getValue() const;
  60. /** Sets the resource referenced by the field. */
  61. void setValue(const HResource& value);
  62. /** Returns the UUID of the resource referenced by the field. */
  63. UUID getUUID() const { return mUUID; }
  64. /** @copydoc GUIElement::setTint */
  65. void setTint(const Color& color) override;
  66. /**
  67. * @name Internal
  68. * @{
  69. */
  70. /** @copydoc GUIElement::_updateLayoutInternal */
  71. void _updateLayoutInternal(const GUILayoutData& data) override;
  72. /** @copydoc GUIElement::_getOptimalSize */
  73. Vector2I _getOptimalSize() const override;
  74. /** @} */
  75. /** Triggered whenever the referenced texture changes. */
  76. Event<void(const HResource&)> onValueChanged;
  77. private:
  78. virtual ~GUITextureField() = default;
  79. /** @copydoc GUIElement::styleUpdated */
  80. void styleUpdated() override;
  81. /**
  82. * Sets the texture referenced by the field by finding the texture with the provided UUID.
  83. *
  84. * @param[in] uuid Unique resource identifier of the texture to show, or empty string if no texture.
  85. * @param[in] triggerEvent Determines should the onValueChanged() event be triggered if the new UUID is
  86. * different from the previous one.
  87. */
  88. void setUUID(const UUID& uuid, bool triggerEvent = true);
  89. /** Triggered when a drag and drop operation finishes over this element. */
  90. void dataDropped(void* data);
  91. /** Triggered when the drop button that displays the game object label is clicked. */
  92. void onDropButtonClicked();
  93. /** Triggered when the clear button is clicked. */
  94. void onClearButtonClicked();
  95. private:
  96. static const UINT32 DEFAULT_LABEL_WIDTH;
  97. GUILayout* mLayout;
  98. GUILabel* mLabel;
  99. GUIDropButton* mDropButton;
  100. GUIButton* mClearButton;
  101. UUID mUUID;
  102. };
  103. /** @} */
  104. }