From BlenderWiki

Jump to: navigation, search

Drag'n'Drop implementation

New Ghost events (defined in GHOST_EventDragnDrop.h) have been created to handle dropping of text, filenames and images.

Sequence of events

- Start sequence (GHOST_kEventDraggingEntered) that tells a drag'n'drop operation has started. Already gives the object data type, and the entering mouse location

- Update mouse position (GHOST_kEventDraggingUpdated) sent upon each mouse move until the drag'n'drop operation stops, to give the updated mouse position. Useful to highlight a potential destination, and update the status (through GHOST_setAcceptDragOperation) telling if the object can be dropped at the current cursor position.

- Abort drag'n'drop sequence (GHOST_kEventDraggingExited) sent when the user moved the mouse outside the window.

- Send the dropped data (GHOST_kEventDraggingDropDone)


Note that on OSX, the user can drop a document on Blender icon to open a document (.blend) file. Implementation wise, it is not a drag'n'drop event per se. This action and double-clicking on a .blend file in OSX Finder trigger a GHOST_kEventOpenMainFile event with the filename as a string parameter.

Notes

The "dropped object" data is freed upon event object release (already handled in the event dispatch loop).

And the mouse position is sent directly in blender client coordinates (y=0 at bottom).

The GHOST_setAcceptDragOperation(TRUE) call must be placed before the user drops the object for it to be accepted.

Current handled data types :

  • Text string (meant to be any string but filename, type = char *)
  • Array of filenames (full paths, type = GHOST_TStringArray )
  • Bitmap image (ImBuf - is it available in x11 & win ?)

Status

Ghost implementation currently done for OSX and Win32

ToDo / next steps

Interface with Ton's DND code to implement the handling of these ghost events in blender event manager, and the operators to use them