From c591893775d3b850d0a88e743c09c91db337fbdc Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 31 Oct 2012 22:06:58 +0100 Subject: [PATCH] added right aligning font drawing functions --- src/graphics/Font.cpp | 20 ++++++++++++++++++++ src/graphics/Font.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp index be96a2c..59059e0 100644 --- a/src/graphics/Font.cpp +++ b/src/graphics/Font.cpp @@ -39,6 +39,18 @@ void Font::DrawString(const char *s, SDL_Surface *dest, const Vector &posit } } +void Font::DrawStringRight(const char *s, SDL_Surface *dest, const Vector &positionIn, int maxChars) const { + if (!sprite) return; + + int length(0); + while (length < maxChars && s[length] != '\0') { + ++length; + } + Vector position(positionIn.X() - length * CharWidth(), positionIn.Y()); + + DrawString(s, dest, position, length); +} + void Font::DrawDigit(int digit, SDL_Surface *dest, const Vector &position) const { if (!sprite) return; @@ -76,6 +88,14 @@ void Font::DrawNumber(int numberIn, SDL_Surface *dest, const Vector &positi } } +void Font::DrawNumberRight(int number, SDL_Surface *dest, const Vector &positionIn, int digits) const { + if (!sprite) return; + + Vector position(positionIn.X() - digits * CharWidth(), positionIn.Y()); + + DrawNumber(number, dest, position, digits); +} + void Font::CreateTypeDescription() { Font f; diff --git a/src/graphics/Font.h b/src/graphics/Font.h index 07cd35f..b981946 100644 --- a/src/graphics/Font.h +++ b/src/graphics/Font.h @@ -31,8 +31,10 @@ public: int CharHeight() const { return sprite->Height(); } void DrawChar(char c, SDL_Surface *dest, const geometry::Vector &position) const; void DrawString(const char *s, SDL_Surface *dest, const geometry::Vector &position, int maxChars = 0) const; + void DrawStringRight(const char *s, SDL_Surface *dest, const geometry::Vector &position, int maxChars = 0) const; 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; + void DrawNumberRight(int n, SDL_Surface *dest, const geometry::Vector &position, int digits = 0) const; public: void SetSprite(const Sprite *s) { sprite = s; } -- 2.39.2