Need help with Drag/Drop

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

ChowNutz
Just popping in
Just popping in
Posts: 5
Joined: Tue Jan 29, 2008 07:20

Need help with Drag/Drop

Postby ChowNutz » Wed Jan 30, 2008 00:51

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

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Wed Jan 30, 2008 12:12

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.

ChowNutz
Just popping in
Just popping in
Posts: 5
Joined: Tue Jan 29, 2008 07:20

Postby ChowNutz » Wed Jan 30, 2008 15:26

what is cegui_reldim?

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

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Wed Jan 30, 2008 16:15

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()

ChowNutz
Just popping in
Just popping in
Posts: 5
Joined: Tue Jan 29, 2008 07:20

Postby ChowNutz » Thu Jan 31, 2008 00:32

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.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 35 guests