mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 17:24:48 -05:00
Add a Painter::drawBitmap() and make Painter::drawText() use it.
This commit is contained in:
parent
73895ce043
commit
e23ac56017
Notes:
sideshowbarker
2024-07-19 18:50:14 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/e23ac560174
4 changed files with 51 additions and 20 deletions
Binary file not shown.
|
@ -80,8 +80,24 @@ void Painter::xorRect(const Rect& rect, Color color)
|
|||
}
|
||||
}
|
||||
|
||||
void Painter::drawBitmap(const Point& point, const char* bitmap, const Size& bitmapSize, Color color)
|
||||
{
|
||||
ASSERT(bitmap);
|
||||
ASSERT(!bitmapSize.isEmpty());
|
||||
|
||||
void Painter::drawText(const Rect& rect, const String& text, TextAlignment alignment, const Color& color)
|
||||
for (int row = 0; row < bitmapSize.height(); ++row) {
|
||||
int y = point.y() + row;
|
||||
int x = point.x();
|
||||
dword* bits = scanline(y);
|
||||
for (int j = 0; j < bitmapSize.width(); ++j) {
|
||||
char fc = bitmap[row * bitmapSize.width() + j];
|
||||
if (fc == '#')
|
||||
bits[x + j] = color.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Painter::drawText(const Rect& rect, const String& text, TextAlignment alignment, Color color)
|
||||
{
|
||||
Point point;
|
||||
|
||||
|
@ -97,25 +113,18 @@ void Painter::drawText(const Rect& rect, const String& text, TextAlignment align
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
for (int row = 0; row < m_font.glyphHeight(); ++row) {
|
||||
int y = point.y() + row;
|
||||
dword* bits = scanline(y);
|
||||
for (unsigned i = 0; i < text.length(); ++i) {
|
||||
byte ch = text[i];
|
||||
if (ch == ' ')
|
||||
continue;
|
||||
const char* glyph = m_font.glyph(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 (int j = 0; j < m_font.glyphWidth(); ++j) {
|
||||
char fc = glyph[row * m_font.glyphWidth() + j];
|
||||
if (fc == '#')
|
||||
bits[x + j] = color.value();
|
||||
}
|
||||
for (unsigned i = 0; i < text.length(); ++i) {
|
||||
byte ch = text[i];
|
||||
if (ch == ' ')
|
||||
continue;
|
||||
const char* glyph = m_font.glyph(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();
|
||||
int y = point.y();
|
||||
drawBitmap({ x, y }, glyph, { m_font.glyphWidth(), m_font.glyphHeight() }, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "Color.h"
|
||||
#include "Point.h"
|
||||
#include "Rect.h"
|
||||
#include "Size.h"
|
||||
#include <AK/String.h>
|
||||
|
||||
class Font;
|
||||
|
@ -15,7 +16,8 @@ public:
|
|||
~Painter();
|
||||
void fillRect(const Rect&, Color);
|
||||
void drawRect(const Rect&, Color);
|
||||
void drawText(const Rect&, const String&, TextAlignment = TextAlignment::TopLeft, const Color& = Color());
|
||||
void drawText(const Rect&, const String&, TextAlignment = TextAlignment::TopLeft, Color = Color());
|
||||
void drawBitmap(const Point&, const char* bitmap, const Size& bitmapSize, Color = Color());
|
||||
|
||||
void xorRect(const Rect&, Color);
|
||||
|
||||
|
|
20
Widgets/Size.h
Normal file
20
Widgets/Size.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
class Size {
|
||||
public:
|
||||
Size() { }
|
||||
Size(int w, int h) : m_width(w), m_height(h) { }
|
||||
|
||||
bool isEmpty() const { return !m_width || !m_height; }
|
||||
|
||||
int width() const { return m_width; }
|
||||
int height() const { return m_height; }
|
||||
|
||||
void setWidth(int w) { m_width = w; }
|
||||
void setHeight(int h) { m_height = h; }
|
||||
|
||||
private:
|
||||
int m_width { 0 };
|
||||
int m_height { 0 };
|
||||
};
|
||||
|
Loading…
Reference in a new issue