BsGUIVector2Field.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include "Math/BsVector2.h"
  7. namespace bs
  8. {
  9. /** @addtogroup GUI-Editor
  10. * @{
  11. */
  12. /**
  13. * A composite GUI object representing an editor field. Editor fields are a combination of a label and an input field.
  14. * Label is optional. This specific implementation displays a Vector2 input field.
  15. */
  16. class BS_ED_EXPORT BS_SCRIPT_EXPORT(m:GUIEditor,api:bed)
  17. GUIVector2Field final : public TGUIField<GUIVector2Field>
  18. {
  19. public:
  20. /** Returns type name of the GUI element used for finding GUI element styles. */
  21. static const String& getGUITypeName();
  22. /** Style type name for the internal X input box. */
  23. static constexpr const char* X_FIELD_STYLE_TYPE = "XFloatField";
  24. /** Style type name for the internal Y input box. */
  25. static constexpr const char* Y_FIELD_STYLE_TYPE = "YFloatField";
  26. GUIVector2Field(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  27. const String& style, const GUIDimensions& dimensions, bool withLabel);
  28. /** Returns the value of the input field. */
  29. BS_SCRIPT_EXPORT(pr:getter,n:Value)
  30. Vector2 getValue() const;
  31. /** Sets a new value in the input field. */
  32. BS_SCRIPT_EXPORT(pr:setter,n:Value)
  33. void setValue(const Vector2& value);
  34. /** Checks is the input field currently active. */
  35. BS_SCRIPT_EXPORT(pr:getter,n:HasInputFocus)
  36. bool hasInputFocus() const;
  37. /** Sets input focus to a specific component's input box. */
  38. BS_SCRIPT_EXPORT()
  39. void setInputFocus(VectorComponent component, bool focus);
  40. /** @copydoc GUIElement::setTint */
  41. void setTint(const Color& color) override;
  42. /** Reports the new value of the vector when the user changes the value of any of the vector components. */
  43. BS_SCRIPT_EXPORT()
  44. Event<void(const Vector2&)> onValueChanged;
  45. /** Reports the new value of an individual vector component when the user changes it. */
  46. BS_SCRIPT_EXPORT()
  47. Event<void(float, VectorComponent)> onComponentChanged;
  48. /** Triggered when an individual component loses or gains focus. */
  49. BS_SCRIPT_EXPORT()
  50. Event<void(bool, VectorComponent)> onComponentFocusChanged;
  51. /** Triggered when the user hits the Enter key with any of the component input boxes in focus. */
  52. BS_SCRIPT_EXPORT()
  53. Event<void(VectorComponent)> onConfirm;
  54. protected:
  55. static const UINT32 ELEMENT_LABEL_WIDTH;
  56. /** @copydoc GUIElement::styleUpdated */
  57. void styleUpdated() override;
  58. /** Triggered when the values in either of the input boxes change. */
  59. void valueChanged(float newValue, VectorComponent component);
  60. /** Triggered when the users confirms input in the input box. */
  61. void inputConfirmed(VectorComponent component);
  62. GUIFloatField* mFieldX = nullptr;
  63. GUIFloatField* mFieldY = nullptr;
  64. };
  65. /** @} */
  66. }