| 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 "BsCorePrerequisites.h" |
| 6 | #include "Utility/BsEvent.h" |
| 7 | #include "Math/BsRect2I.h" |
| 8 | |
| 9 | namespace bs |
| 10 | { |
| 11 | /** @addtogroup Platform-Internal |
| 12 | * @{ |
| 13 | */ |
| 14 | |
| 15 | /** Type of drop event type. This is used when dragging items over drop targets. */ |
| 16 | enum class DropTargetType |
| 17 | { |
| 18 | FileList, |
| 19 | None |
| 20 | }; |
| 21 | |
| 22 | /** |
| 23 | * Drop targets allow you to register a certain portion of a window as a drop target that accepts certain drop types |
| 24 | * from the OS (platform) specific drag and drop system. Accepted drop types are provided by the OS and include things |
| 25 | * like file and item dragging. |
| 26 | * |
| 27 | * You will receive events with the specified drop area as long as it is active. |
| 28 | */ |
| 29 | class BS_CORE_EXPORT DropTarget |
| 30 | { |
| 31 | public: |
| 32 | ~DropTarget(); |
| 33 | |
| 34 | /** Sets the drop target area, in local window coordinates. */ |
| 35 | void setArea(const Rect2I& area); |
| 36 | |
| 37 | /** Returns the drop target area, in local window coordinates. */ |
| 38 | const Rect2I& getArea() const { return mArea;} |
| 39 | |
| 40 | /** Gets the type of drop that this drop target is looking for. Only valid after a drop has been triggered. */ |
| 41 | DropTargetType getDropType() const { return mDropType; } |
| 42 | |
| 43 | /** |
| 44 | * Returns a list of files received by the drop target. Only valid after a drop of FileList type has been triggered. |
| 45 | */ |
| 46 | const Vector<Path>& getFileList() const { return mFileList; } |
| 47 | |
| 48 | /** |
| 49 | * Creates a new drop target. Any drop events that happen on the specified window's drop area will be reported |
| 50 | * through the target's events. |
| 51 | * |
| 52 | * @param[in] window Window to which the drop target will be attached to. |
| 53 | * @param[in] area Area, relative to the window, in which the drop events are allowed. |
| 54 | * @return Newly created drop target. |
| 55 | */ |
| 56 | static SPtr<DropTarget> create(const RenderWindow* window, const Rect2I& area); |
| 57 | |
| 58 | /** |
| 59 | * Triggered when a pointer is being dragged over the drop area. Provides window coordinates of the pointer position. |
| 60 | */ |
| 61 | Event<void(INT32, INT32)> onDragOver; |
| 62 | |
| 63 | /** |
| 64 | * Triggered when the user completes a drop while pointer is over the drop area. Provides window coordinates of the |
| 65 | * pointer position. |
| 66 | */ |
| 67 | Event<void(INT32, INT32)> onDrop; |
| 68 | |
| 69 | /** |
| 70 | * Triggered when a pointer enters the drop area. Provides window coordinates of the pointer position. |
| 71 | */ |
| 72 | Event<void(INT32, INT32)> onEnter; |
| 73 | |
| 74 | /** Triggered when a pointer leaves the drop area. */ |
| 75 | Event<void()> onLeave; |
| 76 | |
| 77 | /** @name Internal |
| 78 | * @{ |
| 79 | */ |
| 80 | |
| 81 | /** Clears all internal values. */ |
| 82 | void _clear(); |
| 83 | |
| 84 | /** Sets the file list and marks the drop event as FileList. */ |
| 85 | void _setFileList(const Vector<Path>& fileList); |
| 86 | |
| 87 | /** Marks the drop area as inactive or active. */ |
| 88 | void _setActive(bool active) { mActive = active; } |
| 89 | |
| 90 | /** Checks is the specified position within the current drop area. Position should be in window local coordinates. */ |
| 91 | bool _isInside(const Vector2I& pos) const; |
| 92 | |
| 93 | /** Returns true if the drop target is active. */ |
| 94 | bool _isActive() const { return mActive; } |
| 95 | |
| 96 | /** Returns a render window this drop target is attached to. */ |
| 97 | const RenderWindow* _getOwnerWindow() const { return mOwnerWindow; } |
| 98 | |
| 99 | /** @} */ |
| 100 | private: |
| 101 | friend class Platform; |
| 102 | |
| 103 | DropTarget(const RenderWindow* ownerWindow, const Rect2I& area); |
| 104 | |
| 105 | Rect2I mArea; |
| 106 | bool mActive; |
| 107 | const RenderWindow* mOwnerWindow; |
| 108 | |
| 109 | DropTargetType mDropType; |
| 110 | Vector<Path> mFileList; |
| 111 | }; |
| 112 | |
| 113 | /** @} */ |
| 114 | } |
| 115 | |
| 116 | |