Added Text as a subclass of Drawable. Fixed syntax error in font.cpp
svn-id: r41981
This commit is contained in:
parent
49e1a07f27
commit
78d5b96f51
3 changed files with 40 additions and 3 deletions
|
@ -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.
|
||||
*/
|
||||
|
||||
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 {
|
||||
assert(dst != NULL);
|
||||
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,
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "draci/draci.h"
|
||||
#include "draci/sprite.h"
|
||||
#include "draci/font.h"
|
||||
|
||||
namespace Draci {
|
||||
|
||||
|
@ -125,6 +126,27 @@ void Sprite::draw(Surface *surface) const {
|
|||
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
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#define DRACI_SPRITE_H
|
||||
|
||||
#include "draci/surface.h"
|
||||
#include "draci/font.h"
|
||||
|
||||
namespace Draci {
|
||||
|
||||
|
@ -70,6 +71,20 @@ public:
|
|||
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue