mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:47:46 +00:00
Use Font in more places.
This commit is contained in:
parent
110d01941a
commit
bd6172e3c7
5 changed files with 18 additions and 14 deletions
|
@ -29,7 +29,7 @@ int EventLoop::exec()
|
||||||
for (auto& queuedEvent : events) {
|
for (auto& queuedEvent : events) {
|
||||||
auto* receiver = queuedEvent.receiver;
|
auto* receiver = queuedEvent.receiver;
|
||||||
auto& event = *queuedEvent.event;
|
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) {
|
if (!receiver) {
|
||||||
switch (event.type()) {
|
switch (event.type()) {
|
||||||
case Event::Quit:
|
case Event::Quit:
|
||||||
|
|
|
@ -9,7 +9,7 @@ Font& Font::defaultFont()
|
||||||
return *f;
|
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_glyphs(glyphs)
|
||||||
, m_glyphWidth(glyphWidth)
|
, m_glyphWidth(glyphWidth)
|
||||||
, m_glyphHeight(glyphHeight)
|
, m_glyphHeight(glyphHeight)
|
||||||
|
|
|
@ -11,16 +11,16 @@ public:
|
||||||
|
|
||||||
const char* glyph(char) const;
|
const char* glyph(char) const;
|
||||||
|
|
||||||
unsigned glyphWidth() const { return m_glyphWidth; }
|
byte glyphWidth() const { return m_glyphWidth; }
|
||||||
unsigned glyphHeight() const { return m_glyphHeight; }
|
byte glyphHeight() const { return m_glyphHeight; }
|
||||||
|
|
||||||
private:
|
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 };
|
const char* const* m_glyphs { nullptr };
|
||||||
|
|
||||||
unsigned m_glyphWidth { 0 };
|
byte m_glyphWidth { 0 };
|
||||||
unsigned m_glyphHeight { 0 };
|
byte m_glyphHeight { 0 };
|
||||||
|
|
||||||
byte m_firstGlyph { 0 };
|
byte m_firstGlyph { 0 };
|
||||||
byte m_lastGlyph { 0 };
|
byte m_lastGlyph { 0 };
|
||||||
|
|
|
@ -78,12 +78,12 @@ void Painter::drawText(const Rect& rect, const String& text, TextAlignment align
|
||||||
if (ch == ' ')
|
if (ch == ' ')
|
||||||
continue;
|
continue;
|
||||||
const char* glyph = m_font.glyph(ch);
|
const char* glyph = m_font.glyph(ch);
|
||||||
if (!ch) {
|
if (!glyph) {
|
||||||
printf("Font doesn't have 0x%02x ('%c')\n", ch, ch);
|
printf("Font doesn't have 0x%02x ('%c')\n", ch, ch);
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
int x = point.x() + i * m_font.glyphWidth();
|
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];
|
char fc = glyph[row * m_font.glyphWidth() + j];
|
||||||
if (fc == '#')
|
if (fc == '#')
|
||||||
bits[x + j] = color.value();
|
bits[x + j] = color.value();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "TerminalWidget.h"
|
#include "TerminalWidget.h"
|
||||||
|
#include "Font.h"
|
||||||
#include "Painter.h"
|
#include "Painter.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -14,8 +15,10 @@ TerminalWidget::TerminalWidget(Widget* parent)
|
||||||
setIsWindow(true);
|
setIsWindow(true);
|
||||||
|
|
||||||
g_tw = this;
|
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());
|
printf("rekt: %d x %d\n", width(), height());
|
||||||
m_screen = new CharacterWithAttributes[rows() * columns()];
|
m_screen = new CharacterWithAttributes[rows() * columns()];
|
||||||
|
@ -62,16 +65,17 @@ CharacterWithAttributes& TerminalWidget::at(unsigned row, unsigned column)
|
||||||
void TerminalWidget::onPaint(PaintEvent&)
|
void TerminalWidget::onPaint(PaintEvent&)
|
||||||
{
|
{
|
||||||
Painter painter(*this);
|
Painter painter(*this);
|
||||||
|
|
||||||
painter.fillRect({ 0, 0, width(), height() }, Color(0, 0, 0));
|
painter.fillRect({ 0, 0, width(), height() }, Color(0, 0, 0));
|
||||||
|
|
||||||
|
auto& font = Font::defaultFont();
|
||||||
|
|
||||||
char buf[2] = { 0, 0 };
|
char buf[2] = { 0, 0 };
|
||||||
for (unsigned row = 0; row < m_rows; ++row) {
|
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) {
|
for (unsigned column = 0; column < m_columns; ++column) {
|
||||||
int x = column * 8;
|
int x = column * font.glyphWidth();
|
||||||
buf[0] = at(row, column).character;
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue