Skip to content

Instantly share code, notes, and snippets.

@eXpl0it3r
Last active November 18, 2016 14:05
Show Gist options
  • Save eXpl0it3r/8753828db2515716159910e20957f57e to your computer and use it in GitHub Desktop.
Save eXpl0it3r/8753828db2515716159910e20957f57e to your computer and use it in GitHub Desktop.
Group Drawable
#include "Group.hpp"
Group::Group()
: m_drawables{} {
}
void Group::draw(sf::RenderTarget& target, sf::RenderStates states) const {
for(const auto& drawable : m_drawables) {
target.draw(drawable, states);
}
}
const sf::Drawable& Group::operator[](std::size_t index) {
return m_drawables[index];
}
std::size_t Group::push_back(const sf::Drawable& drawable) {
m_drawables.push_back(drawable);
return m_drawables.size() - 1;
}
const sf::Drawable& Group::pop_back() {
const auto& drawable = m_drawables.back();
m_drawables.pop_back();
return drawable;
}
#ifndef GROUP_INCLUDED_HPP
#define GROUP_INCLUDED_HPP
#include <SFML/Graphics.hpp>
#include <vector>
#include <functional>
class Group : public sf::Drawable {
public:
Group();
virtual ~Group() = default;
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
const sf::Drawable& operator[](std::size_t index);
std::size_t push_back(const sf::Drawable& drawable);
const sf::Drawable& pop_back();
private:
std::vector<std::reference_wrapper<const sf::Drawable>> m_drawables;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment