[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]);
|
||||
}
|
||||
}
|
||||
23
sys/teton/framebuffer/console.h
Normal file
23
sys/teton/framebuffer/console.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/string/string_view.h>
|
||||
|
||||
#include "framebuffer/framebuffer.h"
|
||||
#include "framebuffer/psf.h"
|
||||
|
||||
class Console {
|
||||
public:
|
||||
explicit Console(Framebuffer& fb, Psf& psf) : framebuf_(fb), psf_(psf) {}
|
||||
|
||||
void WriteChar(char c);
|
||||
void WriteString(glcr::StringView str);
|
||||
|
||||
uint32_t rows() { return framebuf_.height() / (psf_.height() + 1); }
|
||||
uint32_t cols() { return framebuf_.width() / (psf_.width() + 1); }
|
||||
|
||||
private:
|
||||
// TODO: Don't store a reference here.
|
||||
Framebuffer& framebuf_;
|
||||
Psf& psf_;
|
||||
uint64_t cursor_pos_ = 0;
|
||||
};
|
||||
|
|
@ -11,6 +11,9 @@ class Framebuffer {
|
|||
|
||||
void DrawGlyph(uint8_t* glyph);
|
||||
|
||||
uint64_t width() { return fb_info_.width(); }
|
||||
uint64_t height() { return fb_info_.height(); }
|
||||
|
||||
private:
|
||||
// FIXME: Implement Yunq copy or move so we
|
||||
// don't have to store a reference here.
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ class Psf {
|
|||
void DumpHeader();
|
||||
|
||||
uint32_t size() { return header_->numglyph; }
|
||||
uint32_t width() { return header_->width; }
|
||||
uint32_t height() { return header_->height; }
|
||||
|
||||
uint8_t* glyph(uint32_t index) {
|
||||
return reinterpret_cast<uint8_t*>(psf_file_.vaddr() + header_->headersize +
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue