| 309 | } |
| 310 | |
| 311 | void Input::HandleEvent(const SDL_Event& event) { |
| 312 | PROFILER_ZONE(g_profiler_ctx, "Input::HandleEvent"); |
| 313 | // Redirect input events to the controller |
| 314 | switch (event.type) { |
| 315 | case SDL_WINDOWEVENT: |
| 316 | switch (event.window.event) { |
| 317 | case SDL_WINDOWEVENT_FOCUS_LOST: |
| 318 | in_focus_ = false; |
| 319 | break; |
| 320 | case SDL_WINDOWEVENT_FOCUS_GAINED: |
| 321 | if (grab_mouse_) { |
| 322 | Graphics::Instance()->SetWindowGrab(true); |
| 323 | cursor->SetVisible(false); |
| 324 | } |
| 325 | in_focus_ = true; |
| 326 | break; |
| 327 | } |
| 328 | break; |
| 329 | case SDL_MOUSEMOTION: |
| 330 | if (in_focus_) { |
| 331 | last_mouse_event_time = (float)event.common.timestamp; |
| 332 | } |
| 333 | if (use_raw_input) { |
| 334 | mouse_.delta_[0] += event.motion.xrel; |
| 335 | mouse_.delta_[1] += event.motion.yrel; |
| 336 | mouse_.pos_[0] = event.motion.x; |
| 337 | mouse_.pos_[1] = event.motion.y; |
| 338 | } else { |
| 339 | int width; |
| 340 | int height; |
| 341 | SDL_GetWindowSize(Graphics::Instance()->sdl_window_, &width, &height); |
| 342 | if (!grab_mouse_ || event.motion.x != width / 2 || event.motion.y != height / 2) { |
| 343 | mouse_.delta_[0] += event.motion.xrel; |
| 344 | mouse_.delta_[1] += event.motion.yrel; |
| 345 | mouse_.pos_[0] = event.motion.x; |
| 346 | mouse_.pos_[1] = event.motion.y; |
| 347 | } |
| 348 | if (grab_mouse_ && in_focus_ && (event.motion.x < 100 || event.motion.y < 100 || event.motion.x > width - 100 || event.motion.y > height - 100)) { |
| 349 | PROFILER_ZONE(g_profiler_ctx, "WarpMouse"); |
| 350 | SDL_WarpMouseInWindow(Graphics::Instance()->sdl_window_, width / 2, height / 2); |
| 351 | } |
| 352 | } |
| 353 | break; |
| 354 | case SDL_MOUSEBUTTONDOWN: |
| 355 | if (in_focus_) { |
| 356 | last_mouse_event_time = (float)event.common.timestamp; |
| 357 | } |
| 358 | if (!ignore_mouse_frame) { |
| 359 | HandleMouseButtonDown(event.button.button, event.button.clicks); |
| 360 | } |
| 361 | break; |
| 362 | case SDL_MOUSEWHEEL: |
| 363 | if (in_focus_) { |
| 364 | last_mouse_event_time = (float)event.common.timestamp; |
| 365 | } |
| 366 | if (!ignore_mouse_frame) { |
| 367 | mouse_.MouseWheelEvent(event.wheel.x, event.wheel.y); |
| 368 | } |
no test coverage detected