steve3d Posted October 22, 2011 Share 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? Link to comment
frustum Posted October 23, 2011 Share 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. Link to comment
steve3d Posted October 23, 2011 Author Share Posted October 23, 2011 thanks, this trick works! Link to comment
steve3d Posted October 24, 2011 Author Share 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. Link to comment
steve3d Posted October 24, 2011 Author Share Posted October 24, 2011 here is the screenshot. Link to comment
steve3d Posted October 24, 2011 Author Share Posted October 24, 2011 more tests shows that if the widget is a child of tab, then the position is always offseted. Link to comment
manguste Posted October 26, 2011 Share 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. Link to comment
Recommended Posts