BsGUIIntField.h 3.3 KB

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