BsGUICurvesField.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. GUICurvesField::GUICurvesField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  11. const String& style, const GUIDimensions& dimensions, bool withLabel)
  12. : TGUIField(dummy, labelContent, labelWidth, style, dimensions, withLabel)
  13. {
  14. mCurves = GUICurves::create(getSubStyleName(getCurveStyleType()));
  15. mCurves->onClicked.connect(std::bind(&GUICurvesField::clicked, this));
  16. mLayout->addElement(mCurves);
  17. }
  18. void GUICurvesField::setCurve(const TAnimationCurve<float>& curve)
  19. {
  20. const Vector<CurveDrawInfo> drawInfos =
  21. {
  22. CurveDrawInfo(curve, Color::BansheeOrange)
  23. };
  24. mCurves->setCurves(drawInfos);
  25. }
  26. void GUICurvesField::setCurveRange(const TAnimationCurve<float>& curveA, const TAnimationCurve<float>& curveB)
  27. {
  28. const Vector<CurveDrawInfo> drawInfos =
  29. {
  30. CurveDrawInfo(curveA, Color::BansheeOrange),
  31. CurveDrawInfo(curveB, Color::Green)
  32. };
  33. mCurves->setCurves(drawInfos);
  34. }
  35. void GUICurvesField::setTint(const Color& color)
  36. {
  37. if (mLabel != nullptr)
  38. mLabel->setTint(color);
  39. mCurves->setTint(color);
  40. }
  41. Vector2I GUICurvesField::_getOptimalSize() const
  42. {
  43. Vector2I optimalsize = mCurves->_getOptimalSize();
  44. if(mLabel != nullptr)
  45. {
  46. optimalsize.x += mLabel->_getOptimalSize().x;
  47. optimalsize.y = std::max(optimalsize.y, mLabel->_getOptimalSize().y);
  48. }
  49. return optimalsize;
  50. }
  51. void GUICurvesField::styleUpdated()
  52. {
  53. if (mLabel != nullptr)
  54. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  55. mCurves->setStyle(getSubStyleName(getCurveStyleType()));
  56. }
  57. void GUICurvesField::clicked()
  58. {
  59. onClicked();
  60. }
  61. const String& GUICurvesField::getGUITypeName()
  62. {
  63. static String typeName = "GUICurvesField";
  64. return typeName;
  65. }
  66. const String& GUICurvesField::getCurveStyleType()
  67. {
  68. static String STYLE_TYPE = "EditorFieldCurves";
  69. return STYLE_TYPE;
  70. }
  71. }