0x00405409
| 226 | |
| 227 | // 0x00405409 |
| 228 | void createWindow(const Config::Display& cfg) |
| 229 | { |
| 230 | if (!SDL_Init(SDL_INIT_VIDEO)) |
| 231 | { |
| 232 | throw Exception::RuntimeError("Unable to initialise SDL2 video subsystem."); |
| 233 | } |
| 234 | |
| 235 | // Create the window |
| 236 | auto props = getWindowProps(cfg); |
| 237 | _window = SDL_CreateWindowWithProperties(props); |
| 238 | |
| 239 | if (_window == nullptr) |
| 240 | { |
| 241 | SDL_DestroyProperties(props); |
| 242 | throw Exception::RuntimeError("Unable to create SDL3 window."); |
| 243 | } |
| 244 | |
| 245 | #ifdef _WIN32 |
| 246 | // Grab the HWND |
| 247 | _hwnd = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(_window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr); |
| 248 | #endif |
| 249 | |
| 250 | setWindowIcon(); |
| 251 | |
| 252 | auto width = SDL_GetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, 640); |
| 253 | auto height = SDL_GetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, 480); |
| 254 | if (cfg.mode == Config::ScreenMode::window) |
| 255 | { |
| 256 | _lastWindowedResolution = { static_cast<int32_t>(width), static_cast<int32_t>(height) }; |
| 257 | } |
| 258 | |
| 259 | // Create a palette for the window |
| 260 | auto& drawingEngine = Gfx::getDrawingEngine(); |
| 261 | drawingEngine.initialize(_window); |
| 262 | drawingEngine.setVSync(cfg.vsync); |
| 263 | drawingEngine.resize(width, height); |
| 264 | |
| 265 | // SDL2 always activated text input by default on desktop platforms, SDL3 does not. |
| 266 | // TODO: Do this properly and activate/deactivate depending on textbox focus, we should also |
| 267 | // set the input rectangle to avoid IME issues. |
| 268 | SDL_StartTextInput(_window); |
| 269 | |
| 270 | SDL_DestroyProperties(props); |
| 271 | |
| 272 | #if !(defined(__APPLE__) && defined(__MACH__)) |
| 273 | if (cfg.mode != Config::ScreenMode::window) |
| 274 | { |
| 275 | auto startupResolution = getDisplayResolutionByMode(cfg.mode); |
| 276 | if (!setDisplayMode(cfg.mode, startupResolution)) |
| 277 | { |
| 278 | Logging::error("Failed to apply startup display mode"); |
| 279 | } |
| 280 | } |
| 281 | #endif |
| 282 | |
| 283 | SDL_ShowWindow(_window); |
| 284 | } |
| 285 |
no test coverage detected