Use Font in more places.

This commit is contained in:
Andreas Kling 2018-10-11 23:54:34 +02:00
parent 110d01941a
commit bd6172e3c7
Notes: sideshowbarker 2024-07-19 18:50:39 +09:00
5 changed files with 18 additions and 14 deletions

View file

@ -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:

View file

@ -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)

View file

@ -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 };

View file

@ -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();

View file

@ -1,4 +1,5 @@
#include "TerminalWidget.h"
#include "Font.h"
#include "Painter.h"
#include <unistd.h>
#include <signal.h>
@ -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));
}
}
}