| 407 | } |
| 408 | |
| 409 | void SetIcon(SDL_Window* wnd) |
| 410 | { |
| 411 | float dpi = 0.0f; |
| 412 | int wndDisplayIndex = SDL_GetWindowDisplayIndex(wnd); |
| 413 | SDL_GetDisplayDPI(wndDisplayIndex, &dpi, NULL, NULL); |
| 414 | dpi /= 96.0f; |
| 415 | |
| 416 | if (dpi <= 0.0f) dpi = 1.0f; |
| 417 | |
| 418 | stbi_set_flip_vertically_on_load(0); |
| 419 | |
| 420 | int req_format = STBI_rgb_alpha; |
| 421 | int width, height, orig_format; |
| 422 | unsigned char* data = stbi_load(dpi == 1.0f ? "./icon_64x64.png" : "./icon_256x256.png", &width, &height, &orig_format, req_format); |
| 423 | if (data == NULL) { |
| 424 | ed::Logger::Get().Log("Failed to set window icon", true); |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | int depth, pitch; |
| 429 | Uint32 pixel_format; |
| 430 | if (req_format == STBI_rgb) { |
| 431 | depth = 24; |
| 432 | pitch = 3 * width; // 3 bytes per pixel * pixels per row |
| 433 | pixel_format = SDL_PIXELFORMAT_RGB24; |
| 434 | } else { // STBI_rgb_alpha (RGBA) |
| 435 | depth = 32; |
| 436 | pitch = 4 * width; |
| 437 | pixel_format = SDL_PIXELFORMAT_RGBA32; |
| 438 | } |
| 439 | |
| 440 | SDL_Surface* surf = SDL_CreateRGBSurfaceWithFormatFrom((void*)data, width, height, |
| 441 | depth, pitch, pixel_format); |
| 442 | |
| 443 | if (surf == NULL) { |
| 444 | ed::Logger::Get().Log("Failed to create icon SDL_Surface", true); |
| 445 | stbi_image_free(data); |
| 446 | return; |
| 447 | } |
| 448 | |
| 449 | SDL_SetWindowIcon(wnd, surf); |
| 450 | |
| 451 | SDL_FreeSurface(surf); |
| 452 | stbi_image_free(data); |
| 453 | |
| 454 | stbi_set_flip_vertically_on_load(1); |
| 455 | } |
| 456 | void SetDpiAware() |
| 457 | { |
| 458 | #if defined(_WIN32) |
no test coverage detected