Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - aleksailic

Pages: [1]
1
Graphics / Get true bounds of a sprite in transformed container
« on: January 18, 2020, 02:15:50 am »
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 ?

Pages: [1]
anything