
local PANEL = {}

/*---------------------------------------------------------
   Name: Init
---------------------------------------------------------*/
function PANEL:Init()

	self.Material = nil
	self:SetAlpha( 255 )
	
	self:SetMouseInputEnabled( false )
	self:SetKeyboardInputEnabled( false )
	
end


/*---------------------------------------------------------
   Name: Paint
---------------------------------------------------------*/
function PANEL:Paint()
	
	if (!self.Material) then return true end
	
	surface.SetTexture( self.Material )
	surface.SetDrawColor( 255, 255, 255, self.Alpha )
	surface.DrawTexturedRect( 0, 0, self.Width, self.Height ) 
	
	return true
	
end


/*---------------------------------------------------------
   Name: SetAlpha
---------------------------------------------------------*/
function PANEL:SetAlpha( _alpha_ )

	self.Alpha = _alpha_
	
end


/*---------------------------------------------------------
   Name: SetMaterial
---------------------------------------------------------*/
function PANEL:SetMaterial( _matname_ )
	
	self.Material = surface.GetTextureID( _matname_ )
	
	local Mat = Material( _matname_ )
	local Texture = Mat:GetMaterialTexture( "$basetexture" )
	
	self.Width = Texture:GetActualWidth()
	self.Height = Texture:GetActualHeight()
	
	self:InvalidateLayout()
	
end


/*---------------------------------------------------------
   Name: PerformLayout
---------------------------------------------------------*/
function PANEL:PerformLayout()

	if (!self.Material) then return end
	self:SetSize( self.Width, self.Height )

end


vgui.Register( "Material", PANEL, "Panel" )