summaryrefslogtreecommitdiff
path: root/Widgets/WindowManager.cpp
blob: 15fab7a39bc94ae732e640b8705b5d5e887bdd1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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();
}