BsGUICurvesField.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2018 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "GUI/BsGUICurvesField.h"
  4. #include "GUI/BsGUILayout.h"
  5. #include "GUI/BsGUILabel.h"
  6. #include "GUI/BsGUICurves.h"
  7. using namespace std::placeholders;
  8. namespace bs
  9. {
  10. static const TAnimationCurve<float> EMPTY_CURVE;
  11. GUICurvesField::GUICurvesField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  12. const String& style, const GUIDimensions& dimensions, bool withLabel, CurveDrawOptions drawOptions)
  13. : TGUIField(dummy, labelContent, labelWidth, style, dimensions, withLabel)
  14. {
  15. mCurves = GUICurves::create(drawOptions, getSubStyleName(getCurveStyleType()));
  16. mCurves->onClicked.connect(std::bind(&GUICurvesField::clicked, this));
  17. mLayout->addElement(mCurves);
  18. }
  19. void GUICurvesField::setCurve(const TAnimationCurve<float>& curve)
  20. {
  21. const Vector<CurveDrawInfo> drawInfos =
  22. {
  23. CurveDrawInfo(curve, Color::BansheeOrange)
  24. };
  25. mCurves->setCurves(drawInfos);
  26. }
  27. void GUICurvesField::setCurveRange(const TAnimationCurve<float>& curveA, const TAnimationCurve<float>& curveB)
  28. {
  29. const Vector<CurveDrawInfo> drawInfos =
  30. {
  31. CurveDrawInfo(curveA, Color::BansheeOrange),
  32. CurveDrawInfo(curveB, Color::Green)
  33. };
  34. mCurves->setCurves(drawInfos);
  35. }
  36. const TAnimationCurve<float>& GUICurvesField::getCurve() const
  37. {
  38. const Vector<CurveDrawInfo>& curves = mCurves->getCurves();
  39. if(!curves.empty())
  40. return mCurves->getCurves()[0].curve;
  41. return EMPTY_CURVE;
  42. }
  43. const TAnimationCurve<float>& GUICurvesField::getMinCurve() const
  44. {
  45. return getCurve();
  46. }
  47. const TAnimationCurve<float>& GUICurvesField::getMaxCurve() const
  48. {
  49. const Vector<CurveDrawInfo>& curves = mCurves->getCurves();
  50. if(curves.size() > 1)
  51. return mCurves->getCurves()[1].curve;
  52. else if(!curves.empty())
  53. return mCurves->getCurves()[0].curve;
  54. return EMPTY_CURVE;
  55. }
  56. void GUICurvesField::setTint(const Color& color)
  57. {
  58. if (mLabel != nullptr)
  59. mLabel->setTint(color);
  60. mCurves->setTint(color);
  61. }
  62. Vector2I GUICurvesField::_getOptimalSize() const
  63. {
  64. Vector2I optimalsize = mCurves->_getOptimalSize();
  65. if(mLabel != nullptr)
  66. {
  67. optimalsize.x += mLabel->_getOptimalSize().x;
  68. optimalsize.y = std::max(optimalsize.y, mLabel->_getOptimalSize().y);
  69. }
  70. return optimalsize;
  71. }
  72. void GUICurvesField::styleUpdated()
  73. {
  74. if (mLabel != nullptr)
  75. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  76. mCurves->setStyle(getSubStyleName(getCurveStyleType()));
  77. }
  78. void GUICurvesField::clicked()
  79. {
  80. onClicked();
  81. }
  82. const String& GUICurvesField::getGUITypeName()
  83. {
  84. static String typeName = "GUICurvesField";
  85. return typeName;
  86. }
  87. const String& GUICurvesField::getCurveStyleType()
  88. {
  89. static String STYLE_TYPE = "EditorFieldCurves";
  90. return STYLE_TYPE;
  91. }
  92. }