| 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 "Math/BsVector2I.h" |
| 7 | |
| 8 | namespace bs |
| 9 | { |
| 10 | /** @addtogroup GUI |
| 11 | * @{ |
| 12 | */ |
| 13 | |
| 14 | /** Types of GUI mouse events. */ |
| 15 | enum class GUIMouseEventType |
| 16 | { |
| 17 | MouseOver, |
| 18 | MouseOut, |
| 19 | MouseDown, |
| 20 | MouseUp, |
| 21 | MouseDoubleClick, |
| 22 | MouseMove, |
| 23 | MouseWheelScroll, |
| 24 | MouseDrag, |
| 25 | MouseDragStart, |
| 26 | MouseDragEnd, |
| 27 | MouseDragAndDropDragged, |
| 28 | MouseDragAndDropDropped, |
| 29 | MouseDragAndDropLeft |
| 30 | }; |
| 31 | |
| 32 | /** Types of GUI mouse buttons. */ |
| 33 | enum class GUIMouseButton |
| 34 | { |
| 35 | Left, Right, Middle, Count |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * Contains data about a GUI mouse input event. This class may store data for many types of events, and some data might |
| 40 | * not be initialized for some event types. Caller must check event type before relying on the data inside. |
| 41 | */ |
| 42 | class BS_EXPORT GUIMouseEvent |
| 43 | { |
| 44 | public: |
| 45 | GUIMouseEvent() = default; |
| 46 | GUIMouseEvent(bool buttonStates[(int)GUIMouseButton::Count], bool shift, bool ctrl, bool alt); |
| 47 | |
| 48 | /** |
| 49 | * The position of the mouse when the event happened. This is relative to the parent widget of the element this |
| 50 | * event is being sent to. |
| 51 | */ |
| 52 | const Vector2I& getPosition() const { return mPosition; } |
| 53 | |
| 54 | /** Returns the internal type of the event. */ |
| 55 | GUIMouseEventType getType() const { return mType; } |
| 56 | |
| 57 | /** Returns the mouse button involved in the event, if any. */ |
| 58 | GUIMouseButton getButton() const { return mButton; } |
| 59 | |
| 60 | /** Returns drag amount in pixels, if event is drag related. */ |
| 61 | Vector2I getDragAmount() const { return mDragAmount; } |
| 62 | |
| 63 | /** Returns the position where the drag was started from, if event is drag related. */ |
| 64 | Vector2I getDragStartPosition() const { return mDragStartPosition; } |
| 65 | |
| 66 | /** Returns amount of mouse wheel scroll, if event is scroll wheel related. */ |
| 67 | float getWheelScrollAmount() const { return mWheelScrollAmount; } |
| 68 | |
| 69 | /** Checks is the specified mouse button pressed. */ |
| 70 | bool isButtonDown(GUIMouseButton button) const { return mButtonStates[(int)button]; } |
| 71 | |
| 72 | /** Gets the current drag and drop operation type id. Only valid if event is drag and drop related. */ |
| 73 | UINT32 getDragAndDropTypeId() const { return mDragTypeId; } |
| 74 | |
| 75 | /** Returns internal data being dragged by a drag and drop event. . Only valid if event is drag and drop related. */ |
| 76 | void* getDragAndDropData() const { return mDragData; } |
| 77 | |
| 78 | /** Checks is the shift button being held. */ |
| 79 | bool isShiftDown() const { return mShift; } |
| 80 | |
| 81 | /** Checks is the control button being held. */ |
| 82 | bool isCtrlDown() const { return mCtrl; } |
| 83 | |
| 84 | /** Checks is the alt button being held. */ |
| 85 | bool isAltDown() const { return mAlt; } |
| 86 | private: |
| 87 | friend class GUIManager; |
| 88 | |
| 89 | /** Initializes the event with MouseOver event data. */ |
| 90 | void setMouseOverData(const Vector2I& position); |
| 91 | |
| 92 | /** Initializes the event with MouseOut event data. */ |
| 93 | void setMouseOutData(const Vector2I& position); |
| 94 | |
| 95 | /** Initializes the event with MouseMove event data. */ |
| 96 | void setMouseMoveData(const Vector2I& position); |
| 97 | |
| 98 | /** Initializes the event with MouseWheelScroll event data. */ |
| 99 | void setMouseWheelScrollData(float scrollAmount); |
| 100 | |
| 101 | /** Initializes the event with MouseUp event data. */ |
| 102 | void setMouseUpData(const Vector2I& position, GUIMouseButton button); |
| 103 | |
| 104 | /** Initializes the event with MouseDown event data. */ |
| 105 | void setMouseDownData(const Vector2I& position, GUIMouseButton button); |
| 106 | |
| 107 | /** Initializes the event with MouseDoubleClick event data. */ |
| 108 | void setMouseDoubleClickData(const Vector2I& position, GUIMouseButton button); |
| 109 | |
| 110 | /** Initializes the event with MouseDrag event data. */ |
| 111 | void setMouseDragData(const Vector2I& position, const Vector2I& dragStartPosition); |
| 112 | |
| 113 | /** Initializes the event with MouseDragStart event data. */ |
| 114 | void setMouseDragStartData(const Vector2I& position, const Vector2I& dragStartPosition); |
| 115 | |
| 116 | /** Initializes the event with MouseDragEnd event data. */ |
| 117 | void setMouseDragEndData(const Vector2I& position); |
| 118 | |
| 119 | /** Initializes the event with DragAndDropDropped event data. */ |
| 120 | void setDragAndDropDroppedData(const Vector2I& position, UINT32 dragTypeId, void* dragData); |
| 121 | |
| 122 | /** Initializes the event with DragAndDropDragged event data. */ |
| 123 | void setDragAndDropDraggedData(const Vector2I& position, UINT32 dragTypeId, void* dragData); |
| 124 | |
| 125 | /** Initializes the event with DragAndDropLeft event data. */ |
| 126 | void setDragAndDropLeftData(const Vector2I& position, UINT32 dragTypeId, void* dragData); |
| 127 | |
| 128 | bool mButtonStates[(int)GUIMouseButton::Count]; |
| 129 | Vector2I mPosition; |
| 130 | Vector2I mDragStartPosition; |
| 131 | Vector2I mDragAmount; |
| 132 | float mWheelScrollAmount = 0.0f; |
| 133 | GUIMouseEventType mType = GUIMouseEventType::MouseMove; |
| 134 | GUIMouseButton mButton = GUIMouseButton::Left; |
| 135 | UINT32 mDragTypeId; |
| 136 | void* mDragData; |
| 137 | |
| 138 | bool mShift = false; |
| 139 | bool mCtrl = false; |
| 140 | bool mAlt = false; |
| 141 | }; |
| 142 | |
| 143 | /** @} */ |
| 144 | } |