From 576c32dad44a3efade1de613b35facd3dce5afe3 Mon Sep 17 00:00:00 2001 From: Tim Goll Date: Wed, 18 Oct 2023 13:26:23 +0200 Subject: [PATCH 1/5] untested first ideas --- .../terrortown/gamemode/shared/sh_init.lua | 1 + lua/ttt2/libraries/svg.lua | 123 ++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 lua/ttt2/libraries/svg.lua diff --git a/gamemodes/terrortown/gamemode/shared/sh_init.lua b/gamemodes/terrortown/gamemode/shared/sh_init.lua index b5fa6c803e..bef1b0e08f 100644 --- a/gamemodes/terrortown/gamemode/shared/sh_init.lua +++ b/gamemodes/terrortown/gamemode/shared/sh_init.lua @@ -550,6 +550,7 @@ include("ttt2/extensions/input.lua") include("ttt2/extensions/cvars.lua") -- include libraries +include("ttt2/libraries/svg.lua") include("ttt2/libraries/huds.lua") include("ttt2/libraries/hudelements.lua") include("ttt2/libraries/items.lua") diff --git a/lua/ttt2/libraries/svg.lua b/lua/ttt2/libraries/svg.lua new file mode 100644 index 0000000000..fc5a52af08 --- /dev/null +++ b/lua/ttt2/libraries/svg.lua @@ -0,0 +1,123 @@ +--- +-- svg library functions +-- Adds the possibility to render svg files as normal materials +-- @author Mineotopia +-- @author noaccessl +-- @module svg + +if SERVER then + AddCSLuaFile() + + return +end + +local stringFormat = string.format +local stringSub = string.sub +local stringFind = string.find +local stringLen = string.len +local fileRead = file.Read +local format = format +local match = match + +local svgTemplate = [[ + + + + + + %s + + +]] + +local function SetIfEmpty(haystack, needle, pos, needed) + if not stringFind(haystack, needle) then + return string.sub(haystack, 1, pos) .. needed .. string.sub(haystack, pos + string.len(needed)) + end + + return haystack +end + +local function GenerateHTMLElement(w, h, padding, strSVG) + -- make sure svg file has opening and closing tag + local open = string.find(strSVG, '') + local _, close = string.find(strSVG, '%s*$') + + if not open or not close then return end + + strSVG = stringSub(strSVG, open, close) + + -- todo make sure that the svg size in combination witht the padding works here + strSVG = SetIfEmpty(strSVG, "width='(.-)'", 5, "width='' ") + strSVG = SetIfEmpty(strSVG, "height='(.-)'", 5, "height='' ") + + strSVG = string.gsub(strSVG, "width='(.-)'", "width='" .. w - 2 * padding .. "'") + strSVG = string.gsub(strSVG, "height='(.-)'", "height='" .. h - 2 * padding .. "'") + + htmlElement = vgui.Create("DHTML") + htmlElement:SetVisible(false) + htmlElement:SetSize(w, h) + htmlElement:SetHTML(stringFormat(svgTemplate, padding, strSVG)) + + return htmlElement +end + +local materialAttributes = { + ["$translucent"] = 1, + ["$vertexalpha"] = 1, + ["$vertexcolor"] = 1 +} + +local function SetupMaterial(id, name, width, height, mipmapping) + -- set individual material attributes + materialAttributes["$basetexture"] = name + materialAttributes["$mips"] = mipmapping -- does this work to create mipmaps? + + local uniqueName = format("%s,%s,%d,%d", id, match(name, "%d+"), width, height) + + return CreateMaterial(uniqueName, "UnlitGeneric", materialAttributes) +end + +svg = svg or {} + +--- +-- Creates a material from an SVG file that can be used as any other material in GMod. Since normal +-- materials are created from pixelated sources instead of vectorized sources, a basewidth has to be +-- provided. +-- @param string path The filepath to the svg file +-- @param[default=64] number width The base width of the generated material +-- @param[default=64] number height The base height of the generated material +-- @param[default=0] number padding The padding around the material, is included in the set width and height +-- @param[default=true] boolean mipmapping Set to false to disable mipmapping for this material +-- @return nil|Material Returns the created material, nil if failed +-- @note This function is rather compute heavy and it should be therefore avoided to call +-- it from within a rendering hook. Caching of the returned matial is recommended. +-- @realm client +function svg.CreateSVGMaterial(path, width, height, padding, mipmapping) + width = width or 64 + height = height or 64 + mipmapping = (mipmapping ~= false) and 1 or 0 -- enable mipmaps if not set to false explicitly + padding = padding or 0 + + local svgString = fileRead(path, "DATA") -- is data correct? probably not + + if not svgString then return end + + local htmlElement = GenerateHTMLElement(width, height, svgString, padding) + + if not htmlElement then return end + + -- maybe the HTML texture has to be updated once to get material? + + local materialInternal = GetHTMLMaterial(htmlElement) + + -- todo: can the htmlElement be deleted after extracting the material? + + return SetupMaterial(materialInternal:GetString(), materialInternal:GetName(), width, height, mipmapping) +end From b6820f5b762830dc57e8d604cd735b6acb4226da Mon Sep 17 00:00:00 2001 From: Tim Goll Date: Mon, 23 Oct 2023 13:42:22 +0200 Subject: [PATCH 2/5] svg integration tests --- .../tttinfopanel/pure_skin_playerinfo.lua | 11 ++- lua/ttt2/libraries/roles.lua | 3 +- lua/ttt2/libraries/svg.lua | 71 +++++++++++-------- materials/test.svg | 7 ++ materials/test2.svg | 7 ++ materials/test3.svg | 9 +++ 6 files changed, 75 insertions(+), 33 deletions(-) create mode 100644 materials/test.svg create mode 100644 materials/test2.svg create mode 100644 materials/test3.svg diff --git a/gamemodes/terrortown/gamemode/shared/hud_elements/tttinfopanel/pure_skin_playerinfo.lua b/gamemodes/terrortown/gamemode/shared/hud_elements/tttinfopanel/pure_skin_playerinfo.lua index 610dcb1b5a..c5c9111947 100644 --- a/gamemodes/terrortown/gamemode/shared/hud_elements/tttinfopanel/pure_skin_playerinfo.lua +++ b/gamemodes/terrortown/gamemode/shared/hud_elements/tttinfopanel/pure_skin_playerinfo.lua @@ -138,7 +138,16 @@ if CLIENT then if cactive then if rd.iconMaterial then - draw.FilteredShadowedTexture(x2 + 4, y2 + 4, t_lpw - 8, t_lpw - 8, rd.iconMaterial, 255, util.GetDefaultColor(c), t_scale) + --htmlElement:UpdateHTMLTexture() + + --local mat = htmlElement:GetHTMLMaterial() + --local matSetup = SetupMaterial("svg" .. mat:GetName(), 512, 512, 1) + + --draw.FilteredShadowedTexture(x2 + 4, y2 + 4, t_lpw - 8, t_lpw - 8, matSetup, 255, util.GetDefaultColor(c), t_scale) + + --roles.iconHTML:UpdateHTMLTexture() + --draw.FilteredShadowedTexture(x2 + 4, y2 + 4, t_lpw - 8, t_lpw - 8, rd.iconMaterial, 255, util.GetDefaultColor(c), t_scale) + draw.FilteredShadowedTexture(x2, y2 - 200, 512, 512, rd.iconMaterial, 255, util.GetDefaultColor(c), t_scale) end elseif IsValid(tgt) and tgt:IsPlayer() then draw.FilteredShadowedTexture(x2 + 4, y2 + 4, t_lpw - 8, t_lpw - 8, watching_icon, 255, util.GetDefaultColor(c), t_scale) diff --git a/lua/ttt2/libraries/roles.lua b/lua/ttt2/libraries/roles.lua index 2d12756b07..915ea66cc8 100644 --- a/lua/ttt2/libraries/roles.lua +++ b/lua/ttt2/libraries/roles.lua @@ -161,7 +161,8 @@ local function SetupData(roleData) roleData.icon = roleData.icon or ("vgui/ttt/dynamic/roles/icon_" .. roleData.abbr) -- set a roledata icon material to prevent creating new materials each frame - roleData.iconMaterial = Material(roleData.icon) + --roleData.iconMaterial = Material(roleData.icon) + roleData.iconMaterial = svg.CreateSVGMaterial("test2.svg", 512, 512, 48) -- set default colors roleData.dkcolor = util.ColorDarken(roleData.color, 30) diff --git a/lua/ttt2/libraries/svg.lua b/lua/ttt2/libraries/svg.lua index fc5a52af08..4af25d4bc9 100644 --- a/lua/ttt2/libraries/svg.lua +++ b/lua/ttt2/libraries/svg.lua @@ -14,7 +14,6 @@ end local stringFormat = string.format local stringSub = string.sub local stringFind = string.find -local stringLen = string.len local fileRead = file.Read local format = format local match = match @@ -45,23 +44,23 @@ local function SetIfEmpty(haystack, needle, pos, needed) end local function GenerateHTMLElement(w, h, padding, strSVG) - -- make sure svg file has opening and closing tag - local open = string.find(strSVG, '') - local _, close = string.find(strSVG, '%s*$') + -- make sure svg file has opening and closing tag + local open = string.find(strSVG, "") + local _, close = string.find(strSVG, "%s*$") - if not open or not close then return end + if not open or not close then return end strSVG = stringSub(strSVG, open, close) - -- todo make sure that the svg size in combination witht the padding works here + -- todo make sure that the svg size in combination witht the padding works here strSVG = SetIfEmpty(strSVG, "width='(.-)'", 5, "width='' ") strSVG = SetIfEmpty(strSVG, "height='(.-)'", 5, "height='' ") strSVG = string.gsub(strSVG, "width='(.-)'", "width='" .. w - 2 * padding .. "'") strSVG = string.gsub(strSVG, "height='(.-)'", "height='" .. h - 2 * padding .. "'") - htmlElement = vgui.Create("DHTML") - htmlElement:SetVisible(false) + local htmlElement = vgui.Create("DHTML") + htmlElement:SetVisible(false) htmlElement:SetSize(w, h) htmlElement:SetHTML(stringFormat(svgTemplate, padding, strSVG)) @@ -69,19 +68,26 @@ local function GenerateHTMLElement(w, h, padding, strSVG) end local materialAttributes = { - ["$translucent"] = 1, - ["$vertexalpha"] = 1, - ["$vertexcolor"] = 1 + ["$translucent"] = 1, + ["$vertexalpha"] = 1, + ["$vertexcolor"] = 1 } -local function SetupMaterial(id, name, width, height, mipmapping) - -- set individual material attributes - materialAttributes["$basetexture"] = name - materialAttributes["$mips"] = mipmapping -- does this work to create mipmaps? - - local uniqueName = format("%s,%s,%d,%d", id, match(name, "%d+"), width, height) +local function SetupMaterial(name, width, height, mipmapping) + -- set individual material attributes + materialAttributes["$basetexture"] = name + + -- enable mipmapping if not explicitly disabled + if mipmapping ~= false then + materialAttributes["$mipmaps"] = 1 + --materialAttributes["$flags"] = { + -- ["bilinear"] = 1, + -- ["mips"] = 1 + --} + --materialAttributes["$mips"] = mipmapping -- does this work to create mipmaps? + end - return CreateMaterial(uniqueName, "UnlitGeneric", materialAttributes) + return CreateMaterial(name, "UnlitGeneric", materialAttributes) end svg = svg or {} @@ -100,24 +106,27 @@ svg = svg or {} -- it from within a rendering hook. Caching of the returned matial is recommended. -- @realm client function svg.CreateSVGMaterial(path, width, height, padding, mipmapping) - width = width or 64 - height = height or 64 - mipmapping = (mipmapping ~= false) and 1 or 0 -- enable mipmaps if not set to false explicitly - padding = padding or 0 - - local svgString = fileRead(path, "DATA") -- is data correct? probably not + width = width or 64 + height = height or 64 + padding = padding or 0 + + local svgString = fileRead("materials/" .. path, "GAME") + + if not svgString then return end - if not svgString then return end + local htmlElement = GenerateHTMLElement(width, height, padding, svgString) - local htmlElement = GenerateHTMLElement(width, height, svgString, padding) + --return htmlElement - if not htmlElement then return end + if not htmlElement then return end - -- maybe the HTML texture has to be updated once to get material? + -- the HTML element texture has to be updated once to generate a material + htmlElement:UpdateHTMLTexture() - local materialInternal = GetHTMLMaterial(htmlElement) + -- then the material can be extracted from the HTML element + local materialInternal = htmlElement:GetHTMLMaterial() - -- todo: can the htmlElement be deleted after extracting the material? + -- todo: can the htmlElement be deleted after extracting the material? - return SetupMaterial(materialInternal:GetString(), materialInternal:GetName(), width, height, mipmapping) + return SetupMaterial(materialInternal:GetName(), width, height, 1) end diff --git a/materials/test.svg b/materials/test.svg new file mode 100644 index 0000000000..6a12333e39 --- /dev/null +++ b/materials/test.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/materials/test2.svg b/materials/test2.svg new file mode 100644 index 0000000000..fd921ff63b --- /dev/null +++ b/materials/test2.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/materials/test3.svg b/materials/test3.svg new file mode 100644 index 0000000000..40671df7eb --- /dev/null +++ b/materials/test3.svg @@ -0,0 +1,9 @@ + + + + + + + + + From 17dc74df5ece588f5ae9000f7fabb82936478e41 Mon Sep 17 00:00:00 2001 From: Tim Goll Date: Mon, 23 Oct 2023 17:59:57 +0200 Subject: [PATCH 3/5] working mipmapping --- .../tttinfopanel/pure_skin_playerinfo.lua | 11 +- lua/ttt2/extensions/draw.lua | 3 + lua/ttt2/extensions/util.lua | 12 ++ lua/ttt2/libraries/roles.lua | 7 +- lua/ttt2/libraries/svg.lua | 126 +++++++++++++----- .../vgui/ttt/dynamic/roles/icon_inno.svg | 10 ++ 6 files changed, 124 insertions(+), 45 deletions(-) create mode 100644 materials/vgui/ttt/dynamic/roles/icon_inno.svg diff --git a/gamemodes/terrortown/gamemode/shared/hud_elements/tttinfopanel/pure_skin_playerinfo.lua b/gamemodes/terrortown/gamemode/shared/hud_elements/tttinfopanel/pure_skin_playerinfo.lua index c5c9111947..610dcb1b5a 100644 --- a/gamemodes/terrortown/gamemode/shared/hud_elements/tttinfopanel/pure_skin_playerinfo.lua +++ b/gamemodes/terrortown/gamemode/shared/hud_elements/tttinfopanel/pure_skin_playerinfo.lua @@ -138,16 +138,7 @@ if CLIENT then if cactive then if rd.iconMaterial then - --htmlElement:UpdateHTMLTexture() - - --local mat = htmlElement:GetHTMLMaterial() - --local matSetup = SetupMaterial("svg" .. mat:GetName(), 512, 512, 1) - - --draw.FilteredShadowedTexture(x2 + 4, y2 + 4, t_lpw - 8, t_lpw - 8, matSetup, 255, util.GetDefaultColor(c), t_scale) - - --roles.iconHTML:UpdateHTMLTexture() - --draw.FilteredShadowedTexture(x2 + 4, y2 + 4, t_lpw - 8, t_lpw - 8, rd.iconMaterial, 255, util.GetDefaultColor(c), t_scale) - draw.FilteredShadowedTexture(x2, y2 - 200, 512, 512, rd.iconMaterial, 255, util.GetDefaultColor(c), t_scale) + draw.FilteredShadowedTexture(x2 + 4, y2 + 4, t_lpw - 8, t_lpw - 8, rd.iconMaterial, 255, util.GetDefaultColor(c), t_scale) end elseif IsValid(tgt) and tgt:IsPlayer() then draw.FilteredShadowedTexture(x2 + 4, y2 + 4, t_lpw - 8, t_lpw - 8, watching_icon, 255, util.GetDefaultColor(c), t_scale) diff --git a/lua/ttt2/extensions/draw.lua b/lua/ttt2/extensions/draw.lua index 1b0437abc0..261507d88d 100644 --- a/lua/ttt2/extensions/draw.lua +++ b/lua/ttt2/extensions/draw.lua @@ -248,6 +248,9 @@ function draw.Texture(x, y, w, h, material, alpha, color) alpha = alpha or 255 color = color or COLOR_WHITE + -- handle custom mipmaps, returns material if not set + material = svg.GetCustomMipmap(material, h) + surface.SetDrawColor(color.r, color.g, color.b, alpha) surface.SetMaterial(material) diff --git a/lua/ttt2/extensions/util.lua b/lua/ttt2/extensions/util.lua index d6d8b9fa8e..44b224af89 100644 --- a/lua/ttt2/extensions/util.lua +++ b/lua/ttt2/extensions/util.lua @@ -483,6 +483,18 @@ function util.VectorInBounds(vec, lowerBound, upperBound) and vec.z > lowerBound.z and vec.z < upperBound.z end +function util.NextPowerOfTwo(value) + value = value - 1 + + value = bit.bor(value, bit.rshift(value, 1)) + value = bit.bor(value, bit.rshift(value, 2)) + value = bit.bor(value, bit.rshift(value, 4)) + value = bit.bor(value, bit.rshift(value, 8)) + value = bit.bor(value, bit.rshift(value, 16)) + + return value + 1 +end + if CLIENT then local colorsHealth = { healthy = Color(0, 255, 0, 255), diff --git a/lua/ttt2/libraries/roles.lua b/lua/ttt2/libraries/roles.lua index 915ea66cc8..80895f8144 100644 --- a/lua/ttt2/libraries/roles.lua +++ b/lua/ttt2/libraries/roles.lua @@ -161,8 +161,11 @@ local function SetupData(roleData) roleData.icon = roleData.icon or ("vgui/ttt/dynamic/roles/icon_" .. roleData.abbr) -- set a roledata icon material to prevent creating new materials each frame - --roleData.iconMaterial = Material(roleData.icon) - roleData.iconMaterial = svg.CreateSVGMaterial("test2.svg", 512, 512, 48) + if svg.FileExists(roleData.icon) then + roleData.iconMaterial = svg.CreateSVGMaterial(roleData.icon, 512, 512, 32) + else + roleData.iconMaterial = Material(roleData.icon) + end -- set default colors roleData.dkcolor = util.ColorDarken(roleData.color, 30) diff --git a/lua/ttt2/libraries/svg.lua b/lua/ttt2/libraries/svg.lua index 4af25d4bc9..e795624c5a 100644 --- a/lua/ttt2/libraries/svg.lua +++ b/lua/ttt2/libraries/svg.lua @@ -35,6 +35,26 @@ local svgTemplate = [[ ]] +local materialAttributes = { + ["$nodecal"] = 1, + ["$nolod"] = 1, + ["$smooth"] = 1, + ["$translucent"] = 1, + ["$vertexalpha"] = 1, + ["$vertexcolor"] = 1 +} + +local mipmapSizes = { + [8] = true, + [16] = true, + [32] = true, + [64] = true, + [128] = true, + [256] = true, + [512] = true, + [1024] = true +} + local function SetIfEmpty(haystack, needle, pos, needed) if not stringFind(haystack, needle) then return string.sub(haystack, 1, pos) .. needed .. string.sub(haystack, pos + string.len(needed)) @@ -43,7 +63,14 @@ local function SetIfEmpty(haystack, needle, pos, needed) return haystack end -local function GenerateHTMLElement(w, h, padding, strSVG) +local function SetupMaterial(name, width, height) + -- set individual material attributes + materialAttributes["$basetexture"] = name + + return CreateMaterial(name, "UnlitGeneric", materialAttributes) +end + +local function GenerateHTMLElement(width, height, padding, strSVG) -- make sure svg file has opening and closing tag local open = string.find(strSVG, "") local _, close = string.find(strSVG, "%s*$") @@ -56,41 +83,39 @@ local function GenerateHTMLElement(w, h, padding, strSVG) strSVG = SetIfEmpty(strSVG, "width='(.-)'", 5, "width='' ") strSVG = SetIfEmpty(strSVG, "height='(.-)'", 5, "height='' ") - strSVG = string.gsub(strSVG, "width='(.-)'", "width='" .. w - 2 * padding .. "'") - strSVG = string.gsub(strSVG, "height='(.-)'", "height='" .. h - 2 * padding .. "'") + strSVG = string.gsub(strSVG, "width='(.-)'", "width='" .. width - 2 * padding .. "'") + strSVG = string.gsub(strSVG, "height='(.-)'", "height='" .. height - 2 * padding .. "'") local htmlElement = vgui.Create("DHTML") htmlElement:SetVisible(false) - htmlElement:SetSize(w, h) + htmlElement:SetSize(width, height) htmlElement:SetHTML(stringFormat(svgTemplate, padding, strSVG)) return htmlElement end -local materialAttributes = { - ["$translucent"] = 1, - ["$vertexalpha"] = 1, - ["$vertexcolor"] = 1 -} +local function GenerateHTMLMaterial(width, height, padding, strSVG) + width = math.floor(width) + height = math.floor(height) -local function SetupMaterial(name, width, height, mipmapping) - -- set individual material attributes - materialAttributes["$basetexture"] = name + local htmlElement = GenerateHTMLElement(width, height, padding, strSVG) - -- enable mipmapping if not explicitly disabled - if mipmapping ~= false then - materialAttributes["$mipmaps"] = 1 - --materialAttributes["$flags"] = { - -- ["bilinear"] = 1, - -- ["mips"] = 1 - --} - --materialAttributes["$mips"] = mipmapping -- does this work to create mipmaps? - end + if not htmlElement then return end - return CreateMaterial(name, "UnlitGeneric", materialAttributes) + -- the HTML element texture has to be updated once to generate a material + htmlElement:UpdateHTMLTexture() + + -- then the material can be extracted from the HTML element + local materialInternal = htmlElement:GetHTMLMaterial() + local material = SetupMaterial(materialInternal:GetName(), width, height) + + --htmlElement:Remove() + + return material end svg = svg or {} +svg.customMipmaps = svg.customMipmaps or {} --- -- Creates a material from an SVG file that can be used as any other material in GMod. Since normal @@ -110,23 +135,58 @@ function svg.CreateSVGMaterial(path, width, height, padding, mipmapping) height = height or 64 padding = padding or 0 - local svgString = fileRead("materials/" .. path, "GAME") + local strSVG = fileRead("materials/" .. path .. ".svg", "GAME") - if not svgString then return end + if not strSVG then return end - local htmlElement = GenerateHTMLElement(width, height, padding, svgString) + -- generate base material + local material = GenerateHTMLMaterial(width, height, padding, strSVG) + local name = material:GetName() - --return htmlElement + svg.InitializeTable(name) - if not htmlElement then return end + -- if not explicitly disabled, mipmaps should be generated as well + if mipmapping ~= false then + for size in pairs(mipmapSizes) do + if size >= height then continue end - -- the HTML element texture has to be updated once to generate a material - htmlElement:UpdateHTMLTexture() + local mult = size / height - -- then the material can be extracted from the HTML element - local materialInternal = htmlElement:GetHTMLMaterial() + svg.AddCustomMipmap(name, size, GenerateHTMLMaterial(width * mult, size, padding * mult, strSVG)) + end + end + + return material +end - -- todo: can the htmlElement be deleted after extracting the material? +function svg.InitializeTable(name) + svg.customMipmaps[name] = svg.customMipmaps[name] or {} +end + +function svg.AddCustomMipmap(name, height, material) + svg.customMipmaps[name][height] = material +end + +function svg.GetCustomMipmap(material, height) + local name = material:GetName() + + if not svg.IsSVGMaterial(name) then + return material + end + + local nextSize = util.NextPowerOfTwo(height) + + if not svg.customMipmaps[name][nextSize] then + return material + end + + return svg.customMipmaps[name][nextSize] +end + +function svg.FileExists(path) + return file.Exists("materials/" .. path .. ".svg", "GAME") +end - return SetupMaterial(materialInternal:GetName(), width, height, 1) +function svg.IsSVGMaterial(name) + return svg.customMipmaps[name] ~= nil end diff --git a/materials/vgui/ttt/dynamic/roles/icon_inno.svg b/materials/vgui/ttt/dynamic/roles/icon_inno.svg new file mode 100644 index 0000000000..b6073a001a --- /dev/null +++ b/materials/vgui/ttt/dynamic/roles/icon_inno.svg @@ -0,0 +1,10 @@ + + + + + + + + + + From 541390f14a9e4cd5068971a71d101f74a8def1e2 Mon Sep 17 00:00:00 2001 From: Tim Goll Date: Tue, 24 Oct 2023 12:08:50 +0200 Subject: [PATCH 4/5] cleanup --- lua/ttt2/libraries/svg.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lua/ttt2/libraries/svg.lua b/lua/ttt2/libraries/svg.lua index e795624c5a..a2702bdbfc 100644 --- a/lua/ttt2/libraries/svg.lua +++ b/lua/ttt2/libraries/svg.lua @@ -13,10 +13,10 @@ end local stringFormat = string.format local stringSub = string.sub +local stringGSub = string.gsub +local stringLen = string.len local stringFind = string.find local fileRead = file.Read -local format = format -local match = match local svgTemplate = [[ @@ -26,6 +26,7 @@ local svgTemplate = [[ margin: 0; padding: %dpx; overflow: hidden; + background-color: rgba(255,0,0,0); } @@ -57,7 +58,7 @@ local mipmapSizes = { local function SetIfEmpty(haystack, needle, pos, needed) if not stringFind(haystack, needle) then - return string.sub(haystack, 1, pos) .. needed .. string.sub(haystack, pos + string.len(needed)) + return stringSub(haystack, 1, pos) .. needed .. stringSub(haystack, pos + stringLen(needed)) end return haystack @@ -72,8 +73,8 @@ end local function GenerateHTMLElement(width, height, padding, strSVG) -- make sure svg file has opening and closing tag - local open = string.find(strSVG, "") - local _, close = string.find(strSVG, "%s*$") + local open = stringFind(strSVG, "") + local _, close = stringFind(strSVG, "%s*$") if not open or not close then return end @@ -83,8 +84,8 @@ local function GenerateHTMLElement(width, height, padding, strSVG) strSVG = SetIfEmpty(strSVG, "width='(.-)'", 5, "width='' ") strSVG = SetIfEmpty(strSVG, "height='(.-)'", 5, "height='' ") - strSVG = string.gsub(strSVG, "width='(.-)'", "width='" .. width - 2 * padding .. "'") - strSVG = string.gsub(strSVG, "height='(.-)'", "height='" .. height - 2 * padding .. "'") + strSVG = stringGSub(strSVG, "width='(.-)'", "width='" .. width - 2 * padding .. "'") + strSVG = stringGSub(strSVG, "height='(.-)'", "height='" .. height - 2 * padding .. "'") local htmlElement = vgui.Create("DHTML") htmlElement:SetVisible(false) From 3d889901f8bfe94526d63987f407aebe6ecaa843 Mon Sep 17 00:00:00 2001 From: Tim Goll Date: Tue, 24 Oct 2023 12:15:21 +0200 Subject: [PATCH 5/5] color change --- lua/ttt2/libraries/svg.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/ttt2/libraries/svg.lua b/lua/ttt2/libraries/svg.lua index a2702bdbfc..da77ddbc3e 100644 --- a/lua/ttt2/libraries/svg.lua +++ b/lua/ttt2/libraries/svg.lua @@ -26,7 +26,7 @@ local svgTemplate = [[ margin: 0; padding: %dpx; overflow: hidden; - background-color: rgba(255,0,0,0); + background-color: rgba(255,255,255,0); }