mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Get ui::Console to a working state.
This commit is contained in:
parent
5c31e803c8
commit
5469a3a31d
@ -26,8 +26,31 @@ using namespace portapack;
|
|||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
|
void Console::clear() {
|
||||||
|
display.fill_rectangle(
|
||||||
|
screen_rect(),
|
||||||
|
Color::black()
|
||||||
|
);
|
||||||
|
pos = { 0, 0 };
|
||||||
|
}
|
||||||
|
|
||||||
void Console::write(const std::string message) {
|
void Console::write(const std::string message) {
|
||||||
(void)message;
|
const Style& s = style();
|
||||||
|
const Font& font = s.font;
|
||||||
|
const auto rect = screen_rect();
|
||||||
|
for(const auto c : message) {
|
||||||
|
const auto glyph = font.glyph(c);
|
||||||
|
const auto advance = glyph.advance();
|
||||||
|
if( (pos.x + advance.x) > rect.width() ) {
|
||||||
|
crlf();
|
||||||
|
}
|
||||||
|
const Point pos_glyph {
|
||||||
|
static_cast<Coord>(rect.pos.x + pos.x),
|
||||||
|
display.scroll_area_y(pos.y)
|
||||||
|
};
|
||||||
|
display.draw_glyph(pos_glyph, glyph, s.foreground, s.background);
|
||||||
|
pos.x += advance.x;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::writeln(const std::string message) {
|
void Console::writeln(const std::string message) {
|
||||||
@ -36,33 +59,37 @@ void Console::writeln(const std::string message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Console::paint(Painter& painter) {
|
void Console::paint(Painter& painter) {
|
||||||
|
// Do nothing.
|
||||||
(void)painter;
|
(void)painter;
|
||||||
/*
|
}
|
||||||
if( visible() ) {
|
|
||||||
const auto r = screen_rect();
|
void Console::on_show() {
|
||||||
display.scroll_set_area(r.top(), r.bottom());
|
clear();
|
||||||
display.scroll_set_position(0);
|
|
||||||
painter.fill_rectangle(
|
const auto screen_r = screen_rect();
|
||||||
r,
|
display.scroll_set_area(screen_r.top(), screen_r.bottom());
|
||||||
background
|
}
|
||||||
);
|
|
||||||
} else {
|
void Console::on_hide() {
|
||||||
display.scroll_disable();
|
/* TODO: Clear region to eliminate brief flash of content at un-shifted
|
||||||
}
|
* position?
|
||||||
*/
|
*/
|
||||||
|
display.scroll_disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::crlf() {
|
void Console::crlf() {
|
||||||
const auto line_height = style().font.line_height();
|
const Style& s = style();
|
||||||
|
const auto sr = screen_rect();
|
||||||
|
const auto line_height = s.font.line_height();
|
||||||
pos.x = 0;
|
pos.x = 0;
|
||||||
pos.y += line_height;
|
pos.y += line_height;
|
||||||
const int32_t y_excess = pos.y + line_height - size().h;
|
const int32_t y_excess = pos.y + line_height - sr.height();
|
||||||
if( y_excess > 0 ) {
|
if( y_excess > 0 ) {
|
||||||
display.scroll(-line_height);
|
display.scroll(-y_excess);
|
||||||
pos.y -= y_excess;
|
pos.y -= y_excess;
|
||||||
|
|
||||||
const Rect dirty { 0, display.scroll_area_y(pos.y), size().w, line_height };
|
const Rect dirty { sr.left(), display.scroll_area_y(pos.y), sr.width(), line_height };
|
||||||
display.fill_rectangle(dirty, background);
|
display.fill_rectangle(dirty, s.background);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,15 +38,16 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clear();
|
||||||
void write(const std::string message);
|
void write(const std::string message);
|
||||||
void writeln(const std::string message);
|
void writeln(const std::string message);
|
||||||
|
|
||||||
void paint(Painter& painter) override;
|
void paint(Painter& painter) override;
|
||||||
|
|
||||||
private:
|
void on_show() override;
|
||||||
static constexpr Color background { Color::black() };
|
void on_hide() override;
|
||||||
static constexpr Color foreground { Color::white() };
|
|
||||||
|
|
||||||
|
private:
|
||||||
Point pos { 0, 0 };
|
Point pos { 0, 0 };
|
||||||
|
|
||||||
void crlf();
|
void crlf();
|
||||||
|
Loading…
Reference in New Issue
Block a user