BsGUIFloatDistributionField.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. * Triggered when the user clicks on the curve display. Only relevant if the distribution is a curve distribution.
  59. * Provides the sequential index of the clicked curve (0 - x, 1 - y, 2 - z).
  60. */
  61. BS_SCRIPT_EXPORT(in:true)
  62. Event<void(INT32)> onClicked;
  63. /**
  64. * Triggered when the user modifies either of the non-curve (constant) values of the distribution. Only relevant
  65. * if the distribution is not a curve distribution.
  66. */
  67. BS_SCRIPT_EXPORT(in:true)
  68. Event<void()> onConstantModified;
  69. /**
  70. * Triggered when the user confirms inputs in either of the non-curve (constant) values of the distribution. Only
  71. * relevant if the distribution is not a curve distribution.
  72. */
  73. BS_SCRIPT_EXPORT(in:true)
  74. Event<void()> onConstantConfirmed;
  75. /** @name Internal
  76. * @{
  77. */
  78. /** @copydoc GUIElement::_getOptimalSize */
  79. Vector2I _getOptimalSize() const override;
  80. /** @} */
  81. protected:
  82. /** @copydoc GUIElement::styleUpdated */
  83. void styleUpdated() override;
  84. /** Rebuilds the internal GUI components for the current property type. */
  85. void rebuild();
  86. TDistribution<T> mValue = TCurveProperties<T>::getZero();
  87. GUIButton* mDropDownButton = nullptr;
  88. GUIConstantType* mMinInput = nullptr;
  89. GUIConstantType* mMaxInput = nullptr;
  90. std::array<GUILabel*, 2> mLabels = { nullptr, nullptr };
  91. GUICurvesField* mCurveDisplay[NumComponents] = { };
  92. PropertyDistributionType mPropertyType = PDT_Constant;
  93. T mMinConstant = TCurveProperties<T>::getZero();
  94. T mMaxConstant = TCurveProperties<T>::getZero();
  95. TAnimationCurve<float> mMinCurve[NumComponents];
  96. TAnimationCurve<float> mMaxCurve[NumComponents];
  97. SPtr<GUIContextMenu> mContextMenu;
  98. };
  99. /** @} */
  100. /** @addtogroup GUI-Editor
  101. * @{
  102. */
  103. /**
  104. * A composite GUI object representing an editor field. Editor fields are a combination of a label and an input field.
  105. * Label is optional. This specific implementation displays an input field for a floating point distribution.
  106. */
  107. class BS_ED_EXPORT BS_SCRIPT_EXPORT(ed:true,m:GUIEditor)
  108. GUIFloatDistributionField final : public TGUIDistributionField<float, GUIFloatDistributionField>
  109. {
  110. public:
  111. using TGUIDistributionField::TGUIDistributionField;
  112. /** Returns type name of the GUI element used for finding GUI element styles. */
  113. static const String& getGUITypeName();
  114. };
  115. /**
  116. * A composite GUI object representing an editor field. Editor fields are a combination of a label and an input field.
  117. * Label is optional. This specific implementation displays an input field for a 2D vector distribution.
  118. */
  119. class BS_ED_EXPORT BS_SCRIPT_EXPORT(ed:true,m:GUIEditor)
  120. GUIVector2DistributionField final : public TGUIDistributionField<Vector2, GUIVector2DistributionField>
  121. {
  122. public:
  123. using TGUIDistributionField::TGUIDistributionField;
  124. /** Returns type name of the GUI element used for finding GUI element styles. */
  125. static const String& getGUITypeName();
  126. };
  127. /**
  128. * A composite GUI object representing an editor field. Editor fields are a combination of a label and an input field.
  129. * Label is optional. This specific implementation displays an input field for a 3D vector distribution.
  130. */
  131. class BS_ED_EXPORT BS_SCRIPT_EXPORT(ed:true,m:GUIEditor)
  132. GUIVector3DistributionField final : public TGUIDistributionField<Vector3, GUIVector3DistributionField>
  133. {
  134. public:
  135. using TGUIDistributionField::TGUIDistributionField;
  136. /** Returns type name of the GUI element used for finding GUI element styles. */
  137. static const String& getGUITypeName();
  138. };
  139. /** @} */
  140. }