Skip to content

DragDrop module API

ivan-mogilko edited this page Jul 21, 2022 · 2 revisions

DragDrop functions and properties

See also: Drag & Drop module overview

Setting up

This is how you configure the module up.

static bool DragDrop.Enabled
enables or disables DragDrop work, without cancelling any other settings. Disabling this in the middle of the dragging action will reset it at the following game update.

static eKeyCode DragDrop.DefaultHookKey
gets/sets default hook key, that is a key which must be pressed to drag an object, and released to drop it. Set DragDrop.DefaultHookKey = 0; if you don't want to use a strictly defined key, but in that case you will have to call DragDrop.HookKeyDown yourself.

static MouseButton DragDrop.DefaultHookMouseButton
gets/sets default hook mouse button, that is a button which must be pressed to drag an object, and released to drop it. Set DragDrop.DefaultHookMouseButton = 0; if you don't want to use a strictly defined mouse button, but in that case you will have to call DragDrop.HookKeyDown yourself.

static bool DragDrop.AutoTrackHookKey
gets/sets whether the module should automatically track hook key/button's state (pressed, released). When disabled, you should call DragDrop.HookKeyDown and DragDrop.HookKeyUp yourself.

static int DragDrop.DragMinDistance
gets/sets minimal number of pixels the mouse should move before it is considered to be dragging.

static int DragDrop.DragMinTime
gets/sets minimal time (in milliseconds) the hook key should be pressed down before it is considered to be dragging.

static DragDropUnhookAction DragDrop.DefaultUnhookAction
gets/sets the default action that should be performed when the hook key is released. These actions are described by a enum DragDropUnhookAction:

Action Description
eDDUnhookDrop Drop the dragged object at the last cursor position.
eDDUnhookRevert Revert the dragged object to its original position.

this action may be overriden by calling Drop() or Revert().

Event signals

Following attributes work as event "signals", which you may test in repeatedly_execute or repeatedly_execute_always:

static readonly bool DragDrop.EvtWantObject
gets if the hook key was pushed down and the module is looking for a draggable object under the cursor. This is when the user should supply module with the draggable object.

static readonly bool DragDrop.EvtObjectHooked
gets if the draggable object was just hooked. This is when the user may take some action right before the object will be actually dragged around.

static readonly bool DragDrop.EvtDragStarted
gets if the drag just started. This event takes place if the object was kept hooked until the drag conditions were met (minimal drag time and/or distance).

static readonly bool DragDrop.EvtWantDrop
gets if the drag was just released. The event takes place just a tick before the object is actually dropped on a new place, letting user to change drop coordinates by calling DropAt or revert the drag with Revert.

static readonly bool DragDrop.EvtDropped
gets if the object was just dropped on a new position (or reverted). At this point the module still has the saved object's description, drag parameters and last object's coordinates.

static readonly bool DragDrop.EvtCancelled
gets if the object was unhooked before the drag even commenced.

State control

Following attributes and functions tell and control the dragging state:

static readonly bool DragDrop.IsIdle
gets if the module is currently waiting for action.

static readonly bool DragDrop.HasObjectHooked
gets if the module has an object hooked (before dragging, during dragging or at the drop state).

static readonly bool DragDrop.IsDragging
gets if the object is currently being dragged.

static readonly int DragDrop.CurrentKey
gets the key used to hook the current object. May be an imaginary key code. Returns 0 if no object was hooked.

static readonly MouseButton DragDrop.CurrentMouseButton
gets the mouse button used to hook the current object. May be an imaginary mouse button. Returns 0 if no object was hooked.

static readonly int DragDrop.CurrentMode
gets the user-defined drag mode, as set by HookObject call. Returns 0 if no object was hooked.

static readonly int DragDrop.ObjectTag;
gets the user-defined integer tag, as set by HookObject call. Returns 0 if no object was hooked.

static readonly String DragDrop.ObjectSTag
gets the user-defined String tag, as set by HookObject call. Returns 0 if no object was hooked.

static readonly int DragDrop.DragStartX
gets X coordinate of cursor position at which the hook key was pushed down.

static readonly int DragDrop.DragStartY
gets Y coordinate of cursor position at which the hook key was pushed down.

static readonly int DragDrop.ObjectStartX
gets X coordinate of initial object's position.

static readonly int DragDrop.ObjectStartY
gets Y coordinate of initial object's position.

static readonly int DragDrop.ObjectX
gets X coordinate of the current dragged object's position.

static readonly int DragDrop.ObjectY
gets Y coordinate of the current dragged object's position.

static void DragDrop.HookKeyDown(optional int user_key, optional MouseButton mbtn)
notifies a hook key push down. This does not have to be a real keycode, but in that case the module won't be able to automatically track its release.

static void DragDrop.HookKeyUp()
notifies a hook key release. If an object was being dragged, it will be dropped. If an object was hooked up, but not dragged yet, drag will be cancelled.

static void DragDrop.HookObject(int user_mode, int obj_x, int obj_y, optional int tag, optional String stag)
assigns a draggable object for the module. The module will save all parameters and provide them for reading back until drag ends or is cancelled. Starting object coordinates obj_x and obj_y will be used to calculate the relative distance between current cursor coordinates and the object, so that when the cursor moves the object's position will change accordingly.

static void DragDrop.Drop()
immediately drops the object. Does nothing if no object was hooked up.

static void DragDrop.DropAt(int x, int y)
immediately drops the object at the given coordinates. Does nothing if no object was hooked up.

static void DragDrop.Revert()
immediately resets the object to the original position. Does nothing if no object was hooked up.