void Graphics::setTransparent(SDL_Surface *sprite)
{
- SDL_SetColorKey(sprite, SDL_TRUE, SDL_MapRGB(sprite->format, 0, 0, 0));
+ if (sprite)
+ SDL_SetColorKey(sprite, SDL_TRUE, SDL_MapRGB(sprite->format, 0, 0, 0));
}
bool Graphics::canShowMedalMessage() const
SDL_UpdateTexture(texture, NULL, screen->pixels, screen->w * 4);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
+ SDL_RenderClear(renderer);
if (takeRandomScreenShots)
{
#endif
if (!image)
- showErrorAndExit(ERR_FILE, filename);
+ return showErrorAndExit(ERR_FILE, filename), image;
newImage = SDL_ConvertSurface(image, screen->format, 0);
#endif
if (!image)
- showErrorAndExit(ERR_FILE, filename);
+ return showErrorAndExit(ERR_FILE, filename), image;
if ((hue != 0) || (sat != 0) || (value != 0))
{
{
tile[i] = loadImage(filename);
+ if (!tile[i])
+ abort();
+
if (autoAlpha)
{
if ((i < MAP_EXITSIGN) || (i >= MAP_WATERANIM))
}
}
-/*
-Note : We need to search for the right >>> PIXEL SIZE <<< and NOT point size!!
-If a user has a resolution other than approximately 72dpi then
-they will get a small or larger font and this won't work. This might look
-weird since we'll load and delete multiple fonts, but it works...
-*/
-void Graphics::loadFont(int i, const char *filename, int pixelSize)
+void Graphics::loadFont(int i, const char *filename, int pointSize)
{
- int minx, maxx, miny, maxy, advance;
-
- debug(("Attempting to load a font with pixel size of %d...\n", pixelSize));
+ debug(("Attempting to load font %s with point size of %d...\n", filename, pointSize));
if (font[i])
{
TTF_CloseFont(font[i]);
}
- char tempPath[PATH_MAX];
-
- snprintf(tempPath, sizeof tempPath, "%sfont.ttf", engine->userHomeDirectory);
+ #if USEPAK
+ (void)filename;
+ char tempPath[PATH_MAX];
+ snprintf(tempPath, sizeof tempPath, "%sfont.ttf", engine->userHomeDirectory);
+ font[i] = TTF_OpenFont(tempPath, pointSize);
+ #else
+ font[i] = TTF_OpenFont(filename, pointSize);
+ #endif
- bool found = false;
- int size = 0;
-
- while (!found)
+ if (!font[i])
{
- if (font[i])
- {
- TTF_CloseFont(font[i]);
- }
-
- #if USEPAK
- font[i] = TTF_OpenFont(tempPath, ++size);
- #else
- font[i] = TTF_OpenFont("data/vera.ttf", ++size);
- #endif
-
- if (!font[i])
- {
- engine->reportFontFailure();
- }
-
- TTF_GlyphMetrics(font[i], '8', &minx, &maxx, &miny, &maxy, &advance);
-
- // great! we have an exact match
- if (maxx == pixelSize)
- {
- break;
- }
-
- // we've overshot, so we'll use the previous size!
- if (maxx > pixelSize)
- {
- TTF_CloseFont(font[i]);
-
- #if USEPAK
- font[i] = TTF_OpenFont(tempPath, size - 1);
- #else
- font[i] = TTF_OpenFont("data/vera.ttf", size - 1);
- #endif
-
- TTF_GlyphMetrics(font[i], '8', &minx, &maxx, &miny, &maxy, &advance);
-
- break;
- }
-
- if (size >= 100)
- {
- debug(("Pixel size has exceeded 99 pixels! I'm giving up!\n"));
- engine->reportFontFailure();
- }
+ engine->reportFontFailure();
}
TTF_SetFontStyle(font[i], TTF_STYLE_NORMAL);
-
- debug(("Got a match for font size %d - Nearest = %d\n", pixelSize, maxx));
}
Sprite *Graphics::addSprite(const char *name)
{
if (!image)
{
- showErrorAndExit("graphics::blit() - NULL pointer", SDL_GetError());
+ return showErrorAndExit("graphics::blit() - NULL pointer", SDL_GetError());
}
if ((x < -image->w) || (x > 640 + image->w))
text = TTF_RenderUTF8_Shaded(font[fontSize], "FONT_ERROR", fontForeground, fontBackground);
}
+ if (!text)
+ {
+ fprintf(stderr, "Unable to render text: %s\n", SDL_GetError());
+ abort();
+ }
+
if (transparent)
setTransparent(text);
drawRect(120, 420, 400, 10, black, white, screen);
drawRect(121, 421, currentLoading, 8, red, screen);
+ #else
+ (void)amount;
+ (void)max;
#endif
}