Page 1 of 1

Need help with Drag/Drop

Posted: Wed Jan 30, 2008 00:51
by ChowNutz
here is my code....I got the dragging and dropping to work but when I drop it.....it disappears. AND I how would i put any kind of image on the static image instead of using the windowsLook close button?

Code: Select all

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

bool MinigameState::handleDragLeave(const CEGUI::EventArgs& args)
{
   const CEGUI::DragDropEventArgs& ddea = static_cast<const CEGUI::DragDropEventArgs&>(args);
   ddea.window->setProperty("FrameColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");

   return true;
}

bool MinigameState::handleDragDropped(const CEGUI::EventArgs& args)
{
   const CEGUI::DragDropEventArgs& ddea = static_cast<const CEGUI::DragDropEventArgs&>(args);
   ddea.window->setProperty("FrameColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
   ddea.window->addChildWindow(ddea.dragDropItem);

   return true;
}

void MinigameState::init_events( void )
{
   // CEGUI
   CEGUI::WindowManager& wMgr = CEGUI::WindowManager::getSingleton();

   // Init frames
   frameDNA = (CEGUI::FrameWindow*)wMgr.getWindow( "DNA" );
   frameItem = (CEGUI::FrameWindow*)wMgr.getWindow( "blueBarSlot" );
   frameItemIcon = (CEGUI::FrameWindow*)wMgr.getWindow( "blueBarSlot//" );
   frameSlot = (CEGUI::FrameWindow*)wMgr.getWindow( "Slots" );
   frameSlotHolder = (CEGUI::FrameWindow*)wMgr.getWindow( "AcceptBars" );

   dragContainer = (CEGUI::DragContainer*)wMgr.getWindow( "blueBarSlot/" );

   // Init buttons, items, etc
   frameItem->subscribeEvent(CEGUI::Window::EventDragDropItemEnters,CEGUI::Event::Subscriber( &MinigameState::handleDragEnter, this ) );
   frameItem->subscribeEvent(CEGUI::Window::EventDragDropItemLeaves, CEGUI::Event::Subscriber( &MinigameState::handleDragLeave, this ) );
   frameItem->subscribeEvent(CEGUI::Window::EventDragDropItemDropped, CEGUI::Event::Subscriber( &MinigameState::handleDragDropped, this ) );
   frameSlotHolder->subscribeEvent(CEGUI::Window::EventDragDropItemEnters,CEGUI::Event::Subscriber( &MinigameState::handleDragEnter, this ) );
   frameSlotHolder->subscribeEvent(CEGUI::Window::EventDragDropItemLeaves, CEGUI::Event::Subscriber( &MinigameState::handleDragLeave, this ) );
   frameSlotHolder->subscribeEvent(CEGUI::Window::EventDragDropItemDropped, CEGUI::Event::Subscriber( &MinigameState::handleDragDropped, this ) );

   frameItemIcon->setProperty( "Image", "set:WindowsLook image:YellowBar" );
   frameItemIcon->disable();



ChowNutz

Posted: Wed Jan 30, 2008 12:12
by Rackle

Code: Select all

   void onDragItemDropped(CEGUI::DragContainer* pDragItem, CEGUI::Window* pDropTarget)
   {
      if(pDropTarget->isPropertyPresent("FrameColours"))
      {
         pDropTarget->setProperty("FrameColours", colorNormalTarget);
      }
      pDragItem->setPosition(CEGUI::UVector2(cegui_reldim(0.2f), cegui_reldim(0.1f)));
      pDragItem->setSize(CEGUI::UVector2(cegui_reldim(0.8f), cegui_reldim(0.8f)));
   }


My code does not call upon addChildWindow() but calls upon setPosition() and setSize(). However this code is from a while ago and Cegui code may have changed since then.

Posted: Wed Jan 30, 2008 15:26
by ChowNutz
what is cegui_reldim?

and how do i put an image on a static image?

Posted: Wed Jan 30, 2008 16:15
by Rackle
cegui_reldim is a helper macro to create UDim values, in this case relative dimensions (as opposed to absolute). The intention is to place the drag item within the center of the drop target.

Have a look at WidgetGalore for questions regarding the basic usage of widgets. In your case the information you seek is

Code: Select all

/* StaticImage */
ImagesetManager::getSingleton().createImagesetFromImageFile("ImageForStaticImage", "GPN-2000-001437.tga");
DefaultWindow* staticImage = static_cast<DefaultWindow*>(winMgr.getWindow("StaticImage"));
staticImage->setProperty("Image", "set:ImageForStaticImage image:full_image"); // "full_image" is a default name from CEGUIImageset::Imageset()

Posted: Thu Jan 31, 2008 00:32
by ChowNutz

Code: Select all

void onDragItemDropped(CEGUI::DragContainer* pDragItem, CEGUI::Window* pDropTarget)
   {
      if(pDropTarget->isPropertyPresent("FrameColours"))
      {
         pDropTarget->setProperty("FrameColours", colorNormalTarget);
      }
      pDragItem->setPosition(CEGUI::UVector2(cegui_reldim(0.2f), cegui_reldim(0.1f)));
      pDragItem->setSize(CEGUI::UVector2(cegui_reldim(0.8f), cegui_reldim(0.8f)));
   }



Code: Select all

bool MinigameState::handleDragDropped(const CEGUI::EventArgs& args)
{
   const CEGUI::DragDropEventArgs& ddea = static_cast<const CEGUI::DragDropEventArgs&>(args);
   ddea.window->setProperty("FrameColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
   ddea.window->addChildWindow(ddea.dragDropItem);

   return true;
}




K I'm suppose to use the first code instead of the second code in order to get the image to show up after i drop the item? Because I cant put cegui_reldim.