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

Author Topic: 2.6.2 to 3.0.0 Event  (Read 162 times)

0 Members and 1 Guest are viewing this topic.

HeinzK

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
    • ZwiAner
    • Email
2.6.2 to 3.0.0 Event
« on: January 28, 2025, 08:42:05 pm »
//while (pWindow->pollEvent(Event))
while (const std::optional Event = pWindow->pollEvent())
{
  //if (Event.type == sf::Event::Closed)
  if (Event->is<sf::Event::Closed>())
  {
    pWindow->close();   //> Und raus ..:

  }

  //if (Event.type == sf::Event::GainedFocus)
  if (Event->is<sf::Event::GainedFocus>())     //> a) ???:
  { .. }

  //if (Event.type == sf::Event::LostFocus)
  if (Event->is<sf::Event::LostFocus>())       //> b) ???:
  { .. }

  //if (Event.type == sf::Event::MouseWheelScrolled)
  if (Event->is<sf::Event::MouseWheelScrolled>())
  {
    #ifdef ZWIANER_VERSION_K
      pMaus->SetlMausMoveZpp((long)Event.mouseWheelScroll.delta);  //> c) ???:
    #endif
  }

  ..
}

.. what must I do by a) b) c) .. ???
« Last Edit: January 28, 2025, 10:13:04 pm by eXpl0it3r »
The trees, that obstruct the view on the forest, can be allowed to fall! (Die Bäume, die die Sicht auf einen Wald versperren, dürfen gefällt werden!)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11107
    • View Profile
    • development blog
    • Email
Re: 2.6.2 to 3.0.0 Event
« Reply #1 on: January 28, 2025, 10:21:06 pm »
I recommend to check the updated tutorial for event handling, since it comes with example code for each event type (e.g. MouseWheelScrolled).

You can use event->is<T>() if you're not interested in any of the event data or the event doesn't have any data, otherwise you can use event->getIf<T>() to get the event data.

You may also want to use else if so you don't have to check all the event types.

//while (pWindow->pollEvent(Event))
while (const std::optional Event = pWindow->pollEvent())
{
  //if (Event.type == sf::Event::Closed)
  if (Event->is<sf::Event::Closed>())
  {
    pWindow->close();   //> Und raus ..:

  }

  //if (Event.type == sf::Event::GainedFocus)
  else if (Event->is<sf::Event::GainedFocus>())     //> a) ???:
  { .. }

  //if (Event.type == sf::Event::LostFocus)
  else if (Event->is<sf::Event::LostFocus>())       //> b) ???:
  { .. }

  //if (Event.type == sf::Event::MouseWheelScrolled)
  else if (const auto* mouseWheelScrolled = Event->getIf<sf::Event::MouseWheelScrolled>())
  {
    #ifdef ZWIANER_VERSION_K
      pMaus->SetlMausMoveZpp((long)mouseWheelScrolled->delta);  //> c) ???:
    #endif
  }

  ..
}
Official FAQ: https://www.sfml-dev.org/faq/
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/