Browse Source

Expansion of the guiDragAndDropCtrl - support for dragging to any control visible on the canvas.

Areloch 7 years ago
parent
commit
f731a91c78

+ 25 - 2
Engine/source/gui/containers/guiDragAndDropCtrl.cpp

@@ -152,14 +152,24 @@ 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()
 {
 {
    addField( "deleteOnMouseUp", TypeBool, Offset( mDeleteOnMouseUp, GuiDragAndDropControl ),
    addField( "deleteOnMouseUp", TypeBool, Offset( mDeleteOnMouseUp, GuiDragAndDropControl ),
       "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 )
-      target->onControlDropped_callback( dynamic_cast< GuiControl* >( at( 0 ) ), getDropPoint() );
+   if (target)
+      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;
 }
 }
 
 

+ 4 - 0
Engine/source/gui/containers/guiDragAndDropCtrl.h

@@ -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