add background and bgcolor support

This commit is contained in:
Tai @ Flex 2016-10-17 01:36:52 +01:00
parent 646ea29c81
commit 94481f7690

View File

@ -1,12 +1,52 @@
formspeccer = {}
local forms = {}
formspeccer.newform = function(self,formname,formsize)
local colours = {
red="#ff0000",
green="#00ff00",
blue="#0000ff",
yellow="#ffff00",
cyan="#00ffff",
magenta="#ff00ff",
white="#ffffff",
black="#000000",
lightgrey="#cccccc",
mediumgrey="#999999",
darkgrey="#333333",
}
local lookupcolour = function(colourname)
local thecolor = colours[colourname]
if thecolour == nil then
return colourname -- it might already be a code in itself
end
return thecolour
end
formspeccer.newform = function(self,formname,formsize,prefs)
if forms[formname] ~= nil then
minetest.log("error","Form "..formname.." already exists!!")
return -- how to cleanly indicate error and prevent loading?
end
forms[formname] = 'size['..formsize..']'
if prefs then
local pstring = ''
for prefname,value in pairs(prefs) do
if prefname == "bgcolor" then
pstring = pstring .. "bgcolor["..lookupcolour(value).."]"
elseif prefname == "background" then
pstring = pstring .. "background["
pstring = pstring .. value.xy .. ';'
pstring = pstring .. value.wh .. ';'
pstring = pstring .. value.texture
if value.auto_clip ~= false then -- anything different from false, including nil
pstring = pstring .. ";true"
end
pstring = pstring .. "]"
end
end
forms[formname] = forms[formname] .. pstring
end
return formname
end