/*
-Copyright (C) 2004 Parallel Realities
+Copyright (C) 2004-2011 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(sprite->format, 0, 0, 0));
}
-bool Graphics::canShowMedalMessage()
+bool Graphics::canShowMedalMessage() const
{
return (medalMessageTimer <= 0);
}
Sprite *Graphics::addSprite(const char *name)
{
Sprite *sprite = new Sprite;
- strncpy(sprite->name, name, sizeof sprite->name);
+ strlcpy(sprite->name, name, sizeof sprite->name);
spriteList.add(sprite);
}
}
-int Graphics::getWaterAnim()
+int Graphics::getWaterAnim() const
{
return waterAnim;
}
-int Graphics::getSlimeAnim()
+int Graphics::getSlimeAnim() const
{
return slimeAnim;
}
-int Graphics::getLavaAnim()
+int Graphics::getLavaAnim() const
{
return lavaAnim;
}
SDL_Surface *text = TTF_RenderUTF8_Shaded(font[fontSize], in, fontForeground, fontBackground);
if (!text)
- {
text = TTF_RenderUTF8_Shaded(font[fontSize], "FONT_ERROR", fontForeground, fontBackground);
- }
+
+ if (!text)
+ return;
+
+ setTransparent(text);
if (alignment == TXT_RIGHT) x -= text->w;
if (alignment == TXT_CENTERED) center = true;
- setTransparent(text);
blit(text, x, y, dest, center);
SDL_FreeSurface(text);
}
+void Graphics::drawString(const char *in, int x, int y, int alignment, SDL_Surface *dest, SurfaceCache &cache)
+{
+ bool center = false;
+
+ if(!cache.text || strcmp(in, cache.text)) {
+ if(cache.surface)
+ SDL_FreeSurface(cache.surface);
+
+ if(cache.text)
+ ::free(cache.text);
+
+ cache.text = strdup(in);
+
+ cache.surface = TTF_RenderUTF8_Shaded(font[fontSize], in, fontForeground, fontBackground);
+
+ if (!cache.surface)
+ cache.surface = TTF_RenderUTF8_Shaded(font[fontSize], "FONT_ERROR", fontForeground, fontBackground);
+
+ if(!cache.surface)
+ return;
+
+ setTransparent(cache.surface);
+ }
+
+ if (alignment == TXT_RIGHT) x -= cache.surface->w;
+ if (alignment == TXT_CENTERED) center = true;
+
+ blit(cache.surface, x, y, dest, center);
+}
+
void Graphics::clearChatString()
{
chatString[0] = 0;
void Graphics::createChatString(const char *in)
{
- strncat(chatString, " ", sizeof chatString);
- strncat(chatString, in, sizeof chatString);
+ strlcat(chatString, " ", sizeof chatString);
+ strlcat(chatString, in, sizeof chatString);
}
void Graphics::drawChatString(SDL_Surface *surface, int y)
blit(wordSurface, x, y, surface, false);
- SDL_FreeSurface(wordSurface);
-
x += wordSurface->w;
+ SDL_FreeSurface(wordSurface);
+
word = strtok(NULL, " ");
}
}