Page 1 of 1

mouse and window coordinates/positions

Posted: Tue Aug 23, 2005 13:09
by weirdoz
Hi,

I’v got a static image which is positioned relative to it’s parent, and it’s parent is another static image which a part of a lot of other windows and windows in windows etc.
So; when I do the following…

Code: Select all

CEGUI::Point entity_pos = mapEntity_staticImage->getPosition(CEGUI::Absolute);

… I get the position – relative to it’s parent.
However, I would want it’s position relative to the screen size, since I want to calculate the length of a vector from the static image to the current mouse coordinates.
I get the mouse coordinates from event variables (this is all triggered inside a "EventMouseMove” over a specific window)

Code: Select all

CEGUI::MouseEventArgs& me = (CEGUI::MouseEventArgs&)e;
CEGUI::Point mouse_pos = me.position;


So .. I’v got mouse coordinates (position) and the image position but I need either the mouse coordinates relative to the component current “under” the mouse pointer, or the image position relative not to it’s parent but the whole screen.

Anybody got an idea of how to accomplish this?

Greets,
Tomas

Re: mouse and window coordinates/positions

Posted: Tue Aug 23, 2005 13:23
by CrazyEddie
Hi,

To get the screen position of 'this' window do:

Code: Select all

using namespace CEGUI;

Point scrnPt = windowToScreen( Point( 0, 0 ) );


The reason you pass in 0,0 is because you want the position of this window. If you used the position of this window, you call the same method, but on this window's parent:

Code: Select all

using namespace CEGUI;

Point scrnPt = getParent()->windowToScreen( getPosition() );


To get the mouse position in window relative co-ords do:

Code: Select all

using namespace CEGUI;

Point absMouse = MouseCursor::getSingleton().getPosition();

Point wndPt = screenToWindow( absMouse );


Note that in the above 'screenToWindow' will return values that may be relative or absolute - depending upon the active metrics for the window. So you may need to call Window::relativeToAbsolute to get the value as pixels.

Re: mouse and window coordinates/positions

Posted: Tue Aug 23, 2005 13:39
by weirdoz
Worked fine – used the screenToWindow, very useful.

Thanks for the quick help! (and a good GUI-lib)

Greets,
Tomas