Page 1 of 1

Problem positioning dragged & dropped items in scrollable pa

Posted: Fri Feb 03, 2006 06:37
by ZacC
Hi Folks,

I'm in the early stages of making an inventory system for my game, and I've hit a snag.

I have a ScrollablePane with it's content window subscribed to drag and drop event handlers, and that's all working just fine. The problem is that the StaticImages I drop into the ScrollablePane are all stacking on top of eachother.

I have code in DropEventHandler() that checks the number of children in the content window and rearanged them by calling setPosition with the appropriate offsets, but to no avail. They're always drawn at 0,0 and it's driving me insane!

I create the scrollable pane like this:

Code: Select all

   ScrollablePane* slot =
   (ScrollablePane*)WindowManager::getSingleton().createWindow("TaharezLook/ScrollablePane");
   parent->addChildWindow(slot);
   slot->setMetricsMode(CEGUI::Absolute);
   slot->setWindowPosition(position);
   slot->setContentPaneAutoSized(false);
   slot->setWindowSize(UVector2(cegui_reldim(0.6f), cegui_reldim(0.6f)));

   slot->setVisible(true);
   slot->setContentPaneArea(
      CEGUI::Rect(CEGUI::Point(0.0f, 0.00f),
      CEGUI::Size(slot->getAbsoluteWidth()*2,
             slot->getAbsoluteHeight()*2)));

   const Window * constwin = slot->getContentPane();
   const String name = constwin->getName();
   Window* content = WindowManager::getSingleton().getWindow(name);
   content->subscribeEvent(Window::EventDragDropItemEnters, &handleDragEnter);
   content->subscribeEvent(Window::EventDragDropItemLeaves, &handleDragLeave);
       content->subscribeEvent(Window::EventDragDropItemDropped, &handleBigDragDropped);



and I drop StaticImages in with this:

Code: Select all

   int t,numkids;
   float x,y;

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

   ddea.dragDropItem->setSize(Size(0.5f,0.5f));
   ddea.window->addChildWindow(ddea.dragDropItem);

   numkids =ddea.window->getChildCount();
   Window* child= NULL;
   
   for(t=0;t<numkids;t++){
      child=ddea.window->getChildAtIdx(t);
      if(child==NULL) break;
      x=t*50.0f;
      y=0.0f;
      child->setPosition(Absolute, Point(x,y));
   }


Any idea what I'm doing wrong?
Thanks in advance. :shock:

Re: Problem positioning dragged & dropped items in scrollabl

Posted: Fri Feb 03, 2006 13:38
by martignasse
hi,

const Window * constwin = slot->getContentPane();
const String name = constwin->getName();
Window* content = WindowManager::getSingleton().getWindow(name);

Here you get the contentpane, but i see nowhere that you put a widget as the contentpane.

More than that, you put directly the dropped item as child of the scrollablepane, who is normaly the way to assign the contentpane widget to the scrollablepane.

so, logicaly, the dropped item is considered like the contentpane widget(who in this case is smaller than the visible area, so placed at 0, 0).

Hope it help

Re: Problem positioning dragged & dropped items in scrollabl

Posted: Fri Feb 03, 2006 22:06
by ZacC
Ok,
Thanks for the help...
I added a "DefaultWindow" window to the Scrollable Area as a child, subscribed it to the Drag&Drop events, and I get exactly the same results. I also tried using a StaticImage instead of DefaultWindow, but in both cases the dropped icons just stack on top of eachother.

It doesn't matter what I pass to setPosition(), the DragContainer always renders at 0,0 of whatever window it's a child of.

One semi-interesting thing...
In my arrange-inventory loop, if I call:

Code: Select all

child->getChildAtIdx(0)->setPosition(Absolute, Point(x,y));

Instead of:

Code: Select all

child->setPosition(Absolute, Point(x,y));
The icon does move, but it's moving inside its DragContainer, not inside the inventory window, so it gets clipped.

Must be something fundamental that I don't understand, but this makes no sense to me.

Why doesn't setPosition() set position?

Re: Problem positioning dragged & dropped items in scrollabl

Posted: Fri Feb 03, 2006 22:45
by lindquist
it's a bug.
the dragcontainer resets the original position when dragging stops.

so if you set the position in a drag handler, it will get overridden.
You will have to move the positioning code out of the drag handler.

thanx for the reminder

Re: Problem positioning dragged & dropped items in scrollabl

Posted: Sat Feb 04, 2006 16:56
by ZacC
Ahhhh!
Thanks Lundquist!

I moved the organize loop outside the drop handler and now it behaves as expected.

Yay! Cheers! :pint: