Garry's Mod Wiki

Revision Difference

Panel:LocalCursorPos#510959

<function name="LocalCursorPos" parent="Panel" type="classfunc">⤶ <description>Returns the cursor position local to the position of the panel (usually the upper-left corner).</description>⤶ <realm>Client</realm>⤶ <rets>⤶ <ret name="" type="number">The x coordinate</ret>⤶ <ret name="" type="number">The y coordinate</ret>⤶ </rets>⤶ </function>⤶ ⤶ <example>⤶ <description>Create and center a label panel and update its text with the local cursor position.</description>⤶ <code>⤶ 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⤶ </code>⤶ <output></output>⤶ ⤶ </example>