BsGUICurvesField.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2018 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. #include "GUI/BsGUIFieldBase.h"
  6. #include "GUI/BsGUICurves.h"
  7. #include "Animation/BsAnimationCurve.h"
  8. namespace bs
  9. {
  10. class GUICurves;
  11. /** @addtogroup GUI-Editor
  12. * @{
  13. */
  14. /**
  15. * A composite GUI object representing an editor field. Editor fields are a combination of a label and an input field.
  16. * Label is optional. This specific implementation displays an animation curve or a range between two animation curves.
  17. */
  18. class BS_ED_EXPORT BS_SCRIPT_EXPORT(m:GUIEditor,api:bed) GUICurvesField final : public TGUIField<GUICurvesField>
  19. {
  20. public:
  21. /** Returns type name of the GUI element used for finding GUI element styles. */
  22. static const String& getGUITypeName();
  23. /** Style type name for the internal curve field. */
  24. static const String& getCurveStyleType();
  25. GUICurvesField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  26. const String& style, const GUIDimensions& dimensions, bool withLabel,
  27. CurveDrawOptions drawOptions = CurveDrawOptions());
  28. /** Sets an animation curve to display on the field. */
  29. BS_SCRIPT_EXPORT()
  30. void setCurve(const TAnimationCurve<float>& curve);
  31. /** Sets a set of animation curves and displays the difference (range) between them. */
  32. BS_SCRIPT_EXPORT()
  33. void setCurveRange(const TAnimationCurve<float>& curveA, const TAnimationCurve<float>& curveB);
  34. /**
  35. * Returns the curve represented by the field. If the field represents a curve range this returns the minimal
  36. * curve of that range.
  37. */
  38. BS_SCRIPT_EXPORT(pr:getter,n:Curve)
  39. const TAnimationCurve<float>& getCurve() const;
  40. /**
  41. * Returns the minimal curve represented by the field containing a curve range. Returns the only available
  42. * curve if the field doesn't represent a range.
  43. */
  44. BS_SCRIPT_EXPORT(pr:getter,n:MinCurve)
  45. const TAnimationCurve<float>& getMinCurve() const;
  46. /**
  47. * Returns the maximal curve represented by the field containing a curve range. Returns the only available
  48. * curve if the field doesn't represent a range.
  49. */
  50. BS_SCRIPT_EXPORT(pr:getter,n:MaxCurve)
  51. const TAnimationCurve<float>& getMaxCurve() const;
  52. /** @copydoc GUICurves::setRange */
  53. BS_SCRIPT_EXPORT()
  54. void setRange(float xRange, float yRange) { mCurves->setRange(xRange, yRange); }
  55. /** @copydoc GUICurves::setOffset */
  56. BS_SCRIPT_EXPORT()
  57. void setOffset(const Vector2& offset) { mCurves->setOffset(offset); }
  58. /** @copydoc GUICurves::centerAndZoom */
  59. BS_SCRIPT_EXPORT()
  60. void centerAndZoom() { mCurves->centerAndZoom(); }
  61. /** @copydoc GUICurves::setPadding */
  62. BS_SCRIPT_EXPORT(pr:setter,n:Padding)
  63. void setPadding(UINT32 padding) { mCurves->setPadding(padding); }
  64. /** @copydoc GUIElement::setTint */
  65. void setTint(const Color& color) override;
  66. BS_SCRIPT_EXPORT(in:true)
  67. Event<void()> onClicked; /**< Triggered when the user clicks on the GUI element. */
  68. using TGUIField::create;
  69. /**
  70. * Creates a new GUI editor field with a label.
  71. *
  72. * @param[in] drawOptions Options that control which additional curve elements to draw.
  73. * @param[in] labelContent Content to display in the editor field label.
  74. * @param[in] labelWidth Width of the label in pixels.
  75. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  76. * GUIWidget the element is used on. If not specified default style is used.
  77. */
  78. BS_SCRIPT_EXPORT(ec:GUICurvesField)
  79. static GUICurvesField* create(CurveDrawOptions drawOptions, const GUIContent& labelContent, UINT32 labelWidth,
  80. const String& style = StringUtil::BLANK)
  81. {
  82. const String* curStyle = &style;
  83. if (*curStyle == StringUtil::BLANK)
  84. curStyle = &GUICurvesField::getGUITypeName();
  85. return bs_new<GUICurvesField>(PrivatelyConstruct(), labelContent, labelWidth, *curStyle,
  86. GUIDimensions::create(), true, drawOptions);
  87. }
  88. /**
  89. * Creates a new GUI editor field with a label.
  90. *
  91. * @param[in] drawOptions Options that control which additional curve elements to draw.
  92. * @param[in] labelText String to display in the editor field label.
  93. * @param[in] labelWidth Width of the label in pixels.
  94. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  95. * GUIWidget the element is used on. If not specified default style is used.
  96. */
  97. BS_SCRIPT_EXPORT(ec:GUICurvesField)
  98. static GUICurvesField* create(CurveDrawOptions drawOptions, const HString& labelText, UINT32 labelWidth,
  99. const String& style = StringUtil::BLANK)
  100. {
  101. const String* curStyle = &style;
  102. if (*curStyle == StringUtil::BLANK)
  103. curStyle = &GUICurvesField::getGUITypeName();
  104. return bs_new<GUICurvesField>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, *curStyle,
  105. GUIDimensions::create(), true, drawOptions);
  106. }
  107. /**
  108. * Creates a new GUI editor field without a label.
  109. *
  110. * @param[in] drawOptions Options that control which additional curve elements to draw.
  111. * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
  112. * GUIWidget the element is used on. If not specified default style is used.
  113. */
  114. BS_SCRIPT_EXPORT(ec:GUICurvesField)
  115. static GUICurvesField* create(CurveDrawOptions drawOptions, const String& style = StringUtil::BLANK)
  116. {
  117. const String* curStyle = &style;
  118. if (*curStyle == StringUtil::BLANK)
  119. curStyle = &GUICurvesField::getGUITypeName();
  120. return bs_new<GUICurvesField>(PrivatelyConstruct(), GUIContent(), 0, *curStyle,
  121. GUIDimensions::create(), false, drawOptions);
  122. }
  123. /** @name Internal
  124. * @{
  125. */
  126. /** @copydoc GUIElement::_getOptimalSize */
  127. Vector2I _getOptimalSize() const override;
  128. /** @} */
  129. protected:
  130. /** @copydoc GUIElement::styleUpdated */
  131. void styleUpdated() override;
  132. /** Triggered when the child color input field is clicked on. */
  133. void clicked();
  134. GUICurves* mCurves = nullptr;
  135. };
  136. /** @} */
  137. }