
surface.CreateFont( "Verdana", 12, 500, true, false, "GModTooltip" )

local ToolTipData = {}
ToolTipData.TextColor = Color( 40, 40, 20, 255 )
ToolTipData.BackgroundColor = Color( 255, 250, 150, 255 )

local function DrawTooltip( )

	if (!vgui.CursorVisible()) then return end

	local text = GetTooltipText()
	if (!text) then 
	
		ToolTipData.text = nil
		return 
	
	end
	
	local tab = ToolTipData
	local font = "GModTooltip"
	local x, y = gui.MousePos()
	local alpha = 255
	
	surface.SetFont( font )
	local w, h = surface.GetTextSize( text )
	
	x = x - w / 2.0
	y = y - h - 50
	
	if ( y < 0 ) then y = y + 50 end
	if ( x - 8 < 5 ) then x = 5 + 8 end
	if ( x + w + 16 > ScrW() - 5 ) then x = ScrW() - 5 - w - 16 end
	
	if (tab.text != text) then
	
		tab.text = text
		tab.alpha = 0
		tab.yv = 50
		tab.start = RealTime()
	
	end
	
	text = tab.text
	tab.alpha = math.Approach( tab.alpha, 255, (RealTime() - tab.start) * 400 ) 
	tab.yv = math.Approach( tab.yv, 0, (RealTime() - tab.start) * 9 )
	
	ToolTipData.TextColor.a = tab.alpha
	ToolTipData.BackgroundColor.a = tab.alpha
	
	y = y + math.sin( RealTime() * 40 ) * tab.yv * 0.1
	
	alpha	= tab.alpha
	x 		= math.Round(x)
	y 		= math.Round(y)
	
	draw.RoundedBox( 8, x - 8 + 1	, y - 4 + 1	, w + 16	, h + 9		, Color( 0, 0, 0, alpha * 0.5 ) )
	draw.RoundedBox( 8, x - 8 + 2	, y - 4 + 2	, w + 18	, h + 11	, Color( 0, 0, 0, alpha * 0.25 ) )
	draw.RoundedBox( 8, x - 8 		, y - 4		, w + 16	, h + 8		, ToolTipData.BackgroundColor )
	
	draw.DrawText( text, font, x + w * 0.5, y, ToolTipData.TextColor, TEXT_ALIGN_CENTER )
	
end



/*---------------------------------------------------------
	Draws on top of VGUI..
---------------------------------------------------------*/
function GM:PostRenderVGUI()

	self.BaseClass:PostRenderVGUI()
	
	DrawTooltip()

end

