/* +------------------------------------------------------+ ____/ \____ /| - Open source game framework licensed to freely use, | \ / / | copy, modify and sell without restriction | +--\ ^__^ /--+ | | | ~/ \~ | | - created for | | ~~~~~~~~~~~~ | +------------------------------------------------------+ | SPACE ~~~~~ | / | ~~~~~~~ BOX |/ +-------------*/ #pragma once #include #include #define GLM_ENABLE_EXPERIMENTAL #include "glm/common.hpp" #include "glm/gtx/integer.hpp" namespace sb { class Carousel { private: std::uint32_t offset = 0; public: template auto current(Container& container) const { auto location = container.begin(); if (location != container.end()) { std::advance(location, offset); return location; } else { throw std::out_of_range("Container is empty"); } } template void next(const Container& container) { offset = ++offset % container.size(); } template void previous(const Container& container) { offset = glm::mod(--offset, container.size()); } template void increment(const Container& container, int amount) { offset = glm::mod(offset + amount, container.size()); } void beginning() { offset = 0; } template void end(const Container& container) { offset = container.size() - 1; } /* Return true if the carousel currently points to the location at the beginning of the container. */ bool at_beginning() const { return offset == 0; } /* Return true if the carousel currently points to the location at the end of the container. */ template bool at_end(const Container& container) { return offset >= container.size() - 1; } }; }