From a6e0577f30446598bb6b20007c813da2f0387dc2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 11 Oct 2018 23:14:51 +0200 Subject: Some work on window decorations. --- Widgets/Painter.cpp | 18 ++++++++++++++++++ Widgets/Painter.h | 1 + Widgets/TerminalWidget.cpp | 5 +++-- Widgets/WindowManager.cpp | 25 +++++++++++++++++++------ 4 files changed, 41 insertions(+), 8 deletions(-) (limited to 'Widgets') diff --git a/Widgets/Painter.cpp b/Widgets/Painter.cpp index ff53b73713..2f54370106 100644 --- a/Widgets/Painter.cpp +++ b/Widgets/Painter.cpp @@ -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; diff --git a/Widgets/Painter.h b/Widgets/Painter.h index 524548b0af..459ec5ce8a 100644 --- a/Widgets/Painter.h +++ b/Widgets/Painter.h @@ -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: diff --git a/Widgets/TerminalWidget.cpp b/Widgets/TerminalWidget.cpp index 0d404b3f45..ff11ac880b 100644 --- a/Widgets/TerminalWidget.cpp +++ b/Widgets/TerminalWidget.cpp @@ -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)); } } } diff --git a/Widgets/WindowManager.cpp b/Widgets/WindowManager.cpp index 15fab7a39b..467c764ce2 100644 --- a/Widgets/WindowManager.cpp +++ b/Widgets/WindowManager.cpp @@ -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) -- cgit v1.2.3