Panel/LocalCursorPos

From Garry's Mod
Jump to: navigation, search
 Panel:LocalCursorPos( )

Contents

Description

Returns the cursor position local to the position of the panel (usually the upper-left corner).

Returns

number

The x coordinate

Returns

number

The y coordinate

Examples

Example

Create and center a label panel and update its text with the local cursor position.

TestLabel = vgui.Create("DLabel")
TestLabel:SetSize(100, 20)
TestLabel:Center()
TestLabel:SetPaintBackgroundEnabled(true)
TestLabel:SetColor(Color(255, 0, 0))

local x, y = 0, 0

function TestLabel:PerformLayout()

	x, y = self:LocalCursorPos()

	self:SetText(" X: "..x.." , Y: "..y)
	
end

Output:



Panel LocalCursorPos example1.gif
Personal tools
Navigation