Game Development Community

Drag and Drop : How to?

by elvince · in Torque 3D Professional · 06/25/2009 (5:41 am) · 5 replies

Hi,

I looked on a lot forum / ressources in order to learn how to drag&drop object in gui. Sadly I wasn't able to find something that helps me.

Can someone explain me the principles to do a drag&drop?

My goals is to drag a object from an inventory gui to the background (to delete it) or to a shorcut bar.

Thanks,

#1
06/25/2009 (8:04 am)
There is a guiDragAndDropCtrl in the engine, what you have to do is to create a new gui class derived from that to draw your custom gui image, (you can use guiDragAndRopCtrl directly, creating a new instance in script, but I don't know if it renders something) then you can click inside the object ad drag it around, when you drop it, by default it deletes the object, and one object to handle the drop, should implement the onDropControl method, if I remember well. Anyways look at the guiDragAndDropCtrl class and you'll see.
#2
06/26/2009 (3:33 am)
Tahnks for the answer.

Since my post, I find how to start the drag function. In fact, I have added a mouseeventsctrl on top of my object and then create the guiDragAndDropCtrl by script.

Now, I need to figure how I can dragdrop item from different gui. In fact, if I add the guiDragAndDropCtrl to the PlayGui, all the item in "pushdialog" gui don't receive the events and If I put a modeless layer on top on everything then the playgui do not receive the events...

Any idea on how to change to do the trick?
Or do I need to add my control in the same "layer" to have this working?
#3
06/27/2009 (7:02 am)
Well, really don't know because I'm not still at that point, but the gui control that should receive the drop, need to have defined a onControlDropped function, this is the function that is called on a mouse up event. So, if you want that the PlayGui receive a drop object, I think you have to implement in playgui.cs:
function PlayGui::onControlDropped(%this,%obj,%pos);
where %obj is the dragged object id, %pos is the position where the drag ended, don't know if absolute or relative.
#4
06/28/2009 (10:20 am)
This is it Davide. Except that in my case I have multiple layer on top of PlayGui.

So if I want this to works,I need all the gui that may interact in the same layer (like guicontrol).
#5
08/29/2009 (10:10 pm)
@elvince: Look at the guiEditorPalette.ed.cs file for an example of what you are looking for.