BsGUIFloatDistributionField.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 "Particles/BsParticleDistribution.h"
  7. #include "Animation/BsAnimationUtility.h"
  8. namespace bs
  9. {
  10. class GUICurvesField;
  11. /** @addtogroup GUI-Editor-Internal
  12. * @{
  13. */
  14. namespace impl
  15. {
  16. template<class T>
  17. struct TGUIDistributionMeta { };
  18. template<>
  19. struct TGUIDistributionMeta<float>
  20. {
  21. using ConstantField = GUIFloatField;
  22. };
  23. template<>
  24. struct TGUIDistributionMeta<Vector2>
  25. {
  26. using ConstantField = GUIVector2Field;
  27. };
  28. template<>
  29. struct TGUIDistributionMeta<Vector3>
  30. {
  31. using ConstantField = GUIVector3Field;
  32. };
  33. }
  34. /** Templated common class for all GUI distribution field types. */
  35. template<class T, class SELF>
  36. class BS_ED_EXPORT TGUIDistributionField : public TGUIField<SELF>
  37. {
  38. using GUIConstantType = typename impl::TGUIDistributionMeta<T>::ConstantField;
  39. enum { NumComponents = TCurveProperties<T>::NumComponents };
  40. public:
  41. TGUIDistributionField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  42. const String& style, const GUIDimensions& dimensions, bool withLabel);
  43. /** Returns the value of the field. */
  44. BS_SCRIPT_EXPORT(pr:getter,n:Value)
  45. TDistribution<T> getValue() const { return mValue; }
  46. /** Changes the value of the field. */
  47. BS_SCRIPT_EXPORT(pr:setter,n:Value)
  48. void setValue(const TDistribution<T>& value);
  49. /** Returns the type of the currently selected distribution. */
  50. BS_SCRIPT_EXPORT(pr:getter,n:DistributionType)
  51. PropertyDistributionType getType() const { return mPropertyType; }
  52. /** @copydoc GUIElement::setTint */
  53. void setTint(const Color& color) override;
  54. /** Checks if any of the float input fields currently have input focus. Only relevant for non-curve distributions. */
  55. BS_SCRIPT_EXPORT(pr:getter,n:HasInputFocus)
  56. bool hasInputFocus() const;
  57. /**
  58. * Sets input focus to a specific component's input box.
  59. *
  60. * @param[in] rangeComponent Whether to focus on the minimum or the maximum part of the range. Only relevant
  61. * if the distribution represents a constant range.
  62. * @param[in] vectorComponent Vector component to focus on. Only relevant of the distribution constant is
  63. * a vector type, and if the current distribution type is a non-curve (constant)
  64. * type.
  65. * @param[in] focus True to enable focus, false to disable.
  66. */
  67. BS_SCRIPT_EXPORT()
  68. void setInputFocus(RangeComponent rangeComponent, VectorComponent vectorComponent, bool focus);
  69. /**
  70. * Triggered when the user clicks on the curve display. Only relevant if the distribution is a curve distribution.
  71. * Provides the index of the clicked curve.
  72. */
  73. BS_SCRIPT_EXPORT(in:true)
  74. Event<void(VectorComponent)> onClicked;
  75. /**
  76. * Triggered when the user modifies the value of the non-curve (constant) values of the distribution. Only relevant
  77. * if the distribution is not a curve distribution.
  78. */
  79. BS_SCRIPT_EXPORT()
  80. Event<void(RangeComponent, VectorComponent)> onConstantModified;
  81. /**
  82. * Triggered when the user confirms inputs in the non-curve (constant) values of the distribution. Only relevant
  83. * if the distribution is not a curve distribution.
  84. */
  85. BS_SCRIPT_EXPORT()
  86. Event<void(RangeComponent, VectorComponent)> onConstantConfirmed;
  87. /**
  88. * Triggered when a GUI field representing an individual component loses or gains focus. This only applies to
  89. * input fields representing the non-curve (constant) distribution types.
  90. */
  91. BS_SCRIPT_EXPORT()
  92. Event<void(bool, RangeComponent, VectorComponent)> onConstantFocusChanged;
  93. /** @name Internal
  94. * @{
  95. */
  96. /** @copydoc GUIElement::_getOptimalSize */
  97. Vector2I _getOptimalSize() const override;
  98. /** @} */
  99. protected:
  100. /** @copydoc GUIElement::styleUpdated */
  101. void styleUpdated() override;
  102. /** Rebuilds the internal GUI components for the current property type. */
  103. void rebuild();
  104. TDistribution<T> mValue = TCurveProperties<T>::getZero();
  105. GUIButton* mDropDownButton = nullptr;
  106. GUIConstantType* mMinInput = nullptr;
  107. GUIConstantType* mMaxInput = nullptr;
  108. std::array<GUILabel*, 2> mLabels = { nullptr, nullptr };
  109. GUICurvesField* mCurveDisplay[NumComponents] = { };
  110. PropertyDistributionType mPropertyType = PDT_Constant;
  111. T mMinConstant = TCurveProperties<T>::getZero();
  112. T mMaxConstant = TCurveProperties<T>::getZero();
  113. TAnimationCurve<float> mMinCurve[NumComponents];
  114. TAnimationCurve<float> mMaxCurve[NumComponents];
  115. SPtr<GUIContextMenu> mContextMenu;
  116. };
  117. /** @} */
  118. /** @addtogroup GUI-Editor
  119. * @{
  120. */
  121. /**
  122. * A composite GUI object representing an editor field. Editor fields are a combination of a label and an input field.
  123. * Label is optional. This specific implementation displays an input field for a floating point distribution.
  124. */
  125. class BS_ED_EXPORT BS_SCRIPT_EXPORT(m:GUIEditor,api:bed)
  126. GUIFloatDistributionField final : public TGUIDistributionField<float, GUIFloatDistributionField>
  127. {
  128. public:
  129. using TGUIDistributionField::TGUIDistributionField;
  130. /** Returns type name of the GUI element used for finding GUI element styles. */
  131. static const String& getGUITypeName();
  132. };
  133. /**
  134. * A composite GUI object representing an editor field. Editor fields are a combination of a label and an input field.
  135. * Label is optional. This specific implementation displays an input field for a 2D vector distribution.
  136. */
  137. class BS_ED_EXPORT BS_SCRIPT_EXPORT(m:GUIEditor,api:bed)
  138. GUIVector2DistributionField final : public TGUIDistributionField<Vector2, GUIVector2DistributionField>
  139. {
  140. public:
  141. using TGUIDistributionField::TGUIDistributionField;
  142. /** Returns type name of the GUI element used for finding GUI element styles. */
  143. static const String& getGUITypeName();
  144. };
  145. /**
  146. * A composite GUI object representing an editor field. Editor fields are a combination of a label and an input field.
  147. * Label is optional. This specific implementation displays an input field for a 3D vector distribution.
  148. */
  149. class BS_ED_EXPORT BS_SCRIPT_EXPORT(m:GUIEditor,api:bed)
  150. GUIVector3DistributionField final : public TGUIDistributionField<Vector3, GUIVector3DistributionField>
  151. {
  152. public:
  153. using TGUIDistributionField::TGUIDistributionField;
  154. /** Returns type name of the GUI element used for finding GUI element styles. */
  155. static const String& getGUITypeName();
  156. };
  157. /** @} */
  158. }