Fix blit implementation
This commit is contained in:
parent
6a4d2d0375
commit
569a4370c0
@ -1,4 +1,3 @@
|
||||
local Util = require("util")
|
||||
local Text = require("gfx.text")
|
||||
local TextProgress = Text:new()
|
||||
|
||||
@ -12,18 +11,22 @@ 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())
|
||||
local text = self:getText()
|
||||
if #text == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
self:_getWindow().blit(self:getText(), Util.valueToHex(fg), Util.valueToHex(bg))
|
||||
local activePart = math.ceil(#text * self:getProgress())
|
||||
|
||||
local fg = { }
|
||||
local bg = { }
|
||||
|
||||
for i=1,#text do
|
||||
table.insert(fg, colors.toBlit(i > activePart and self:getFgColor() or self:getBgColor()))
|
||||
table.insert(bg, colors.toBlit(i > activePart and self:getBgColor() or self:getFgColor()))
|
||||
end
|
||||
|
||||
self:_getWindow().blit(text, table.concat(fg), table.concat(bg))
|
||||
end
|
||||
|
||||
return TextProgress
|
@ -1,13 +1,7 @@
|
||||
local Util = {}
|
||||
|
||||
function Util.valueToHex(value)
|
||||
local collect = {}
|
||||
while value > 0 do
|
||||
local idx = value % 16
|
||||
table.insert(collect, 1, ("0123456789ABCDEF"):sub(idx, idx))
|
||||
value = bit.brshift(value, 4)
|
||||
end
|
||||
return table.concat(collect)
|
||||
function Util.toHexChar(v)
|
||||
return ("0123456789ABCDEF"):sub(v, v)
|
||||
end
|
||||
|
||||
return Util
|
Loading…
x
Reference in New Issue
Block a user