4 * Created on: Aug 8, 2012
8 #ifndef GRAPHICS_FONT_H_
9 #define GRAPHICS_FONT_H_
12 #include "../geometry/Point.h"
19 // TODO: maybe fix fonts to use a 8x8 tile sprite for all chars
23 explicit Font(const Sprite *sprite, int digitsCol = 0, int digitsRow = 0)
24 : sprite(sprite), digitsCol(digitsCol), digitsRow(digitsRow) {
25 MapRange('0', '9', digitsCol, digitsRow);
29 int CharWidth() const { return sprite->Width(); }
30 int CharHeight() const { return sprite->Height(); }
31 void DrawChar(char c, SDL_Surface *dest, geometry::Point<int> position) const;
32 void DrawString(const char *s, SDL_Surface *dest, geometry::Point<int> position, int maxChars = 0) const;
33 void DrawDigit(int d, SDL_Surface *dest, geometry::Point<int> position) const;
34 void DrawNumber(int n, SDL_Surface *dest, geometry::Point<int> position, int digits = 0) const;
37 bool HasChar(char c) const { return map[(unsigned char)c].mapped; };
38 void MapChar(char c, int col, int row) { map[(unsigned char)c].mapped = true; map[(unsigned char)c].col = col; map[(unsigned char)c].row = row; };
39 void MapRange(char from, char to, int colStart, int row) {
41 for (unsigned char c(from); c <= to; ++c, ++col) {
48 Mapping() : mapped(false), col(0), row(0) { }
62 #endif /* GRAPHICS_FONT_H_ */