BsGUIDropDownHitBox.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * Helper class used for detecting when a certain area is in focus,
  8. * and getting notified when that state changes.
  9. */
  10. class BS_EXPORT GUIDropDownHitBox : public GUIElementContainer
  11. {
  12. public:
  13. /**
  14. * Returns type name of the GUI element used for finding GUI element styles.
  15. */
  16. static const String& getGUITypeName();
  17. /**
  18. * Creates a new drop down hit box that will detect mouse input over certain area.
  19. * You must call "setBounds" to define the area.
  20. *
  21. * @param captureMouseOver If true mouse over/out/move events will be captured by this control
  22. * and wont be passed to other GUI elements.
  23. * @param captureMousePresses If true mouse clicks will be captured by this control and wont be passed
  24. * to other GUI elements.
  25. */
  26. static GUIDropDownHitBox* create(bool captureMouseOver, bool captureMousePresses);
  27. /**
  28. * Creates a new drop down hit box that will detect mouse input over certain area.
  29. * You must call "setBounds" to define the area.
  30. *
  31. * @param captureMouseOver If true mouse over/out/move events will be captured by this control
  32. * and wont be passed to other GUI elements.
  33. * @param captureMousePresses If true mouse clicks will be captured by this control and wont be passed
  34. * to other GUI elements.
  35. */
  36. static GUIDropDownHitBox* create(bool captureMouseOver, bool captureMousePresses, const GUIOptions& options);
  37. /**
  38. * Sets a single rectangle bounds in which the hitbox will capture mouse events.
  39. */
  40. void setBounds(const Rect2I& bounds);
  41. /**
  42. * Sets complex bounds consisting of multiple rectangles in which the hitbox will capture mouse events.
  43. */
  44. void setBounds(const Vector<Rect2I>& bounds);
  45. /**
  46. * Triggered when hit box loses focus (e.g. user clicks outside of its bounds).
  47. */
  48. Event<void()> onFocusLost;
  49. /**
  50. * Triggered when hit box gains focus (e.g. user clicks inside of its bounds).
  51. */
  52. Event<void()> onFocusGained;
  53. private:
  54. GUIDropDownHitBox(bool captureMouseOver, bool captureMousePresses, const GUIDimensions& dimensions);
  55. /**
  56. * @copydoc GUIElementContainer::updateClippedBounds
  57. */
  58. void updateClippedBounds() override;
  59. /**
  60. * @copydoc GUIElementContainer::_commandEvent
  61. */
  62. virtual bool _commandEvent(const GUICommandEvent& ev) override;
  63. /**
  64. * @copydoc GUIElementContainer::_mouseEvent
  65. */
  66. virtual bool _mouseEvent(const GUIMouseEvent& ev) override;
  67. /**
  68. * @copydoc GUIElementContainer::_isInBounds
  69. */
  70. virtual bool _isInBounds(const Vector2I position) const override;
  71. Vector<Rect2I> mBounds;
  72. bool mCaptureMouseOver;
  73. bool mCaptureMousePresses;
  74. };
  75. }