Page 1 of 1

Problem getting a window's screen(absolute) position

Posted: Fri Sep 03, 2010 11:31
by tirbison
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.

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

Posted: Fri Sep 03, 2010 14:07
by tirbison
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;
}

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

Posted: Sun Sep 05, 2010 09:07
by CrazyEddie
You should look at the CEGUI::CoordConverter helper class: http://www.cegui.org.uk/docs/current/cl ... erter.html

CE.

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

Posted: Mon Sep 06, 2010 07:27
by tirbison
Thanks a lot.