mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 16:14:38 +00:00
Expansion of the guiDragAndDropCtrl - support for dragging to any control visible on the canvas.
This commit is contained in:
parent
68efd8e22a
commit
f731a91c78
2 changed files with 29 additions and 2 deletions
|
|
@ -152,8 +152,15 @@ ConsoleDocClass( GuiDragAndDropControl,
|
||||||
"@ingroup GuiUtil"
|
"@ingroup GuiUtil"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
IMPLEMENT_CALLBACK(GuiDragAndDropControl, onControlDragCancelled, void, (), (),
|
||||||
|
"Called when the we cancel out of the drag and drop action.\n"
|
||||||
|
"@see GuiDragAndDropControl::onControlDragCancelled");
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
GuiDragAndDropControl::GuiDragAndDropControl() : mDeleteOnMouseUp(true), mUseWholeCanvas(false)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void GuiDragAndDropControl::initPersistFields()
|
void GuiDragAndDropControl::initPersistFields()
|
||||||
{
|
{
|
||||||
|
|
@ -161,6 +168,9 @@ void GuiDragAndDropControl::initPersistFields()
|
||||||
"If true, the control deletes itself when the left mouse button is released.\n\n"
|
"If true, the control deletes itself when the left mouse button is released.\n\n"
|
||||||
"If at this point, the drag&drop control still contains its payload, it will be deleted along with the control." );
|
"If at this point, the drag&drop control still contains its payload, it will be deleted along with the control." );
|
||||||
|
|
||||||
|
addField("useWholeCanvas", TypeBool, Offset(mUseWholeCanvas, GuiDragAndDropControl),
|
||||||
|
"If true, the control can be tested against ANY control active on the canvas instead of just the direct parent.\n\n");
|
||||||
|
|
||||||
Parent::initPersistFields();
|
Parent::initPersistFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,8 +236,10 @@ void GuiDragAndDropControl::onMouseUp(const GuiEvent& event)
|
||||||
mouseUnlock();
|
mouseUnlock();
|
||||||
|
|
||||||
GuiControl* target = findDragTarget( event.mousePoint, "onControlDropped" );
|
GuiControl* target = findDragTarget( event.mousePoint, "onControlDropped" );
|
||||||
if( target )
|
if (target)
|
||||||
target->onControlDropped_callback( dynamic_cast< GuiControl* >( at( 0 ) ), getDropPoint() );
|
target->onControlDropped_callback(dynamic_cast<GuiControl*>(at(0)), getDropPoint());
|
||||||
|
else
|
||||||
|
onControlDragCancelled_callback();
|
||||||
|
|
||||||
if( mDeleteOnMouseUp )
|
if( mDeleteOnMouseUp )
|
||||||
deleteObject();
|
deleteObject();
|
||||||
|
|
@ -239,6 +251,13 @@ GuiControl* GuiDragAndDropControl::findDragTarget( Point2I mousePoint, const cha
|
||||||
{
|
{
|
||||||
// If there are any children and we have a parent.
|
// If there are any children and we have a parent.
|
||||||
GuiControl* parent = getParent();
|
GuiControl* parent = getParent();
|
||||||
|
|
||||||
|
if (mUseWholeCanvas)
|
||||||
|
{
|
||||||
|
parent->setVisible(false);
|
||||||
|
parent = getRoot();
|
||||||
|
}
|
||||||
|
|
||||||
if (size() && parent)
|
if (size() && parent)
|
||||||
{
|
{
|
||||||
mVisible = false;
|
mVisible = false;
|
||||||
|
|
@ -252,6 +271,10 @@ GuiControl* GuiDragAndDropControl::findDragTarget( Point2I mousePoint, const cha
|
||||||
dropControl = dropControl->getParent();
|
dropControl = dropControl->getParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mUseWholeCanvas)
|
||||||
|
parent->setVisible(true);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,8 @@ class GuiDragAndDropControl : public GuiControl
|
||||||
/// If true, the control deletes itself when the left mouse button is released.
|
/// If true, the control deletes itself when the left mouse button is released.
|
||||||
bool mDeleteOnMouseUp;
|
bool mDeleteOnMouseUp;
|
||||||
|
|
||||||
|
bool mUseWholeCanvas;
|
||||||
|
|
||||||
/// Controls may want to react when they are dragged over, entered or exited.
|
/// Controls may want to react when they are dragged over, entered or exited.
|
||||||
SimObjectPtr<GuiControl> mLastTarget;
|
SimObjectPtr<GuiControl> mLastTarget;
|
||||||
|
|
||||||
|
|
@ -81,6 +83,8 @@ class GuiDragAndDropControl : public GuiControl
|
||||||
DECLARE_DESCRIPTION( "A special control that implements drag&drop behavior.\n"
|
DECLARE_DESCRIPTION( "A special control that implements drag&drop behavior.\n"
|
||||||
"The control will notify other controls as it moves across the canvas.\n"
|
"The control will notify other controls as it moves across the canvas.\n"
|
||||||
"Content can be attached through dynamic fields or child objects." );
|
"Content can be attached through dynamic fields or child objects." );
|
||||||
|
|
||||||
|
DECLARE_CALLBACK(void, onControlDragCancelled, ());
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue