Added Text as a subclass of Drawable. Fixed syntax error in font.cpp

svn-id: r41981
This commit is contained in:
Denis Kasak 2009-07-01 01:11:48 +00:00
parent 49e1a07f27
commit 78d5b96f51
3 changed files with 40 additions and 3 deletions

View file

@ -212,7 +212,7 @@ void Font::drawChar(Surface *dst, uint8 chr, int tx, int ty) const {
* @param spacing Space to leave between individual characters. Defaults to 0. * @param spacing Space to leave between individual characters. Defaults to 0.
*/ */
void Font::drawString(Surface *dst, const byte *str, uint len void Font::drawString(Surface *dst, const byte *str, uint len,
int x, int y, int spacing) const { int x, int y, int spacing) const {
assert(dst != NULL); assert(dst != NULL);
assert(x >= 0); assert(x >= 0);
@ -245,7 +245,7 @@ void Font::drawString(Surface *dst, const byte *str, uint len
void Font::drawString(Surface *dst, const Common::String &str, void Font::drawString(Surface *dst, const Common::String &str,
int x, int y, int spacing) const { int x, int y, int spacing) const {
drawString(dst, str, str.size(), x, y, spacing); drawString(dst, (byte *) str.c_str(), str.size(), x, y, spacing);
} }
/** /**

View file

@ -27,6 +27,7 @@
#include "draci/draci.h" #include "draci/draci.h"
#include "draci/sprite.h" #include "draci/sprite.h"
#include "draci/font.h"
namespace Draci { namespace Draci {
@ -124,7 +125,28 @@ void Sprite::draw(Surface *surface) const {
Common::Rect r(_x, _y, _x + _width, _y + _height); Common::Rect r(_x, _y, _x + _width, _y + _height);
surface->markDirtyRect(r); surface->markDirtyRect(r);
} }
Text::Text(const Common::String &str, Font *font, byte fontColour, uint spacing) {
uint len = str.size();
_text = new byte[len];
memcpy(_text, str.c_str(), len);
_length = len;
_spacing = spacing;
_colour = fontColour;
_font = font;
}
Text::~Text() {
delete _text;
}
void Text::draw(Surface *surface) const {
_font->setColour(_colour);
_font->drawString(surface, _text, _length, _x, _y, _spacing);
}
} // End of namespace Draci } // End of namespace Draci

View file

@ -27,6 +27,7 @@
#define DRACI_SPRITE_H #define DRACI_SPRITE_H
#include "draci/surface.h" #include "draci/surface.h"
#include "draci/font.h"
namespace Draci { namespace Draci {
@ -70,7 +71,21 @@ public:
byte *_data; //!< Pointer to a buffer containing raw sprite data (row-wise) byte *_data; //!< Pointer to a buffer containing raw sprite data (row-wise)
}; };
class Text : public Drawable {
public:
Text(const Common::String &str, Font *font, byte fontColour, uint spacing = 0);
~Text();
void draw(Surface *surface) const;
byte *_text;
uint _length;
uint8 _colour;
uint _spacing;
Font *_font;
};
} // End of namespace Draci } // End of namespace Draci
#endif // DRACI_SPRITE_H #endif // DRACI_SPRITE_H