Add Linux taskbar icon (#6)

This commit is contained in:
Reonu 2024-04-23 02:21:52 +01:00 committed by Mr-Wiseguy
parent a6e34bb49b
commit 25a3837b37
2 changed files with 53 additions and 0 deletions

BIN
icons/512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

View File

@ -30,6 +30,9 @@
#include "SDL_syswm.h"
#endif
#define STB_IMAGE_IMPLEMENTATION
#include "../../lib/rt64/src/contrib/stb/stb_image.h"
extern "C" void init();
/*extern "C"*/ void start(ultramodern::WindowHandle window_handle, const ultramodern::audio_callbacks_t* audio_callbacks, const ultramodern::input_callbacks_t* input_callbacks);
@ -55,10 +58,60 @@ ultramodern::gfx_callbacks_t::gfx_data_t create_gfx() {
return {};
}
#if defined(__linux__)
bool SetImageAsIcon(const char* filename, SDL_Window* window)
{
// Read data
int width, height, bytesPerPixel;
void* data = stbi_load(filename, &width, &height, &bytesPerPixel, 4);
// Calculate pitch
int pitch;
pitch = width * 4;
pitch = (pitch + 3) & ~3;
// Setup relevance bitmask
int Rmask, Gmask, Bmask, Amask;
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
Rmask = 0x000000FF;
Gmask = 0x0000FF00;
Bmask = 0x00FF0000;
Amask = 0xFF000000;
#else
Rmask = 0xFF000000;
Gmask = 0x00FF0000;
Bmask = 0x0000FF00;
Amask = 0x000000FF;
#endif
SDL_Surface* surface;
if (data != NULL) {
surface = SDL_CreateRGBSurfaceFrom(data, width, height, 32, pitch, Rmask, Gmask,
Bmask, Amask);
}
if (surface == NULL) {
if (data != NULL) {
stbi_image_free(data);
}
return false;
} else {
SDL_SetWindowIcon(window,surface);
SDL_FreeSurface(surface);
stbi_image_free(data);
return true;
}
}
#endif
SDL_Window* window;
ultramodern::WindowHandle create_window(ultramodern::gfx_callbacks_t::gfx_data_t) {
window = SDL_CreateWindow("Zelda 64: Recompiled", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1600, 960, SDL_WINDOW_RESIZABLE );
#if defined(__linux__)
SetImageAsIcon("icons/512.png",window);
#endif
if (window == nullptr) {
exit_error("Failed to create window: %s\n", SDL_GetError());