1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:27:45 +00:00

Factor out individual glyph drawing into Painter::draw_glyph().

This commit is contained in:
Andreas Kling 2019-01-15 04:44:47 +01:00
parent 6d8043767e
commit dfff2996d2
5 changed files with 22 additions and 21 deletions

View file

@ -424,14 +424,14 @@ void Terminal::paint()
Painter painter(*m_backing);
painter.fill_rect(rect, Color::Black);
char buf[2] = { 0, 0 };
for (unsigned row = 0; row < m_rows; ++row) {
for (word row = 0; row < m_rows; ++row) {
int y = row * font.glyphHeight();
for (unsigned column = 0; column < m_columns; ++column) {
for (word column = 0; column < m_columns; ++column) {
char ch = m_buffer[(row * 160) + (column * 2)];
if (ch == ' ')
continue;
int x = column * font.glyphWidth();
//buf[0] = at(row, column).character;
buf[0] = m_buffer[(row * 160) + (column * 2)];
painter.draw_text({ x + 2, y + 2, font.glyphWidth(), font.glyphHeight() }, buf, Painter::TextAlignment::TopLeft, Color(0xa0, 0xa0, 0xa0));
painter.draw_glyph({ x + 2, y + 2 }, ch, Color(0xa0, 0xa0, 0xa0));
}
}

View file

@ -1,11 +1,6 @@
#include "Color.h"
#include <AK/Assertions.h>
Color::Color(byte r, byte g, byte b)
{
m_value = (r << 16) | (g << 8) | b;
}
Color::Color(NamedColor named)
{
struct {

View file

@ -21,7 +21,7 @@ public:
Color() { }
Color(NamedColor);
Color(byte r, byte g, byte b);
Color(byte r, byte g, byte b) : m_value((r << 16) | (g << 8) | b) { }
Color(RGBA32 rgba) : m_value(rgba) { }
RGBA32 value() const { return m_value; }

View file

@ -93,6 +93,18 @@ void Painter::draw_bitmap(const Point& p, const CharacterBitmap& bitmap, Color c
}
}
void Painter::draw_glyph(const Point& point, char ch, Color color)
{
auto* bitmap = font().glyphBitmap(ch);
if (!bitmap) {
dbgprintf("Font doesn't have 0x%02x ('%c')\n", ch, ch);
ASSERT_NOT_REACHED();
}
int x = point.x();
int y = point.y();
draw_bitmap({ x, y }, *bitmap, color);
}
void Painter::draw_text(const Rect& rect, const String& text, TextAlignment alignment, Color color)
{
Point point;
@ -109,18 +121,11 @@ void Painter::draw_text(const Rect& rect, const String& text, TextAlignment alig
ASSERT_NOT_REACHED();
}
for (unsigned i = 0; i < text.length(); ++i) {
for (unsigned i = 0; i < text.length(); ++i, point.moveBy(font().glyphWidth(), 0)) {
byte ch = text[i];
if (ch == ' ')
continue;
auto* bitmap = font().glyphBitmap(ch);
if (!bitmap) {
dbgprintf("Font doesn't have 0x%02x ('%c')\n", ch, ch);
ASSERT_NOT_REACHED();
}
int x = point.x() + i * font().glyphWidth();
int y = point.y();
draw_bitmap({ x, y }, *bitmap, color);
draw_glyph(point, ch, color);
}
}

View file

@ -27,6 +27,7 @@ public:
enum class TextAlignment { TopLeft, CenterLeft, Center };
void draw_text(const Rect&, const String&, TextAlignment = TextAlignment::TopLeft, Color = Color());
void draw_glyph(const Point&, char, Color);
const Font& font() const { return *m_font; }