1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:57:35 +00:00

More rage hacking on Widgets. Some very basic text drawing. :^)

This commit is contained in:
Andreas Kling 2018-10-10 20:06:58 +02:00
parent 6f37429f57
commit 77bac7216c
7 changed files with 341 additions and 28 deletions

View file

@ -15,16 +15,281 @@ Painter::~Painter()
ASSERT(rc == 0);
}
void Painter::fillRect(Rect rect, Color color)
static dword* scanline(int y)
{
rect.moveBy(m_widget.x(), m_widget.y());
SDL_Rect sdlRect;
sdlRect.x = rect.x();
sdlRect.y = rect.y();
sdlRect.w = rect.width();
sdlRect.h = rect.height();
int rc = SDL_FillRect(FrameBufferSDL::the().surface(), &sdlRect, color.value());
ASSERT(rc == 0);
auto& surface = *FrameBufferSDL::the().surface();
return (dword*)(((byte*)surface.pixels) + (y * surface.pitch));
}
void Painter::fillRect(const Rect& rect, Color color)
{
Rect r = rect;
r.moveBy(m_widget.x(), m_widget.y());
for (int y = r.top(); y < r.bottom(); ++y) {
dword* bits = scanline(y);
for (int x = r.left(); x < r.right(); ++x) {
bits[x] = color.value();
}
}
}
const char* peanut8x7[] {
" #### "
" # # "
" # # "
" ###### "
" # # "
" # # "
"### ###",
" ##### "
" # # "
" # # "
" ###### "
" # # "
" # # "
" ##### ",
" #### "
" # # "
" # "
" # "
" # "
" # # "
" #### ",
" ##### "
" # # "
" # # "
" # # "
" # # "
" # # "
" ##### ",
" ###### "
" # # "
" # "
" #### "
" # "
" # # "
" ###### ",
" ###### "
" # # "
" # "
" #### "
" # "
" # "
" # ",
" #### "
" # # "
" # "
" # ###"
" # # "
" # # "
" #### ",
" # # "
" # # "
" # # "
" ###### "
" # # "
" # # "
" # # ",
" ### "
" # "
" # "
" # "
" # "
" # "
" ### ",
" ##### "
" # # "
" # "
" # "
" # "
" # # "
" ### ",
" ### ###"
" # # "
" # # "
" ### "
" # # "
" # # "
" ### ###",
" ### "
" # "
" # "
" # "
" # "
" # # "
" ###### ",
" # # "
" ## ## "
" # ## # "
" # # "
" # # "
" # # "
"### ###",
" # # "
" ## # "
" # # # "
" # # # "
" # ## "
" # # "
" # # ",
" #### "
" # # "
" # # "
" # # "
" # # "
" # # "
" #### ",
" ##### "
" # # "
" # # "
" #### "
" # "
" # "
" ### ",
" #### "
" # # "
" # # "
" # # "
" # # # "
" # # "
" ### # ",
" ##### "
" # # "
" # # "
" #### "
" # # "
" # # "
" ### # ",
" #### "
" # # "
" # "
" #### "
" # "
" # # "
" #### ",
" ##### "
"# # # "
" # "
" # "
" # "
" # "
" ### ",
"### ###"
" # # "
" # # "
" # # "
" # # "
" # # "
" #### ",
"### ### "
" # # "
" # # "
" # # "
" # # "
" # "
" # ",
"### ###"
" # # "
" # # "
" # # "
" # ## # "
" ## ## "
" # # ",
"## ## "
" # # "
" # # "
" # "
" # # "
" # # "
"## ## ",
"## ## "
" # # "
" # # "
" # # "
" # "
" # "
" ### ",
" ###### "
" # # "
" # "
" # "
" # "
" # # "
" ###### ",
" #### "
" # "
" # "
" # "
" # "
" # "
" #### ",
" # "
" ## "
" ## "
" ## "
" ## "
" ## "
" # ",
" #### "
" # "
" # "
" # "
" # "
" # "
" #### ",
};
void Painter::drawText(const Point& point, const String& text, const Color& color)
{
Point p = point;
p.moveBy(m_widget.x(), m_widget.y());
byte fontWidth = 8;
byte fontHeight = 7;
auto* font = peanut8x7;
for (int row = 0; row < fontHeight; ++row) {
int y = p.y() + row;
dword* bits = scanline(y);
for (unsigned i = 0; i < text.length(); ++i) {
const char* fontCharacter = font[text[i] - 'A'];
int x = p.x() + i * fontWidth;
for (unsigned j = 0; j < fontWidth; ++j) {
char fc = fontCharacter[row * fontWidth + j];
if (fc == '#')
bits[x + j] = color.value();
}
}
}
}