local Util = require("util") local Text = require("gfx.text") local TextProgress = Text:new() function TextProgress:getProgress() return math.max(0, math.min(self.progress or 0, 1)) end function TextProgress:setProgress(progress) self.progress = progress end function TextProgress:draw() getmetatable(getmetatable(self)).draw(self) local width = self:getWidth() local activePart = math.ceil(width * self:getProgress()) local fg = 0 local bg = 0 for i=self:getWidth(),1,-1 do fg = bit.blshift(fg, 4) + (i > activePart and self:getFgColor() or self:getBgColor()) bg = bit.blshift(fg, 4) + (i > activePart and self:getBgColor() or self:getFgColor()) end self:_getWindow().blit(self:getText(), Util.valueToHex(fg), Util.valueToHex(bg)) end return TextProgress