X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FFont.h;h=c879dcedf73e4fc8a6803cac9651e1e7c0e538af;hb=cc3d698b8c1ad09d7a3f9e3f28bc84e0ac1735ea;hp=082e4c01d56357c0ab3f07bfd7f004e45fc3d96b;hpb=2f2dad58f3b9f7c98cf20211929ff31f5ebf5e5f;p=l2e.git diff --git a/src/graphics/Font.h b/src/graphics/Font.h index 082e4c0..c879dce 100644 --- a/src/graphics/Font.h +++ b/src/graphics/Font.h @@ -1,59 +1,49 @@ -/* - * Font.h - * - * Created on: Aug 8, 2012 - * Author: holy - */ - #ifndef GRAPHICS_FONT_H_ #define GRAPHICS_FONT_H_ #include "Sprite.h" -#include "../geometry/Point.h" +#include "../geometry/Vector.h" -#include #include namespace graphics { -// TODO: maybe fix fonts to use a 8x8 tile sprite for all chars class Font { public: - explicit Font(const Sprite *sprite, int digitsCol = 0, int digitsRow = 0) - : sprite(sprite), digitsCol(digitsCol), digitsRow(digitsRow) { - MapRange('0', '9', digitsCol, digitsRow); + static const int TYPE_ID = 404; + +public: + explicit Font(const Sprite *sprite = 0, int colOffset = 0, int rowOffset = 0) + : sprite(sprite), colOffset(colOffset), rowOffset(rowOffset) { + } public: int CharWidth() const { return sprite->Width(); } int CharHeight() const { return sprite->Height(); } - void DrawChar(char c, SDL_Surface *dest, geometry::Point position) const; - void DrawString(const char *s, SDL_Surface *dest, geometry::Point position, int maxChars = 0) const; - void DrawDigit(int d, SDL_Surface *dest, geometry::Point position) const; - void DrawNumber(int n, SDL_Surface *dest, geometry::Point position, int digits = 0) const; + int StringWidth(const char *) const; + int StringHeight(const char *) const; + + void DrawChar(char c, SDL_Surface *dest, const geometry::Vector &position) const; + void DrawString(const char *s, SDL_Surface *dest, const geometry::Vector &position, int maxWidth = 0) const; + void DrawStringRight(const char *s, SDL_Surface *dest, const geometry::Vector &position, int maxWidth = 0) const; + void DrawDigit(int d, SDL_Surface *dest, const geometry::Vector &position) const; + void DrawNumber(int n, SDL_Surface *dest, const geometry::Vector &position, int digits = 0) const; + void DrawNumberRight(int n, SDL_Surface *dest, const geometry::Vector &position, int digits = 0) const; public: - bool HasChar(char c) const { return map[(unsigned char)c].mapped; }; - 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; }; - void MapRange(char from, char to, int colStart, int row) { - int col(colStart); - for (unsigned char c(from); c <= to; ++c, ++col) { - MapChar(c, col, row); - } - } + void SetSprite(const Sprite *s) { sprite = s; } + void SetColOffset(int n) { colOffset = n; } + void SetRowOffset(int n) { rowOffset = n; } + + static void CreateTypeDescription(); + static void Construct(void *); private: - struct Mapping { - Mapping() : mapped(false), col(0), row(0) { } - bool mapped; - int col; - int row; - }; const Sprite *sprite; - Mapping map[256]; - int digitsCol; - int digitsRow; + int colOffset; + int rowOffset; };