+/*
+ * Font.cpp
+ *
+ * Created on: Aug 8, 2012
+ * Author: holy
+ */
+
+#include "Font.h"
+
+#include "../geometry/operators.h"
+#include "../geometry/Vector.h"
+
+#include <cmath>
+
+using geometry::Point;
+using geometry::Vector;
+using std::pow;
+
+namespace graphics {
+
+void Font::DrawDigit(int digit, SDL_Surface *dest, Point<int> position) const {
+ sprite->Draw(dest, position, digitsCol + digit, digitsRow);
+}
+
+void Font::DrawNumber(int numberIn, SDL_Surface *dest, Point<int> positionIn, int digits) const {
+ int number(numberIn);
+ if (digits > 0 && numberIn >= pow(10.0, digits)) {
+ numberIn = pow(10.0, digits) - 1;
+ }
+
+ Point<int> position(positionIn);
+ Vector<int> step(sprite->Width(), 0);
+
+ if (digits > 0) {
+ int i(digits - 1);
+ while (number < pow(10.0, i)) {
+ position += step;
+ --i;
+ }
+ }
+
+ int m(10);
+ while (m <= number) {
+ m *= 10;
+ }
+
+ while (m > 9) {
+ m /= 10;
+ DrawDigit((number / m) % 10, dest, position);
+ position += step;
+ }
+}
+
+}