[Teton] Factor drawing glyphs to screen into a separate class.
This commit is contained in:
parent
fe44804dd9
commit
afdb024c36
6 changed files with 60 additions and 7 deletions
28
sys/teton/framebuffer/console.cpp
Normal file
28
sys/teton/framebuffer/console.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include "framebuffer/console.h"
|
||||
|
||||
void Console::WriteChar(char c) {
|
||||
uint64_t row = cursor_pos_ / cols();
|
||||
uint64_t fb_row = row * (psf_.height() + 1);
|
||||
uint64_t col = cursor_pos_ % cols();
|
||||
uint64_t fb_col = col * (psf_.width() + 1);
|
||||
|
||||
uint8_t* glyph = psf_.glyph(c);
|
||||
|
||||
for (uint8_t r = fb_row; r < fb_row + psf_.height(); r++) {
|
||||
for (uint8_t c = fb_col; c < fb_col + psf_.width(); c++) {
|
||||
uint8_t glyph_offset = psf_.width() - (c - fb_col) - 1;
|
||||
if ((glyph[r] & (1 << glyph_offset))) {
|
||||
framebuf_.DrawPixel(r, c, 0xFFFFFFF);
|
||||
} else {
|
||||
framebuf_.DrawPixel(r, c, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cursor_pos_++;
|
||||
}
|
||||
void Console::WriteString(glcr::StringView str) {
|
||||
for (uint64_t i = 0; i < str.size(); i++) {
|
||||
WriteChar(str[i]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue