Problems with DnD Example

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

User avatar
Ludi
Quite a regular
Quite a regular
Posts: 59
Joined: Sun Aug 13, 2006 12:33

Problems with DnD Example

Postby Ludi » Sun Aug 13, 2006 21:12

Hi,

first congratulations to the new RC2. Works without problems so far. And the mouse cursor Z-Value is finally fixed :) And Minesweeper is really cool :)

So, now to the problem. I'm using the code from this thread: http://www.cegui.org.uk/phpBB2/viewtopic.php?t=1040. I've modified the code, so that it works with the 0.5.0 RC2.

The DragItem disappears, when moving to another "drop target". And when I move the DragItem within the start "drop target", it doesn't reset its position. Can anyone help me?

Here is the whole example, it a modified Sample_FirstWindow. I removed the whole comments.

Code: Select all

#include "Sample_FirstWindow.h"
#include "CEGUI.h"

int main(int argc, char *argv[])
{
    FirstWindowSample app;
    return app.run();
}

bool handleDragEnter(const CEGUI::EventArgs& args)
{
   using namespace CEGUI;

   const DragDropEventArgs& ddea = static_cast<const DragDropEventArgs&>(args);
   ddea.window->setProperty("FrameColours", "tl:FF00FF00 tr:FF00FF00 bl:FF00FF00 br:FF00FF00");
   return true;
}

bool handleDragLeave(const CEGUI::EventArgs& args)
{
   using namespace CEGUI;

   const DragDropEventArgs& ddea = static_cast<const DragDropEventArgs&>(args);
   ddea.window->setProperty("FrameColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
   return true;
}

bool handleDragDropped(const CEGUI::EventArgs& args)
{
   using namespace CEGUI;

   const DragDropEventArgs& ddea = static_cast<const DragDropEventArgs&>(args);
   ddea.window->setProperty("FrameColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
   ddea.window->addChildWindow(ddea.dragDropItem);
   return true;
}

CEGUI::Window* createDragDropSlot(CEGUI::Window* parent, const CEGUI::UVector2& position)
{
   using namespace CEGUI;

   Window* slot = WindowManager::getSingleton().createWindow("TaharezLook/StaticImage");
   parent->addChildWindow(slot);
   slot->setPosition(position);
   slot->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim(0.2f)));
   slot->subscribeEvent(Window::EventDragDropItemEnters, &handleDragEnter);
   slot->subscribeEvent(Window::EventDragDropItemLeaves, &handleDragLeave);
   slot->subscribeEvent(Window::EventDragDropItemDropped, &handleDragDropped);

   return slot;
}
bool FirstWindowSample::initialiseSample()
{
    using namespace CEGUI;
    Imageset* taharezImages = ImagesetManager::getSingleton().createImageset("TaharezLook.imageset");
    System::getSingleton().setDefaultMouseCursor(&taharezImages->getImage("MouseArrow"));
    FontManager::getSingleton().createFont("Commonwealth-10.font");
    WidgetLookManager::getSingleton().parseLookNFeelSpecification("TaharezLook.looknfeel");
    SchemeManager::getSingleton().loadScheme("TaharezLookWidgets.scheme");
    WindowManager& winMgr = WindowManager::getSingleton();
    DefaultWindow* root = (DefaultWindow*)winMgr.createWindow("DefaultWindow", "Root");
    System::getSingleton().setGUISheet(root);

   Window* rs = winMgr.createWindow("TaharezLook/FrameWindow");
   root->addChildWindow(rs);
   rs->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim( 0.25f)));
   rs->setSize(UVector2(cegui_reldim(0.33f), cegui_reldim( 0.33f)));
   rs->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
   rs->setMinSize(UVector2(cegui_reldim(0.1f), cegui_reldim( 0.1f)));
   rs->setText("Rucksack");

   // create main equipped items window.
   Window* eq = winMgr.createWindow("TaharezLook/FrameWindow");
   root->addChildWindow(eq);
   eq->setPosition(UVector2(cegui_reldim(0.57f), cegui_reldim( 0.25f)));
   eq->setSize(UVector2(cegui_reldim(0.33f), cegui_reldim( 0.33f)));
   eq->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
   eq->setMinSize(UVector2(cegui_reldim(0.1f), cegui_reldim( 0.1f)));
   eq->setText("Equipped Items");

   // add slots to rucksack
   Window* startSlot =
      createDragDropSlot(rs, UVector2(cegui_reldim(0.05f), cegui_reldim(0.2f)));
   createDragDropSlot(rs, UVector2(cegui_reldim(0.3f), cegui_reldim(0.2f)));
   createDragDropSlot(rs, UVector2(cegui_reldim(0.55f), cegui_reldim(0.2f)));
   createDragDropSlot(rs, UVector2(cegui_reldim(0.05f), cegui_reldim(0.5f)));
   createDragDropSlot(rs, UVector2(cegui_reldim(0.3f), cegui_reldim(0.5f)));
   createDragDropSlot(rs, UVector2(cegui_reldim(0.55f), cegui_reldim(0.5f)));

   // add slots to equipment window
   createDragDropSlot(eq, UVector2(cegui_reldim(0.05f), cegui_reldim(0.2f)));
   createDragDropSlot(eq, UVector2(cegui_reldim(0.3f), cegui_reldim(0.2f)));
   createDragDropSlot(eq, UVector2(cegui_reldim(0.55f), cegui_reldim(0.2f)));
   createDragDropSlot(eq, UVector2(cegui_reldim(0.05f), cegui_reldim(0.5f)));
   createDragDropSlot(eq, UVector2(cegui_reldim(0.3f), cegui_reldim(0.5f)));
   createDragDropSlot(eq, UVector2(cegui_reldim(0.55f), cegui_reldim(0.5f)));

   // create a drag/drop item
   DragContainer* item = static_cast<DragContainer*>(
      winMgr.createWindow("DragContainer", "theItem"));
   item->setPosition(UVector2(cegui_reldim(0.05f), cegui_reldim(0.05f)));
   item->setSize(UVector2(cegui_reldim(0.9f), cegui_reldim(0.9f)));

   // set a static image as drag container's contents
   Window* itemIcon = winMgr.createWindow("TaharezLook/StaticImage");
   item->addChildWindow(itemIcon);
   itemIcon->setPosition(UVector2(cegui_reldim(0), cegui_reldim(0)));
   itemIcon->setSize(UVector2(cegui_reldim(1), cegui_reldim(1)));
   itemIcon->setProperty("Image", "set:TaharezLook image:CloseButtonNormal");
   // disable to allow inputs to pass through.
   itemIcon->disable();

   // set starting slot for the item.
   startSlot ->addChildWindow(item);     // return true so that the samples framework knows that initialisation was a
    // success, and that it should now run the sample.
    return true;
}
void FirstWindowSample::cleanupSample()
{
}

