BsGUIIntField.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 integer input field.
  14. */
  15. class BS_ED_EXPORT GUIIntField : public TGUIField<GUIIntField>
  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. GUIIntField(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. INT32 getValue() const;
  26. /** Sets a new value in the input field, it returns the clamped value according to range and step. */
  27. INT32 setValue(INT32 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(INT32 min, INT32 max);
  33. /** Sets the minimum change allowed for the input field. */
  34. void setStep(INT32 step);
  35. /** Returns the minimum change allowed for the input field. */
  36. INT32 getStep() const { return mStep; }
  37. /** Checks is the input field currently active. */
  38. bool hasInputFocus() const { return mHasInputFocus; }
  39. /** @copydoc GUIElement::setTint */
  40. void setTint(const Color& color) override;
  41. Event<void(INT32)> onValueChanged; /**< Triggers when the internal value changes. */
  42. Event<void()> onConfirm; /**< Triggered when the user hits the Enter key with the input box in focus. */
  43. /** @name Internal
  44. * @{
  45. */
  46. /**
  47. * Sets a new value in the input field, and also allows you to choose should the field trigger an onValueChanged
  48. * event.
  49. */
  50. void _setValue(INT32 value, bool triggerEvent);
  51. /** @} */
  52. protected:
  53. virtual ~GUIIntField();
  54. /** @copydoc GUIElement::_hasCustomCursor */
  55. bool _hasCustomCursor(const Vector2I position, CursorType& type) const override;
  56. /** @copydoc GUIElement::_mouseEvent */
  57. bool _mouseEvent(const GUIMouseEvent& ev) override;
  58. /** @copydoc GUIElement::styleUpdated */
  59. void styleUpdated() override;
  60. /** Triggered when the input box value changes. */
  61. void valueChanged(const WString& newValue);
  62. /**
  63. * Triggered when the input box value changes, but unlike the previous overload the value is parsed into an integer
  64. * value.
  65. */
  66. void valueChanged(INT32 newValue);
  67. /** Triggers when the input box receives or loses keyboard focus. */
  68. void focusChanged(bool focus);
  69. /** Triggered when the users confirms input in the input box. */
  70. void inputConfirmed();
  71. /** Updates the underlying input box with the text representing the provided integer value. */
  72. void setText(INT32 value);
  73. /** Clamps the provided value to current valid range, and step interval. */
  74. INT32 applyRangeAndStep(INT32 value) const;
  75. /** Callback that checks can the provided string be converted to an integer value. */
  76. static bool intFilter(const WString& str);
  77. static const INT32 DRAG_SPEED;
  78. GUIInputBox* mInputBox;
  79. INT32 mValue;
  80. INT32 mLastDragPos;
  81. INT32 mMinValue;
  82. INT32 mMaxValue;
  83. INT32 mStep;
  84. bool mIsDragging;
  85. bool mIsDragCursorSet;
  86. bool mHasInputFocus;
  87. };
  88. /** @} */
  89. }