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