Drag and Drop control appearing behind the dialog
by David Callaway · in Torque 3D Professional · 07/26/2011 (5:37 pm) · 3 replies
I have been attempting to build a drag and drop inventory like the one posted here
http://www.garagegames.com/community/forums/viewthread/125232
I finally got it working in the GUI editor, but when I try it in my game, the button that is on the mouse cursor appears behind the original button it was dragged from, and any other graphic in the dialog box for that matter. I have tried pushing the dialog to different layers, and I have tried PushToBack, BringToFront the controls, but have had no luck. Thus I appeal to you, Oh great Torque masters. If anyone has any knowledge on this subject I will be eternally grateful.
Here is my code:
DragDropGui.gui
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(DragDropGui) {
position = "0 0";
extent = "1680 1050";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "1";
helpTag = "0";
new GuiBitmapCtrl() {
bitmap = "art/images/inventoryslot_empty.png";
wrap = "0";
position = "231 140";
extent = "64 64";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiBitmapCtrl() {
bitmap = "art/images/inventoryslot_empty.png";
wrap = "0";
position = "560 143";
extent = "64 64";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiBitmapButtonCtrl(droptarget) {
bitmapMode = "Centered";
autoFitExtents = "0";
useModifiers = "0";
useStates = "1";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "1";
position = "564 148";
extent = "55 52";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiBitmapButtonCtrl(Source) {
bitmap = "art/images/rocketlauncher.png";
bitmapMode = "Stretched";
autoFitExtents = "0";
useModifiers = "0";
useStates = "0";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "1";
position = "229 140";
extent = "65 65";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
locked = "1";
canSave = "1";
canSaveDynamicFields = "0";
};
};
//--- OBJECT WRITE END ---
DragDropGui.cs
function DragDropGui::StartDrag (%this)
{
echo("1");
}
function droptarget::onControlDragged(%this,%payload,%position)
{
echo("2");
}
function droptarget::onControlDragEntered(%this,%payload,%position)
{
echo("3");
}
function droptarget::onControlDragExit(%this,%payload,%position)
{
echo("4");
}
function droptarget::onControlDropped(%this,%payload,%position)
{
%this.bitmap=%payload.bitmap;
echo("5");
}
function Source::onMouseDragged(%this)
{
echo ("dragged");
echo ("bitmap = " @ %this.bitmap);
%position = %this.getGlobalPosition();
%cursorpos = Canvas.getCursorPos();
%payload = new GuiBitmapCtrl() {
profile = "GuiDefaultProfile";
horizSizing = "width";
vertSizing = "height";
position = "0 0";
extent = "32 32";
minExtent = "8 8";
visible = "1";
helpTag = "0";
bitmap = %this.bitmap;
wrap = "0";
};
//Canvas.getContent().bringToFront(%this); this doesn't seem to help
%xOffset = getWord(%payload.extent, 0) /2;
%yOffset = getWord(%payload.extent, 1) / 2;
// position where the drag will start, to prevent visible jumping. Down and to the right also
%xPos = getWord(%cursorpos, 0) +32;//%xOffset;//+32;
%yPos = getWord(%cursorpos, 1) +32; //%yOffset;//+ 32;
//Now create the drag and drop control which will be deleted when mouse is up, delivering its payload
%dragCtrl = new GuiDragAndDropControl() {
canSaveDynamicFields = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = %xPos SPC %yPos;
extent = %payload.extent;
MinExtent = "32 32";
canSave = "1";
Visible = "1";
hovertime = "1000";
deleteOnMouseUp = true;
};
%dragCtrl.add(%payload);
Canvas.getContent().add(%dragCtrl);
//We want the new dragdrop to be offset from the cursor
%dragCtrl.startDragging(%xOffset , %yOffset );
}
and leaving nothing to chance here is my call in default.bind.cs
function calldragndrop(%val)
{
echo("in calldragndrop");
if(%val )
{
if (ConsoleDlg.isAwake()) //if the console is open
{ //do nothing
return;
}
if ( DragDropGui.isAwake() )
{
// close the Inventory screen.
Canvas.popDialog( DragDropGui );
}
else
{
Canvas.pushDialog( DragDropGui);
}
}
}
GlobalActionMap.bind(keyboard, "ctrl t", calldragndrop);
http://www.garagegames.com/community/forums/viewthread/125232
I finally got it working in the GUI editor, but when I try it in my game, the button that is on the mouse cursor appears behind the original button it was dragged from, and any other graphic in the dialog box for that matter. I have tried pushing the dialog to different layers, and I have tried PushToBack, BringToFront the controls, but have had no luck. Thus I appeal to you, Oh great Torque masters. If anyone has any knowledge on this subject I will be eternally grateful.
Here is my code:
DragDropGui.gui
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(DragDropGui) {
position = "0 0";
extent = "1680 1050";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "1";
helpTag = "0";
new GuiBitmapCtrl() {
bitmap = "art/images/inventoryslot_empty.png";
wrap = "0";
position = "231 140";
extent = "64 64";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiBitmapCtrl() {
bitmap = "art/images/inventoryslot_empty.png";
wrap = "0";
position = "560 143";
extent = "64 64";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiBitmapButtonCtrl(droptarget) {
bitmapMode = "Centered";
autoFitExtents = "0";
useModifiers = "0";
useStates = "1";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "1";
position = "564 148";
extent = "55 52";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiBitmapButtonCtrl(Source) {
bitmap = "art/images/rocketlauncher.png";
bitmapMode = "Stretched";
autoFitExtents = "0";
useModifiers = "0";
useStates = "0";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "1";
position = "229 140";
extent = "65 65";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
locked = "1";
canSave = "1";
canSaveDynamicFields = "0";
};
};
//--- OBJECT WRITE END ---
DragDropGui.cs
function DragDropGui::StartDrag (%this)
{
echo("1");
}
function droptarget::onControlDragged(%this,%payload,%position)
{
echo("2");
}
function droptarget::onControlDragEntered(%this,%payload,%position)
{
echo("3");
}
function droptarget::onControlDragExit(%this,%payload,%position)
{
echo("4");
}
function droptarget::onControlDropped(%this,%payload,%position)
{
%this.bitmap=%payload.bitmap;
echo("5");
}
function Source::onMouseDragged(%this)
{
echo ("dragged");
echo ("bitmap = " @ %this.bitmap);
%position = %this.getGlobalPosition();
%cursorpos = Canvas.getCursorPos();
%payload = new GuiBitmapCtrl() {
profile = "GuiDefaultProfile";
horizSizing = "width";
vertSizing = "height";
position = "0 0";
extent = "32 32";
minExtent = "8 8";
visible = "1";
helpTag = "0";
bitmap = %this.bitmap;
wrap = "0";
};
//Canvas.getContent().bringToFront(%this); this doesn't seem to help
%xOffset = getWord(%payload.extent, 0) /2;
%yOffset = getWord(%payload.extent, 1) / 2;
// position where the drag will start, to prevent visible jumping. Down and to the right also
%xPos = getWord(%cursorpos, 0) +32;//%xOffset;//+32;
%yPos = getWord(%cursorpos, 1) +32; //%yOffset;//+ 32;
//Now create the drag and drop control which will be deleted when mouse is up, delivering its payload
%dragCtrl = new GuiDragAndDropControl() {
canSaveDynamicFields = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = %xPos SPC %yPos;
extent = %payload.extent;
MinExtent = "32 32";
canSave = "1";
Visible = "1";
hovertime = "1000";
deleteOnMouseUp = true;
};
%dragCtrl.add(%payload);
Canvas.getContent().add(%dragCtrl);
//We want the new dragdrop to be offset from the cursor
%dragCtrl.startDragging(%xOffset , %yOffset );
}
and leaving nothing to chance here is my call in default.bind.cs
function calldragndrop(%val)
{
echo("in calldragndrop");
if(%val )
{
if (ConsoleDlg.isAwake()) //if the console is open
{ //do nothing
return;
}
if ( DragDropGui.isAwake() )
{
// close the Inventory screen.
Canvas.popDialog( DragDropGui );
}
else
{
Canvas.pushDialog( DragDropGui);
}
}
}
GlobalActionMap.bind(keyboard, "ctrl t", calldragndrop);
Torque 3D Owner Matt Huston
Atomic Banzai Games
Instead of
Try