summaryrefslogtreecommitdiff
path: root/Widgets
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-10-12 12:29:58 +0200
committerAndreas Kling <awesomekling@gmail.com>2018-10-12 12:29:58 +0200
commite23ac5601741441fea916f605a562d11c9982baa (patch)
tree639f927b9877daa52d2a003413e63974cea58f58 /Widgets
parent73895ce043fcd4eeb6f84645dc1b46ca58788e62 (diff)
downloadserenity-e23ac5601741441fea916f605a562d11c9982baa.zip
Add a Painter::drawBitmap() and make Painter::drawText() use it.
Diffstat (limited to 'Widgets')
-rw-r--r--Widgets/FrameBuffer.obin47688 -> 0 bytes
-rw-r--r--Widgets/Painter.cpp47
-rw-r--r--Widgets/Painter.h4
-rw-r--r--Widgets/Size.h20
4 files changed, 51 insertions, 20 deletions
diff --git a/Widgets/FrameBuffer.o b/Widgets/FrameBuffer.o
deleted file mode 100644
index 73b4ce2597..0000000000
--- a/Widgets/FrameBuffer.o
+++ /dev/null
Binary files differ
diff --git a/Widgets/Painter.cpp b/Widgets/Painter.cpp
index c872d22868..08c6389111 100644
--- a/Widgets/Painter.cpp
+++ b/Widgets/Painter.cpp
@@ -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);
}
}
diff --git a/Widgets/Painter.h b/Widgets/Painter.h
index c01f093eea..d7eeedce26 100644
--- a/Widgets/Painter.h
+++ b/Widgets/Painter.h
@@ -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);
diff --git a/Widgets/Size.h b/Widgets/Size.h
new file mode 100644
index 0000000000..a50e7b3086
--- /dev/null
+++ b/Widgets/Size.h
@@ -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 };
+};
+