mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-11-04 18:29:41 +01:00
Use LoadImage
in LoadIcon
This de-duplicates the code, simplifying the codebase and reducing the number of code paths that needs to be maintained. It also adds robustness checks to LoadIcon that weren't there before (checking that loading the file succeeded and that decoding the file also succeeded). Now, you might think that loading the image with alpha will change things in some way. But actually, I tested it, and I'm pretty sure it doesn't. Since my window manager, i3, doesn't display icons, I've had to resort to this hacky multi-liner ( https://unix.stackexchange.com/a/48866 ) to dump the icon to a PAM file. I don't know what a PAM file is and all my various attempts to convert it into something readable failed. But what I did instead was just grab the icon of the game before this commit (on 2.3, just to be extra sure), and `diff`ed it with the grabbed icon now, and they end up being the exact same file. So there's literally no difference. The only other consideration is that LoadImage needs to be exported, since it's implemented in GraphicsResources.cpp. I just opted to forward-declare it right before LoadIcon in Screen.cpp, since it's really the only other time it's used. No need to create a new header file for it or anything.
This commit is contained in:
parent
a5c3bd97a0
commit
dd24343141
2 changed files with 17 additions and 31 deletions
|
@ -16,7 +16,8 @@ extern "C"
|
||||||
extern const char* lodepng_error_text(unsigned code);
|
extern const char* lodepng_error_text(unsigned code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_Surface* LoadImage(const char *filename)
|
/* Don't declare `static`, this is used elsewhere */
|
||||||
|
SDL_Surface* LoadImage(const char *filename)
|
||||||
{
|
{
|
||||||
//Temporary storage for the image that's loaded
|
//Temporary storage for the image that's loaded
|
||||||
SDL_Surface* loadedImage = NULL;
|
SDL_Surface* loadedImage = NULL;
|
||||||
|
|
|
@ -8,18 +8,6 @@
|
||||||
#include "GraphicsUtil.h"
|
#include "GraphicsUtil.h"
|
||||||
#include "Vlogging.h"
|
#include "Vlogging.h"
|
||||||
|
|
||||||
// Used to create the window icon
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
extern unsigned lodepng_decode24(
|
|
||||||
unsigned char** out,
|
|
||||||
unsigned* w,
|
|
||||||
unsigned* h,
|
|
||||||
const unsigned char* in,
|
|
||||||
size_t insize
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScreenSettings_default(struct ScreenSettings* _this)
|
void ScreenSettings_default(struct ScreenSettings* _this)
|
||||||
{
|
{
|
||||||
_this->windowWidth = 320;
|
_this->windowWidth = 320;
|
||||||
|
@ -120,29 +108,26 @@ void Screen::GetSettings(struct ScreenSettings* settings)
|
||||||
settings->badSignal = badSignalEffect;
|
settings->badSignal = badSignalEffect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
/* Apple doesn't like icons anymore... */
|
||||||
void Screen::LoadIcon(void)
|
void Screen::LoadIcon(void)
|
||||||
{
|
{
|
||||||
#ifndef __APPLE__
|
|
||||||
unsigned char *fileIn;
|
}
|
||||||
size_t length;
|
#else
|
||||||
unsigned char *data;
|
SDL_Surface* LoadImage(const char* filename);
|
||||||
unsigned int width, height;
|
|
||||||
FILESYSTEM_loadAssetToMemory("VVVVVV.png", &fileIn, &length, false);
|
void Screen::LoadIcon(void)
|
||||||
lodepng_decode24(&data, &width, &height, fileIn, length);
|
{
|
||||||
FILESYSTEM_freeMemory(&fileIn);
|
SDL_Surface* icon = LoadImage("VVVVVV.png");
|
||||||
SDL_Surface *icon = SDL_CreateRGBSurfaceWithFormatFrom(
|
if (icon == NULL)
|
||||||
data,
|
{
|
||||||
width,
|
return;
|
||||||
height,
|
}
|
||||||
24,
|
|
||||||
width * 3,
|
|
||||||
SDL_PIXELFORMAT_RGB24
|
|
||||||
);
|
|
||||||
SDL_SetWindowIcon(m_window, icon);
|
SDL_SetWindowIcon(m_window, icon);
|
||||||
SDL_FreeSurface(icon);
|
SDL_FreeSurface(icon);
|
||||||
SDL_free(data);
|
|
||||||
#endif /* __APPLE__ */
|
|
||||||
}
|
}
|
||||||
|
#endif /* __APPLE__ */
|
||||||
|
|
||||||
void Screen::ResizeScreen(int x, int y)
|
void Screen::ResizeScreen(int x, int y)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue