opus/sys/modules/opus/ui/components/NftImage.lua

35 lines
840 B
Lua
Raw Normal View History

local class = require('opus.class')
local UI = require('opus.ui')
2019-02-06 04:03:57 +00:00
UI.NftImage = class(UI.Window)
UI.NftImage.defaults = {
UIElement = 'NftImage',
}
function UI.NftImage:postInit()
if self.image and not (self.ey or self.height) then
2019-02-06 04:03:57 +00:00
self.height = self.image.height
end
if self.image and not (self.ex or self.width) then
2019-02-06 04:03:57 +00:00
self.width = self.image.width
end
end
function UI.NftImage:draw()
self:clear()
2019-02-06 04:03:57 +00:00
if self.image then
2019-07-11 01:02:46 +00:00
-- due to blittle, the background and foreground transparent
-- color is the same as the background color
local bg = self:getProperty('backgroundColor')
2019-02-06 04:03:57 +00:00
for y = 1, self.image.height do
for x = 1, #self.image.text[y] do
2019-07-11 01:02:46 +00:00
self:write(x, y, self.image.text[y][x], self.image.bg[y][x], self.image.fg[y][x] or bg)
2019-02-06 04:03:57 +00:00
end
end
end
end
function UI.NftImage:setImage(image)
self.image = image
end