--[[
	lua/autorun/client/OubHack/vgui/oh_DPowerToggle.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
*******************************************************************************/

-- Tab used at the top of the screen.

local PANEL = {}

PANEL.AColour = Color(255,255,255,255)
PANEL.DAColour = Color(0,0,0,255)

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


function PANEL:Init()
	self.Active = true;
	self.DeactiveTitle = "Deactivated"
	self.ActiveTitle = "Activated"
	self.Color = Color(0,255,0,255)
	self.OffsetW = 15
	self.Move = -1
	self.Hdin = false;
end

function PANEL:SetDeactiveTitle(title)
	self.DeactiveTitle = title
end

function PANEL:SetActiveTitle(title)
	self.ActiveTitle = title
end

function PANEL:SetActive(bool)
	self.Active = bool
end

function PANEL:LogPos(x,y)
	self.XX = x;
	self.YY = y;
end

function PANEL:Hide()
	self.Move = -2
	self.Hiding = true;
end

function PANEL:Show()
	self.Move = -1
	self.Hiding = false;
end

surface.CreateFont ("ScoreboardText", ScreenScale(5), 400, true, false, "oh_small")
surface.CreateFont ("ScoreboardText", ScreenScale(10), 400, true, false, "oh_large")
function PANEL:Paint()
	local x,y = 2,0
	local w,h = self.OffsetW,self:GetTall()
	if self.Move == -1 then
		self:SetSize(self.OffsetW,self:GetTall())
		self:SetPos(self.XX-self.OffsetW+10,y)
	elseif self.Move >= 0 then
		self:SetSize(self.OffsetW+5,self:GetTall())
		self:SetPos(self.XX-self.OffsetW,y)
	elseif self.Move == -2 then
		self:SetPos(self.XX-self.OffsetW+10,y)
	end
	
	if self.OffsetW != 15 then -- Only draw if it's not hiding (15px)
		local scale = math.Clamp( h/(ScrH()*0.25), 0, 1 )
		surface.SetDrawColor( self.Color.r, 0, 0, 80+80*scale )
		surface.SetTexture( Gradient )
		surface.DrawTexturedRect( x+2, y+2, w-4, h*0.75 )
		
		local scale = math.Clamp( h/(ScrH()*0.25), 0, 1 )
		surface.SetDrawColor( 0, self.Color.g, 0, 80+80*scale )
		surface.SetTexture( Gradient_UP )
		surface.DrawTexturedRect( x+2, y+2, w-4, h )
		
			surface.SetDrawColor(self.Color)
		surface.DrawRect( x+1, y+1, w-2, 1 ) 
		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+2, 1, h-2 )
	end
	if self.OffsetW > 140 then 
		draw.DrawText("OubHack" or "", "oh_large", w/2,h/2, self.Color,TEXT_ALIGN_LEFT)
	end
	if self.OffsetW > 70 then
		
		if self.Active then
			draw.DrawText(self.ActiveTitle or "", "ScoreboardText", 5,5, self.AColour,TEXT_ALIGN_LEFT)
		else
			if self.OffsetW > 100 then
			draw.DrawText(self.DeactiveTitle or "", "ScoreboardText", w-(w/2)-30,h-20, self.DAColour,TEXT_ALIGN_LEFT)
			end
		end
	end
	-- surface.SetDrawColor(self.OutlineColour)
	-- surface.DrawRect( x+1, y+1, w-2, 1 ) 
	-- 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 )
	

	if self.Active then
		self.Color.g = math.Approach(self.Color.g,255,25)
		self.Color.r = math.Approach(self.Color.r,0,25)
	else
		self.Color.g = math.Approach(self.Color.g,0,25)
		self.Color.r = math.Approach(self.Color.r,255,25)
	end

	if self.Move == 1 then
		self.OffsetW = math.Approach(self.OffsetW,150,10)
		if self.OffsetW == 150 then self.Move = 0 end
	elseif self.Move == -1 then
		self.OffsetW = math.Approach(self.OffsetW,50,10)
		if self.OffsetW == 50 then self.Move = 0 end
	elseif self.Move == -2 then 
		self.OffsetW = math.Approach(self.OffsetW,15,10)
	end


end


function PANEL:OnCursorEntered()
	if self.Hiding then return false end
	self.Move = 1 
end
 
 
function PANEL:OnCursorExited()
	if self.Hiding then return false end
	self.Move = -1
end

function PANEL:OnMousePressed()
	if self.Hiding then return false end
	if self.Active then
		self.Active = false;
	else
		self.Active = true;
	end
	if self.DoClick and type(self.DoClick) == "function" then self.DoClick() end
end
oubhack:RegisterVgui("oh_DPowerToggle",PANEL,"DPanel")