MCPcopy Create free account
hub / github.com/SFML/SFML / Application

Class Application

examples/event_handling/EventHandling.cpp:30–401  ·  view source on GitHub ↗

/////////////////////////////////////////////////////// \brief Application class ///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

28///
29////////////////////////////////////////////////////////////
30class Application
31{
32public:
33 ////////////////////////////////////////////////////////////
34 Application()
35 {
36 m_window.setVerticalSyncEnabled(true);
37 m_logText.setFillColor(sf::Color::White);
38 m_handlerText.setFillColor(sf::Color::White);
39 m_handlerText.setStyle(sf::Text::Bold);
40 m_handlerText.setPosition({380.f, 260.f});
41 m_instructions.setFillColor(sf::Color::White);
42 m_instructions.setStyle(sf::Text::Bold);
43 m_instructions.setPosition({380.f, 310.f});
44 }
45
46 // The visitor we pass to event->visit in the "Visitor" handler
47 // Make sure all defined operator()s return the same type.
48 // The operator()s can also have void return type if there is nothing to return.
49 struct Visitor
50 {
51 explicit Visitor(Application& app) : application(app)
52 {
53 }
54
55 std::optional<std::string> operator()(const sf::Event::Closed&)
56 {
57 application.m_window.close();
58 return std::nullopt;
59 }
60
61 std::optional<std::string> operator()(const sf::Event::KeyPressed& keyPress)
62 {
63 // When the enter key is pressed, switch to the next handler type
64 if (keyPress.code == sf::Keyboard::Key::Enter)
65 {
66 application.m_handlerType = HandlerType::Overload;
67 application.m_handlerText.setString("Current Handler: Overload");
68 }
69
70 return "Key Pressed: " + sf::Keyboard::getDescription(keyPress.scancode).toAnsiString();
71 }
72
73 std::optional<std::string> operator()(const sf::Event::KeyReleased& keyRelease)
74 {
75 return "Key Released: " + sf::Keyboard::getDescription(keyRelease.scancode).toAnsiString();
76 }
77
78 std::optional<std::string> operator()(const sf::Event::MouseMoved& mouseMoved)
79 {
80 return "Mouse Moved: " + vec2ToString(mouseMoved.position);
81 }
82
83 std::optional<std::string> operator()(const sf::Event::MouseButtonPressed&)
84 {
85 return "Mouse Pressed";
86 }
87

Callers

nothing calls this directly

Calls 2

resourcesDirFunction · 0.70
VideoModeClass · 0.50

Tested by

no test coverage detected