diff --git a/Widgets/EventLoop.cpp b/Widgets/EventLoop.cpp index aa227eb99bb..c396c149038 100644 --- a/Widgets/EventLoop.cpp +++ b/Widgets/EventLoop.cpp @@ -29,7 +29,7 @@ int EventLoop::exec() for (auto& queuedEvent : events) { auto* receiver = queuedEvent.receiver; auto& event = *queuedEvent.event; - printf("EventLoop: Object{%p} event %u (%s)\n", receiver, (unsigned)event.type(), event.name()); + //printf("EventLoop: Object{%p} event %u (%s)\n", receiver, (unsigned)event.type(), event.name()); if (!receiver) { switch (event.type()) { case Event::Quit: diff --git a/Widgets/Font.cpp b/Widgets/Font.cpp index a4bda1a184e..7fda3bff5cc 100644 --- a/Widgets/Font.cpp +++ b/Widgets/Font.cpp @@ -9,7 +9,7 @@ Font& Font::defaultFont() return *f; } -Font::Font(const char* const* glyphs, unsigned glyphWidth, unsigned glyphHeight, byte firstGlyph, byte lastGlyph) +Font::Font(const char* const* glyphs, byte glyphWidth, byte glyphHeight, byte firstGlyph, byte lastGlyph) : m_glyphs(glyphs) , m_glyphWidth(glyphWidth) , m_glyphHeight(glyphHeight) diff --git a/Widgets/Font.h b/Widgets/Font.h index 1c53e4d4496..7429b3f021b 100644 --- a/Widgets/Font.h +++ b/Widgets/Font.h @@ -11,16 +11,16 @@ public: const char* glyph(char) const; - unsigned glyphWidth() const { return m_glyphWidth; } - unsigned glyphHeight() const { return m_glyphHeight; } + byte glyphWidth() const { return m_glyphWidth; } + byte glyphHeight() const { return m_glyphHeight; } private: - Font(const char* const* glyphs, unsigned glyphWidth, unsigned glyphHeight, byte firstGlyph, byte lastGlyph); + Font(const char* const* glyphs, byte glyphWidth, byte glyphHeight, byte firstGlyph, byte lastGlyph); const char* const* m_glyphs { nullptr }; - unsigned m_glyphWidth { 0 }; - unsigned m_glyphHeight { 0 }; + byte m_glyphWidth { 0 }; + byte m_glyphHeight { 0 }; byte m_firstGlyph { 0 }; byte m_lastGlyph { 0 }; diff --git a/Widgets/Painter.cpp b/Widgets/Painter.cpp index 4750d17419d..19b38224b89 100644 --- a/Widgets/Painter.cpp +++ b/Widgets/Painter.cpp @@ -78,12 +78,12 @@ void Painter::drawText(const Rect& rect, const String& text, TextAlignment align if (ch == ' ') continue; const char* glyph = m_font.glyph(ch); - if (!ch) { + if (!glyph) { printf("Font doesn't have 0x%02x ('%c')\n", ch, ch); ASSERT_NOT_REACHED(); } int x = point.x() + i * m_font.glyphWidth(); - for (unsigned j = 0; j < m_font.glyphWidth(); ++j) { + for (int j = 0; j < m_font.glyphWidth(); ++j) { char fc = glyph[row * m_font.glyphWidth() + j]; if (fc == '#') bits[x + j] = color.value(); diff --git a/Widgets/TerminalWidget.cpp b/Widgets/TerminalWidget.cpp index ff11ac880bc..c96d5fc7a26 100644 --- a/Widgets/TerminalWidget.cpp +++ b/Widgets/TerminalWidget.cpp @@ -1,4 +1,5 @@ #include "TerminalWidget.h" +#include "Font.h" #include "Painter.h" #include #include @@ -14,8 +15,10 @@ TerminalWidget::TerminalWidget(Widget* parent) setIsWindow(true); g_tw = this; + + auto& font = Font::defaultFont(); - setRect({ 100, 300, (columns() * 8) + 4, (rows() * 10) + 4 }); + setRect({ 100, 300, (columns() * font.glyphWidth()) + 4, (rows() * font.glyphHeight()) + 4 }); printf("rekt: %d x %d\n", width(), height()); m_screen = new CharacterWithAttributes[rows() * columns()]; @@ -62,16 +65,17 @@ CharacterWithAttributes& TerminalWidget::at(unsigned row, unsigned column) void TerminalWidget::onPaint(PaintEvent&) { Painter painter(*this); - painter.fillRect({ 0, 0, width(), height() }, Color(0, 0, 0)); + auto& font = Font::defaultFont(); + char buf[2] = { 0, 0 }; for (unsigned row = 0; row < m_rows; ++row) { - int y = row * 10; + int y = row * font.glyphHeight(); for (unsigned column = 0; column < m_columns; ++column) { - int x = column * 8; + int x = column * font.glyphWidth(); buf[0] = at(row, column).character; - painter.drawText({ x + 2, y + 2, width(), 10 }, buf, Painter::TextAlignment::TopLeft, Color(0xa0, 0xa0, 0xa0)); + painter.drawText({ x + 2, y + 2, width(), font.glyphHeight() }, buf, Painter::TextAlignment::TopLeft, Color(0xa0, 0xa0, 0xa0)); } } }