~aleteoryx/muditaos

muditaos/module-apps/apps-common/windows/BrightnessWindow.cpp -rw-r--r-- 2.3 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
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
80
81
82
83
84
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include <module-gui/gui/input/InputEvent.hpp>
#include <module-gui/gui/widgets/Arc.hpp>
#include "BrightnessWindow.hpp"

namespace gui
{
    BrightnessWindow::BrightnessWindow(app::ApplicationCommon *app, const std::string &name) : AppWindow(app, name)
    {
        buildInterface();
    }

    void BrightnessWindow::addBox()
    {
        border = new Rect(this,
                          0,
                          style::window::brightness::box::top_offset,
                          style::window::brightness::box::width,
                          style::window::brightness::box::height);
        border->setEdges(RectangleEdge::Top);
    }

    void BrightnessWindow::addBrightnessText()
    {
        brightnessText = new BrightnessBox(
            this, style::window::brightness::title::left_offset, style::window::brightness::title::top_offset);
    }

    void BrightnessWindow::addBrightnessBar()
    {
        brightnessBar = new HBarGraph(this,
                                      style::window::brightness::bar::left_offset + 20,
                                      style::window::brightness::bar::top_offset,
                                      style::window::brightness::bar::brightness_levels);
    }

    void BrightnessWindow::buildInterface()
    {
        AppWindow::buildInterface();
        addBox();
        addBrightnessText();
        addBrightnessBar();
    }

    void BrightnessWindow::rebuild()
    {}

    void BrightnessWindow::destroyInterface()
    {
        erase();
    }

    BrightnessWindow::~BrightnessWindow()
    {
        destroyInterface();
    }

    void BrightnessWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {}

    bool BrightnessWindow::onInput(const gui::InputEvent &inputEvent)
    {
        if (!inputEvent.isShortRelease()) {
            return false;
        }

        int update = brightnessBar->getValue();
        if (inputEvent.is(gui::KeyCode::KEY_VOLUP)) {
            update++;
        }

        if (inputEvent.is(gui::KeyCode::KEY_VOLDN)) {
            update--;
        }

        if (update >= 0) {
            brightnessBar->setValue(update);
        }

        return AppWindow::onInput(inputEvent);
    }
} // namespace gui