BsGUIIntField.h 3.4 KB

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