Files
MuditaOS/module-gui/gui/widgets/Arc.cpp
Maciej Janicki e6fdf0e22c [EGD-5333] Change renderer to follow command design pattern
Changes draw command implementation to properly follow
command design pattern. All drawing commands have been
moved to separate inheriting draw commands from renderer.

Other changes:
- New draw methods overloads have been added to pixel renderer.
 Now pixel rendering methods are in one class.
- Simplified draw commands naming.
- Changed variable naming in draw commands to be more verbose.
- Changed {x,y} pairs to Points where possible.
2021-02-03 16:24:48 +01:00

118 lines
3.1 KiB
C++

// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include <module-utils/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::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