Function call for createGauge is now: createGauge(gaugeName, width, height, x, y, gaugeText, orientation, r, g, b)
Function call for setGaugeStyleSheet is now: setGaugeStyleSheet(gaugeName, css, cssback, csstext)
All the other functions for gauges are called in exactly the same manner.
Here is the code for them:
function createGauge(gaugeName, width, height, x, y, gaugeText, orientation, r, g, b)
gaugeText = gaugeText or ""
orientation = orientation or "horizontal"
assert(table.contains({"horizontal","vertical","goofy","batty"},orientation), "createGauge: orientation must be horizontal, vertical, goofy, or batty")
if r ~= nil then
if g == nil then
r,g,b = getRGB(r)
end
else
-- default colors
r,g,b = 128,128,128
end
local tbl = {width = width, height = height, x = x, y = y, text = gaugeText, r = r, g = g, b = b, orientation = orientation, value = 1}
createLabel(gaugeName .. "_back", 0,0,0,0,1)
setBackgroundColor(gaugeName .. "_back", r, g, b, 100)
createLabel(gaugeName .. "_front", 0,0,0,0,1)
setBackgroundColor(gaugeName .. "_front", r, g, b, 255)
createLabel(gaugeName .. "_text", 0,0,0,0,1)
setBackgroundColor(gaugeName .. "_text", 0, 0, 0, 0)
-- save new values in table
gaugesTable[gaugeName] = tbl
resizeGauge(gaugeName, tbl.width, tbl.height)
moveGauge(gaugeName, tbl.x, tbl.y)
setGaugeText(gaugeName, gaugeText, "black")
showGauge(gaugeName)
end
function hideGauge(gaugeName)
assert(gaugesTable[gaugeName], "hideGauge: no such gauge exists.")
hideWindow(gaugeName .. "_back")
hideWindow(gaugeName .. "_front")
hideWindow(gaugeName .. "_text")
end
function showGauge(gaugeName)
assert(gaugesTable[gaugeName], "showGauge: no such gauge exists.")
showWindow(gaugeName .. "_back")
showWindow(gaugeName .. "_front")
showWindow(gaugeName .. "_text")
end
function resizeGauge(gaugeName, width, height)
assert(gaugesTable[gaugeName], "resizeGauge: no such gauge exists.")
assert(width and height, "resizeGauge: need to have both width and height.")
resizeWindow(gaugeName .. "_back", width, height)
resizeWindow(gaugeName .. "_text", width, height)
-- save new values in table
gaugesTable[gaugeName].width, gaugesTable[gaugeName].height = width, height
setGauge(gaugeName, gaugesTable[gaugeName].value, 1)
end
function moveGauge(gaugeName, x, y)
assert(gaugesTable[gaugeName], "moveGauge: no such gauge exists.")
assert(x and y, "moveGauge: need to have both X and Y dimensions.")
moveWindow(gaugeName .. "_back", x, y)
moveWindow(gaugeName .. "_text", x, y)
-- save new values in table
gaugesTable[gaugeName].x, gaugesTable[gaugeName].y = x, y
setGauge(gaugeName, gaugesTable[gaugeName].value, 1)
end
function setGaugeStyleSheet(gaugeName, css, cssback, csstext)
if not setLabelStyleSheet then return end -- mudlet 1.0.5 and lower compatibility
assert(gaugesTable[gaugeName], "setGaugeStyleSheet: no such gauge exists.")
setLabelStyleSheet(gaugeName .. "_back", cssback or css)
setLabelStyleSheet(gaugeName .. "_front", css)
setLabelStyleSheet(gaugeName .. "_text", csstext or "")
end
function setGaugeText(gaugeName, gaugeText, r, g, b)
assert(gaugesTable[gaugeName], "setGaugeText: no such gauge exists.")
if r ~= nil then
if g == nil then
r,g,b = getRGB(r)
end
else
r,g,b = 0,0,0
end
gaugeText = gaugeText or ""
local echoString = [[<font color="#]] .. RGB2Hex(r,g,b) .. [[">]] .. gaugeText .. [[</font>]]
echo(gaugeName .. "_text", echoString)
-- save new values in table
gaugesTable[gaugeName].text = echoString
end
function setGauge(gaugeName, currentValue, maxValue, gaugeText)
assert(gaugesTable[gaugeName], "setGauge: no such gauge exists.")
assert(currentValue and maxValue, "setGauge: need to have both current and max values.")
local value = currentValue / maxValue
-- save new values in table
gaugesTable[gaugeName].value = value
local info = gaugesTable[gaugeName]
local x,y,w,h = info.x, info.y, info.width, info.height
if info.orientation == "horizontal" then
resizeWindow(gaugeName .. "_front", w * value, h)
moveWindow(gaugeName .. "_front", x, y)
elseif info.orientation == "vertical" then
resizeWindow(gaugeName .. "_front", w, h * value)
moveWindow(gaugeName .. "_front", x, y + h * (1 - value))
elseif info.orientation == "goofy" then
resizeWindow(gaugeName .. "_front", w * value, h)
moveWindow(gaugeName .. "_front", x + w * (1 - value), y)
elseif info.orientation == "batty" then
resizeWindow(gaugeName .. "_front", w, h * value)
moveWindow(gaugeName .. "_front", x, y)
end
setGaugeText(gaugeName, gaugeText)
end