1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

More hacking on Widgets.

This commit is contained in:
Andreas Kling 2018-10-11 16:52:40 +02:00
parent c37ded0ae4
commit a4491e9630
9 changed files with 150 additions and 2 deletions

79
Widgets/WindowManager.cpp Normal file
View file

@ -0,0 +1,79 @@
#include "WindowManager.h"
#include "Painter.h"
#include "Widget.h"
#include "AbstractScreen.h"
WindowManager& WindowManager::the()
{
static WindowManager* s_the = new WindowManager;
return *s_the;
}
WindowManager::WindowManager()
{
}
WindowManager::~WindowManager()
{
}
void WindowManager::paintWindowFrames()
{
for (auto* widget : m_windows) {
paintWindowFrame(*widget);
}
}
void WindowManager::paintWindowFrame(Widget& widget)
{
Painter p(*AbstractScreen::the().rootWidget());
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;
Rect topRect {
widget.x() - windowFrameWidth,
widget.y() - windowTitleBarHeight - windowFrameWidth,
widget.width() + windowFrameWidth * 2,
windowTitleBarHeight + windowFrameWidth };
Rect bottomRect {
widget.x() - windowFrameWidth,
widget.y() + widget.height(),
widget.width() + windowFrameWidth * 2,
windowFrameWidth };
Rect leftRect {
widget.x() - windowFrameWidth,
widget.y(),
windowFrameWidth,
widget.height()
};
Rect rightRect {
widget.x() + widget.width(),
widget.y(),
windowFrameWidth,
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));
p.drawText(topRect, widget.windowTitle(), Painter::TextAlignment::Center, Color(255, 255, 255));
}
void WindowManager::addWindow(Widget& widget)
{
m_windows.set(&widget);
}
void WindowManager::notifyTitleChanged(Widget&)
{
AbstractScreen::the().rootWidget()->update();
}