BsGUIDropDownHitBox.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsPrerequisites.h"
  5. #include "GUI/BsGUIElementContainer.h"
  6. namespace bs
  7. {
  8. /** @addtogroup GUI-Internal
  9. * @{
  10. */
  11. /** Helper class used for detecting when a certain area is in focus, and getting notified when that state changes. */
  12. class BS_EXPORT GUIDropDownHitBox : public GUIElementContainer
  13. {
  14. public:
  15. /** Returns type name of the GUI element used for finding GUI element styles. */
  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[in] captureMouseOver If true mouse over/out/move events will be captured by this control and wont be
  22. * passed to other GUI elements.
  23. * @param[in] 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. You must call setBounds() to
  29. * define the area.
  30. *
  31. * @param[in] captureMouseOver If true mouse over/out/move events will be captured by this control and wont be
  32. * passed to other GUI elements.
  33. * @param[in] captureMousePresses If true mouse clicks will be captured by this control and wont be passed to
  34. * other GUI elements.
  35. * @param[in] options Options that allow you to control how is the element positioned and sized.
  36. * This will override any similar options set by style.
  37. */
  38. static GUIDropDownHitBox* create(bool captureMouseOver, bool captureMousePresses, const GUIOptions& options);
  39. /** Sets a single rectangle bounds in which the hitbox will capture mouse events. */
  40. void setBounds(const Rect2I& bounds);
  41. /** Sets complex bounds consisting of multiple rectangles in which the hitbox will capture mouse events. */
  42. void setBounds(const Vector<Rect2I>& bounds);
  43. /** Triggered when hit box loses focus (for example user clicks outside of its bounds). */
  44. Event<void()> onFocusLost;
  45. /** Triggered when hit box gains focus (for example user clicks inside of its bounds). */
  46. Event<void()> onFocusGained;
  47. private:
  48. GUIDropDownHitBox(bool captureMouseOver, bool captureMousePresses, const GUIDimensions& dimensions);
  49. /** @copydoc GUIElementContainer::updateClippedBounds */
  50. void updateClippedBounds() override;
  51. /** @copydoc GUIElementContainer::_commandEvent */
  52. bool _commandEvent(const GUICommandEvent& ev) override;
  53. /** @copydoc GUIElementContainer::_mouseEvent */
  54. bool _mouseEvent(const GUIMouseEvent& ev) override;
  55. /** @copydoc GUIElementContainer::_isInBounds */
  56. bool _isInBounds(const Vector2I position) const override;
  57. Vector<Rect2I> mBounds;
  58. bool mCaptureMouseOver;
  59. bool mCaptureMousePresses;
  60. };
  61. /** @} */
  62. }