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

Author Topic: Using sf::Events  (Read 978 times)

0 Members and 1 Guest are viewing this topic.

MaxPain

  • Newbie
  • *
  • Posts: 19
    • View Profile
Using sf::Events
« on: November 19, 2020, 03:27:25 pm »

I am wondering what is the best way to implement the use of sf :: Event in a class and how this is handled.
For example: what is the best way to make a button class that should handle mouse pressed and release.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Using sf::Events
« Reply #1 on: November 20, 2020, 09:37:17 am »
There's no "best way" or rather what fits best, depends on your code (and experience).

I personally, would probably just implement functions like "OnClick()" for the button class and have an additional class, that receives all sf::Event from the event loop, knows all the widgets and determines for a mouse button event which widget is located at the position and calls OnClick for that button instance.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything