BsGUIFloatField.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 floating point input field.
  14. */
  15. class BS_ED_EXPORT GUIFloatField : public TGUIField<GUIFloatField>
  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. GUIFloatField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  23. const String& style, const GUIDimensions& dimensions, bool withLabel);
  24. /** Returns the value of the input field. */
  25. float getValue() const { return mValue; }
  26. /** Sets a new value in the input field. */
  27. void setValue(float value);
  28. /**
  29. * Sets a minimum and maximum allow values in the input field. Set to large negative/positive values if you don't
  30. * require clamping.
  31. */
  32. void setRange(float min, float max);
  33. /** Checks is the input field currently active. */
  34. bool hasInputFocus() const { return mHasInputFocus; }
  35. /** @copydoc GUIElement::setTint */
  36. void setTint(const Color& color) override;
  37. Event<void(float)> onValueChanged; /**< Triggers when the field value changes. */
  38. Event<void()> onConfirm; /**< Triggered when the user hits the Enter key with the input box in focus. */
  39. /** @name Internal
  40. * @{
  41. */
  42. /**
  43. * Sets a new value in the input field, and also allows you to choose should the field trigger an onValueChanged
  44. * event.
  45. */
  46. void _setValue(float value, bool triggerEvent);
  47. /** @} */
  48. protected:
  49. virtual ~GUIFloatField();
  50. /** @copydoc GUIElementContainer::_hasCustomCursor */
  51. bool _hasCustomCursor(const Vector2I position, CursorType& type) const override;
  52. /** @copydoc GUIElementContainer::_mouseEvent */
  53. virtual bool _mouseEvent(const GUIMouseEvent& ev) override;
  54. /** @copydoc GUIElementContainer::styleUpdated */
  55. void styleUpdated() override;
  56. /** Triggered when the input box value changes. */
  57. void valueChanged(const WString& newValue);
  58. /**
  59. * Triggered when the input box value changes, but unlike the previous overload the value is parsed into a floating
  60. * point value.
  61. */
  62. void valueChanged(float newValue);
  63. /** Triggers when the input box receives or loses keyboard focus. */
  64. void focusChanged(bool focus);
  65. /** Triggered when the users confirms input in the input box. */
  66. void inputConfirmed();
  67. /** Callback that checks can the provided string be converted to a floating point value. */
  68. static bool floatFilter(const WString& str);
  69. static const float DRAG_SPEED;
  70. GUIInputBox* mInputBox;
  71. float mValue;
  72. INT32 mLastDragPos;
  73. float mMinValue;
  74. float mMaxValue;
  75. bool mIsDragging;
  76. bool mHasInputFocus;
  77. };
  78. /** @} */
  79. }