Problem getting a window's screen(absolute) position

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

tirbison
Just popping in
Just popping in
Posts: 4
Joined: Fri Sep 03, 2010 08:22

Problem getting a window's screen(absolute) position

Postby tirbison » Fri Sep 03, 2010 11:31

Hi
I am trying to create my own slider class which contains cegui::slider as a class member.
when the user clicks on the slider, I want the slider thumbnail to be set to the clicked point. To do that I need the absolute X position of the slider window and the absolute mouse click position.
here is the code I wrote

Code: Select all

   
bool handleMouseDown(const CEGUI::EventArgs& e)
   {    
      
      const MouseEventArgs& m_evt = static_cast<const MouseEventArgs&>(e);
      
      float mouse_abs_x = m_evt.position.d_x ;
      float window_abs_x = m_evt.window->getXPosition().asAbsolute(800);
      float val = mouse_abs_x - window_abs_x;
...



however value of window_abs_x is not correct (I am sure that application window width is 800). I couldnt find what the problem is. besides where can I get the 'base'.

thanks in advance and for your time.

tirbison
Just popping in
Just popping in
Posts: 4
Joined: Fri Sep 03, 2010 08:22

Re: Problem getting a window's screen(absolute) position

Postby tirbison » Fri Sep 03, 2010 14:07

ok I managed to get a windows screen position, here is the code

Code: Select all

float get_screen_x_of_window(Window* p_wnd)
{
   float screen_x =0;
   while (p_wnd->getParent())
   {
      float parent_w = p_wnd->getParentPixelWidth();
      const UDim& posX = p_wnd->getXPosition();
      screen_x +=  parent_w * posX.d_scale + posX.d_offset;
      p_wnd = p_wnd->getParent();
   }
        return screen_x;
}

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

Re: Problem getting a window's screen(absolute) position

Postby CrazyEddie » Sun Sep 05, 2010 09:07

You should look at the CEGUI::CoordConverter helper class: http://www.cegui.org.uk/docs/current/cl ... erter.html

CE.

tirbison
Just popping in
Just popping in
Posts: 4
Joined: Fri Sep 03, 2010 08:22

Re: Problem getting a window's screen(absolute) position

Postby tirbison » Mon Sep 06, 2010 07:27

Thanks a lot.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 12 guests