~aleteoryx/muditaos

ref: 0823d82e5141f44812c54debf07245d0ca746124 muditaos/module-gui/gui/widgets/Window.cpp -rw-r--r-- 1.8 KiB
0823d82e — Radoslaw Wicik [EGD-3743] Update copyrights in fies - add empty line after license 5 years 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
/*
 * Window.cpp
 *
 *  Created on: 6 mar 2019
 *      Author: robert
 */
#include <algorithm>
// gui
#include "../Common.hpp"
#include "../core/BoundingBox.hpp"
#include "../core/DrawCommand.hpp"
#include "Window.hpp"
#include <InputEvent.hpp>

namespace gui
{
    Window::Window(std::string name) : Item(), refreshMode{RefreshModes::GUI_REFRESH_FAST}, name{name}
    {}

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

    void Window::onClose()
    {}

    void Window::getRefreshArea(RefreshModes &mode, uint16_t &x, uint16_t &y, uint16_t &w, uint16_t &h)
    {
        x    = widgetArea.x;
        y    = widgetArea.y;
        w    = widgetArea.w;
        h    = widgetArea.h;
        mode = refreshMode;
    }

    bool Window::handleSwitchData(SwitchData *data)
    {
        return true;
    }

    std::list<DrawCommand *> Window::buildDrawList()
    {

        std::list<DrawCommand *> commands;
        std::list<DrawCommand *> childrenCommands = Item::buildDrawList();

        DrawCommand *clearCommand = new DrawCommand();
        clearCommand->id          = DrawCommandID::GUI_DRAW_CLEAR;

        commands.push_back(clearCommand);

        if (!childrenCommands.empty()) {
            commands.splice(commands.end(), childrenCommands);
        }

        return commands;
    }

    bool Window::onInput(const InputEvent &inputEvent)
    {
        if (focusItem != nullptr && focusItem->onInput(inputEvent)) {
            return true;
        }
        if (inputCallback != nullptr && inputCallback(*this, inputEvent)) {
            return true;
        }
        if (handleNavigation(inputEvent)) {
            return true;
        }
        return inputEvent.state == InputEvent::State::keyReleasedShort &&
               inputEvent.keyCode == gui::KeyCode::KEY_ENTER && onActivated(nullptr);
    }

} /* namespace gui */