More textgpu fixes

This commit is contained in:
Łukasz Magiera 2016-02-09 22:55:26 +01:00
parent 7731fcbe29
commit b06532228c

View File

@ -133,6 +133,7 @@ function textgpu.start()
y = math.floor(y) y = math.floor(y)
if not vertical then if not vertical then
if not tbuffer[y] then if not tbuffer[y] then
native.log("GPU Set failed: under buffer")
return false return false
end end
tbuffer[y] = insertString(tbuffer[y], value, x) tbuffer[y] = insertString(tbuffer[y], value, x)
@ -160,7 +161,7 @@ function textgpu.start()
local btbuf = {} local btbuf = {}
local ftbuf = {} local ftbuf = {}
for i=1, h do for i=1, h do
if i + y - 2 <= h and i + y > 1 then if i + y - 2 <= _height and i + y > 1 then
ttbuf[i] = tbuffer[y + i - 1] and usub(tbuffer[y + i - 1], x, x + w - 1) or (" "):rep(w) ttbuf[i] = tbuffer[y + i - 1] and usub(tbuffer[y + i - 1], x, x + w - 1) or (" "):rep(w)
btbuf[i] = bbuffer[y + i - 1] and bbuffer[y + i - 1]:sub(x, x + w - 1) or background:rep(w) btbuf[i] = bbuffer[y + i - 1] and bbuffer[y + i - 1]:sub(x, x + w - 1) or background:rep(w)
ftbuf[i] = fbuffer[y + i - 1] and fbuffer[y + i - 1]:sub(x, x + w - 1) or foreground:rep(w) ftbuf[i] = fbuffer[y + i - 1] and fbuffer[y + i - 1]:sub(x, x + w - 1) or foreground:rep(w)
@ -186,15 +187,14 @@ function textgpu.start()
if not line then linex = j end if not line then linex = j end
line = (line or "") line = (line or "")
if lwrite then if lwrite then
local wx = (tx + linex)|0 local wx = (tx + x + linex - 1)|0
local wy = (ty + y + i - 1)|0 local wy = (ty + y + i - 1)|0
tbuffer[wy] = tbuffer[wy] or (" "):rep(utf8.len(line)) if tbuffer[wy] then
write("\x1b[4" .. bg .. "m") write("\x1b[4" .. bg .. "m\x1b[3" .. fg .. "m\x1b[" .. wy .. ";" .. wx .. "H" .. line)
write("\x1b[3" .. fg .. "m") tbuffer[wy] = insertString(tbuffer[wy], line, wx)
write("\x1b[" .. wy .. ";" .. wx .. "H" .. line) bbuffer[wy] = insertString(bbuffer[wy], bg:rep(utf8.len(line)), wx)
tbuffer[wy] = insertString(tbuffer[wy], line, wx) fbuffer[wy] = insertString(fbuffer[wy], fg:rep(utf8.len(line)), wx)
bbuffer[wy] = insertString(bbuffer[wy], bg:rep(utf8.len(line)), wx) end
fbuffer[wy] = insertString(fbuffer[wy], fg:rep(utf8.len(line)), wx)
bg = btbuf[i]:sub(j,j) bg = btbuf[i]:sub(j,j)
fg = ftbuf[i]:sub(j,j) fg = ftbuf[i]:sub(j,j)
@ -206,16 +206,14 @@ function textgpu.start()
line = (line or "") .. usub(ttbuf[i], j,j) line = (line or "") .. usub(ttbuf[i], j,j)
end end
if line then if line then
local wx = (tx + linex)|0 local wx = (tx + x + linex - 1)|0
local wy = (ty + y + i - 1)|0 local wy = (ty + y + i - 1)|0
tbuffer[wy] = tbuffer[wy] or (" "):rep(utf8.len(line)) if tbuffer[wy] then
write("\x1b[4" .. bg .. "m") write("\x1b[4" .. bg .. "m\x1b[3" .. fg .. "m\x1b[" .. wy .. ";" .. wx .. "H" .. line)
write("\x1b[3" .. fg .. "m") tbuffer[wy] = insertString(tbuffer[wy], line, wx)
write("\x1b[" .. wy .. ";" .. wx .. "H" .. line) bbuffer[wy] = insertString(bbuffer[wy], bg:rep(utf8.len(line)), wx)
tbuffer[wy] = insertString(tbuffer[wy], line, wx) fbuffer[wy] = insertString(fbuffer[wy], fg:rep(utf8.len(line)), wx)
bbuffer[wy] = insertString(bbuffer[wy], bg:rep(utf8.len(line)), wx) end
fbuffer[wy] = insertString(fbuffer[wy], fg:rep(utf8.len(line)), wx)
line = nil line = nil
linex = nil linex = nil
lwrite = false lwrite = false
@ -234,7 +232,7 @@ function textgpu.start()
checkArg(5, ch, "string") checkArg(5, ch, "string")
ch = usub(ch, 1, 1):rep(math.floor(w)) ch = usub(ch, 1, 1):rep(math.floor(w))
for i=1, h do for i=1, h do
if i + y - 1 <= h and i + y > 1 then if i + y - 1 <= _height and i + y > 1 then
gpu.set(x, y + i - 1, ch) gpu.set(x, y + i - 1, ch)
end end
end end