Skip to content

Commit

Permalink
add frame blur using material and frameCornerRadius config value
Browse files Browse the repository at this point in the history
  • Loading branch information
plally committed Aug 3, 2023
1 parent 074adf6 commit 6548943
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lua/mapvote/client/modules/style_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ MapVote.style = {
colorGreen = Color( 166, 227, 161 ),
colorPurple = Color( 203, 166, 247 ),
colorCloseButton = Color( 240, 62, 92 ),
frameBlurLevel = 0,
frameBackgroundBlur = 0,
frameBlur = 0, -- if using a non transparent color this should always be 0
frameCornerRadius = 5,
configLabelFont = "MapVote_ConfigNameLabel",
mapVoteTitleFont = "MapVote_Title",

Expand Down
24 changes: 22 additions & 2 deletions lua/mapvote/client/vgui/frame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ function PANEL:SetHideOnClose( hide )
end

function PANEL:Init()
local blur = MapVote.style.frameBlur or 0
if blur > 0 then
self.blurMat = Material( "pp/blurscreen" )
self.blurMat:SetFloat( "$blur", blur )
self.blurMat:Recompute()
end

local circleSegments = 30
self.btnClose:SetSize( 25, 25 )
---@diagnostic disable-next-line: duplicate-set-field
Expand Down Expand Up @@ -81,10 +88,23 @@ function PANEL:Init()
end

function PANEL:Paint( w, h )
for _ = 1, MapVote.style.frameBlurLevel do
for _ = 1, MapVote.style.frameBackgroundBlur do
Derma_DrawBackgroundBlur( self, self.m_fCreateTime )
end
draw.RoundedBox( 10, 0, 0, w, h, MapVote.style.colorPrimaryBG )
self:ApplyBlur()
draw.RoundedBox( MapVote.style.frameCornerRadius, 0, 0, w, h, MapVote.style.colorPrimaryBG )
end

function PANEL:ApplyBlur()
if not self.blurMat then return end

surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( self.blurMat )

render.UpdateScreenEffectTexture()

local x, y = self:LocalToScreen( 0, 0 )
surface.DrawTexturedRect( -x, -y, ScrW(), ScrH())
end

vgui.Register( "MapVote_Frame", PANEL, "DFrame" )

0 comments on commit 6548943

Please sign in to comment.