--[[
	lua/autorun/client/OubHack/oubhack_skin.lua
	Oubliette | (STEAM_0:1:34029133)
	===DStream===
]]

/******************************************************************************
 .d88888b.  888     888 888888b.   888    888        d8888  .d8888b.  888    d8P  
d88P" "Y88b 888     888 888  "88b  888    888       d88888 d88P  Y88b 888   d8P   
888     888 888     888 888  .88P  888    888      d88P888 888    888 888  d8P    
888     888 888     888 8888888K.  8888888888     d88P 888 888        888d88K     
888     888 888     888 888  "Y88b 888    888    d88P  888 888        8888888b    
888     888 888     888 888    888 888    888   d88P   888 888    888 888  Y88b   
Y88b. .d88P Y88b. .d88P 888   d88P 888    888  d8888888888 Y88b  d88P 888   Y88b  
 "Y88888P"   "Y88888P"  8888888P"  888    888 d88P     888  "Y8888P"  888    Y88b 
 By Oubliete and UnknownAlias
*******************************************************************************/
-- Skin
local SKIN = {}

SKIN.Author = "Oubliette";

local Gradient = surface.GetTextureID( "gui/gradient_down" )
local Gradient_UP = surface.GetTextureID( "gui/gradient_up" )

local texgrad = Material("gui/gradient_down")
local texgrad_up = Material("gui/gradient_up")

SKIN.TransB = Color( 180, 180, 180, 50 )

SKIN.PropSheet = Color( 100, 100, 100, 140 )
SKIN.Tab = SKIN.PropSheet
SKIN.TabInactive = Color( 80,80, 80, 120 )

SKIN.bg_color = Color( 20, 20, 20, 120 )
SKIN.bg_color_sleep = Color( 50, 50, 50, 120 )
SKIN.bg_color_dark = Color( 0, 0, 0, 160 )
SKIN.bg_color_bright = Color( 70, 70, 70, 140 )

SKIN.bg_color_alt = Color(0,20,0)

SKIN.lv_hover = Color( 20, 255, 20, 120 )
SKIN.lv_seleceted = Color( 20, 255, 20, 200 )

local div4 = ScrH() * 0.25

function SKIN:DrawGenericBackground( x, y, w, h, color, skip_top, panel )
	-- Change the colours of everything if OubHack is in HideMode. 
	if panel and panel.State then
		if !oubhack.hidemode then
			panel.OutlineColor = Color(0,180,0,200)
			if panel.State == 1 then
				panel.Green = math.Approach(panel.Green or 0,180,15)
			elseif panel.State == 0 then
				panel.Green = math.Approach(panel.Green or 0,0,15)
			end
		else
			panel.OutlineColor = Color(180,0,0,200)
			if panel.State == 1 then
				panel.Red = math.Approach(panel.Red or 0,180,15)
			elseif panel.State == 0 then
				panel.Red = math.Approach(panel.Red or 0,0,15)
			end
		end
	end

	surface.SetDrawColor( color )
	surface.DrawRect( x, y, w, h )

	surface.SetDrawColor( 0, 0, 0, 120 )
	if !skip_top then surface.DrawRect( x, y, w-1, 1 ) end
	surface.DrawRect( x, y, 1, h-1 )
	surface.DrawRect( x, y+h-1, w, 1 )
	surface.DrawRect( x+w-1, y, 1, h-1 )
	-- Outline
	surface.SetDrawColor( panel.OutlineColor or Color(255,255,255,255) )
	if !skip_top then surface.DrawRect( x+1, y+1, w-2, 1 ) end
	surface.DrawRect( x+1, y+1, 1, h-2 )
	surface.DrawRect( x+1, y+h-2, w-2, 1 )
	surface.DrawRect( x+w-2, y+1, 1, h-2 )
	-- Gradient pattern
	local scale = math.Clamp( h/(ScrH()*0.25), 0, 1 )
	surface.SetDrawColor( 0, 0, 0, 20+80*scale )
	surface.SetTexture( oubhack.Grad_DOWN )
	surface.DrawTexturedRect( x+2, y+2, w-4, h*0.75 )
	surface.SetDrawColor( Color( panel.Red or 0, panel.Green or 0, 0, 20+80*scale ) );
	surface.SetTexture( oubhack.Grad_UP )
	surface.DrawTexturedRect( x+2, y+2, w-4, h )
	if panel and panel.ClassName == "DFrame" then	
		surface.SetDrawColor(panel.OutlineColor)
		surface.DrawRect( 0, 22, w, 1 )
		if !panel.DontDrawCatLines then
			surface.DrawRect( 200, 22, 1, h )
		end
	end
end

--[[
	Panels
			]]---
			
function SKIN:PaintPanel( panel )
	if panel.m_bPaintBackground then
		local w, h = panel:GetSize()
		self:DrawGenericBackground( 0, 0, w, h, panel.m_bgColor or self.TransB, false, panel )
	end	
end

--[[
	Frames
			]]---

function SKIN:PaintFrame( panel )
	local w, h = panel:GetWide(),panel:GetTall()
	self:DrawGenericBackground( 0, 0, w, h, self.TransB, false, panel )
end

--[[
	Property sheets
					]]---
					
