~aleteoryx/muditaos

muditaos/module-gui/gui/widgets/Rect.cpp -rw-r--r-- 3.0 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright (c) 2017-2025, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

/*
 * Rect.cpp
 *
 *  Created on: 6 mar 2019
 *      Author: robert
 */

#include "../core/BoundingBox.hpp"
#include "../core/DrawCommand.hpp"

#include "Rect.hpp"
#include "Style.hpp"
#include <log/log.hpp>

namespace gui
{

    Rect::Rect(Item *parent, const uint32_t &x, const uint32_t &y, const uint32_t &w, const uint32_t &h)
    {
        setArea({int16_t(x), int16_t(y), uint16_t(w), uint16_t(h)});
        setMinimumHeight(h);
        setMinimumWidth(w);

        this->parent = parent;
        if (parent != nullptr) {
            parent->addWidget(this);
        }
    }

    Rect::Rect() : Rect(nullptr, 0, 0, 0, 0)
    {}

    void Rect::setFillColor(const Color &color)
    {
        fillColor = color;
        setFilled(true);
    }

    void Rect::setBorderColor(const Color &color)
    {
        borderColor = color;
    }

    void Rect::setPenWidth(uint8_t width)
    {
        penWidth = width;
    }

    void Rect::setPenFocusWidth(uint8_t width)
    {
        penFocusWidth = width;
    }

    void Rect::setEdges(RectangleEdge edges)
    {
        this->edges = edges;
    }
    void Rect::setCorners(RectangleRoundedCorner corners)
    {
        this->corners = corners;
    }

    void Rect::setFlat(RectangleFlatEdge flats)
    {
        flatEdges = flats;
    }

    void Rect::setFilled(bool val)
    {
        filled = val;
    }

    void Rect::setYaps(RectangleYap yaps)
    {
        this->yaps = yaps;
        if (yaps & (RectangleYap::BottomLeft | RectangleYap::TopLeft)) {
            padding.left = yapSize;
        }
        else {
            padding.left = 0;
        }
        if (yaps & (RectangleYap::BottomRight | RectangleYap::TopRight)) {
            padding.right = yapSize;
        }
        else {
            padding.right = 0;
        }
    }

    void Rect::setYapSize(unsigned short value)
    {
        yapSize = value;
    }

    void Rect::buildDrawListImplementation(std::list<Command> &commands)
    {
        auto rect = std::make_unique<DrawRectangle>();

        rect->origin    = {drawArea.x, drawArea.y};
        rect->width     = drawArea.w;
        rect->height    = drawArea.h;
        rect->areaX     = widgetArea.x;
        rect->areaY     = widgetArea.y;
        rect->areaW     = widgetArea.w;
        rect->areaH     = widgetArea.h;
        rect->corners   = corners;
        rect->flatEdges = this->flatEdges;
        rect->edges     = edges;
        rect->yaps      = yaps;
        rect->yapSize   = yapSize;
        rect->radius    = radius;
        if (focus) {
            rect->penWidth = penFocusWidth;
        }
        else {
            rect->penWidth = penWidth;
        }

        rect->filled      = filled;
        rect->borderColor = borderColor;
        rect->fillColor   = fillColor;

        commands.emplace_back(std::move(rect));
    }

    void Rect::accept(GuiVisitor &visitor)
    {
        visitor.visit(*this);
    }

} /* namespace gui */