BsGUIFloatDistributionField.h 6.7 KB

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