4 * Created on: Aug 8, 2012
10 #include "../geometry/operators.h"
11 #include "../geometry/Vector.h"
15 using geometry::Point;
16 using geometry::Vector;
21 void Font::DrawChar(char c, SDL_Surface *dest, Point<int> position) const {
22 if (!HasChar(c)) return;
23 const Mapping &m(map[(unsigned char)c]);
24 sprite->Draw(dest, position, m.col, m.row);
27 void Font::DrawString(const char *s, SDL_Surface *dest, Point<int> positionIn, int maxChars) const {
28 Point<int> position(positionIn);
29 Vector<int> step(CharWidth(), 0);
30 for (int i(0); s[i] && (maxChars <= 0 || i < maxChars); ++i, position += step) {
31 DrawChar(s[i], dest, position);
35 void Font::DrawDigit(int digit, SDL_Surface *dest, Point<int> position) const {
36 sprite->Draw(dest, position, digitsCol + digit, digitsRow);
39 void Font::DrawNumber(int numberIn, SDL_Surface *dest, Point<int> positionIn, int digits) const {
41 if (digits > 0 && numberIn >= pow(10.0, digits)) {
42 numberIn = pow(10.0, digits) - 1;
45 Point<int> position(positionIn);
46 Vector<int> step(sprite->Width(), 0);
50 while (number < pow(10.0, i) && i > 0) {
63 DrawDigit((number / m) % 10, dest, position);