added renderToContext to Canvas

This commit is contained in:
Djeeberjr 2023-01-30 16:06:13 +01:00
parent df86bae738
commit 881aad743d

View File

@ -1,5 +1,6 @@
package lib.ui;
import kernel.ui.WindowContext;
import lib.Pos;
import lib.Rect;
import kernel.ui.Pixel;
@ -67,6 +68,28 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> from Array<Array<Pix
y: height()
});
}
/**
Renders the canvas directly to the context
**/
public function renderToContext(ctx: WindowContext){
for (lineIndex => line in this) {
if (line == null || line.length == 0) {
continue;
}
for (pixelIndex => pixel in line) {
if (pixel == null) {
continue;
}
ctx.setCursorPos(pixelIndex, lineIndex);
ctx.setBackgroundColor(pixel.bg);
ctx.setTextColor(pixel.textColor);
ctx.write(pixel.char);
}
}
}
}
class CanvasKeyValueIterator {