riveranb
Topic Author
Posts: 10
Joined: 20 Aug 2019, 05:48

UI screen space viewport

13 Nov 2019, 09:53

Is there a API to get screen space viewport information of any UIElement?

From the following post
viewtopic.php?f=3&t=1542&p=8842&hilit=s ... +box#p8842

I know UIElement.PointToScreen() can calculate screen space coordinate.
So maybe I can compute screen viewport as
var begin = uielement.PointToScreen(new Point(0, 0));
var end = uielement.PointToScreen(new Point(uielement.width, uielement.height));
Rect viewport = new Rect(begin.x, begin.y, end.x - begin.x, end.y - begin.y);
Is this viable? or is there already existed some API to do this?

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1974
Joined: 22 Dec 2011, 19:20

Re: UI screen space viewport

13 Nov 2019, 11:19

Yes, you can use PointToScreen to determine the coordinates and bounds in screen space of any UIElement:
Point p0 = element.PointToScreen(new Point(0, 0));
Point p1 = element.PointToScreen(new Point(element.RenderSize.Width, element.RenderSize.Height));
Rect viewport = new Rect(p0, p1);
 
riveranb
Topic Author
Posts: 10
Joined: 20 Aug 2019, 05:48

Re: UI screen space viewport

13 Nov 2019, 11:50

Alright, understood.
Thank you for quick reply!

Who is online

Users browsing this forum: No registered users and 10 guests