function SKIN:PaintPropertySheet( panel )
	local ActiveTab = panel:GetActiveTab()
	local Offset = 0
	
	if ActiveTab then
		local w, h, padding = panel:GetWide(), panel:GetTall(), panel:GetPadding()
		Offset = ActiveTab:GetTall()
		surface.SetDrawColor( self.PropSheet )
		surface.SetTexture( oubhack.Grad_DOWN )
		surface.DrawTexturedRect( 2, Offset, w-4, h*0.75 )
		
		local tab = ActiveTab:GetWide()
		local x, _ = ActiveTab:GetPos()
		local tab_offset = -panel.tabScroller.pnlCanvas.x --panel.tabScroller.OffsetX
		local x1, x2 = math.Round( x+padding+1-tab_offset ), math.Round( x+padding+tab-2-tab_offset )
		surface.SetDrawColor( 200, 200, 200, 200 )
		local left, right = (x1 >= 0 and x1 <= w), (x2 >= 0 and x2 <= w)
		if left then
			surface.DrawRect( 2, Offset, x1-1, 1 )
			surface.DrawRect( x1, Offset, 1, 2 )
		end
		if right then
			surface.DrawRect( x2, Offset, w-x2-2, 1 )
			surface.DrawRect( x2, Offset, 1, 2 )
		end
		if !left and !right then
			surface.DrawRect( 2, Offset, w-4, 1 )
		end
	end
end

--[[
		  Tabs
					]]---

function SKIN:PaintTab( panel )
	local w, h = panel:GetWide(), panel:GetTall()
	if panel:GetPropertySheet():GetActiveTab() == panel then
		// Opened tabs
		surface.SetTexture( oubhack.Grad_UP )
		surface.SetDrawColor( SKIN.Tab )
		surface.DrawTexturedRect( 0, h*0.05, w, h*0.95 )
		surface.SetDrawColor( 200, 200, 200, 200 )
		surface.DrawTexturedRect( 1, 0, 1, h )
		surface.DrawTexturedRect( w-2, 0, 1, h )
	else
		// Closed tabs
		surface.SetDrawColor( SKIN.TabInactive )
		surface.SetTexture( oubhack.Grad_UP )
		surface.DrawTexturedRect( 0, h*0.30, w, h*0.70 )
		surface.SetDrawColor( 120, 120, 120, 120 )
		surface.DrawTexturedRect( 1, h*0.25, 1, h*0.75 )
		surface.DrawTexturedRect( w-2, h*0.25, 1, h*0.75 )
	end
end

--[[
		List veiws
						]]---
						
function SKIN:PaintPanelList( panel )
	if ( panel.m_bBackground ) then
		draw.RoundedBox( 4, 0, 0, panel:GetWide(), panel:GetTall(), Color(0,0,0,255) )
	end
end
function SKIN:PaintListView( panel )
	if ( panel.m_bBackground ) then
		local x,y = 0,0
		local w,h = panel:GetWide(),panel:GetTall()
		local scale = math.Clamp( panel:GetTall()/(ScrH()*0.25), 0, 1 )
		surface.SetDrawColor( 0, 0, 0, 120+80*scale )
		surface.SetTexture( oubhack.Grad_DOWN )
		surface.DrawTexturedRect( x, y+2, w, h*0.75 )
		
		surface.SetDrawColor(0,0,0,255)
		surface.DrawRect( x+1, y+1, 1, h-2 )
		surface.DrawRect( x+1, y+h-2, w-2, 1 )
		surface.DrawRect( x+w-1, y+1, 1, h-2 )
	end
end

function SKIN:PaintListViewLine( panel )
	local Col = nil
	if ( panel:IsSelected() ) then
			Col = self.lv_seleceted
	elseif ( panel.Hovered ) then
			Col = self.lv_hover
	elseif ( panel.m_bAlt ) then
			Col = self.bg_color_dark
	else
			return
	end
	surface.SetDrawColor( Col.r, Col.g, Col.b, Col.a )
	surface.SetMaterial(oubhack.TexGrad_DOWN)
	surface.DrawTexturedRect( 2, 1, panel:GetWide()-2, panel:GetTall() -2)
end



--[[
		Buttons
					]]--
					
function SKIN:SchemeButton( panel )
	panel:SetFont( "QDefaultSmall" )
	if ( panel:GetDisabled() ) then
		panel:SetTextColor( Color(0,255,0,255) )
	else
		panel:SetTextColor( Color(255,255,255,255) )
	end
	DLabel.ApplySchemeSettings( panel )
end

--[[
		Num Slider
		     		   ]]--

function SKIN:PaintNumSlider( panel )
    local w, h = panel:GetSize()
    self:DrawGenericBackground( 0, 0, w, h, Color( 255, 255, 255, 20 ), true, panel )
    surface.SetDrawColor( 0, 0, 0, 200 )
    surface.DrawRect( 3, h/2, w-6, 1 )
end

--[[
			Tool Tip
								]]--

function SKIN:PaintTooltip( panel )
		LocalPlayer():ChatPrint(" VAUBG")
        local w, h = panel:GetSize()
        self:DrawGenericBackground( 0, 0, w, h, self.bg_color, panel)
        panel:DrawArrow( 0, 0 )
end

derma.DefineSkin("oubhack",SKIN.Desc,SKIN)
