BsGUIIntField.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 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 { return mValue; }
  26. /** Sets a new value in the input field. */
  27. void 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. /** 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(INT32)> onValueChanged; /**< Triggers when the internal value changes. */
  38. Event<void()> onConfirm; /**< Triggered when the user hits the Enter key with the input box in focus. */
  39. /** @cond INTERNAL */
  40. /**
  41. * Sets a new value in the input field, and also allows you to choose should the field trigger an onValueChanged
  42. * event.
  43. */
  44. void _setValue(INT32 value, bool triggerEvent);
  45. /** @endcond */
  46. protected:
  47. virtual ~GUIIntField();
  48. /** @copydoc GUIElement::_hasCustomCursor */
  49. bool _hasCustomCursor(const Vector2I position, CursorType& type) const override;
  50. /** @copydoc GUIElement::_mouseEvent */
  51. bool _mouseEvent(const GUIMouseEvent& ev) override;
  52. /** @copydoc GUIElement::styleUpdated */
  53. void styleUpdated() override;
  54. /** Triggered when the input box value changes. */
  55. void valueChanged(const WString& newValue);
  56. /**
  57. * Triggered when the input box value changes, but unlike the previous overload the value is parsed into an integer
  58. * value.
  59. */
  60. void valueChanged(INT32 newValue);
  61. /** Triggers when the input box receives or loses keyboard focus. */
  62. void focusChanged(bool focus);
  63. /** Triggered when the users confirms input in the input box. */
  64. void inputConfirmed();
  65. /** Callback that checks can the provided string be converted to an integer value. */
  66. static bool intFilter(const WString& str);
  67. static const INT32 DRAG_SPEED;
  68. GUIInputBox* mInputBox;
  69. INT32 mValue;
  70. INT32 mLastDragPos;
  71. INT32 mMinValue;
  72. INT32 mMaxValue;
  73. bool mIsDragging;
  74. bool mIsDragCursorSet;
  75. bool mHasInputFocus;
  76. };
  77. /** @} */
  78. }