Problem positioning dragged & dropped items in scrollable pa

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
ZacC
Just popping in
Just popping in
Posts: 3
Joined: Thu Feb 02, 2006 22:37

Problem positioning dragged & dropped items in scrollable pa

Postby ZacC » Fri Feb 03, 2006 06:37

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:

User avatar
martignasse
Just can't stay away
Just can't stay away
Posts: 227
Joined: Thu Apr 14, 2005 08:10
Location: Lyon, FRANCE

Re: Problem positioning dragged & dropped items in scrollabl

Postby martignasse » Fri Feb 03, 2006 13:38

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

User avatar
ZacC
Just popping in
Just popping in
Posts: 3
Joined: Thu Feb 02, 2006 22:37

Re: Problem positioning dragged & dropped items in scrollabl

Postby ZacC » Fri Feb 03, 2006 22:06

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?

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Re: Problem positioning dragged & dropped items in scrollabl

Postby lindquist » Fri Feb 03, 2006 22:45

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

User avatar
ZacC
Just popping in
Just popping in
Posts: 3
Joined: Thu Feb 02, 2006 22:37

Re: Problem positioning dragged & dropped items in scrollabl

Postby ZacC » Sat Feb 04, 2006 16:56

Ahhhh!
Thanks Lundquist!

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

Yay! Cheers! :pint:


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 5 guests