[Bf-taskforce25] Drag & Drop into 2.5

Elia Sarti vekoon at gmail.com
Mon Jul 20 14:37:16 CEST 2009


The new Blender's event system having centralized (and separated) event 
handling from actual application logic/UI makes it highly feasible to 
introduce new Architectural changes like it is in this case Drag and Drop.


Integration

Initial implementation is aimed at making it possible to drag Blender 
data inside of editors. This will include dragging a material from e.g. 
the Outliner over an Object into the outliner itself, thus applying that 
material to the object, or dragging from a button in the UI to another 
button etc. Later also cross-editor drag and drop will/should be 
integrated (like in dragging a Material from the Outliner to an object 
in the 3d view). There could also be implementation of modifier keys to 
allow move/copy/replace drag and drop.

Further integration could be to enable dragging of files from the OS 
file browser into Blender and open those files also using modifier keys 
to append/link or other type of logic. For instance you drag a .blend 
file and it gets opened. You drag an image over the 3d view and that 
gets set as the background for that view (just examples).


Implementation

Two more event types will be added to the event system: MOUSEDRAG and 
MOUSEDROP. The first event will be sent when the user presses the (left) 
mouse button and start moving the mouse, as soon as the cursor moves 
over a certain amount of pixels. This event will continue to be sent 
until the user releases the mouse button which will generate a MOUSEDROP 
event.

Two Context fields will be added: "drag_pointer" and "drop_pointer" 
(CTX_data_drag_pointer and CTX_data_drop_pointer).
They will be in the form of RNA pointers (thus the name) to make 
everything reusable. The first, "drag_pointer", will represent the data 
currently being moved while the second, "drop_pointer", will represent 
the data the first is being moved upon.

The effective logic will be implemented through operators.
An idea is to implement some operator (maybe at WM level) which handles 
most generic coupling of data. For instance "drag Material onto Object" 
should always give the same expected result and separating this logic 
into separate operator I think makes it easier. Or it could be just some 
function into the API to handle these common situations but an operator 
is better in my opinion as it should allow for more customization.

Every editor will then implement own operators to do custom logic (if it 
needs to).
To continue with the example above when the OS tells Blender the user is 
dragging a file over the 3d view, we could create an RNA pointer 
representing it (although I'm not sure a RNA struct for this exists as 
of now, but can be added I guess?). The 3d view will have an operator 
associated with the MOUSEDROP event and will check the type of the 
"drag_pointer" RNA pointer. If the type is a file and the file type is 
image, it will set the background (if possible) to that image. Otherwise 
it will just call the generic WM function/operator which will check the 
type of the pointer and once it knows it's a File will check the 
extension to be .blend and in that case will open that file into Blender.


Details and Issues

If I'm not mistaken as of now Context only returns "active" 
window/space/area/region in terms of what it was when the event was 
generated. It would be nice to have both "active" and "target" with 
target being the "active" in terms of where the mouse pointer or input are.
I'm not sure this is really necessary but we just need a way to retrieve 
drag data from where the MOUSEDRAG was generated and drop data from 
where the MOUSEDROP is generated.
I admit I didn't look much at the code yet so I could be wrong. Maybe 
this can already be done? For instance, if we do the 
MOUSEDRAG-associated operator modal then maybe we can catch the 
MOUSEDROP event in the modal() callback, set some custom data in it and 
then tell the system to keep on broadcasting the event? I'm not sure 
this is doable and in that case how much of a hack it is.


Sorry no mock-ups for this, I hope it's clear enough.
I think it's all. Of course feel free to comment and raise (or clear) 
doubts.




More information about the Bf-taskforce25 mailing list