Move program icon into a function.
This commit is contained in:
+42
-27
@@ -698,6 +698,42 @@ U64 __rdtsc()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* TODO: In the future, this should just accept either a bitmap or image
|
||||||
|
* path. This is to be determined. One cool feature this might
|
||||||
|
* support is displaying certain information in the program icon by
|
||||||
|
* drawing into a bitmap. */
|
||||||
|
void SDLSetProgramIcon(SDL_Window *Window)
|
||||||
|
{
|
||||||
|
SDL_Surface *icon;
|
||||||
|
|
||||||
|
U32 Rmask, Gmask, Bmask, Amask;
|
||||||
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||||
|
S32 shift_by = (program_icon.bytes_per_pixel == 3) ? 8 : 0;
|
||||||
|
Rmask = 0xff000000 >> shift_by;
|
||||||
|
Gmask = 0x00ff0000 >> shift_by;
|
||||||
|
Bmask = 0x0000ff00 >> shift_by;
|
||||||
|
Amask = 0x000000ff >> shift_by;
|
||||||
|
#else
|
||||||
|
Rmask = 0x000000ff;
|
||||||
|
Gmask = 0x0000ff00;
|
||||||
|
Bmask = 0x00ff0000;
|
||||||
|
Amask = (program_icon.bytes_per_pixel == 3) ? 0 : 0xff000000;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
icon = SDL_CreateRGBSurfaceFrom(
|
||||||
|
(void *)program_icon.pixel_data,
|
||||||
|
program_icon.width, program_icon.height,
|
||||||
|
program_icon.bytes_per_pixel * 8,
|
||||||
|
program_icon.bytes_per_pixel * program_icon.width,
|
||||||
|
Rmask, Gmask, Bmask, Amask);
|
||||||
|
if(icon) {
|
||||||
|
SDL_SetWindowIcon(Window, icon);
|
||||||
|
SDL_FreeSurface(icon);
|
||||||
|
} else {
|
||||||
|
/* TODO: This didn't work . . . SDL_GetError() */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
S32 main(S32 argc, char *argv[])
|
S32 main(S32 argc, char *argv[])
|
||||||
{
|
{
|
||||||
sdl_state SDLState;
|
sdl_state SDLState;
|
||||||
@@ -729,9 +765,6 @@ S32 main(S32 argc, char *argv[])
|
|||||||
if(Window) {
|
if(Window) {
|
||||||
SDL_Renderer *Renderer;
|
SDL_Renderer *Renderer;
|
||||||
|
|
||||||
SDL_Surface* icon;
|
|
||||||
Uint32 rmask, gmask, bmask, amask;
|
|
||||||
|
|
||||||
SDL_DisplayMode display_mode;
|
SDL_DisplayMode display_mode;
|
||||||
SDL_GetCurrentDisplayMode(0, &display_mode);
|
SDL_GetCurrentDisplayMode(0, &display_mode);
|
||||||
|
|
||||||
@@ -739,30 +772,6 @@ S32 main(S32 argc, char *argv[])
|
|||||||
SDL_SetWindowPosition(Window, (display_mode.w - RESOLUTION_WIDTH),
|
SDL_SetWindowPosition(Window, (display_mode.w - RESOLUTION_WIDTH),
|
||||||
(display_mode.h - RESOLUTION_HEIGHT));
|
(display_mode.h - RESOLUTION_HEIGHT));
|
||||||
|
|
||||||
/* Set program icon. */
|
|
||||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
||||||
int shift = (program_icon.bytes_per_pixel == 3) ? 8 : 0;
|
|
||||||
rmask = 0xff000000 >> shift;
|
|
||||||
gmask = 0x00ff0000 >> shift;
|
|
||||||
bmask = 0x0000ff00 >> shift;
|
|
||||||
amask = 0x000000ff >> shift;
|
|
||||||
#else
|
|
||||||
rmask = 0x000000ff;
|
|
||||||
gmask = 0x0000ff00;
|
|
||||||
bmask = 0x00ff0000;
|
|
||||||
amask = (program_icon.bytes_per_pixel == 3) ? 0 : 0xff000000;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
icon = SDL_CreateRGBSurfaceFrom(
|
|
||||||
(void *)program_icon.pixel_data,
|
|
||||||
program_icon.width, program_icon.height,
|
|
||||||
program_icon.bytes_per_pixel * 8,
|
|
||||||
program_icon.bytes_per_pixel * program_icon.width,
|
|
||||||
rmask, gmask, bmask, amask);
|
|
||||||
|
|
||||||
SDL_SetWindowIcon(Window, icon);
|
|
||||||
SDL_FreeSurface(icon);
|
|
||||||
|
|
||||||
/* "Wayland needs an event loop and rendering or it won't function."
|
/* "Wayland needs an event loop and rendering or it won't function."
|
||||||
* https://github.com/libsdl-org/SDL/issues/7699#issuecomment-1545684792 */
|
* https://github.com/libsdl-org/SDL/issues/7699#issuecomment-1545684792 */
|
||||||
/* NOTE: This means that we need to readraw to even resize the
|
/* NOTE: This means that we need to readraw to even resize the
|
||||||
@@ -781,6 +790,12 @@ S32 main(S32 argc, char *argv[])
|
|||||||
void *BaseAddress = (void *)(0);
|
void *BaseAddress = (void *)(0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SDLSetProgramIcon(Window);
|
||||||
|
#if 0
|
||||||
|
if(SDL_ShowCursor(SDL_DISABLE) < 0) {
|
||||||
|
/* TODO: This didn't work . . . SDL_GetError() */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
GlobalRunning = TRUE;
|
GlobalRunning = TRUE;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user