User avatar
Ludi
Quite a regular
Quite a regular
Posts: 59
Joined: Sun Aug 13, 2006 12:33

Postby Ludi » Mon Aug 14, 2006 20:55

Hi,

okay, I solved my problem, again ;), on my own.

I replaced this code:

Code: Select all

bool handleDragDropped(const CEGUI::EventArgs& args)
{
   using namespace CEGUI;

   const DragDropEventArgs& ddea = static_cast<const DragDropEventArgs&>(args);
   ddea.window->setProperty("FrameColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
   ddea.window->addChildWindow(ddea.dragDropItem);
   return true;
}


with that:

Code: Select all

bool handleDragDropped(const CEGUI::EventArgs& args)
{
   using namespace CEGUI;

   const DragDropEventArgs& ddea = static_cast<const DragDropEventArgs&>(args);
   ddea.window->setProperty("FrameColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
   ddea.window->addChildWindow(ddea.dragDropItem);
   ddea.dragDropItem->setPosition(UVector2(cegui_reldim(0.04f), cegui_reldim(0.04f)));
   return true;
}

User avatar
Ludi
Quite a regular
Quite a regular
Posts: 59
Joined: Sun Aug 13, 2006 12:33

Postby Ludi » Mon Aug 14, 2006 21:10

Okay, next question :)

The addChildWindow method removes the window from its old target and add it to its new target. So, how can I clone the ddea.window? I want to add a copy of it.

And how can I hold a copy of the DragContainer in its normal position? I want to move the DragContainer around, but at the same time, I want to see the item of it in its origin.

kalitbri
Just popping in
Just popping in
Posts: 3
Joined: Wed Aug 09, 2006 08:08
Location: Taipei, Taiwan

Postby kalitbri » Fri Aug 18, 2006 02:39

To achieve your goal, one important thing is to get the original parent of the DragContainer. fortunately, we can get it by using ddea.dragDropItem->getParent().

Here are my modified function of handleDragDropped():

Code: Select all

bool handleDragDropped(const CEGUI::EventArgs& args)
{
   using namespace CEGUI;
   //char buf[64];

   const DragDropEventArgs& ddea = static_cast<const DragDropEventArgs&>(args);

   // get drag source window
   Window *dragSrc = ddea.dragDropItem->getParent();

   // make drag source window frame to red
   //if (dragSrc)
   //   dragSrc->setProperty("FrameColours", "tl:FFFF0000 tr:FFFF0000 bl:FFFF0000 br:FFFF0000");

   sprintf(buf, "Drag: From %s to %s", (dragSrc) ? dragSrc->getName().c_str() : "NULL", ddea.window->getName().c_str());
   CEGUI::Logger::getSingleton().logEvent(buf);

   ddea.window->setProperty("FrameColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
   ddea.window->addChildWindow(ddea.dragDropItem);
   ddea.dragDropItem->setPosition(UVector2(cegui_reldim(0.04f), cegui_reldim(0.04f)));
   return true;
}


To create a copy of your object, I didn't find any clone method for objects. But in a better way, I suggest that you write a dedicated function to create a copy of the object, by creating a new object of same type and copy the necessary parameters to the new object, instead of just cloning the object.

Hope this helps.

Brian

User avatar
Ludi
Quite a regular
Quite a regular
Posts: 59
Joined: Sun Aug 13, 2006 12:33

Postby Ludi » Fri Aug 18, 2006 14:39

Thanks for your tip. I already had the same idea ;)

Greetings


Return to “Help”

Who is online

Users browsing this forum: No registered users and 19 guests