new post | browse code | authors | help | about

LuaBin 2.0

Viewing file root / lua / vgui / Material.lua

  1.  
  2. local PANEL = {}
  3.  
  4. /*---------------------------------------------------------
  5.    Name: Init
  6. ---------------------------------------------------------*/
  7. function PANEL:Init()
  8.  
  9.         self.Material = nil
  10.         self.AutoSize = true
  11.         self:SetAlpha( 255 )
  12.        
  13.         self:SetMouseInputEnabled( false )
  14.         self:SetKeyboardInputEnabled( false )
  15.        
  16. end
  17.  
  18.  
  19. /*---------------------------------------------------------
  20.    Name: Paint
  21. ---------------------------------------------------------*/
  22. function PANEL:Paint()
  23.        
  24.         if (!self.Material) then return true end
  25.        
  26.         surface.SetMaterial( self.Material )
  27.         surface.SetDrawColor( 255, 255, 255, self.Alpha )
  28.         surface.DrawTexturedRect( 0, 0, self:GetWide(), self:GetTall() )
  29.        
  30.         return true
  31.        
  32. end
  33.  
  34.  
  35. /*---------------------------------------------------------
  36.    Name: SetAlpha
  37. ---------------------------------------------------------*/
  38. function PANEL:SetAlpha( _alpha_ )
  39.  
  40.         self.Alpha = _alpha_
  41.        
  42. end
  43.  
  44.  
  45. /*---------------------------------------------------------
  46.    Name: SetMaterial
  47. ---------------------------------------------------------*/
  48. function PANEL:SetMaterial( _matname_ )
  49.        
  50.         //self.Material = surface.GetTextureID( _matname_ )
  51.        
  52.         self.Material = Material( _matname_ )
  53.         local Texture = self.Material:GetMaterialTexture( "$basetexture" )
  54.         if ( Texture ) then
  55.                 self.Width = Texture:GetActualWidth()
  56.                 self.Height = Texture:GetActualHeight()
  57.         else
  58.                 self.Width = 32
  59.                 self.Height = 32
  60.         end
  61.        
  62.         self:InvalidateLayout()
  63.        
  64. end
  65.  
  66.  
  67. /*---------------------------------------------------------
  68.    Name: PerformLayout
  69. ---------------------------------------------------------*/
  70. function PANEL:PerformLayout()
  71.  
  72.         if (!self.Material) then return end
  73.         if (!self.AutoSize) then return end
  74.        
  75.         self:SetSize( self.Width, self.Height )
  76.  
  77. end
  78.  
  79.  
  80. vgui.Register( "Material", PANEL, "Button" )