class DragAndDrop

Handles GUI drag and drop operations.

When active GUI elements will be notified of any drag events and will be able to retrieve dragged data. When cursor is released the data will be dropped and underlying GUI elements will be notified the data is dropped. The dropped data is also available for a single frame via GetDropData() method.

Public

Constructors

DragAndDrop

DragAndDrop()

Methods

~DragAndDrop

~DragAndDrop() noexcept

StartDrag

void StartDrag(const SPtr<DragAndDropData> &data)

Starts a drag operation with the specified data.

This means GUI elements will start receiving drag and drop related events and they may choose to handle them.

data
Some operation specific data that is just passed through to however needs it.

StartDrag

void StartDrag(const SPtr<DragAndDropData> &data, Function<void (bool)> &&dropCallback, bool needsValidDropTarget = false)

Starts a drag operation with the specified data.

This means GUI elements will start receiving drag and drop related events and they may choose to handle them.

data
Some operation specific data that is just passed through to however needs it.
dropCallback
The drop callback that gets triggered whenever mouse button is released and drag operation ends. You should perform any cleanup here.
needsValidDropTarget
(optional) Determines whether the drop operation may happen anywhere or does the GUI element need to specifically accept the drag of this type. If false all GUI elements we mouse over will receive drag/drop events, otherwise only those that specifically subscribe to the specified drag operation of this typeId will. Additionally this will determine the cursor displayed (whether or not it can have a "denied" state).

IsDragInProgress

bool IsDragInProgress() const

Returns true if drag is currently in progress.

IsDropInProgress

bool IsDropInProgress() const

Returns true if a drop operation happened this frame.

GetDragTypeId

u32 GetDragTypeId() const

Get RTTI ID of the dragged data.

Only valid if drag is in progress.

GetDropTypeId

u32 GetDropTypeId() const

Get RTTI ID of the dropped data.

Only valid if drop is in progress.

GetDragData

SPtr<DragAndDropData> GetDragData() const

Gets drag specific data specified when the drag started.

Only valid if drag is in progress.

GetDropData

SPtr<DragAndDropData> GetDropData() const

Gets drag specific data specified when the drag started.

Only valid if drop is in progress. This is only valid for a single frame when a drop happens.

NeedsValidDropTarget

bool NeedsValidDropTarget() const

Determines whether the drop operation may happen anywhere or does the GUI element need to specifically accept the drag of this type.

If false all GUI elements we mouse over will receive drag/drop events, otherwise only those that specifically subscribe to the specified drag operation of this typeId will.

Additionally this will determine the cursor displayed (whether or not it can have a "denied" state).

AddDropCallback

void AddDropCallback(Function<void (bool)> &&dropCallback)

Registers a new callback that will be triggered when dragged item is dropped.

Provided parameter specifies if the drop operation was handled by anyone or not.

Update

void Update()

Called once per frame.

Checks if drag ended, drop started/ended or if window loses focus.

staticInstance

static T &Instance()

Returns a reference to the module instance.

Module has to have been started up first otherwise an exception will be thrown.

staticInstancePtr

static T *InstancePtr()

Returns a pointer to the module instance.

Module has to have been started up first otherwise an exception will be thrown.

staticShutDown

static void ShutDown()

Shuts down this module and frees any resources it is using.

staticIsStarted

static bool IsStarted()

Query if the module has been started.

Fields

OnDragEnded

Event<void (const PointerEvent &, DragCallbackInfo &)> OnDragEnded

Triggers a callback when user releases the pointer and the drag operation ends.

Provided parameters inform the subscriber where the pointer was released, and allows the subscriber to note whether the drag operation was processed or not.

Protected

Methods

~Module<T>

virtual ~Module<T>() = default

OnStartUp

virtual void OnStartUp()

Override if you want your module to be notified once it has been constructed and started.

OnShutDown

virtual void OnShutDown()

Override if you want your module to be notified just before it is deleted.

staticInstanceInternal

static T *&InstanceInternal()

Returns a singleton instance of this module.

staticIsDestroyed

static bool &IsDestroyed()

Checks has the Module been shut down.

staticIsStartedUp

static bool &IsStartedUp()

Checks has the Module been started up.

Private

Methods

EndDrag

void EndDrag(bool processed)

Triggers any drop callbacks, clears callback data and starts drop operation.

MouseCaptureChanged

void MouseCaptureChanged()

Called by the render thread whenever mouse capture state changes.

This can happen when window loses focus (for example alt+tab). In that case we want to end the drag even if the user is still holding the dragged item.

CursorReleased

void CursorReleased(const PointerEvent &event)

Called by the input system when pointer is released.

Fields

mDragData

SPtr<DragAndDropData> mDragData

mDropData

SPtr<DragAndDropData> mDropData

mDropCallbacks

Vector<Function<void (bool)>> mDropCallbacks

mNeedsValidDropTarget

bool mNeedsValidDropTarget

mIsDropActiveThisFrame

bool mIsDropActiveThisFrame

mMouseCaptureChangedConn

HEvent mMouseCaptureChangedConn

mCaptureChanged

std::atomic<bool> mCaptureChanged

mCaptureActive

std::atomic<int> mCaptureActive

mCaptureChangeFrame

std::atomic<u64> mCaptureChangeFrame