Page 1 of 1

Coordinates getting messed with drag container

Posted: Tue Nov 22, 2005 16:40
by Tyn
Hey all

I'm trying to attach a static image that has already been defined in the layout file to a drag container, with the container being defined in code. The problem is that although the static image should be relative to the container but do not work out as expected, it has been created to the correct size of the image and the image having dimensions of 0,0,1,1. Here's the code:

Code: Select all

         CEGUI::WindowManager *mWinMgr = CEGUI::WindowManager::getSingletonPtr();

         // Set up drag container
         CEGUI::DragContainer* mDC =
            (CEGUI::DragContainer*)mWinMgr->createWindow(
               "DragContainer", "RegimentScreen/SoldierFireTeamDragCtr1");
         mDC->setWindowPosition(CEGUI::UVector2(CEGUI::cegui_reldim(0.230f), CEGUI::cegui_reldim(0.664f)));
         mDC->setWindowSize(CEGUI::UVector2(CEGUI::cegui_reldim(0.030f), CEGUI::cegui_reldim(0.026f)));

         // Set up the contained static image
         CEGUI::StaticImage* mSI =
            (CEGUI::StaticImage*)mWinMgr->getWindow("RegimentScreen/SoldierFireTeamSel1");
         mDC->addChildWindow(mSI);
         mSI->setWindowPosition(CEGUI::UVector2(CEGUI::cegui_reldim(0.0f), CEGUI::cegui_reldim(0.0f)));
         mSI->setWindowSize(CEGUI::UVector2(CEGUI::cegui_reldim(1.0f), CEGUI::cegui_reldim(1.0f)));

         CEGUI::Rect mSIPos = mSI->getRect(CEGUI::Absolute);
         CEGUI::Rect mSIPosRel = mSI->getRect(CEGUI::Relative);
         CEGUI::Rect mDCPos = mDC->getRect(CEGUI::Absolute);
         CEGUI::Rect mDCPosRel = mDC->getRect(CEGUI::Relative);


The last four lines are me testing the relative and absolute positions of both the drag container (mDC) and the image (mSI). These are the results ( in format Left,Top,Right,Bottom ):

Static image: Absolute ( 0, 0, 20, 31) Relative (0,0,1,1)
Container: Absolute (510,236,530,267) Relative (0.664,0.230,0.690,0.253)

As you can see, the container is in the right place, and although the relative coords of 0,0,1,1 should place the image in the right place, it seems to be taking the top left corner of the screen as the position to derive it's coords from. Can anyone see anything wrong with how I'm lining up the image?

Re: Coordinates getting messed with drag container

Posted: Tue Nov 22, 2005 19:06
by martignasse

Code: Select all

mDC->setWindowSize(CEGUI::UVector2(CEGUI::cegui_reldim(0.030f), CEGUI::cegui_reldim(0.026f)));
It's depend where you put you'r DragContainer but size like that could be very thin values... :roll:

other than that, please be more explicit about
The problem is that although the static image should be relative to the container but do not work out as expected

Re: Coordinates getting messed with drag container

Posted: Tue Nov 22, 2005 19:21
by Tyn
Sure thing, what's happening is that the image that is a child of the drag container instead of aligning with the containers' top left hand corner, is aligning with the top left of the screen.

I don't think the fineness of the values are the problem, I'd expect this to be a problem when the values were less than one pixel but the display is 1024x768, I don't see a reason for there to be a problem.

Re: Coordinates getting messed with drag container

Posted: Thu Nov 24, 2005 10:33
by Tyn
Solved now, thanks to CE on IRC. The problem was that the drag container wasn't a child of anything in the layout, adding this line fixed the problems:

Code: Select all

mWinMgr->getWindow("RegimentScreenWindow")->addChildWindow(mDC);

Cheers CE :pint: