/* +------------------------------------------------------+ ____/ \____ /| - 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 { template class Selection { private: std::uint32_t offset = 0; const Container& container; public: Selection(const Container& container) : container(container) {} auto current() const { auto location = container.begin(); if (location != container.end()) { std::advance(location, offset); return location; } else { throw std::out_of_range("No options currently in selection"); } } void next() { offset = ++offset % container.size(); } void previous() { offset = glm::mod(--offset, container.size()); } void increment(int amount) { offset = glm::mod(offset + amount, container.size()); } void beginning() { offset = 0; } void end() { offset = container.size() - 1; } /*! * @return true if the selection currently points to the location at the beginning of the container */ bool at_beginning() const { return offset == 0; } /*! * @return true if the selection currently points to the location at the end of the container */ bool at_end() { return offset >= container.size() - 1; } }; }