Drag-and-Drop?
by Chad Kilgore · in Torque Game Builder · 11/06/2006 (10:10 am) · 3 replies
I am trying to make a gui window similar to the skill window found in GuildWars. However, I am having some difficulty in determining how the guidraganddropctrl functions. When there is no entity inside of it, I can move it around all over the place. Yet when I put an guichunkedbitmapctrl in it (matching the draganddrop extent), the drag-and-drop functionality disappears.
I've looked at how people have done inventories using torque, but i've noticed that they are typically using scene objects and not gui elements.
Can anyone help me out here?

I've looked at how people have done inventories using torque, but i've noticed that they are typically using scene objects and not gui elements.
Can anyone help me out here?

#2
It just so happens that in TGB we have a control that does just what you're looking for. We make use of it in the level builder when you drag and drop items from the 'Create' panel into your scene. Here's a small rundown on one way that it can be used.
Step 1 - Create the control (GuiDragAndDropControl)
Step 2 - Implement 'onControlDropped' method for controls that you want to be aware of this
Keep in mind this is all just pseudo-code, but it should get you 99% the way there!
Cheers,
-Justin
01/25/2007 (7:35 pm)
Chad,It just so happens that in TGB we have a control that does just what you're looking for. We make use of it in the level builder when you drag and drop items from the 'Create' panel into your scene. Here's a small rundown on one way that it can be used.
Step 1 - Create the control (GuiDragAndDropControl)
function MyControl::onMouseDragged( %this )
{
%root = Canvas.getContent();
%position = %this.getGlobalPosition();
%offset = Canvas.getCursorPos()
%dragControl = new GuiDragAndDropControl()
{
Profile = "GuiTransparentProfile";
Position = %position;
Extent = %this.getExtent();
[b]deleteOnMouseUp = true;[/b] // This control will be nuked when you let go of it
};
%dragControl.add(%this);
%root.add(%dragControl);
%xOffset = getWord(%offset, 0) - getWord(%position, 0);
%yOffset = getWord(%offset, 1) - getWord(%position, 1);
%dragControl.startDragging(%xOffset, %yOffset);
}Step 2 - Implement 'onControlDropped' method for controls that you want to be aware of this
function YourDestinationBar::onControlDropped(%this, %control, %position)
{
// add to this bar
%this.add( %control )
}Keep in mind this is all just pseudo-code, but it should get you 99% the way there!
Cheers,
-Justin
#3
Since it is a callback, I presume that only someone with access to the source can know: which classes get this callback?
Thanks for posting this pseudocode!
02/07/2007 (11:04 pm)
Justin DuJardin wrote:Quote: function YourDestinationBar::onControlDropped(%this, %control, %position)I went looking for the onControlDropped() callback in the docs, without success. I grepped it out of dumpConsoleClasses( ), but not for any Gui elements I understood.
Since it is a callback, I presume that only someone with access to the source can know: which classes get this callback?
Thanks for posting this pseudocode!
Torque Owner Teck Lee Tan