Getting the screen pos of a vgui component.

Hi all. I want to do a OnMouseIn (and OnMouseOut) function, so I need where the mouse is, and where the vgui component is. The mouse is easy, just a function. The problem is to get the screen (or window if windowed mode) relative pos of vgui component. I thought to do this for get his own pos and the parent pos and the parent of the parent pos and… But it falls on a infinite loop instead:

[lua]
– Where self is the vgui component.
local parenting = self
local _x,_y = self:GetPos()
local __x, __y
while (parenting:GetParent() != nil) and (parenting:GetParent():GetPos() != nil) do
__x, __y = parenting:GetParent():GetPos()
_x = __x + _x
_y = __y + _y
end
[/lua]

Why not just do it in think?

[lua]
function Panel:Think()
if self:GetPos() != nil && self:GetParent():GetPos() != nil then
local x, y = self:GetPos()
local Px, Py = self:GetParent():GetPos()
self.x = Px + x
self.y = Py + y
end
end
[/lua]

Edit:

If your not actually making the panel I think this is how it would go.

[lua]
self.Think = function()
–ect
end
[/lua]

You didn’t understand me. That function I have in PANEL:Paint() (or whatever). Really I have this:

[lua]
function PANEL:Paint()
– …
– I skip some code because I’m sure that is not the problem.
local parenting = self
local _x,_y = self:GetPos()
local __x, __y
while (parenting:GetParent() != nil) and (parenting:GetParent():GetPos() != nil) do
__x, __y = parenting:GetParent():GetPos()
_x = __x + _x
_y = __y + _y
end
self:SetRpos(Vector(_x,_y))
return true
end

function PANEL:Think()
local mx, my = gui.MousePos()
if (mx > self:GetRpos().x) and (my > self:GetRpos().y) and (mx > self:GetRpos().x + self:GetWide()) and (my > self:GetRpos().y + self:GetTall()) then
print(self.Label:GetValue())
end
end
[/lua]

Oh I see my bad on that one, just take out the loop and do a simple check.

[lua]
if self:GetPos() != nil && self:GetParent():GetPos() != nil then

end
[/lua]

Instead of the loop.

you don’t need the while loop.

Beaten by find me!!!

[editline]01:30PM[/editline]

Why don’t you just use panel:LocalToScreen.

Because I didn’t know that. Thanks.