X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FFont.cpp;fp=src%2Fgraphics%2FFont.cpp;h=ca06a076a80c251a17f7fead31171d7ce5c6a1a3;hb=8e0746ace8c76025faad3259a819d57610407bb8;hp=a11850001717eae97289cdb2158c8aa129d32c1c;hpb=31883e0019783f10553ddcc122a49728934bd832;p=l2e.git diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp index a118500..ca06a07 100644 --- a/src/graphics/Font.cpp +++ b/src/graphics/Font.cpp @@ -8,6 +8,7 @@ #include "Font.h" #include +#include using geometry::Vector; using std::pow; @@ -15,12 +16,16 @@ using std::pow; namespace graphics { void Font::DrawChar(char c, SDL_Surface *dest, const Vector &position) const { + if (!sprite) return; + int col(colOffset + (c % 0x10)); int row(rowOffset + (c / 0x10)); sprite->Draw(dest, position, col, row); } void Font::DrawString(const char *s, SDL_Surface *dest, const Vector &positionIn, int maxChars) const { + if (!sprite) return; + Vector position(positionIn); Vector step(CharWidth(), 0); for (int i(0); s[i] && (maxChars <= 0 || i < maxChars); ++i, position += step) { @@ -29,10 +34,14 @@ void Font::DrawString(const char *s, SDL_Surface *dest, const Vector &posit } void Font::DrawDigit(int digit, SDL_Surface *dest, const Vector &position) const { + if (!sprite) return; + DrawChar(digit + 0x30, dest, position); } void Font::DrawNumber(int numberIn, SDL_Surface *dest, const Vector &positionIn, int digits) const { + if (!sprite) return; + int number(numberIn); if (digits > 0 && numberIn >= pow(10.0, digits)) { numberIn = pow(10.0, digits) - 1;