Advertisement
TheXnator

Untitled

Jul 11th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. local PANEL = {}
  2. PANEL.Done = false
  3. PANEL.maskSize = 16 --Default for 32
  4.  
  5. function PANEL:Init()
  6.     self.Avatar = vgui.Create("AvatarImage", self)
  7.     self.Avatar:SetPaintedManually(true)
  8. end
  9.  
  10. function PANEL:PerformLayout()
  11.     self.Avatar:SetSize(self:GetWide(), self:GetTall())
  12. end
  13.  
  14. function PANEL:SetMaskSize(size)
  15.     self.maskSize = size
  16. end
  17.  
  18. function PANEL:Paint(w, h)
  19.     if ( self.Done == true ) then
  20.         return
  21.     end
  22.  
  23.     render.ClearStencil()
  24.     render.SetStencilEnable(true)
  25.  
  26.     render.SetStencilWriteMask( 1 )
  27.     render.SetStencilTestMask( 1 )
  28.  
  29.     render.SetStencilFailOperation( STENCIL_REPLACE )
  30.     render.SetStencilPassOperation( STENCIL_ZERO )
  31.     render.SetStencilZFailOperation( STENCIL_ZERO )
  32.     render.SetStencilCompareFunction( STENCIL_NEVER )
  33.     render.SetStencilReferenceValue( 1 )
  34.  
  35.      draw.RoundedBox(18, 0, 0, w, h, color_white)
  36.  
  37.     render.SetStencilFailOperation( STENCIL_ZERO )
  38.     render.SetStencilPassOperation( STENCIL_REPLACE )
  39.     render.SetStencilZFailOperation( STENCIL_ZERO )
  40.     render.SetStencilCompareFunction( STENCIL_EQUAL ) -- STENCILCOMPARISONFUNCTION_EQUAL will only draw what you draw as the mask.
  41.     render.SetStencilReferenceValue( 1 )
  42.  
  43.     self.Avatar:SetPaintedManually(false)
  44.     self.Avatar:PaintManual()
  45.     self.Avatar:SetPaintedManually(true)
  46.  
  47.     render.SetStencilEnable(false)
  48.     render.ClearStencil()
  49.  
  50.     self.Done = true
  51. end
  52.  
  53. function PANEL:SetPlayer(ply, size)
  54.     self.Avatar:SetPlayer(ply, size)
  55. end
  56.  
  57. function PANEL:SetSteamID(steamid, size)
  58.     self.Avatar:SetSteamID(util.SteamIDTo64(steamid), size)
  59. end
  60.  
  61. vgui.Register("FancyAvatarImage", PANEL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement