diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-01-08 22:28:08 -0500 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-01-08 22:28:08 -0500 |
| commit | 98e0462e4f6b13ff26af5211409352d45dd9453e (patch) | |
| tree | fbff14dc9a0fffdda409d9989f2e34cd4bb265f6 /gamemode/utility | |
| parent | 4879eb1d78520ce0ac9b0bb0ef5244cf65ad7c99 (diff) | |
| download | artery-98e0462e4f6b13ff26af5211409352d45dd9453e.tar.gz artery-98e0462e4f6b13ff26af5211409352d45dd9453e.tar.bz2 artery-98e0462e4f6b13ff26af5211409352d45dd9453e.zip | |
Add a ton of icons, more work on refactoring
Diffstat (limited to 'gamemode/utility')
| -rw-r--r-- | gamemode/utility/fn.lua | 1 | ||||
| -rw-r--r-- | gamemode/utility/stream.lua | 2 | ||||
| -rw-r--r-- | gamemode/utility/svg/cl_svg.lua | 98 |
3 files changed, 101 insertions, 0 deletions
diff --git a/gamemode/utility/fn.lua b/gamemode/utility/fn.lua index 7c53150..343f27d 100644 --- a/gamemode/utility/fn.lua +++ b/gamemode/utility/fn.lua @@ -226,4 +226,5 @@ function fn.flatten(tbl) end return ret end + return fn diff --git a/gamemode/utility/stream.lua b/gamemode/utility/stream.lua index cdf3933..75beb4c 100644 --- a/gamemode/utility/stream.lua +++ b/gamemode/utility/stream.lua @@ -1,4 +1,6 @@ --[[ + Public functions: + CreateStream(data_or_nil) A stream object, has the methods: stream:WriteString(string) :: nil stream:WriteInt(num,bytes) :: nil diff --git a/gamemode/utility/svg/cl_svg.lua b/gamemode/utility/svg/cl_svg.lua new file mode 100644 index 0000000..623c9e1 --- /dev/null +++ b/gamemode/utility/svg/cl_svg.lua @@ -0,0 +1,98 @@ +local svg = {} +local fn = nrequire("fn.lua") +local file_cache_max_size = 100 +local file_cache_size = 0 +local file_cache = {} + +local function readsvg(path) + if file_cache[path] == nil then + if file_cache_size > file_cache_max_size then + local k,_ = next(file_cache) --Random replacement + file_cache[k] = nil + end + file_cache[path] = file.Read(path,"GAME") + end + return file_cache[path] +end + +local function updatesvg(self) + if self.path ~= self.svgpath then + self.svgdata = readsvg(self.path) + assert(self.svgdata ~= nil,"Could not open file:" .. self.path) + self.svgpath = self.path + end + local bgf = "" + local fgf = "" + if self.bg ~= nil then + bgf = string.format("svg{background:%s}",self.bg) + end + if self.fg ~= nil then + fgf = string.format("svg path{fill:%s}",self.fg) + end + self.html:SetHTML(string.format([[ +<style>%s%sbody{overflow:hidden}</style><body>%s</body> +]],bgf,fgf,self.svgdata)) +end + +local function updatesvgimg(self,newpath) + self.path = newpath + self:Update() +end + +local function updatesvgfg(self,fore) + self.fg = fore + self:Update() +end + +local function updatesvgbg(self,back) + self.bg = back + self:Update() +end + +local toprocess = {} +function svg.MaterialFromSVG(spath,background,foreground) + local html = vgui.Create("DHTML") + local svgdata = readsvg(spath) + local bgf = "" + local fgf = "" + if background ~= nil then + bgf = string.format("svg{background:%s}",background) + end + if foreground ~= nil then + fgf = string.format("svg path{fill:%s}",foreground) + end + html:SetHTML(string.format([[ +<style>%s%sbody{overflow:hidden}</style><body>%s</body> +]],bgf,fgf,svgdata)) + local mat = {} + toprocess[#toprocess + 1] = {mat,html} + return mat +end + +hook.Add("Think","process_svg_materials",function() + for k,v in ipairs(toprocess) do + local hm = v[2]:GetHTMLMaterial() + if hm then + v[1].material = hm + end + for i = k,#toprocess do + toprocess[i] = toprocess[i + 1] + end + end +end) + +function svg.SvgOnDpanel(spath,background,foreground,dpanel) + local ret = {} + ret.html = vgui.Create("DHTML",dpanel) + ret.path = spath + ret.fg = foreground + ret.bg = background + ret.UpdateForeground = updatesvgfg + ret.UpdateBackground = updatesvgbg + ret.UpdateImage = updatesvgimg + ret.Update = updatesvg + ret:Update() + return ret +end + +return svg |
