
local SKIN = {}

SKIN.bg_color 					= Color( 90, 90, 90, 240 )
SKIN.bg_color_sleep 			= Color( 60, 60, 60, 240 )
SKIN.bg_color_dark				= Color( 50, 50, 50, 255 )
SKIN.control_color 				= Color( 110, 110, 110, 255 )
SKIN.control_color_highlight	= Color( 130, 130, 130, 255 )
SKIN.control_color_active 		= Color( 110, 150, 200, 255 )
SKIN.control_color_bright 		= Color( 255, 200, 100, 255 )


/*---------------------------------------------------------
   DefineControl
---------------------------------------------------------*/
function SKIN:DrawGenericBackground( x, y, w, h, color )

	draw.RoundedBox( 4, x, y, w, h, color )

end

/*---------------------------------------------------------
   DefineControl
---------------------------------------------------------*/
function SKIN:DrawButtonBorder( x, y, w, h, depressed )

	w = w - 1
	h = h - 1

	if ( !depressed ) then
		surface.SetDrawColor( 180, 180, 180, 255 )
	else
		surface.SetDrawColor( 40, 40, 40, 255 )
	end
	surface.DrawLine( 0, 0, w, 0 )
	surface.DrawLine( 0, 0, 0, h )
	
	if ( !depressed ) then
		surface.SetDrawColor( 40, 40, 40, 255 )
	else
		surface.SetDrawColor( 180, 180, 180, 255 )
	end
	surface.DrawLine( w, 0, w, h )
	surface.DrawLine( 0, h, w, h )

end


/*---------------------------------------------------------
	Frame
---------------------------------------------------------*/
function SKIN:PaintFrame( panel )

	local color = self.bg_color_sleep

	if ( panel:IsActive() ) then color = self.bg_color end

	self:DrawGenericBackground( 0, 0, panel:GetWide(), panel:GetTall(), color )

end

function SKIN:LayoutFrame( panel )

	panel.btnClose:SetPos( panel:GetWide() - 22, 4 )
	panel.btnClose:SetSize( 18, 18 )
	
	panel.lblTitle:SetPos( 8, 2 )
	panel.lblTitle:SetSize( panel:GetWide() - 25, 20 )

end


/*---------------------------------------------------------
	Button
---------------------------------------------------------*/
function SKIN:PaintButton( panel )

	if ( panel.m_bBackground ) then
	
		local col = self.control_color
		
		if ( panel.Depressed ) then
			col = self.control_color_active
		elseif ( panel.Hovered ) then
			col = self.control_color_highlight
		end
		
		surface.SetDrawColor( col.r, col.g, col.b, col.a )
		surface.DrawRect( 0, 0, panel:GetWide(), panel:GetTall() )
	
	end
	
	if ( panel.m_bBorder ) then
		self:DrawButtonBorder( 0, 0, panel:GetWide(), panel:GetTall(), panel.Depressed )
	end

end

function SKIN:SchemeButton( panel )

	panel:SetFont( "Default" )

end

/*---------------------------------------------------------
	SysButton
---------------------------------------------------------*/
function SKIN:PaintSysButton( panel )

	self:PaintButton( panel )

end

function SKIN:SchemeSysButton( panel )

	panel:SetFont( "Marlett" )

end


/*---------------------------------------------------------
	ImageButton
---------------------------------------------------------*/
function SKIN:PaintImageButton( panel )

	self:PaintButton( panel )

end
function SKIN:LayoutImageButton( panel )

	if ( panel.m_bBorder ) then
		panel.m_Image:SetPos( 1, 1 )
		panel.m_Image:SetSize( panel:GetWide()-2, panel:GetTall()-2 )
	else
		panel.m_Image:SetPos( 0, 0 )
		panel.m_Image:SetSize( panel:GetWide(), panel:GetTall() )
	end

	

end

/*---------------------------------------------------------
	PaneList
---------------------------------------------------------*/
function SKIN:PaintPanelList( panel )

	draw.RoundedBox( 4, 0, 0, panel:GetWide(), panel:GetTall(), self.bg_color_dark )

end

/*---------------------------------------------------------
	ScrollBar
---------------------------------------------------------*/
function SKIN:PaintVScrollBar( panel )

	surface.SetDrawColor( self.bg_color.r, self.bg_color.g, self.bg_color.b, self.bg_color.a )
	surface.DrawRect( 0, 0, panel:GetWide(), panel:GetTall() )

