steve3d Posted October 22, 2011 Posted October 22, 2011 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?
frustum Posted October 23, 2011 Posted October 23, 2011 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.
steve3d Posted October 24, 2011 Author Posted October 24, 2011 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.
steve3d Posted October 24, 2011 Author Posted October 24, 2011 more tests shows that if the widget is a child of tab, then the position is always offseted.
manguste Posted October 26, 2011 Posted October 26, 2011 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.
Recommended Posts