1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

Factor out icon loading to Screen::LoadIcon()

This is so it can be called multiple times without having to duplicate
code.
This commit is contained in:
Misa 2020-10-31 20:25:27 -07:00 committed by Ethan Lee
parent c371d30509
commit 6d8b8d08b9
2 changed files with 28 additions and 21 deletions

View file

@ -62,27 +62,7 @@ void Screen::init(
);
SDL_SetWindowTitle(m_window, "VVVVVV");
unsigned char *fileIn = NULL;
size_t length = 0;
unsigned char *data;
unsigned int width, height;
FILESYSTEM_loadFileToMemory("VVVVVV.png", &fileIn, &length);
lodepng_decode24(&data, &width, &height, fileIn, length);
FILESYSTEM_freeMemory(&fileIn);
SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(
data,
width,
height,
24,
width * 3,
0x000000FF,
0x0000FF00,
0x00FF0000,
0x00000000
);
SDL_SetWindowIcon(m_window, icon);
SDL_FreeSurface(icon);
free(data);
LoadIcon();
// FIXME: This surface should be the actual backbuffer! -flibit
m_screen = SDL_CreateRGBSurface(
@ -109,6 +89,31 @@ void Screen::init(
ResizeScreen(windowWidth, windowHeight);
}
void Screen::LoadIcon()
{
unsigned char *fileIn = NULL;
size_t length = 0;
unsigned char *data;
unsigned int width, height;
FILESYSTEM_loadFileToMemory("VVVVVV.png", &fileIn, &length);
lodepng_decode24(&data, &width, &height, fileIn, length);
FILESYSTEM_freeMemory(&fileIn);
SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(
data,
width,
height,
24,
width * 3,
0x000000FF,
0x0000FF00,
0x00FF0000,
0x00000000
);
SDL_SetWindowIcon(m_window, icon);
SDL_FreeSurface(icon);
free(data);
}
void Screen::ResizeScreen(int x, int y)
{
static int resX = 320;

View file

@ -16,6 +16,8 @@ public:
bool badSignal
);
void LoadIcon();
void ResizeScreen(int x, int y);
void ResizeToNearestMultiple();
void GetWindowSize(int* x, int* y);