2015-07-08 15:39:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui_console.hpp"
|
|
|
|
|
2015-08-01 21:31:51 +00:00
|
|
|
#include "portapack.hpp"
|
|
|
|
using namespace portapack;
|
|
|
|
|
2015-07-08 15:39:24 +00:00
|
|
|
namespace ui {
|
|
|
|
|
2015-09-26 17:56:57 +00:00
|
|
|
void Console::clear() {
|
|
|
|
display.fill_rectangle(
|
|
|
|
screen_rect(),
|
|
|
|
Color::black()
|
|
|
|
);
|
|
|
|
pos = { 0, 0 };
|
2015-10-17 02:36:07 +00:00
|
|
|
display.scroll_set_position(0);
|
2015-09-26 17:56:57 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 00:23:20 +00:00
|
|
|
void Console::write(const std::string& message) {
|
2015-09-26 17:56:57 +00:00
|
|
|
const Style& s = style();
|
|
|
|
const Font& font = s.font;
|
|
|
|
const auto rect = screen_rect();
|
|
|
|
for(const auto c : message) {
|
2015-12-02 01:28:22 +00:00
|
|
|
if( c == '\n' ) {
|
2015-09-26 17:56:57 +00:00
|
|
|
crlf();
|
2015-12-02 01:28:22 +00:00
|
|
|
} else {
|
|
|
|
const auto glyph = font.glyph(c);
|
|
|
|
const auto advance = glyph.advance();
|
2016-11-28 18:39:10 +00:00
|
|
|
if( (pos.x() + advance.x()) > rect.width() ) {
|
2015-12-02 01:28:22 +00:00
|
|
|
crlf();
|
|
|
|
}
|
|
|
|
const Point pos_glyph {
|
2016-11-28 18:39:10 +00:00
|
|
|
rect.pos.x() + pos.x(),
|
|
|
|
display.scroll_area_y(pos.y())
|
2015-12-02 01:28:22 +00:00
|
|
|
};
|
|
|
|
display.draw_glyph(pos_glyph, glyph, s.foreground, s.background);
|
2016-11-28 18:39:10 +00:00
|
|
|
pos += { advance.x(), 0 };
|
2015-09-26 17:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-08 15:39:24 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 00:23:20 +00:00
|
|
|
void Console::writeln(const std::string& message) {
|
2015-07-08 15:39:24 +00:00
|
|
|
write(message);
|
|
|
|
crlf();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Console::paint(Painter& painter) {
|
2015-09-26 17:56:57 +00:00
|
|
|
// Do nothing.
|
2015-07-08 15:39:24 +00:00
|
|
|
(void)painter;
|
2015-09-26 17:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Console::on_show() {
|
|
|
|
const auto screen_r = screen_rect();
|
|
|
|
display.scroll_set_area(screen_r.top(), screen_r.bottom());
|
2015-10-17 02:36:07 +00:00
|
|
|
|
|
|
|
clear();
|
2015-09-26 17:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Console::on_hide() {
|
|
|
|
/* TODO: Clear region to eliminate brief flash of content at un-shifted
|
|
|
|
* position?
|
|
|
|
*/
|
|
|
|
display.scroll_disable();
|
2015-07-08 15:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Console::crlf() {
|
2015-09-26 17:56:57 +00:00
|
|
|
const Style& s = style();
|
|
|
|
const auto sr = screen_rect();
|
|
|
|
const auto line_height = s.font.line_height();
|
2016-11-28 18:39:10 +00:00
|
|
|
pos = { 0, pos.y() + line_height };
|
|
|
|
const int32_t y_excess = pos.y() + line_height - sr.height();
|
2015-07-08 15:39:24 +00:00
|
|
|
if( y_excess > 0 ) {
|
2015-09-26 17:56:57 +00:00
|
|
|
display.scroll(-y_excess);
|
2016-11-28 18:39:10 +00:00
|
|
|
pos = { pos.x(), pos.y() - y_excess };
|
2015-07-08 15:39:24 +00:00
|
|
|
|
2016-11-28 18:39:10 +00:00
|
|
|
const Rect dirty { sr.left(), display.scroll_area_y(pos.y()), sr.width(), line_height };
|
2015-09-26 17:56:57 +00:00
|
|
|
display.fill_rectangle(dirty, s.background);
|
2015-07-08 15:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|