Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- concommand.Add("triangle", function(ply)
- local w = 500
- local h = 500
- local frame = vgui.Create("DFrame")
- frame:SetSize(w, h)
- frame.triangle = {
- { x = w/2, y = 0 },
- { x = w, y = h },
- { x = 0, y = h }
- }
- frame:Center()
- frame:MakePopup()
- frame.Paint = function(pnl, w, h)
- surface.SetDrawColor(20, 20, 20)
- surface.DrawRect(0, 0, w, h)
- draw.NoTexture()
- surface.SetDrawColor(40, 40, 40)
- surface.DrawPoly(pnl.triangle)
- end
- local avatar = vgui.Create("triangleAvatar", frame);
- avatar:SetSize(64, 64);
- avatar:SetPos(w/2 - avatar:GetWide()/2, h/2 - avatar:GetTall());
- avatar:SetPlayer(LocalPlayer(), 128);
- avatar:SetReserve(true);
- end)
- local function drawTriangle(w, h, reserve)
- local tbl = {}
- if (reserve) then
- tbl = {
- { x = 0, y = 0 },
- { x = w, y = 0 },
- { x = w/2, y = h }
- }
- else
- tbl = {
- { x = w/2, y = 0 },
- { x = w, y = h },
- { x = 0, y = h }
- }
- end
- surface.DrawPoly(tbl)
- end
- local PANEL = {}
- function PANEL:Init()
- self.avatar = vgui.Create( "AvatarImage", self )
- self.avatar:SetPaintedManually( true )
- end
- function PANEL:PerformLayout()
- self.avatar:SetSize( self:GetWide(), self:GetTall() )
- end
- function PANEL:SetPlayer( ply, size )
- self.avatar:SetPlayer( ply, size )
- end
- function PANEL:SetReserve(bool)
- self.avatar.Direction = bool;
- end
- function PANEL:Paint( w, h )
- render.ClearStencil()
- render.SetStencilEnable( true )
- render.SetStencilWriteMask( 1 )
- render.SetStencilTestMask( 1 )
- render.SetStencilFailOperation( STENCILOPERATION_REPLACE )
- render.SetStencilPassOperation( STENCILOPERATION_ZERO )
- render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
- render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_NEVER )
- render.SetStencilReferenceValue( 1 )
- draw.NoTexture()
- surface.SetDrawColor(color_white)
- drawTriangle(w, h, self.avatar.Direction);
- render.SetStencilFailOperation( STENCILOPERATION_ZERO )
- render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
- render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
- render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
- render.SetStencilReferenceValue( 1 )
- self.avatar:PaintManual()
- render.SetStencilEnable( false )
- render.ClearStencil()
- end
- vgui.Register( "triangleAvatar", PANEL )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement