~aleteoryx/muditaos

ref: sign_test muditaos/module-gui/gui/widgets/Arc.cpp -rw-r--r-- 3.2 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <log/log.hpp>
#include "Arc.hpp"
#include "DrawCommand.hpp"

namespace gui
{
    Arc::ShapeParams &Arc::ShapeParams::setCenterPoint(Point _center) noexcept
    {
        center = _center;
        return *this;
    }

    Arc::ShapeParams &Arc::ShapeParams::setRadius(Length _radius) noexcept
    {
        radius = _radius;
        return *this;
    }

    Arc::ShapeParams &Arc::ShapeParams::setStartAngle(trigonometry::Degrees _angle) noexcept
    {
        start = _angle;
        return *this;
    }

    Arc::ShapeParams &Arc::ShapeParams::setSweepAngle(trigonometry::Degrees _angle) noexcept
    {
        sweep = _angle;
        return *this;
    }

    Arc::ShapeParams &Arc::ShapeParams::setBorderColor(Color _color) noexcept
    {
        borderColor = _color;
        return *this;
    }

    Arc::ShapeParams &Arc::ShapeParams::setPenWidth(std::uint8_t _width) noexcept
    {
        penWidth = _width;
        return *this;
    }

    Arc::ShapeParams &Arc::ShapeParams::setFocusPenWidth(std::uint8_t _width) noexcept
    {
        focusPenWidth = _width;
        return *this;
    }

    Arc::Arc(Item *parent, const ShapeParams &params)
        : Arc{parent,
              params.center,
              params.radius,
              params.start,
              params.sweep,
              params.borderColor,
              params.penWidth,
              params.focusPenWidth}
    {}

    Arc::Arc(Item *parent,
             Point _center,
             Length _radius,
             trigonometry::Degrees _start,
             trigonometry::Degrees _sweep,
             Color _color,
             std::uint8_t _penWidth,
             std::uint8_t _focusPenWidth)
        : Item{}, center{_center}, radius{_radius}, start{_start}, sweep{_sweep}, color{_color}, penWidth{_penWidth},
          focusPenWidth{_focusPenWidth}
    {
        const auto x        = center.x - radius;
        const auto y        = center.y - radius;
        const auto diameter = 2 * radius;
        setArea(BoundingBox(x, y, diameter, diameter));
        setMinimumWidth(diameter);
        setMinimumHeight(diameter);

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

    void Arc::setCenter(Point point) noexcept
    {
        center = point;
    }

    void Arc::setStartAngle(trigonometry::Degrees angle) noexcept
    {
        start = angle;
    }

    void Arc::setSweepAngle(trigonometry::Degrees angle) noexcept
    {
        sweep = angle;
    }

    trigonometry::Degrees Arc::getSweepAngle() const noexcept
    {
        return sweep;
    }

    trigonometry::Degrees Arc::getStartAngle() const noexcept
    {
        return start;
    }

    void Arc::buildDrawListImplementation(std::list<Command> &commands)
    {
        auto arc   = std::make_unique<DrawArc>(center, radius, start, sweep, focus ? focusPenWidth : penWidth, color);
        arc->areaX = widgetArea.x;
        arc->areaY = widgetArea.y;
        arc->areaW = widgetArea.w;
        arc->areaH = widgetArea.h;

        commands.emplace_back(std::move(arc));
    }
} // namespace gui