BsGUIResourceField.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. /**
  13. * GUI object that displays a field in which a Resource can be dragged and dropped. The field accepts a Resource of a
  14. * specific type and displays an optional label.
  15. */
  16. class BS_SCR_BED_EXPORT GUIResourceField : public GUIElementContainer
  17. {
  18. struct PrivatelyConstruct {};
  19. public:
  20. /** Returns type name of the GUI element used for finding GUI element styles. */
  21. static const String& getGUITypeName();
  22. /**
  23. * Creates a new resource GUI editor field.
  24. *
  25. * @param[in] typeNamespace Namespace of the type this field accepts.
  26. * @param[in] type Type name of the type this field accepts. Must derive from Resource.
  27. * @param[in] options Options controlling the label, style and layout of the field.
  28. */
  29. static GUIResourceField* create(const String& typeNamespace, const String& type, const GUIFieldOptions& options);
  30. GUIResourceField(const PrivatelyConstruct& dummy, const String& typeNamespace, const String& type,
  31. const GUIContent& labelContent, UINT32 labelWidth, const String& style, const GUIDimensions& dimensions,
  32. bool withLabel);
  33. /** Returns the resource referenced by the field, if any. */
  34. HResource getValue() const;
  35. /** Sets the resource referenced by the field. */
  36. void setValue(const HResource& value);
  37. /** Returns the resource referenced by the field. Returns empty string with no resource is referenced. */
  38. UUID getUUID() const { return mUUID; }
  39. /** @copydoc GUIElement::setTint */
  40. void setTint(const Color& color) override;
  41. /**
  42. * Triggered whenever the referenced resource changes. Provides a weak handle of the resource, or empty handle if
  43. * no resource is referenced.
  44. */
  45. Event<void(const HResource&)> onValueChanged;
  46. /** @name Internal
  47. * @{
  48. */
  49. /** @copydoc GUIElement::_updateLayoutInternal */
  50. void _updateLayoutInternal(const GUILayoutData& data) override;
  51. /** @copydoc GUIElement::_getOptimalSize */
  52. Vector2I _getOptimalSize() const override;
  53. /** @} */
  54. private:
  55. virtual ~GUIResourceField() = default;
  56. /**
  57. * Sets the resource referenced by the field by finding the resource with the provided UUID.
  58. *
  59. * @param[in] uuid Unique resource identifier of the resource to show, or empty string if no resource.
  60. * @param[in] triggerEvent Determines should the onValueChanged() event be triggered if the new UUID is
  61. * different from the previous one.
  62. */
  63. void setUUID(const UUID& uuid, bool triggerEvent = true);
  64. /** @copydoc GUIElement::styleUpdated */
  65. void styleUpdated() override;
  66. /** Triggered when a drag and drop operation finishes over this element. */
  67. void dataDropped(void* data);
  68. /** Triggered when the drop button that displays the game object label is clicked. */
  69. void onDropButtonClicked();
  70. /** Triggered when the clear button is clicked. */
  71. void onClearButtonClicked();
  72. private:
  73. static const UINT32 DEFAULT_LABEL_WIDTH;
  74. GUILayout* mLayout;
  75. GUILabel* mLabel;
  76. GUIDropButton* mDropButton;
  77. GUIButton* mClearButton;
  78. String mNamespace;
  79. String mType;
  80. UUID mUUID;
  81. };
  82. /** @} */
  83. }