Jump to content

how to get absolute position of a Widget on screen?


photo

Recommended Posts

Posted

I'm now using following code to get a Widget's absolute position on screen

int x = widget.getPositionX(), y = widget.getPositionY();
Widget parent = widget.getParent();
while(parent != 0)
{
x += parent.getPositionX();
y += parent.getPositionY();
parent = parent.getParent();
}

 

in very simple gui, these code will get correct position, but in some complex gui, it will get wrong position. so How can I get a widget's absolute position on screen?

Posted

Another trick is:

x = widget.getPositionX() + (gui.getMouseX() - widget.getMouseX());

y = widget.getPositionY() + (gui.getMouseY() - widget.getMouseY());

 

I will add functions to obtain screen space positions into the GUI system.

Posted

frustum, your code works like mine, there will be some widget which position can not be get correctly, see the attachement.

I want to get position of name WidgetEditLine, the caclulated position is wrong.

Posted

more tests shows that if the widget is a child of tab, then the position is always offseted.

Posted

Can you point out what offset are you talking about or mark what is wrong in red? And it would be great if you can provide a test scene.

×
×
  • Create New...