renderTo method
void
renderTo(
- Screen screen,
- Rectangle area, {
- UvStyle fallbackStyle = const UvStyle(),
Render this braille canvas into screen within area.
Implementation
void renderTo(
Screen screen,
Rectangle area, {
UvStyle fallbackStyle = const UvStyle(),
}) {
final bh = _dots.length;
final bw = bh == 0 ? 0 : _dots[0].length;
for (var cy = 0; cy < cellHeight && area.minY + cy < area.maxY; cy++) {
for (var cx = 0; cx < cellWidth && area.minX + cx < area.maxX; cx++) {
var codePoint = 0;
UvStyle? style;
final bx = cx * 2;
final by = cy * 4;
void sample(int dx, int dy, int bit) {
final x = bx + dx;
final y = by + dy;
if (y >= 0 && y < bh && x >= 0 && x < bw) {
final dotStyle = _dots[y][x];
if (dotStyle != null) {
codePoint |= bit;
style ??= dotStyle;
}
}
}
sample(0, 0, 0x01);
sample(0, 1, 0x02);
sample(0, 2, 0x04);
sample(0, 3, 0x40);
sample(1, 0, 0x08);
sample(1, 1, 0x10);
sample(1, 2, 0x20);
sample(1, 3, 0x80);
if (codePoint != 0) {
putCell(
screen,
area.minX + cx,
area.minY + cy,
String.fromCharCode(0x2800 + codePoint),
style ?? fallbackStyle,
);
}
}
}
}