Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local PANEL = {}
- function PANEL:Init()
- self.icon = vgui.Create("AvatarImage", self)
- self.icon:SetPos(0, 0)
- self.icon:SetSize(1, 1)
- self.icon:NoClipping(true)
- self.icon:SetPaintedManually(true)
- self.segments = 24
- self.rotation = 0
- self:MakePoly(self:GetWide(), self:GetTall())
- end
- function PANEL:SetCircleSegments(segments)
- self.segments = segments
- self:MakePoly(self:GetWide(), self:GetTall())
- end
- function PANEL:SetRotation(rotation)
- self.rotation = rotation * math.pi / 180
- self:MakePoly(self:GetWide(), self:GetTall())
- end
- function PANEL:MakePoly(w, h)
- local poly = {}
- for i = self.rotation, self.rotation + math.pi * 2 - 0.001, math.pi * 2 / self.segments do
- poly[#poly + 1] = {
- x = math.cos(i)*w/2 + w/2,
- y = math.sin(i)*h/2 + h/2,
- u = math.cos(i)/2+0.5,
- v = math.sin(i)/2+0.5
- }
- end
- self.poly = poly
- end
- function PANEL:PerformLayout()
- local w, h = self:GetWide(), self:GetTall()
- self.icon:SetPos(w/2, h/2)
- self:MakePoly(w, h)
- end
- function PANEL:SetPlayer(ply, size)
- self.icon:SetPlayer(ply, size)
- end
- function PANEL:Paint(w, h)
- if not self.poly or not self.icon then return end
- self.icon:PaintManual()
- surface.DrawPoly(self.poly)
- end
- vgui.Register("DPolyAvatar", PANEL)
Advertisement
Add Comment
Please, Sign In to add comment