summaryrefslogtreecommitdiff
path: root/LibGUI/GStyle.cpp
blob: c74193d04aa91854d01ef1e3a8f506205ce048fa (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
#include <LibGUI/GStyle.h>
#include <SharedGraphics/Painter.h>

static GStyle* s_the;

GStyle& GStyle::the()
{
    if (!s_the)
        s_the = new GStyle;
    return *s_the;
}

GStyle::GStyle()
{
}

void GStyle::paint_button(Painter& painter, const Rect& rect, GButtonStyle button_style, bool pressed, bool hovered)
{
    Color button_color = Color::LightGray;
    Color highlight_color = Color::White;
    Color shadow_color = Color(96, 96, 96);

    if (button_style == GButtonStyle::Normal)
        painter.draw_rect(rect, Color::Black, true);

    painter.translate(rect.location());

    if (pressed) {
        // Base
        painter.fill_rect({ 1, 1, rect.width() - 2, rect.height() - 2 }, button_color);

        // Sunken shadow
        painter.draw_line({ 1, 1 }, { rect.width() - 2, 1 }, shadow_color);
        painter.draw_line({ 1, 2 }, {1, rect.height() - 2 }, shadow_color);

        // Bottom highlight
        painter.draw_line({ rect.width() - 2, 1 }, { rect.width() - 2, rect.height() - 3 }, highlight_color);
        painter.draw_line({ 1, rect.height() - 2 }, { rect.width() - 2, rect.height() - 2 }, highlight_color);
    } else if (button_style == GButtonStyle::Normal || (button_style == GButtonStyle::CoolBar && hovered)) {
        // Base
        painter.fill_rect({ 3, 3, rect.width() - 5, rect.height() - 5 }, button_color);

        // White highlight
        painter.draw_line({ 1, 1 }, { rect.width() - 2, 1 }, highlight_color);
        painter.draw_line({ 1, 2 }, { 1, rect.height() - 2 }, highlight_color);

        // Gray shadow
        painter.draw_line({ rect.width() - 2, 1 }, { rect.width() - 2, rect.height() - 3 }, shadow_color);
        painter.draw_line({ 1, rect.height() - 2 }, { rect.width() - 2, rect.height() - 2 }, shadow_color);
    }

    painter.translate(-rect.location().x(), -rect.location().y());
}

void GStyle::paint_surface(Painter& painter, const Rect& rect)
{
    painter.fill_rect({ rect.x(), rect.y() + 1, rect.width(), rect.height() - 2 }, Color::LightGray);
    painter.draw_line(rect.top_left(), rect.top_right(), Color::White);
    painter.draw_line(rect.bottom_left(), rect.bottom_right(), Color::DarkGray);
    painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), Color::White);
    painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), Color::DarkGray);
}