BsGUIIntField.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIFieldBase.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief A composite GUI object representing an editor field. Editor fields are a combination
  8. * of a label and an input field. Label is optional. This specific implementation
  9. * displays a integer input field.
  10. */
  11. class BS_ED_EXPORT GUIIntField : public TGUIField<GUIIntField>
  12. {
  13. public:
  14. /**
  15. * Returns type name of the GUI element used for finding GUI element styles.
  16. */
  17. static const String& getGUITypeName();
  18. /**
  19. * Style type name for the internal input box.
  20. */
  21. static const String& getInputStyleType();
  22. GUIIntField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  23. const String& style, const GUIDimensions& dimensions, bool withLabel);
  24. /**
  25. * @brief Returns the value of the input field.
  26. */
  27. INT32 getValue() const { return mValue; }
  28. /**
  29. * @brief Sets a new value in the input field.
  30. */
  31. void setValue(INT32 value);
  32. /**
  33. * @brief Sets a minimum and maximum allow values in the input field.
  34. * Set to large negative/positive values if you don't require clamping.
  35. */
  36. void setRange(INT32 min, INT32 max);
  37. /**
  38. * @brief Checks is the input field currently active.
  39. */
  40. bool hasInputFocus() const { return mHasInputFocus; }
  41. /**
  42. * @copydoc GUIElement::setTint
  43. */
  44. virtual void setTint(const Color& color) override;
  45. Event<void(INT32)> onValueChanged; /**< Triggers when the internal value changes. */
  46. Event<void()> onConfirm; /**< Triggered when the user hits the Enter key with the input box in focus. */
  47. protected:
  48. virtual ~GUIIntField();
  49. /**
  50. * @copydoc GUIElement::_hasCustomCursor
  51. */
  52. bool _hasCustomCursor(const Vector2I position, CursorType& type) const override;
  53. /**
  54. * @copydoc GUIElement::_mouseEvent
  55. */
  56. bool _mouseEvent(const GUIMouseEvent& ev) override;
  57. /**
  58. * @copydoc GUIElement::styleUpdated
  59. */
  60. void styleUpdated() override;
  61. /**
  62. * @brief Triggered when the input box value changes.
  63. */
  64. void valueChanged(const WString& newValue);
  65. /**
  66. * @brief Triggered when the input box value changes, but unlike the previous
  67. * overload the value is parsed into an integer value.
  68. */
  69. void valueChanged(INT32 newValue);
  70. /**
  71. * @brief Triggers when the input box receives or loses keyboard focus.
  72. */
  73. void focusChanged(bool focus);
  74. /**
  75. * @brief Triggered when the users confirms input in the input box.
  76. */
  77. void inputConfirmed();
  78. /**
  79. * @brief Callback that checks can the provided string be
  80. * converted to an integer value.
  81. */
  82. static bool intFilter(const WString& str);
  83. static const INT32 DRAG_SPEED;
  84. GUIInputBox* mInputBox;
  85. INT32 mValue;
  86. INT32 mLastDragPos;
  87. INT32 mMinValue;
  88. INT32 mMaxValue;
  89. bool mIsDragging;
  90. bool mIsDragCursorSet;
  91. bool mHasInputFocus;
  92. };
  93. }