diff options
Diffstat (limited to 'advtrains/texture.lua')
-rw-r--r-- | advtrains/texture.lua | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/advtrains/texture.lua b/advtrains/texture.lua index e6d83b0..34fe83c 100644 --- a/advtrains/texture.lua +++ b/advtrains/texture.lua @@ -67,6 +67,8 @@ end) tx_lib.multiply = mkmodifier("[multiply:%s", {tx.escape}) tx_lib.resize = mkmodifier("[resize:%dx%d", {}) tx_lib.transform = mkmodifier("[transform%s", {tx.escape}) +tx_lib.makealpha = mkmodifier("[makealpha:%s", {tx.escape}) +tx_lib.verticalframe = mkmodifier("[verticalframe:%d:%d]", {}) -- [combine @@ -93,8 +95,11 @@ function tx.combine(w, h, bg) return obj end -function combine:add_fill(x, y, ...) - return self:add(x, y, tx.fill(...)) +function combine:add_fill(x, y, w, h, ...) + if w < 1 or h < 1 then + return obj + end + return self:add(x, y, tx.fill(w, h, ...)) end local function add_multicolor_fill(n, self, x, y, w, h, ...) @@ -225,4 +230,31 @@ function combine:add_n7seg(x, y, w, h, n, prec, ...) return self:add_str7seg(x, y, w, h, pfx .. ("0"):rep(prec-#str-#pfx) .. str, ...) end +function combine:add_small_digit(x, y, s, d, fill) + d = math.floor(tonumber(d)) + if not d or d ~= d or d < 0 or d > 9 then + error("invalid value passed to advtrains.combine_texture:add_small_digit") + end + return self:add(x, y, tx"advtrains_hud_smallnum.png":verticalframe(10, d):makealpha"black":multiply(fill):resize(3*s, 5*s)) +end + +function combine:add_smallnum(x, y, s, n, prec, ...) + if not (type(n) == "number" and type(prec) == "number") then + error("invalid number or precision passed to numeric display") + elseif n < 0 then + error("cannot use negative number") + elseif prec < 0 then + error("cannot use negative length") + end + n = math.floor(n) + local digits = {} + for k = prec, 1, -1 do + digits[k] = n % 10 + n = math.floor(n/10) + end + for k, d in ipairs(digits) do + self:add_small_digit(x+4*s*(k-1), y, s, d, ...) + end +end + return tx |