| 257 | } |
| 258 | |
| 259 | bool InputManager::parseEvent(const SDL_Event& ev) |
| 260 | { |
| 261 | bool causedEvent = false; |
| 262 | switch(ev.type) |
| 263 | { |
| 264 | case SDL_JOYAXISMOTION: |
| 265 | //if it switched boundaries |
| 266 | if((abs(ev.jaxis.value) > DEADZONE) != (abs(mPrevAxisValues[ev.jaxis.which][ev.jaxis.axis]) > DEADZONE)) |
| 267 | { |
| 268 | int normValue; |
| 269 | if(abs(ev.jaxis.value) <= DEADZONE) |
| 270 | normValue = 0; |
| 271 | else |
| 272 | if(ev.jaxis.value > 0) |
| 273 | normValue = 1; |
| 274 | else |
| 275 | normValue = -1; |
| 276 | |
| 277 | mWindow->input(getInputConfigByDevice(ev.jaxis.which), Input(ev.jaxis.which, TYPE_AXIS, ev.jaxis.axis, normValue, false)); |
| 278 | causedEvent = true; |
| 279 | } |
| 280 | |
| 281 | mPrevAxisValues[ev.jaxis.which][ev.jaxis.axis] = ev.jaxis.value; |
| 282 | return causedEvent; |
| 283 | |
| 284 | case SDL_JOYBUTTONDOWN: |
| 285 | case SDL_JOYBUTTONUP: |
| 286 | mWindow->input(getInputConfigByDevice(ev.jbutton.which), Input(ev.jbutton.which, TYPE_BUTTON, ev.jbutton.button, ev.jbutton.state == SDL_PRESSED, false)); |
| 287 | return true; |
| 288 | |
| 289 | case SDL_JOYHATMOTION: |
| 290 | mWindow->input(getInputConfigByDevice(ev.jhat.which), Input(ev.jhat.which, TYPE_HAT, ev.jhat.hat, ev.jhat.value, false)); |
| 291 | return true; |
| 292 | |
| 293 | case SDL_KEYDOWN: |
| 294 | if(ev.key.keysym.sym == SDLK_F4) |
| 295 | { |
| 296 | SDL_Event* quit = new SDL_Event(); |
| 297 | quit->type = SDL_QUIT; |
| 298 | SDL_PushEvent(quit); |
| 299 | return false; |
| 300 | } |
| 301 | |
| 302 | mWindow->input(getInputConfigByDevice(DEVICE_KEYBOARD), Input(DEVICE_KEYBOARD, TYPE_KEY, ev.key.keysym.sym, 1, false)); |
| 303 | return true; |
| 304 | |
| 305 | case SDL_KEYUP: |
| 306 | mWindow->input(getInputConfigByDevice(DEVICE_KEYBOARD), Input(DEVICE_KEYBOARD, TYPE_KEY, ev.key.keysym.sym, 0, false)); |
| 307 | return true; |
| 308 | |
| 309 | case SDL_USEREVENT: |
| 310 | if (ev.user.code == SDL_USEREVENT_POLLDEVICES) { |
| 311 | //poll joystick / HID again |
| 312 | std::vector<InputDevice> currentDevices = getInputDevices(); |
| 313 | //compare device lists to see if devices were added/deleted |
| 314 | if (currentDevices != inputDevices) { |
| 315 | LOG(LogInfo) << "Device configuration changed!"; |
| 316 | inputDevices = currentDevices; |