74 lines
1.5 KiB
C++
74 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "shape.hpp"
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace shapes
|
|
{
|
|
|
|
class Group : public Shape
|
|
{
|
|
public:
|
|
Group() = default;
|
|
|
|
Group(Group&& other) : m_shapes{std::move(other.m_shapes)}
|
|
{
|
|
}
|
|
|
|
Group& operator=(Group&& other)
|
|
{
|
|
// TODO: overit
|
|
m_shapes = std::move(other.m_shapes);
|
|
return *this;
|
|
}
|
|
|
|
template <class TShape, class... TArgs> void AddShape(TArgs&&... args)
|
|
{
|
|
m_shapes.emplace_back(std::make_unique<TShape>(std::forward<TArgs>(args)...));
|
|
}
|
|
|
|
void Translate(const math::Vector& offset) override
|
|
{
|
|
ShapesCall<&Shape::Translate>(offset);
|
|
}
|
|
|
|
void Rotate(const math::Vector& center, float angle) override
|
|
{
|
|
ShapesCall<&Shape::Rotate>(center, angle);
|
|
}
|
|
|
|
void Scale(const math::Vector& center, float factor) override
|
|
{
|
|
ShapesCall<&Shape::Scale>(center, factor);
|
|
}
|
|
|
|
void Draw(Renderer& renderer) const override
|
|
{
|
|
ShapesCall<&Shape::Draw>(renderer);
|
|
}
|
|
|
|
~Group() override = default;
|
|
|
|
private:
|
|
std::vector<std::unique_ptr<Shape>> m_shapes;
|
|
|
|
template <auto TFun, class... TArgs> void ShapesCall(TArgs&&... args)
|
|
{
|
|
for (auto& shape : m_shapes)
|
|
{
|
|
(shape.get()->*TFun)(std::forward<TArgs>(args)...);
|
|
}
|
|
}
|
|
|
|
template <auto TFun, class... TArgs> void ShapesCall(TArgs&&... args) const
|
|
{
|
|
for (const auto& shape : m_shapes)
|
|
{
|
|
(shape.get()->*TFun)(std::forward<TArgs>(args)...);
|
|
}
|
|
}
|
|
};
|
|
|
|
} // namespace shapes
|