BsGUISliderField.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "GUI/BsGUIFieldBase.h"
  6. namespace bs
  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. /** Gets the minimum percentual variation of the handle position */
  29. float getStep() const;
  30. /** Sets a new value in the input field/slider, it returns the clamped value according to range and step. */
  31. float setValue(float value);
  32. /**
  33. * Sets a minimum and maximum allow values in the input field. Set to large negative/positive values if you don't
  34. * require clamping.
  35. */
  36. void setRange(float min, float max);
  37. /**
  38. * Sets a step that defines the minimal increment the value can be increased/decreased by. Set to zero to have no
  39. * step.
  40. */
  41. void setStep(float step);
  42. /** Checks is the input field currently active. */
  43. bool hasInputFocus() const { return mHasInputFocus; }
  44. /** @copydoc GUIElement::setTint */
  45. void setTint(const Color& color) override;
  46. Event<void(float)> onValueChanged; /**< Triggers when the field value changes. */
  47. /** @name Internal
  48. * @{
  49. */
  50. /**
  51. * Sets a new value in the input field, and also allows you to choose should the field trigger an onValueChanged
  52. * event.
  53. */
  54. void _setValue(float value, bool triggerEvent);
  55. /** @} */
  56. protected:
  57. virtual ~GUISliderField() = default;
  58. /** @copydoc GUIElementContainer::styleUpdated */
  59. void styleUpdated() override;
  60. /** Triggered when the input box value changes definitively. */
  61. void inputBoxValueChanged(bool confirmed = true);
  62. /** Triggered when the input box value is changing. */
  63. void inputBoxValueChanging(const String& newValue);
  64. /** Triggered when the slider is moved. */
  65. void sliderChanged(float newValue);
  66. /** Triggers when the input box receives or loses keyboard focus. */
  67. void inputBoxFocusChanged(bool focus);
  68. /** Callback that checks can the provided string be converted to a floating point value. */
  69. static bool floatFilter(const String& str);
  70. GUIInputBox* mInputBox;
  71. GUISliderHorz* mSlider;
  72. bool mHasInputFocus;
  73. };
  74. /** @} */
  75. }