end
function SKIN:LayoutVScrollBar( panel )

	local Wide = panel:GetWide()
	local Scroll = panel:GetScroll()
	local BarSize = panel:BarScale() * (panel:GetTall() - (Wide * 2))
	local Track = panel:GetTall() - (Wide * 2) - BarSize
	Track = Track + 1
	
	Scroll = Scroll * Track
	
	panel.btnGrip:SetPos( 0, Wide + Scroll )
	panel.btnGrip:SetSize( Wide, BarSize )
	
	panel.btnUp:SetPos( 0, 0, Wide, Wide )
	panel.btnUp:SetSize( Wide, Wide )
	
	panel.btnDown:SetPos( 0, panel:GetTall() - Wide, Wide, Wide )
	panel.btnDown:SetSize( Wide, Wide )

end

/*---------------------------------------------------------
	ScrollBar
---------------------------------------------------------*/
function SKIN:PaintScrollBarGrip( panel )

	surface.SetDrawColor( self.control_color.r, self.control_color.g, self.control_color.b, self.control_color.a )
	surface.DrawRect( 0, 0, panel:GetWide(), panel:GetTall() )

	self:DrawButtonBorder( 0, 0, panel:GetWide(), panel:GetTall() )

end


/*---------------------------------------------------------
	ScrollBar
---------------------------------------------------------*/
function SKIN:PaintMenu( panel )

	local w = panel:GetWide()
	local h = panel:GetTall()
	
	surface.SetDrawColor( 255, 255, 255, 240 )
	surface.DrawRect( 0, 0, w, h )
	
	surface.SetDrawColor( 0, 0, 0, 200 )
	surface.DrawOutlinedRect( 0, 0, w, h )

end
function SKIN:LayoutMenu( panel )
	
	
	
	local w = panel:GetMinimumWidth()
	
	// Find the widest one
	for k, pnl in pairs( panel.Panels ) do
	
		pnl:PerformLayout()
		w = math.max( w, pnl:GetWide() )
	
	end
	
	// Allow 1 px border around the whole thing
	panel:SetWide( w + 2 )
	
	local y = 1
	
	for k, pnl in pairs( panel.Panels ) do
	
		pnl:SetWide( w )
		pnl:SetPos( 1, y )
		pnl:PerformLayout()
		
		y = y + pnl:GetTall()
	
	end
	
	panel:SetTall( y + 1 )

end

/*---------------------------------------------------------
	ScrollBar
---------------------------------------------------------*/
function SKIN:PaintMenuOption( panel )

	if ( panel.m_bBackground && panel.Hovered ) then
	
		local col = nil
		
		if ( panel.Depressed ) then
			col = self.control_color_bright
		else
			col = self.control_color_active
		end
		
		surface.SetDrawColor( col.r, col.g, col.b, col.a )
		surface.DrawRect( 0, 0, panel:GetWide(), panel:GetTall() )
	
	end
	
end
function SKIN:LayoutMenuOption( panel )

	// The menu takes care of the width
	panel:SetTall( 18 )
	
end
function SKIN:SchemeMenuOption( panel )

	panel:SetFGColor( 40, 40, 40, 255 )
	
end


/*---------------------------------------------------------
	TextEntry
---------------------------------------------------------*/
function SKIN:PaintTextEntry( panel )

	if ( panel.m_bBackground ) then
	
		surface.SetDrawColor( 240, 240, 240, 255 )
		surface.DrawRect( 0, 0, panel:GetWide(), panel:GetTall() )
	
	end
	
	panel:DrawTextEntryText( panel.m_colText, panel.m_colHighlight, panel.m_colCursor )
	
	if ( panel.m_bBorder ) then
	
		surface.SetDrawColor( 20, 20, 20, 255 )
		surface.DrawOutlinedRect( 0, 0, panel:GetWide(), panel:GetTall() )
	
	end

	
end
function SKIN:SchemeTextEntry( panel )

	panel:SetTextColor( Color( 20, 20, 20, 255 ) )
	panel:SetHighlightColor( Color( 20, 200, 250, 255 ) )
	panel:SetCursorColor( Color( 0, 0, 100, 255 ) )

end

/*---------------------------------------------------------
	Label
---------------------------------------------------------*/
function SKIN:PaintLabel( panel )
	return false
end

function SKIN:SchemeLabel( panel )

	local col = panel:GetTextColor()
	if ( col ) then
	
		panel:SetFGColor( col.r, col.g, col.b, col.a )
	
	else
	
		panel:SetFGColor( 200, 200, 200, 255 )
	
	end

end



derma.DefineSkin( "Default", "Made to look like regular VGUI", SKIN )