AvatarImage

– CHECK LAST POST (Has working Lua code there)

Hi, I’m trying to round the AvatarImage to make it circular, however I can’t seem to get it to work.
I’ve searched the forums on trying this and I’ve found a stencil code form “Handsome Matt”, Also some other code from someone else and joined them together however unsure if this is how it should go.

Sorry kind of a noob with this stencil stuff, I think the mask code should work however yet doesn’t. Any help is awesome, Thanks in advance.

I’d like to see how you do it if you do get it done.
It could be very useful, but I’ve not messed with stencils sorry :stuck_out_tongue:

What you mean by it doesnt work? Just saying “This doesnt work” without providing any lua errors or what its supposed to do doesnt allow us to help you.

Sorry about that, What I mean is no mask is applied the avatarimage is still it’s original shape and doesn’t change at all.

**EDIT —
**
So I now have it working I ditched the old method and just used drawPoly, I had some trouble getting the dam image showing.
Which I had to create some extra methods to the original code to set the “AvatarImage” (self.Avatar) which are at the bottom.

[Lua]
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:Paint(w, h)
render.ClearStencil() – some people are so messy
render.SetStencilEnable(true)

render.SetStencilWriteMask( 1 )
render.SetStencilTestMask( 1 )


render.SetStencilFailOperation( STENCIL_REPLACE )
render.SetStencilPassOperation( STENCIL_ZERO )
render.SetStencilZFailOperation( STENCIL_ZERO )
render.SetStencilCompareFunction( STENCIL_NEVER )
render.SetStencilReferenceValue( 1 )


-- draw your mask here, diamond, circle or whatever.
local triangle = {
}


surface.SetDrawColor(Color(225, 0, 0))
for a = 1, 15 do -- For extra aa
    for i = 0, 360, a do
        local _i = i * math.pi/180;
        local t = { x = math.cos(_i)*(25)+w/2, y = math.sin(_i)*(25)+h/2 }


        table.insert(triangle, t)
    end
end
draw.NoTexture()
surface.DrawPoly(triangle)


render.SetStencilFailOperation( STENCIL_ZERO )
render.SetStencilPassOperation( STENCIL_REPLACE )
render.SetStencilZFailOperation( STENCIL_ZERO )
render.SetStencilCompareFunction( STENCIL_EQUAL ) -- STENCILCOMPARISONFUNCTION_EQUAL will only draw what you draw as the mask.
render.SetStencilReferenceValue( 1 )


self.Avatar:SetPaintedManually(false)
self.Avatar:PaintManual()
self.Avatar:SetPaintedManually(true)


render.SetStencilEnable(false)
render.ClearStencil() -- you're welcome, bitch.

end

function PANEL:SetPlayer(ply, size)
self.Avatar:SetPlayer(ply, size)
end

function PANEL:SetSteamID( steamid, size)
self.Avatar:SetSteamID(steamid, size)
end

vgui.Register(“FancyAvatarImage”, PANEL)

[/lua]