Change derma panel shape

Hi everyone !

Basically I want to know how to change the shape of a derma panel ^^
Like it is normally a square/rectangle. Would like for example a triangle… Thanks ^^

Bye c:

EDIT

I should maybe have posted this in “Problems that don’t need their own thread”. Sorry.

Look into

and

You could technically fake it by simply overwriting your frames Paint call and in that you draw a triangle using surface.DrawPoly

[editline]METAMIST IS GAY LUL[/editline]

https://vgy.me/FQtdLN.jpg

[lua]
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)
draw.NoTexture()
surface.SetDrawColor(20, 20, 20, 200)
surface.DrawPoly(pnl.triangle)
end
end)
[/lua]

But how do I use something like Category:AvatarImage on a surface.DrawPoly ?

https://vgy.me/RymaD8.png

Link to pastebin where spacing aren’t messed up (blame Atom.io)



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 )


Thank you for this. But is there a way to just show the avatar on the HUD using surface.DrawRect (or something like that). I don’t really need to have the derma. I could maybe try to hide the derme… but would be better just have a surface.Something() with the avatar on it ^^

EDIT

Sorry for being annoying ! :c

The DFrame element is not required. You can remove it.

So can the player’s avatar be a texture or a material ?

https://vgy.me/OmGpZW.jpg

Made an enhanced avatar image.

Use PANEL:SetType(type [int], direction [bool]) on your enhanced avatar panel.

Here’s the 5 different numbers you can choose for type.

  1. Hexagon
  2. Triangle
  3. Circle
  4. Square
  5. Pentagon

Direction is optional, it defaults to false if not set.
Panel defaults to square if you don’t set anything.
Only hexagon (1) and triangle (2) have support for direction.

Pastebin with only EnhancedAvatarImage panel

[lua]
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(“EnhancedAvatarImage”, frame);
avatar:SetSize(128, 128);
avatar:SetPos(w/2 - avatar:GetWide()/2, h/2 - avatar:GetTall());
avatar:SetPlayer(LocalPlayer(), 128);
avatar:SetType(1, false);
end)

local PANEL = {}

function PANEL:DrawHexagon(w, h)
local tbl = {};

if (self.avatar.direction) then
tbl = {
{ x = w/2, y = 0 },
{ x = w, y = h/2 - h/4 },
{ x = w, y = h/2 + h/4 },
{ x = w/2, y = h },
{ x = 0, y = h/2 + h/4 },
{ x = 0, y = h/2 - h/4 }
}
else
tbl = {
{ x = w/2 - w/4, y = 0 },
{ x = w/2 + w/4, y = 0 },
{ x = w, y = h/2 },
{ x = w/2 + w/4, y = h },
{ x = w/2 - w/4, y = h },
{ x = 0, y = h/2 }
}
end

surface.DrawPoly(tbl);
end

function PANEL:DrawTriangle(w, h)
local tbl = {}

if (self.avatar.direction) 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

function PANEL:DrawCircle(w, h)
local x = w/2;
local y = h/2;
local radius = h/2;
local seg = 360;

local cir = {}
table.insert( cir, { x = x, y = y } )
for i = 0, seg do
local a = math.rad( ( i / seg ) * -360 )
table.insert( cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius } )
end
local a = math.rad( 0 )
table.insert( cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius } )
surface.DrawPoly( cir )
end

function PANEL:DrawSquare(w, h)
local tbl = {
{ x = 0, y = 0 },
{ x = w, y = 0 },
{ x = w, y = h },
{ x = 0, y = h }
}

surface.DrawPoly(tbl);
end

function PANEL:DrawPentagon(w, h)
local tbl = {
{ x = w/2, y = 0 },
{ x = w, y = h * 0.4 },
{ x = w - w/5, y = h },
{ x = 0 + w/5, y = h },
{ x = 0, y = h * 0.4 }
}

surface.DrawPoly(tbl);
end

function PANEL:Init()
self.avatar = vgui.Create( “AvatarImage”, self )
self.avatar:SetPaintedManually( true )
self.avatar.type = 4; – default to square
self.avatar.direction = false;
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:SetType(type, direction)
self.avatar.type = type;
self.avatar.direction = direction;
end

function PANEL:GetType()
local type = self.avatar.type;
local direction = self.avatar.direction;

return type, direction;
end

function PANEL:DrawPolygon(w, h)
local type, direction = self:GetType();

if (type == 1) then self:DrawHexagon(w, h); end
if (type == 2) then self:DrawTriangle(w, h); end
if (type == 3) then self:DrawCircle(w, h); end
if (type == 4) then self:DrawSquare(w, h); end
if (type == 5) then self:DrawPentagon(w, h); end
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)
self:DrawPolygon(w, h);

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( “EnhancedAvatarImage”, PANEL )

hook.Add(“HUDPaint”, “mycoolhud!!!”, function()
local scrH = ScrH();

if (!IsValid(MyHUD_Avatar)) then
MyHUD_Avatar = vgui.Create(“EnhancedAvatarImage”);
MyHUD_Avatar:SetSize(128, 128);
MyHUD_Avatar:SetPos(5, scrH/2 - MyHUD_Avatar:GetTall() / 2);
MyHUD_Avatar:SetType(5, true);
MyHUD_Avatar:SetPlayer(LocalPlayer(), 128);
end
end)
[/lua]