2013-09-10 19:29:17 +00:00
|
|
|
class Snapshot < Grid
|
2013-08-04 21:12:18 +00:00
|
|
|
|
2013-08-27 18:02:40 +00:00
|
|
|
def self.build(data)
|
|
|
|
data = data.map { |cells|
|
|
|
|
cells.map { |cell|
|
|
|
|
Cell.new(cell[0], Brush.new(cell[1]))
|
|
|
|
}
|
|
|
|
}
|
2013-08-14 15:24:36 +00:00
|
|
|
|
2013-09-10 19:29:17 +00:00
|
|
|
new(data)
|
2013-08-25 18:49:23 +00:00
|
|
|
end
|
|
|
|
|
2013-08-27 18:02:40 +00:00
|
|
|
def thumbnail(w, h)
|
|
|
|
x = 0
|
2013-09-10 19:29:17 +00:00
|
|
|
y = height - h - trailing_empty_lines
|
2013-08-27 18:02:40 +00:00
|
|
|
y = 0 if y < 0
|
2013-08-05 16:18:49 +00:00
|
|
|
|
2013-09-10 19:29:17 +00:00
|
|
|
crop(x, y, w, h)
|
2013-07-09 21:40:21 +00:00
|
|
|
end
|
2013-07-25 16:02:58 +00:00
|
|
|
|
2013-08-25 18:49:23 +00:00
|
|
|
private
|
2013-08-04 21:12:18 +00:00
|
|
|
|
2013-09-10 19:29:17 +00:00
|
|
|
def trailing_empty_lines
|
|
|
|
n = 0
|
|
|
|
|
|
|
|
(height - 1).downto(0) do |y|
|
|
|
|
break unless line_empty?(y)
|
|
|
|
n += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
n
|
|
|
|
end
|
|
|
|
|
|
|
|
def line_empty?(y)
|
|
|
|
lines[y].empty? || lines[y].all? { |cell| cell.empty? }
|
|
|
|
end
|
2013-08-25 18:49:23 +00:00
|
|
|
|
2013-07-09 21:40:21 +00:00
|
|
|
end
|