/*   _                                
    ( )                               
   _| |   __   _ __   ___ ___     _ _ 
 /'_` | /'__`\( '__)/' _ ` _ `\ /'_` )
( (_| |(  ___/| |   | ( ) ( ) |( (_| |
`\__,_)`\____)(_)   (_) (_) (_)`\__,_) 

	DImage

*/

PANEL = {}

AccessorFunc( PANEL, "m_Material", 	"Material" )
AccessorFunc( PANEL, "m_Color", 	"ImageColor" )

/*---------------------------------------------------------

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

	self:SetImageColor( Color( 255, 255, 255, 255 ) )
	self:SetMouseInputEnabled( false )
	self:SetKeyboardInputEnabled( false )
	
end


/*---------------------------------------------------------

---------------------------------------------------------*/
function PANEL:SetImage( strImage )

	local Mat = Material( strImage )
	local Texture = Mat:GetMaterialTexture( "$basetexture" )
	if ( Texture ) then
		self.ActualWidth = Texture:GetActualWidth()
		self.ActualHeight = Texture:GetActualHeight()
	else
		self.ActualWidth = 32
		self.ActualHeight = 32
	end
	
	self:SetMaterial( Mat )
	
end


/*---------------------------------------------------------

---------------------------------------------------------*/
function PANEL:SizeToContents( strImage )

	self:SetSize( self.ActualWidth, self.ActualHeight )

end


/*---------------------------------------------------------

---------------------------------------------------------*/
function PANEL:Paint()

	local Mat = self:GetMaterial()
	if (!Mat) then return true end

	surface.SetMaterial( Mat )
	surface.SetDrawColor( self.m_Color.r, self.m_Color.g, self.m_Color.b, self.m_Color.a )
	surface.DrawTexturedRect( 0, 0, self:GetWide(), self:GetTall() )
	return true

end



derma.DefineControl( "DImage", "A simple image", PANEL, "Panel" )