#pragma once #include "shape.hpp" #include #include namespace shapes { /** * @brief Group shape * * Represents a group of shapes that can be used as a canvas */ class Group : public Shape { public: Group() = default; Group(const Group&) = delete; Group& operator=(const Group&) = delete; Group(Group&&) = default; Group& operator=(Group&&) = default; template requires std::derived_from void AddShape(TArgs&&... args) { m_shapes.emplace_back(std::make_unique(std::forward(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: // calls a member function on all shapes in the group template void ShapesCall(this TSelf&& self, TArgs&&... args) { for (auto& shape : self.m_shapes) (shape.get()->*Fun)(std::forward(args)...); } private: std::vector> m_shapes; }; } // namespace shapes