Thomasims

DPolyAvatar

Dec 30th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. local PANEL = {}
  2.  
  3. function PANEL:Init()
  4.     self.icon = vgui.Create("AvatarImage", self)
  5.     self.icon:SetPos(0, 0)
  6.     self.icon:SetSize(1, 1)
  7.     self.icon:NoClipping(true)
  8.     self.icon:SetPaintedManually(true)
  9.     self.segments = 24
  10.     self.rotation = 0
  11.     self:MakePoly(self:GetWide(), self:GetTall())
  12. end
  13.  
  14. function PANEL:SetCircleSegments(segments)
  15.     self.segments = segments
  16.     self:MakePoly(self:GetWide(), self:GetTall())
  17. end
  18.  
  19. function PANEL:SetRotation(rotation)
  20.     self.rotation = rotation * math.pi / 180
  21.     self:MakePoly(self:GetWide(), self:GetTall())
  22. end
  23.  
  24. function PANEL:MakePoly(w, h)
  25.     local poly = {}
  26.    
  27.     for i = self.rotation, self.rotation + math.pi * 2 - 0.001, math.pi * 2 / self.segments do
  28.         poly[#poly + 1] = {
  29.             x = math.cos(i)*w/2 + w/2,
  30.             y = math.sin(i)*h/2 + h/2,
  31.             u = math.cos(i)/2+0.5,
  32.             v = math.sin(i)/2+0.5
  33.         }
  34.     end
  35.    
  36.     self.poly = poly
  37. end
  38.  
  39. function PANEL:PerformLayout()
  40.     local w, h = self:GetWide(), self:GetTall()
  41.     self.icon:SetPos(w/2, h/2)
  42.     self:MakePoly(w, h)
  43. end
  44.  
  45. function PANEL:SetPlayer(ply, size)
  46.     self.icon:SetPlayer(ply, size)
  47. end
  48.  
  49. function PANEL:Paint(w, h)
  50.     if not self.poly or not self.icon then return end
  51.     self.icon:PaintManual()
  52.     surface.DrawPoly(self.poly)
  53. end
  54.  
  55. vgui.Register("DPolyAvatar", PANEL)
Advertisement
Add Comment
Please, Sign In to add comment