| 102 | } |
| 103 | |
| 104 | void AbyssEngine::processEvents(const std::chrono::duration<double> deltaTime) { |
| 105 | const absl::btree_map<uint8_t, Enums::MouseButton> buttonMap = { |
| 106 | {SDL_BUTTON_LEFT, Enums::MouseButton::Left}, {SDL_BUTTON_RIGHT, Enums::MouseButton::Right}, {SDL_BUTTON_MIDDLE, Enums::MouseButton::Middle}}; |
| 107 | SDL_Event event; |
| 108 | while (SDL_PollEvent(&event)) { |
| 109 | ImGui_ImplSDL2_ProcessEvent(&event); |
| 110 | switch (event.type) { |
| 111 | case SDL_QUIT: |
| 112 | _running = false; |
| 113 | return; |
| 114 | case SDL_MOUSEMOTION: { |
| 115 | const auto mx = (event.motion.x - _renderRect.x) * 800 / _renderRect.w; |
| 116 | const auto my = (event.motion.y - _renderRect.y) * 600 / _renderRect.h; |
| 117 | _mouseOverGameWindow = mx >= 0 && mx < 800 && my >= 0 && my < 600; |
| 118 | |
| 119 | _mouseState.setPosition(std::clamp(mx, 0, 799), std::clamp(my, 0, 599)); |
| 120 | } break; |
| 121 | case SDL_MOUSEBUTTONDOWN: |
| 122 | if (_videoStream != nullptr && event.button.button == SDL_BUTTON_LEFT) { |
| 123 | _videoStream->stopVideo(); |
| 124 | break; |
| 125 | } |
| 126 | _mouseState.setButtonState(buttonMap.at(event.button.button), true); |
| 127 | break; |
| 128 | case SDL_MOUSEBUTTONUP: |
| 129 | _mouseState.setButtonState(buttonMap.at(event.button.button), false); |
| 130 | break; |
| 131 | case SDL_KEYDOWN: |
| 132 | // If alt/option+enter is pressed, toggle fullscreen |
| 133 | if (event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod & KMOD_ALT) != 0) { |
| 134 | if (const auto flags = SDL_GetWindowFlags(_window.get()); (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == 0) { |
| 135 | SDL_SetWindowFullscreen(_window.get(), SDL_WINDOW_FULLSCREEN_DESKTOP); |
| 136 | } else { |
| 137 | SDL_SetWindowFullscreen(_window.get(), 0); |
| 138 | } |
| 139 | updateRenderRect(); |
| 140 | } |
| 141 | break; |
| 142 | case SDL_WINDOWEVENT: |
| 143 | if (event.window.event == SDL_WINDOWEVENT_RESIZED) { |
| 144 | updateRenderRect(); |
| 145 | } |
| 146 | |
| 147 | break; |
| 148 | default: |
| 149 | break; |
| 150 | } |
| 151 | |
| 152 | if (_videoStream == nullptr && _currentScene != nullptr) |
| 153 | _currentScene->processEvent(event); |
| 154 | } |
| 155 | |
| 156 | if (_videoStream != nullptr) { |
| 157 | _videoStream->update(static_cast<uint32_t>(deltaTime.count() * 1000.0)); |
| 158 | } else if (_currentScene != nullptr) |
| 159 | _currentScene->update(deltaTime); |
| 160 | } |
| 161 |
nothing calls this directly
no test coverage detected