nwm opacity / improvements - env cleanup
This commit is contained in:
@@ -3,55 +3,64 @@
|
||||
]]
|
||||
|
||||
local Terminal = require('opus.terminal')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local colors = _G.colors
|
||||
local device = _G.device
|
||||
|
||||
local scale = .5
|
||||
local xs, ys = 6 * scale, 9 * scale
|
||||
|
||||
local Glasses = { }
|
||||
|
||||
function Glasses.create(name, sx, sy, w, h)
|
||||
w, h = w or 46, h or 19
|
||||
sx, sy = sx or 1, sy or 20
|
||||
function Glasses.create(args)
|
||||
local opts = {
|
||||
x = 1, y = 20,
|
||||
width = 51, height = 19,
|
||||
scale = .5,
|
||||
name = 'glasses',
|
||||
opacity = 0xff,
|
||||
}
|
||||
Util.merge(opts, args)
|
||||
|
||||
local xs, ys = 6 * opts.scale, 9 * opts.scale
|
||||
local glasses = device['plethora:glasses']
|
||||
local canvas = glasses.canvas()
|
||||
local _, cy = 1, 1
|
||||
local lines = { }
|
||||
local map = {
|
||||
['0'] = 0xF0F0F0FF,
|
||||
['1'] = 0xF2B233FF,
|
||||
['2'] = 0xE57FD8FF,
|
||||
['3'] = 0x99B2F2FF,
|
||||
['4'] = 0xDEDE6CFF,
|
||||
['5'] = 0x7FCC19FF,
|
||||
['6'] = 0xF2B2CCFF,
|
||||
['7'] = 0x4C4C4CFF,
|
||||
['8'] = 0x999999FF,
|
||||
['9'] = 0x4C99B2FF,
|
||||
['a'] = 0xB266E5FF,
|
||||
['b'] = 0x3366CCFF,
|
||||
['c'] = 0x7F664CFF,
|
||||
['d'] = 0x57A64EFF,
|
||||
['e'] = 0xCC4C4CFF,
|
||||
['f'] = 0x191919FF,
|
||||
['0'] = 0xF0F0F000,
|
||||
['1'] = 0xF2B23300,
|
||||
['2'] = 0xE57FD800,
|
||||
['3'] = 0x99B2F200,
|
||||
['4'] = 0xDEDE6C00,
|
||||
['5'] = 0x7FCC1900,
|
||||
['6'] = 0xF2B2CC00,
|
||||
['7'] = 0x4C4C4C00,
|
||||
['8'] = 0x99999900,
|
||||
['9'] = 0x4C99B200,
|
||||
['a'] = 0xB266E500,
|
||||
['b'] = 0x3366CC00,
|
||||
['c'] = 0x7F664C00,
|
||||
['d'] = 0x57A64E00,
|
||||
['e'] = 0xCC4C4C00,
|
||||
['f'] = 0x19191900,
|
||||
}
|
||||
|
||||
for k,v in pairs(map) do
|
||||
map[k] = v + opts.opacity
|
||||
end
|
||||
|
||||
-- Position bottom left
|
||||
local pos = { x = sx * xs, y = sy * ys }
|
||||
local pos = { x = opts.x * xs, y = opts.y * ys }
|
||||
|
||||
local function init(group)
|
||||
for y = 1, h do
|
||||
for y = 1, opts.height do
|
||||
lines[y] = {
|
||||
text = { },
|
||||
bg = { }
|
||||
}
|
||||
for x = 1, w do
|
||||
for x = 1, opts.width do
|
||||
lines[y].bg[x] = group.addRectangle(x * xs, y * ys, xs, ys, 0xF0F0F04F)
|
||||
lines[y].text[x] = group.addText({ x * xs, y * ys }, '', 0x7FCC19FF)
|
||||
lines[y].text[x].setScale(scale)
|
||||
lines[y].text[x].setScale(opts.scale)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -60,21 +69,9 @@ function Glasses.create(name, sx, sy, w, h)
|
||||
init(group)
|
||||
|
||||
local gterm = Terminal.window({
|
||||
getSize = function()
|
||||
return w, h
|
||||
end,
|
||||
isColor = function()
|
||||
return true
|
||||
end,
|
||||
clear = function()
|
||||
for y = 1, h do
|
||||
for x = 1, w do
|
||||
local ln = lines[y]
|
||||
ln.bg[x].setColor(0xF0F0F04F)
|
||||
ln.text[x].setText('')
|
||||
end
|
||||
end
|
||||
end,
|
||||
blit = function(text, fg, bg)
|
||||
for x = 1, #text do
|
||||
local ln = lines[cy]
|
||||
@@ -86,19 +83,11 @@ function Glasses.create(name, sx, sy, w, h)
|
||||
setCursorPos = function(_, y)
|
||||
cy = y -- full lines are always blit
|
||||
end,
|
||||
getTextColor = function()
|
||||
return colors.white
|
||||
end,
|
||||
setTextColor = function() end,
|
||||
getBackgroundColor = function()
|
||||
return colors.black
|
||||
end,
|
||||
setBackgroundColor = function() end,
|
||||
setCursorBlink = function() end,
|
||||
}, 1, 1, w, h, true)
|
||||
}, 1, 1, opts.width, opts.height, true)
|
||||
|
||||
function gterm.setTextScale() end
|
||||
function gterm.getPosition() return sx, sy end
|
||||
function gterm.getPosition() return opts.x, opts.y end
|
||||
function gterm.setVisible() end
|
||||
function gterm.raise()
|
||||
local g = canvas.addGroup(pos)
|
||||
@@ -110,9 +99,12 @@ function Glasses.create(name, sx, sy, w, h)
|
||||
function gterm.destroy()
|
||||
group.remove()
|
||||
end
|
||||
function gterm.getTextScale()
|
||||
return opts.scale
|
||||
end
|
||||
|
||||
gterm.name = name
|
||||
gterm.side = name
|
||||
gterm.name = opts.name
|
||||
gterm.side = opts.name
|
||||
gterm.type = 'glasses'
|
||||
|
||||
return gterm
|
||||
|
||||
Reference in New Issue
Block a user