4 * Created on: Aug 8, 2012
10 #include "../loader/TypeDescription.h"
15 using geometry::Vector;
16 using loader::FieldDescription;
17 using loader::TypeDescription;
22 void Font::DrawChar(char c, SDL_Surface *dest, const Vector<int> &position) const {
25 int col(colOffset + (c % 0x10));
26 int row(rowOffset + (c / 0x10));
27 sprite->Draw(dest, position, col, row);
30 void Font::DrawString(const char *s, SDL_Surface *dest, const Vector<int> &positionIn, int maxChars) const {
33 Vector<int> position(positionIn);
34 Vector<int> step(CharWidth(), 0);
35 for (int i(0); s[i] && (maxChars <= 0 || i < maxChars); ++i, position += step) {
36 DrawChar(s[i], dest, position);
40 void Font::DrawDigit(int digit, SDL_Surface *dest, const Vector<int> &position) const {
43 DrawChar(digit + 0x30, dest, position);
46 void Font::DrawNumber(int numberIn, SDL_Surface *dest, const Vector<int> &positionIn, int digits) const {
50 if (digits > 0 && numberIn >= pow(10.0, digits)) {
51 numberIn = pow(10.0, digits) - 1;
54 Vector<int> position(positionIn);
55 Vector<int> step(sprite->Width(), 0);
59 while (number < pow(10.0, i) && i > 0) {
72 DrawDigit((number / m) % 10, dest, position);
78 void Font::CreateTypeDescription() {
81 int numberId(TypeDescription::GetTypeId("Number"));
82 int spriteId(TypeDescription::GetTypeId("Sprite"));
84 TypeDescription &td(TypeDescription::CreateOrGet("Font"));
85 td.SetSize(sizeof(Font));
87 td.AddField("sprite", FieldDescription(((char *)&f.sprite) - ((char *)&f), spriteId, true));
88 td.AddField("columnoffset", FieldDescription(((char *)&f.colOffset) - ((char *)&f), numberId, false));
89 td.AddField("rowoffset", FieldDescription(((char *)&f.rowOffset) - ((char *)&f), numberId, false));