namespace graphics {
+int Font::StringWidth(const char *s) const {
+ int width(0), col(0);
+ for (int i(0); s[i]; ++i) {
+ if (s[i] == '\n') {
+ if (width < col) {
+ width = col;
+ }
+ col = 0;
+ } else {
+ ++col;
+ }
+ }
+ return (width < col ? col : width) * CharWidth();
+}
+
+int Font::StringHeight(const char *s) const {
+ if (*s == '\0') {
+ return 0;
+ }
+ int height(1);
+ for (; *s; ++s) {
+ if (*s == '\n') {
+ ++height;
+ }
+ }
+ return height * CharHeight();
+}
+
+
void Font::DrawChar(char c, SDL_Surface *dest, const Vector<int> &position) const {
if (!sprite) return;
public:
int CharWidth() const { return sprite->Width(); }
int CharHeight() const { return sprite->Height(); }
+ int StringWidth(const char *) const;
+ int StringHeight(const char *) const;
+
void DrawChar(char c, SDL_Surface *dest, const geometry::Vector<int> &position) const;
void DrawString(const char *s, SDL_Surface *dest, const geometry::Vector<int> &position, int maxWidth = 0) const;
void DrawStringRight(const char *s, SDL_Surface *dest, const geometry::Vector<int> &position, int maxWidth = 0) const;