Garry's Mod Wiki

PANEL:TestHover

  boolean PANEL:TestHover( number x, number y )

Description

Called to test if the panel is being hovered by the mouse. This will only be called if the panel's parent is being hovered.

Arguments

1 number x
The x coordinate of the cursor, in screen space.
2 number y
The y coordinate of the cursor, in screen space.

Returns

1 boolean
Return false when the cursor is not considered on the panel, true if it is considered on the panel. Do not return anything for default behavior.

Example

Makes the button detect clicks as if the button was circular - not rectangular.

concommand.Add( "testvgui1", function() local frame = vgui.Create( "DFrame" ) frame:SetSize( 300, 400 ) frame:Center() frame:MakePopup() local DermaButton = vgui.Create( "DButton", frame ) DermaButton:SetText( "Say hi" ) DermaButton:SetPos( 25, 50 ) DermaButton:SetSize( 250, 250 ) function DermaButton:DoClick( self ) chat.AddText( "Hello world" ) end function DermaButton:TestHover( x, y ) local x, y = self:ScreenToLocal( x, y ) -- Convert to local coordinates local dist = math.sqrt( (x - self:GetWide() / 2) ^ 2 + ( y - self:GetTall() / 2 ) ^ 2 ) -- Simple distance calculation return dist < math.min( self:GetWide(), self:GetTall() ) / 2 -- Return true if the cursor is within the buttons circular radius end function DermaButton:Paint( w, h ) -- Original size draw.RoundedBox( 0, 0, 0, w, h, Color( 255, 255, 255, 128 ) ) -- Circular visualization local size = math.min( w, h ) / 2 surface.DrawCircle( w / 2, h / 2, size, Color( 255, 120, 0 ) ) end end )