BsGUIDropDownHitBox.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 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 captureMouse If true mouse clicks will be captured by this control and wont be passed
  22. * to other GUI elements.
  23. */
  24. static GUIDropDownHitBox* create(bool captureMouse);
  25. /**
  26. * Creates a new drop down hit box that will detect mouse input over certain area.
  27. * You must call "setBounds" to define the area.
  28. *
  29. * @param captureMouse If true mouse clicks will be captured by this control and wont be passed
  30. * to other GUI elements.
  31. * @param layoutOptions Options that allows you to control how is the element positioned in
  32. * GUI layout. This will override any similar options set by style.
  33. */
  34. static GUIDropDownHitBox* create(bool captureMouse, const GUIOptions& layoutOptions);
  35. /**
  36. * Sets a single rectangle bounds in which the hitbox will capture mouse events.
  37. */
  38. void setBounds(const RectI& bounds) { mBounds.clear(); mBounds.push_back(bounds); }
  39. /**
  40. * Sets complex bounds consisting of multiple rectangles in which the hitbox will capture mouse events.
  41. */
  42. void setBounds(const Vector<RectI>& bounds) { mBounds = bounds; }
  43. /**
  44. * Triggered when hit box loses focus (e.g. user clicks outside of its bounds).
  45. */
  46. Event<void()> onFocusLost;
  47. /**
  48. * Triggered when hit box gains focus (e.g. user clicks inside of its bounds).
  49. */
  50. Event<void()> onFocusGained;
  51. private:
  52. GUIDropDownHitBox(bool captureMouse, const GUILayoutOptions& layoutOptions);
  53. virtual bool commandEvent(const GUICommandEvent& ev);
  54. virtual bool mouseEvent(const GUIMouseEvent& ev);
  55. virtual bool _isInBounds(const Vector2I position) const;
  56. Vector<RectI> mBounds;
  57. bool mCaptureMouse;
  58. };
  59. }