mouse and window coordinates/positions

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
weirdoz
Just popping in
Just popping in
Posts: 2
Joined: Fri Apr 08, 2005 11:26
Contact:

mouse and window coordinates/positions

Postby weirdoz » Tue Aug 23, 2005 13:09

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

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: mouse and window coordinates/positions

Postby CrazyEddie » Tue Aug 23, 2005 13:23

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.

User avatar
weirdoz
Just popping in
Just popping in
Posts: 2
Joined: Fri Apr 08, 2005 11:26
Contact:

Re: mouse and window coordinates/positions

Postby weirdoz » Tue Aug 23, 2005 13:39

Worked fine – used the screenToWindow, very useful.

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

Greets,
Tomas


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 6 guests