Jump to content

how to get absolute position of a Widget on screen?


photo

Recommended Posts

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?

Link to comment

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.

Link to comment

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.

Link to comment
×
×
  • Create New...