mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-04 15:09:40 +00:00
Some work on window decorations.
This commit is contained in:
parent
a4491e9630
commit
a6e0577f30
|
@ -42,6 +42,24 @@ void Painter::fillRect(const Rect& rect, Color color)
|
|||
}
|
||||
}
|
||||
|
||||
void Painter::drawRect(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);
|
||||
if (y == r.top() || y == (r.bottom() - 1)) {
|
||||
for (int x = r.left(); x < r.right(); ++x) {
|
||||
bits[x] = color.value();
|
||||
}
|
||||
} else {
|
||||
bits[r.left()] = color.value();
|
||||
bits[r.right() - 1] = color.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Painter::drawText(const Rect& rect, const String& text, TextAlignment alignment, const Color& color)
|
||||
{
|
||||
Point point;
|
||||
|
|
|
@ -13,6 +13,7 @@ public:
|
|||
explicit Painter(Widget&);
|
||||
~Painter();
|
||||
void fillRect(const Rect&, Color);
|
||||
void drawRect(const Rect&, Color);
|
||||
void drawText(const Rect&, const String&, TextAlignment = TextAlignment::TopLeft, const Color& = Color());
|
||||
|
||||
private:
|
||||
|
|
|
@ -15,7 +15,8 @@ TerminalWidget::TerminalWidget(Widget* parent)
|
|||
|
||||
g_tw = this;
|
||||
|
||||
setRect({ 100, 300, columns() * 8, rows() * 10 });
|
||||
setRect({ 100, 300, (columns() * 8) + 4, (rows() * 10) + 4 });
|
||||
|
||||
printf("rekt: %d x %d\n", width(), height());
|
||||
m_screen = new CharacterWithAttributes[rows() * columns()];
|
||||
for (unsigned row = 0; row < m_rows; ++row) {
|
||||
|
@ -70,7 +71,7 @@ void TerminalWidget::onPaint(PaintEvent&)
|
|||
for (unsigned column = 0; column < m_columns; ++column) {
|
||||
int x = column * 8;
|
||||
buf[0] = at(row, column).character;
|
||||
painter.drawText({ x, y, width(), 10 }, buf, Painter::TextAlignment::TopLeft, Color(0xa0, 0xa0, 0xa0));
|
||||
painter.drawText({ x + 2, y + 2, width(), 10 }, buf, Painter::TextAlignment::TopLeft, Color(0xa0, 0xa0, 0xa0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ void WindowManager::paintWindowFrame(Widget& widget)
|
|||
printf("WM: paintWindowFrame %s{%p}, rect: %d,%d %dx%d\n", widget.className(), &widget, widget.rect().x(), widget.rect().y(), widget.rect().width(), widget.rect().height());
|
||||
|
||||
static const int windowFrameWidth = 2;
|
||||
static const int windowTitleBarHeight = 14;
|
||||
static const int windowTitleBarHeight = 16;
|
||||
|
||||
Rect topRect {
|
||||
widget.x() - windowFrameWidth,
|
||||
|
@ -59,12 +59,25 @@ void WindowManager::paintWindowFrame(Widget& widget)
|
|||
widget.height()
|
||||
};
|
||||
|
||||
p.fillRect(topRect, Color(0x40, 0x40, 0xc0));
|
||||
p.fillRect(bottomRect, Color(0x40, 0x40, 0xc0));
|
||||
p.fillRect(leftRect, Color(0x40, 0x40, 0xc0));
|
||||
p.fillRect(rightRect, Color(0x40, 0x40, 0xc0));
|
||||
static const Color windowBorderColor(0x00, 0x00, 0x80);
|
||||
static const Color windowTitleColor(0xff, 0xff, 0xff);
|
||||
|
||||
p.drawText(topRect, widget.windowTitle(), Painter::TextAlignment::Center, Color(255, 255, 255));
|
||||
Rect borderRect {
|
||||
topRect.x() - 1,
|
||||
topRect.y() - 1,
|
||||
topRect.width() + 2,
|
||||
windowFrameWidth + windowTitleBarHeight + widget.height() + 4
|
||||
};
|
||||
p.drawRect(borderRect, Color(255, 255, 255));
|
||||
borderRect.inflate(2, 2);
|
||||
p.drawRect(borderRect, windowBorderColor);
|
||||
|
||||
p.fillRect(topRect, windowBorderColor);
|
||||
p.fillRect(bottomRect, windowBorderColor);
|
||||
p.fillRect(leftRect, windowBorderColor);
|
||||
p.fillRect(rightRect, windowBorderColor);
|
||||
|
||||
p.drawText(topRect, widget.windowTitle(), Painter::TextAlignment::Center, windowTitleColor);
|
||||
}
|
||||
|
||||
void WindowManager::addWindow(Widget& widget)
|
||||
|
|
Loading…
Reference in a new issue