canvas overhaul
This commit is contained in:
@@ -1,19 +1,28 @@
|
||||
local class = require('opus.class')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local lookup = '0123456789abcdef'
|
||||
|
||||
-- handle files produced by Paint
|
||||
UI.Image = class(UI.Window)
|
||||
UI.Image.defaults = {
|
||||
UIElement = 'Image',
|
||||
event = 'button_press',
|
||||
}
|
||||
function UI.Image:setParent()
|
||||
if self.image then
|
||||
function UI.Image:postInit()
|
||||
if self.filename then
|
||||
self.image = Util.readLines(self.filename)
|
||||
end
|
||||
|
||||
if self.image and not (self.height or self.ey) then
|
||||
self.height = #self.image
|
||||
end
|
||||
if self.image and not self.width then
|
||||
self.width = #self.image[1]
|
||||
if self.image and not (self.width or self.ex) then
|
||||
for i = 1, self.height do
|
||||
self.width = math.max(self.width or 0, #self.image[i])
|
||||
end
|
||||
end
|
||||
UI.Window.setParent(self)
|
||||
end
|
||||
|
||||
function UI.Image:draw()
|
||||
@@ -22,19 +31,22 @@ function UI.Image:draw()
|
||||
for y = 1, #self.image do
|
||||
local line = self.image[y]
|
||||
for x = 1, #line do
|
||||
local ch = line[x]
|
||||
if type(ch) == 'number' then
|
||||
if ch > 0 then
|
||||
self:write(x, y, ' ', ch)
|
||||
end
|
||||
else
|
||||
self:write(x, y, ch)
|
||||
local ch = lookup:find(line:sub(x, x))
|
||||
if ch then
|
||||
self:write(x, y, ' ', 2 ^ (ch -1))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
self:drawChildren()
|
||||
end
|
||||
|
||||
function UI.Image:setImage(image)
|
||||
self.image = image
|
||||
end
|
||||
|
||||
function UI.Image.example()
|
||||
return UI.Image {
|
||||
filename = 'test.paint',
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user