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