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, const Point<int> &position) const {
22 int col(colOffset + (c % 0x10));
23 int row(rowOffset + (c / 0x10));
24 sprite->Draw(dest, position, col, row);
27 void Font::DrawString(const char *s, SDL_Surface *dest, const 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, const Point<int> &position) const {
36 DrawChar(digit + 0x30, dest, position);
39 void Font::DrawNumber(int numberIn, SDL_Surface *dest, const 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);