I have created 2 wrapper classes for easier UI managments. That are given below
struct Button: public sf::Drawable, public sf::Transformable{
sf::Sprite sprite;
void handle(const sf::Event& event){
if(event.type == sf::Event::EventType::mouseButtonReleased)
if(sprite.getGlobalBounds().contains({ event.mouseButton.x, event.mouseButton.y })
std::cout << "Clicked!";
}
void draw(sf::RenderTarget& target, sf::RenderStates states) const override {
states.transform *= getTransform();
target.draw(sprite,states);
}
}
struct ButtonGroup: public sf::Drawable, public sf::Transformable{
std::list<Button> buttons;
void handle(const sf::Event& event){
for(auto& button : buttons)
button.handle(event);
}
void draw(sf::RenderTarget& target, sf::RenderStates states) const override {
states.transform *= getTransform();
for (auto& button : buttons)
button.draw(target,states);
}
}
Basic idea is that I can position buttons relative to buttongroup, and then be free to move buttongroup as I wish. This idea is properly executed when rendering is considered, renderstates takes care of transform propagation, however bounding box checking in the event does not work as intenteded as button event handler is unaware of transformations given to buttongroup. What is the concensus on this issue? Should I somehow put and propagate renderState into handling function and then somehow apply that transform to globalBounds()' rect ?