~aleteoryx/muditaos

muditaos/module-gui/gui/widgets/Circle.cpp -rw-r--r-- 2.7 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
// 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 <log/log.hpp>
#include "Circle.hpp"
#include "DrawCommand.hpp"

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

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

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

    Circle::ShapeParams &Circle::ShapeParams::setFocusBorderColor(Color _color) noexcept
    {
        focusBorderColor = _color;
        return *this;
    }

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

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

    Circle::ShapeParams &Circle::ShapeParams::setFillColor(Color _color) noexcept
    {
        isFilled  = true;
        fillColor = _color;
        return *this;
    }

    Circle::Circle(Item *parent, const Circle::ShapeParams &params)
        : Circle{parent,
                 params.center,
                 params.radius,
                 params.borderColor,
                 params.focusBorderColor,
                 params.penWidth,
                 params.focusPenWidth,
                 params.isFilled,
                 params.fillColor}
    {}

    Circle::Circle(Item *parent,
                   Point _center,
                   Length _radius,
                   Color _borderColor,
                   Color _focusBorderColor,
                   std::uint8_t _penWidth,
                   std::uint8_t _focusPenWidth,
                   bool _filled,
                   Color _fillColor)
        : Arc{parent, _center, _radius, 0, trigonometry::FullAngle, _borderColor, _penWidth, _focusPenWidth},
          isFilled{_filled}, fillColor{_fillColor}, focusBorderColor{_focusBorderColor}
    {}

    void Circle::buildDrawListImplementation(std::list<Command> &commands)
    {
        auto circle = std::make_unique<DrawCircle>(
            center, radius, focus ? focusPenWidth : penWidth, focus ? focusBorderColor : color, isFilled, fillColor);
        circle->areaX = widgetArea.x;
        circle->areaY = widgetArea.y;
        circle->areaW = widgetArea.w;
        circle->areaH = widgetArea.h;

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