Advertisement
Guest User

Untitled

a guest
Nov 1st, 2016
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. concommand.Add("triangle", function(ply)
  2.   local w = 500
  3.   local h = 500
  4.  
  5.   local frame = vgui.Create("DFrame")
  6.   frame:SetSize(w, h)
  7.   frame.triangle = {
  8.     { x = w/2, y = 0 },
  9.     { x = w, y = h },
  10.     { x = 0, y = h }
  11.   }
  12.   frame:Center()
  13.   frame:MakePopup()
  14.   frame.Paint = function(pnl, w, h)
  15.     surface.SetDrawColor(20, 20, 20)
  16.     surface.DrawRect(0, 0, w, h)
  17.  
  18.     draw.NoTexture()
  19.     surface.SetDrawColor(40, 40, 40)
  20.     surface.DrawPoly(pnl.triangle)
  21.   end
  22.  
  23.   local avatar = vgui.Create("triangleAvatar", frame);
  24.   avatar:SetSize(64, 64);
  25.   avatar:SetPos(w/2 - avatar:GetWide()/2, h/2 - avatar:GetTall());
  26.   avatar:SetPlayer(LocalPlayer(), 128);
  27.   avatar:SetReserve(true);
  28. end)
  29.  
  30. local function drawTriangle(w, h, reserve)
  31.   local tbl = {}
  32.  
  33.   if (reserve) then
  34.     tbl = {
  35.       { x = 0, y = 0 },
  36.       { x = w, y = 0 },
  37.       { x = w/2, y = h }
  38.     }
  39.   else
  40.     tbl = {
  41.       { x = w/2, y = 0 },
  42.       { x = w, y = h },
  43.       { x = 0, y = h }
  44.     }
  45.   end
  46.  
  47.   surface.DrawPoly(tbl)
  48. end
  49. local PANEL = {}
  50.  
  51. function PANEL:Init()
  52.   self.avatar = vgui.Create( "AvatarImage", self )
  53.   self.avatar:SetPaintedManually( true )
  54. end
  55.  
  56. function PANEL:PerformLayout()
  57.   self.avatar:SetSize( self:GetWide(), self:GetTall() )
  58. end
  59.  
  60. function PANEL:SetPlayer( ply, size )
  61.   self.avatar:SetPlayer( ply, size )
  62. end
  63.  
  64. function PANEL:SetReserve(bool)
  65.   self.avatar.Direction = bool;
  66. end
  67.  
  68. function PANEL:Paint( w, h )
  69.   render.ClearStencil()
  70.   render.SetStencilEnable( true )
  71.  
  72.   render.SetStencilWriteMask( 1 )
  73.   render.SetStencilTestMask( 1 )
  74.  
  75.   render.SetStencilFailOperation( STENCILOPERATION_REPLACE )
  76.   render.SetStencilPassOperation( STENCILOPERATION_ZERO )
  77.   render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
  78.   render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_NEVER )
  79.   render.SetStencilReferenceValue( 1 )
  80.  
  81.   draw.NoTexture()
  82.   surface.SetDrawColor(color_white)
  83.   drawTriangle(w, h, self.avatar.Direction);
  84.  
  85.   render.SetStencilFailOperation( STENCILOPERATION_ZERO )
  86.   render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
  87.   render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
  88.   render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
  89.   render.SetStencilReferenceValue( 1 )
  90.  
  91.   self.avatar:PaintManual()
  92.  
  93.   render.SetStencilEnable( false )
  94.   render.ClearStencil()
  95. end
  96. vgui.Register( "triangleAvatar", PANEL )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement