|
39 | 39 | ////////////////////////////////////////////////////////////
|
40 | 40 | // Convert sf::Event to sfEvent
|
41 | 41 | ////////////////////////////////////////////////////////////
|
42 |
| -[[nodiscard]] inline bool convertEvent(const std::optional<sf::Event>& sfmlEvent, sfEvent* event) |
| 42 | +[[nodiscard]] inline bool convertEvent(const std::optional<sf::Event>& sfmlEvent, sfEvent& event) |
43 | 43 | {
|
44 | 44 | if (!sfmlEvent)
|
45 | 45 | return false;
|
46 | 46 |
|
47 | 47 | if (sfmlEvent->is<sf::Event::Closed>())
|
48 | 48 | {
|
49 |
| - event->type = sfEvtClosed; |
| 49 | + event.type = sfEvtClosed; |
50 | 50 | }
|
51 | 51 | else if (const auto* resized = sfmlEvent->getIf<sf::Event::Resized>())
|
52 | 52 | {
|
53 |
| - event->type = sfEvtResized; |
54 |
| - event->size.size = convertVector2(resized->size); |
| 53 | + event.type = sfEvtResized; |
| 54 | + event.size.size = convertVector2(resized->size); |
55 | 55 | }
|
56 | 56 | else if (sfmlEvent->is<sf::Event::FocusLost>())
|
57 | 57 | {
|
58 |
| - event->type = sfEvtFocusLost; |
| 58 | + event.type = sfEvtFocusLost; |
59 | 59 | }
|
60 | 60 | else if (sfmlEvent->is<sf::Event::FocusGained>())
|
61 | 61 | {
|
62 |
| - event->type = sfEvtFocusGained; |
| 62 | + event.type = sfEvtFocusGained; |
63 | 63 | }
|
64 | 64 | else if (const auto* textEntered = sfmlEvent->getIf<sf::Event::TextEntered>())
|
65 | 65 | {
|
66 |
| - event->type = sfEvtTextEntered; |
67 |
| - event->text.unicode = textEntered->unicode; |
| 66 | + event.type = sfEvtTextEntered; |
| 67 | + event.text.unicode = textEntered->unicode; |
68 | 68 | }
|
69 | 69 | else if (const auto* keyReleased = sfmlEvent->getIf<sf::Event::KeyReleased>())
|
70 | 70 | {
|
71 |
| - event->type = sfEvtKeyReleased; |
72 |
| - event->key.code = static_cast<sfKeyCode>(keyReleased->code); |
73 |
| - event->key.scancode = static_cast<sfScancode>(keyReleased->scancode); |
74 |
| - event->key.alt = keyReleased->alt; |
75 |
| - event->key.control = keyReleased->control; |
76 |
| - event->key.shift = keyReleased->shift; |
77 |
| - event->key.system = keyReleased->system; |
| 71 | + event.type = sfEvtKeyReleased; |
| 72 | + event.key.code = static_cast<sfKeyCode>(keyReleased->code); |
| 73 | + event.key.scancode = static_cast<sfScancode>(keyReleased->scancode); |
| 74 | + event.key.alt = keyReleased->alt; |
| 75 | + event.key.control = keyReleased->control; |
| 76 | + event.key.shift = keyReleased->shift; |
| 77 | + event.key.system = keyReleased->system; |
78 | 78 | }
|
79 | 79 | else if (const auto* keyPressed = sfmlEvent->getIf<sf::Event::KeyPressed>())
|
80 | 80 | {
|
81 |
| - event->type = sfEvtKeyPressed; |
82 |
| - event->key.code = static_cast<sfKeyCode>(keyPressed->code); |
83 |
| - event->key.scancode = static_cast<sfScancode>(keyPressed->scancode); |
84 |
| - event->key.alt = keyPressed->alt; |
85 |
| - event->key.control = keyPressed->control; |
86 |
| - event->key.shift = keyPressed->shift; |
87 |
| - event->key.system = keyPressed->system; |
| 81 | + event.type = sfEvtKeyPressed; |
| 82 | + event.key.code = static_cast<sfKeyCode>(keyPressed->code); |
| 83 | + event.key.scancode = static_cast<sfScancode>(keyPressed->scancode); |
| 84 | + event.key.alt = keyPressed->alt; |
| 85 | + event.key.control = keyPressed->control; |
| 86 | + event.key.shift = keyPressed->shift; |
| 87 | + event.key.system = keyPressed->system; |
88 | 88 | }
|
89 | 89 | else if (const auto* mouseWheelScrolled = sfmlEvent->getIf<sf::Event::MouseWheelScrolled>())
|
90 | 90 | {
|
91 |
| - event->type = sfEvtMouseWheelScrolled; |
92 |
| - event->mouseWheelScroll.wheel = static_cast<sfMouseWheel>(mouseWheelScrolled->wheel); |
93 |
| - event->mouseWheelScroll.delta = mouseWheelScrolled->delta; |
94 |
| - event->mouseWheelScroll.position = convertVector2(mouseWheelScrolled->position); |
| 91 | + event.type = sfEvtMouseWheelScrolled; |
| 92 | + event.mouseWheelScroll.wheel = static_cast<sfMouseWheel>(mouseWheelScrolled->wheel); |
| 93 | + event.mouseWheelScroll.delta = mouseWheelScrolled->delta; |
| 94 | + event.mouseWheelScroll.position = convertVector2(mouseWheelScrolled->position); |
95 | 95 | }
|
96 | 96 | else if (const auto* mouseButtonPressed = sfmlEvent->getIf<sf::Event::MouseButtonPressed>())
|
97 | 97 | {
|
98 |
| - event->type = sfEvtMouseButtonPressed; |
99 |
| - event->mouseButton.button = static_cast<sfMouseButton>(mouseButtonPressed->button); |
100 |
| - event->mouseButton.position = convertVector2(mouseButtonPressed->position); |
| 98 | + event.type = sfEvtMouseButtonPressed; |
| 99 | + event.mouseButton.button = static_cast<sfMouseButton>(mouseButtonPressed->button); |
| 100 | + event.mouseButton.position = convertVector2(mouseButtonPressed->position); |
101 | 101 | }
|
102 | 102 | else if (const auto* mouseButtonReleased = sfmlEvent->getIf<sf::Event::MouseButtonReleased>())
|
103 | 103 | {
|
104 |
| - event->type = sfEvtMouseButtonReleased; |
105 |
| - event->mouseButton.button = static_cast<sfMouseButton>(mouseButtonReleased->button); |
106 |
| - event->mouseButton.position = convertVector2(mouseButtonReleased->position); |
| 104 | + event.type = sfEvtMouseButtonReleased; |
| 105 | + event.mouseButton.button = static_cast<sfMouseButton>(mouseButtonReleased->button); |
| 106 | + event.mouseButton.position = convertVector2(mouseButtonReleased->position); |
107 | 107 | }
|
108 | 108 | else if (const auto* mouseMoved = sfmlEvent->getIf<sf::Event::MouseMoved>())
|
109 | 109 | {
|
110 |
| - event->type = sfEvtMouseMoved; |
111 |
| - event->mouseMove.position = convertVector2(mouseMoved->position); |
| 110 | + event.type = sfEvtMouseMoved; |
| 111 | + event.mouseMove.position = convertVector2(mouseMoved->position); |
112 | 112 | }
|
113 | 113 | else if (const auto* mouseMovedRaw = sfmlEvent->getIf<sf::Event::MouseMovedRaw>())
|
114 | 114 | {
|
115 |
| - event->type = sfEvtMouseMovedRaw; |
116 |
| - event->mouseMoveRaw.delta = convertVector2(mouseMovedRaw->delta); |
| 115 | + event.type = sfEvtMouseMovedRaw; |
| 116 | + event.mouseMoveRaw.delta = convertVector2(mouseMovedRaw->delta); |
117 | 117 | }
|
118 | 118 | else if (sfmlEvent->is<sf::Event::MouseEntered>())
|
119 | 119 | {
|
120 |
| - event->type = sfEvtMouseEntered; |
| 120 | + event.type = sfEvtMouseEntered; |
121 | 121 | }
|
122 | 122 | else if (sfmlEvent->is<sf::Event::MouseLeft>())
|
123 | 123 | {
|
124 |
| - event->type = sfEvtMouseLeft; |
| 124 | + event.type = sfEvtMouseLeft; |
125 | 125 | }
|
126 | 126 | else if (const auto* joystickButtonPressed = sfmlEvent->getIf<sf::Event::JoystickButtonPressed>())
|
127 | 127 | {
|
128 |
| - event->type = sfEvtJoystickButtonPressed; |
129 |
| - event->joystickButton.joystickId = joystickButtonPressed->joystickId; |
130 |
| - event->joystickButton.button = joystickButtonPressed->button; |
| 128 | + event.type = sfEvtJoystickButtonPressed; |
| 129 | + event.joystickButton.joystickId = joystickButtonPressed->joystickId; |
| 130 | + event.joystickButton.button = joystickButtonPressed->button; |
131 | 131 | }
|
132 | 132 | else if (const auto* joystickButtonReleased = sfmlEvent->getIf<sf::Event::JoystickButtonReleased>())
|
133 | 133 | {
|
134 |
| - event->type = sfEvtJoystickButtonReleased; |
135 |
| - event->joystickButton.joystickId = joystickButtonReleased->joystickId; |
136 |
| - event->joystickButton.button = joystickButtonReleased->button; |
| 134 | + event.type = sfEvtJoystickButtonReleased; |
| 135 | + event.joystickButton.joystickId = joystickButtonReleased->joystickId; |
| 136 | + event.joystickButton.button = joystickButtonReleased->button; |
137 | 137 | }
|
138 | 138 | else if (const auto* joystickMoved = sfmlEvent->getIf<sf::Event::JoystickMoved>())
|
139 | 139 | {
|
140 |
| - event->type = sfEvtJoystickMoved; |
141 |
| - event->joystickMove.joystickId = joystickMoved->joystickId; |
142 |
| - event->joystickMove.axis = static_cast<sfJoystickAxis>(joystickMoved->axis); |
143 |
| - event->joystickMove.position = joystickMoved->position; |
| 140 | + event.type = sfEvtJoystickMoved; |
| 141 | + event.joystickMove.joystickId = joystickMoved->joystickId; |
| 142 | + event.joystickMove.axis = static_cast<sfJoystickAxis>(joystickMoved->axis); |
| 143 | + event.joystickMove.position = joystickMoved->position; |
144 | 144 | }
|
145 | 145 | else if (const auto* joystickConnected = sfmlEvent->getIf<sf::Event::JoystickConnected>())
|
146 | 146 | {
|
147 |
| - event->type = sfEvtJoystickConnected; |
148 |
| - event->joystickConnect.joystickId = joystickConnected->joystickId; |
| 147 | + event.type = sfEvtJoystickConnected; |
| 148 | + event.joystickConnect.joystickId = joystickConnected->joystickId; |
149 | 149 | }
|
150 | 150 | else if (const auto* joystickDisconnected = sfmlEvent->getIf<sf::Event::JoystickDisconnected>())
|
151 | 151 | {
|
152 |
| - event->type = sfEvtJoystickDisconnected; |
153 |
| - event->joystickConnect.joystickId = joystickDisconnected->joystickId; |
| 152 | + event.type = sfEvtJoystickDisconnected; |
| 153 | + event.joystickConnect.joystickId = joystickDisconnected->joystickId; |
154 | 154 | }
|
155 | 155 | else if (const auto* touchBegan = sfmlEvent->getIf<sf::Event::TouchBegan>())
|
156 | 156 | {
|
157 |
| - event->type = sfEvtTouchBegan; |
158 |
| - event->touch.finger = touchBegan->finger; |
159 |
| - event->touch.position = convertVector2(touchBegan->position); |
| 157 | + event.type = sfEvtTouchBegan; |
| 158 | + event.touch.finger = touchBegan->finger; |
| 159 | + event.touch.position = convertVector2(touchBegan->position); |
160 | 160 | }
|
161 | 161 | else if (const auto* touchMoved = sfmlEvent->getIf<sf::Event::TouchMoved>())
|
162 | 162 | {
|
163 |
| - event->type = sfEvtTouchMoved; |
164 |
| - event->touch.finger = touchMoved->finger; |
165 |
| - event->touch.position = convertVector2(touchMoved->position); |
| 163 | + event.type = sfEvtTouchMoved; |
| 164 | + event.touch.finger = touchMoved->finger; |
| 165 | + event.touch.position = convertVector2(touchMoved->position); |
166 | 166 | }
|
167 | 167 | else if (const auto* touchEnded = sfmlEvent->getIf<sf::Event::TouchEnded>())
|
168 | 168 | {
|
169 |
| - event->type = sfEvtTouchEnded; |
170 |
| - event->touch.finger = touchEnded->finger; |
171 |
| - event->touch.position = convertVector2(touchEnded->position); |
| 169 | + event.type = sfEvtTouchEnded; |
| 170 | + event.touch.finger = touchEnded->finger; |
| 171 | + event.touch.position = convertVector2(touchEnded->position); |
172 | 172 | }
|
173 | 173 | else if (const auto* sensorChanged = sfmlEvent->getIf<sf::Event::SensorChanged>())
|
174 | 174 | {
|
175 |
| - event->type = sfEvtSensorChanged; |
176 |
| - event->sensor.sensorType = static_cast<sfSensorType>(sensorChanged->type); |
177 |
| - event->sensor.value = convertVector3(sensorChanged->value); |
| 175 | + event.type = sfEvtSensorChanged; |
| 176 | + event.sensor.sensorType = static_cast<sfSensorType>(sensorChanged->type); |
| 177 | + event.sensor.value = convertVector3(sensorChanged->value); |
178 | 178 | }
|
179 | 179 |
|
180 | 180 | return true;
|
|
0 commit comments