BsGUIIntField.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. protected:
  47. virtual ~GUIIntField();
  48. /**
  49. * @copydoc GUIElement::updateClippedBounds
  50. */
  51. void updateClippedBounds() override;
  52. /**
  53. * @copydoc GUIElement::_hasCustomCursor
  54. */
  55. bool _hasCustomCursor(const Vector2I position, CursorType& type) const override;
  56. /**
  57. * @copydoc GUIElement::_mouseEvent
  58. */
  59. bool _mouseEvent(const GUIMouseEvent& ev) override;
  60. /**
  61. * @copydoc GUIElement::styleUpdated
  62. */
  63. void styleUpdated() override;
  64. /**
  65. * @brief Triggered when the input box value changes.
  66. */
  67. void valueChanged(const WString& newValue);
  68. /**
  69. * @brief Triggered when the input box value changes, but unlike the previous
  70. * overload the value is parsed into an integer value.
  71. */
  72. void valueChanged(INT32 newValue);
  73. /**
  74. * @brief Triggers when the input box receives keyboard focus.
  75. */
  76. void focusGained();
  77. /**
  78. * @brief Triggers when the input box loses keyboard focus.
  79. */
  80. void focusLost();
  81. /**
  82. * @brief Callback that checks can the provided string be
  83. * converted to an integer value.
  84. */
  85. static bool intFilter(const WString& str);
  86. static const INT32 DRAG_SPEED;
  87. GUIInputBox* mInputBox;
  88. INT32 mValue;
  89. INT32 mLastDragPos;
  90. INT32 mMinValue;
  91. INT32 mMaxValue;
  92. bool mIsDragging;
  93. bool mIsDragCursorSet;
  94. bool mHasInputFocus;
  95. };
  96. }