![]() |
Gorgon Game Engine
|
Drag and drop facilities in Gorgon Library has two starting points: within the system, and from the operating system.
Both systems can be handled the same way. To receive drop and drag related events, a DropTarget should be created. This is a layer that works very similarly to a regular input layer. However, it will not invoke any actions unless an object is being dragged. If the event is starting within the system, a drag source can be created to capture events about the drag operation. This allows source to receive events without any connection to the target.
While drag continues, source event will keep receiving move event. Targeted mouse event will receive over event if hit test succeeds. If it accepts over event, target layer will receive move and drop events. If mouse exits the current target area, out event will fire. This will be fired even if over event returns false, allowing the destination to change and restore pointer shape. If target event handler accepts drop event, source will receive accept event. If it is not accepted or there is no target that accepts the data, source will receive cancel event. Any object is allowed to cancel drag operation. During move event, destination can return false to denote that the dragged object can no longer be dropped over it and out event of the source is called. If destination returns false to drop event, drag operation will be canceled. If an operation is canceled and if the object is over a layer, out event is called before cancel event.
During drag operation, only layers derived from DropTarget will receive over events. This will prevent any layers changing the mouse cursor during the drag operation. For full drag with symbol and cursor, source should set the cursor to drag, and keep symbol drawn on a high level layer on move event. Targets should change the cursor whether they can accept the drop. Targets will receive out event even if they reject over, allowing them to set back cursor to original.
It is possible to perform drag operation without holding the mouse button. Start the drag operation after a click or a mouse up. It will work without any problems. Droping requires clicking in this case. The target will not receive a click event if drag is dropped this way.
If the data is coming from OS, do not trust it to be available until drop time. Even if it is provided, it might be incomplete. Thus, re-check the data if it is arriving from the OS. You may check if the drag operation is coming from the OS using IsFromOS function of DragInfo. Additionally, you should check IsDataReady function if you are to use the data before it is dropped. This function will return true if the data is really available to use.