From: Daniel Karbach Date: Fri, 31 Aug 2012 19:13:57 +0000 (+0200) Subject: made Font default constructible X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=8e0746ace8c76025faad3259a819d57610407bb8;p=l2e.git made Font default constructible --- 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; diff --git a/src/graphics/Font.h b/src/graphics/Font.h index 8644802..571431d 100644 --- a/src/graphics/Font.h +++ b/src/graphics/Font.h @@ -18,7 +18,7 @@ namespace graphics { class Font { public: - explicit Font(const Sprite *sprite, int colOffset = 0, int rowOffset = 0) + explicit Font(const Sprite *sprite = 0, int colOffset = 0, int rowOffset = 0) : sprite(sprite), colOffset(colOffset), rowOffset(rowOffset) { } @@ -31,6 +31,11 @@ public: void DrawDigit(int d, SDL_Surface *dest, const geometry::Vector &position) const; void DrawNumber(int n, SDL_Surface *dest, const geometry::Vector &position, int digits = 0) const; +public: + void SetSprite(const Sprite *s) { sprite = s; } + void SetColOffset(int n) { colOffset = n; } + void SetRowOffset(int n) { rowOffset = n; } + private: const Sprite *sprite; int colOffset;