BsGUISliderField.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. #include "BsGUIFieldBase.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup GUI-Editor
  9. * @{
  10. */
  11. /**
  12. * A composite GUI object representing an editor field. Editor fields are a combination of a label and an input field.
  13. * Label is optional. This specific implementation displays a horizontal slider and a floating point input box.
  14. */
  15. class BS_ED_EXPORT GUISliderField : public TGUIField<GUISliderField>
  16. {
  17. public:
  18. /** Returns type name of the GUI element used for finding GUI element styles. */
  19. static const String& getGUITypeName();
  20. /** Style type name for the internal input box. */
  21. static const String& getInputStyleType();
  22. /** Style type name for the internal slider. */
  23. static const String& getSliderStyleType();
  24. GUISliderField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  25. const String& style, const GUIDimensions& dimensions, bool withLabel);
  26. /** Returns the value of the input field/slider. */
  27. float getValue() const;
  28. /** Sets a new value in the input field/slider. */
  29. void setValue(float value);
  30. /**
  31. * Sets a minimum and maximum allow values in the input field. Set to large negative/positive values if you don't
  32. * require clamping.
  33. */
  34. void setRange(float min, float max);
  35. /**
  36. * Sets a step that defines the minimal increment the value can be increased/decreased by. Set to zero to have no
  37. * step.
  38. */
  39. void setStep(float step);
  40. /** @copydoc GUIElement::setTint */
  41. void setTint(const Color& color) override;
  42. Event<void(float)> onValueChanged; /**< Triggers when the field value changes. */
  43. /** @name Internal
  44. * @{
  45. */
  46. /**
  47. * Sets a new value in the input field, and also allows you to choose should the field trigger an onValueChanged
  48. * event.
  49. */
  50. void _setValue(float value, bool triggerEvent);
  51. /** @} */
  52. protected:
  53. virtual ~GUISliderField();
  54. /** @copydoc GUIElementContainer::styleUpdated */
  55. void styleUpdated() override;
  56. /** Triggered when the input box value changes. */
  57. void valueChanged(const WString& newValue);
  58. /** Triggered when the slider is moved. */
  59. void sliderChanged(float newValue);
  60. /** Callback that checks can the provided string be converted to a floating point value. */
  61. static bool floatFilter(const WString& str);
  62. GUIInputBox* mInputBox;
  63. GUISliderHorz* mSlider;
  64. };
  65. /** @} */
  66. }