diff options
author | Denis Kasak | 2009-07-27 04:14:59 +0000 |
---|---|---|
committer | Denis Kasak | 2009-07-27 04:14:59 +0000 |
commit | fa59e4b16b502716c527bf2e809f684007039dac (patch) | |
tree | 3bd4c683dfa5189b7bc35f560cba82abc588f083 /engines/draci | |
parent | ddf8f1cbb539e60eada6dfeaea560498ac89e3bc (diff) | |
download | scummvm-rg350-fa59e4b16b502716c527bf2e809f684007039dac.tar.gz scummvm-rg350-fa59e4b16b502716c527bf2e809f684007039dac.tar.bz2 scummvm-rg350-fa59e4b16b502716c527bf2e809f684007039dac.zip |
* Added Sprite::getPixel() (takes into account whether a sprite is mirrored or scaled)
* Made the Text class internally store a Common::String instead of a byte *
svn-id: r42835
Diffstat (limited to 'engines/draci')
-rw-r--r-- | engines/draci/sprite.cpp | 48 | ||||
-rw-r--r-- | engines/draci/sprite.h | 13 |
2 files changed, 40 insertions, 21 deletions
diff --git a/engines/draci/sprite.cpp b/engines/draci/sprite.cpp index 04308a3eed..31a55bfddb 100644 --- a/engines/draci/sprite.cpp +++ b/engines/draci/sprite.cpp @@ -126,6 +126,28 @@ void Sprite::setMirrorOff() { _mirror = false; } + +int Sprite::getPixel(int x, int y) const { + + Common::Rect rect = getRect(); + + int dy = y - rect.top; + int dx = x - rect.left; + + // Calculate scaling factors + double scaleX = double(_scaledWidth) / _width; + double scaleY = double(_scaledHeight) / _height; + + int sy = lround(dy * scaleY); + int sx = lround(dx * scaleX); + + if (_mirror) + return _data[sy * _width + (_width - sx)]; + else + return _data[sy * _width + sx]; +} + + void Sprite::drawScaled(Surface *surface, bool markDirty) const { Common::Rect sourceRect(0, 0, _width, _height); @@ -269,6 +291,7 @@ void Sprite::draw(Surface *surface, bool markDirty) const { surface->markDirtyRect(destRect); } } + Common::Rect Sprite::getRect(bool scaled) const { if (scaled) @@ -279,15 +302,11 @@ Common::Rect Sprite::getRect(bool scaled) const { Text::Text(const Common::String &str, Font *font, byte fontColour, int x, int y, uint spacing) { - uint len = str.size(); - _length = len; - _x = x; _y = y; _delay = 0; - _text = new byte[len]; - memcpy(_text, str.c_str(), len); + _text = str; _spacing = spacing; _colour = fontColour; @@ -295,27 +314,17 @@ Text::Text(const Common::String &str, Font *font, byte fontColour, _font = font; _width = _font->getStringWidth(str, _spacing); - _height = _font->getFontHeight(); + _height = _font->getStringHeight(str); _scaledWidth = _width; _scaledHeight = _height; } -Text::~Text() { - delete[] _text; -} - void Text::setText(const Common::String &str) { - delete[] _text; - - uint len = str.size(); - _length = len; - _width = _font->getStringWidth(str, _spacing); - _height = _font->getFontHeight(); + _height = _font->getStringHeight(str); - _text = new byte[len]; - memcpy(_text, str.c_str(), len); + _text = str; } void Text::setColour(byte fontColour) { @@ -328,7 +337,8 @@ void Text::setSpacing(uint spacing) { void Text::draw(Surface *surface, bool markDirty) const { _font->setColour(_colour); - _font->drawString(surface, _text, _length, _x, _y, _spacing); + + _font->drawString(surface, _text, _x, _y, _spacing); } // TODO: Handle scaled parameter properly by implementing Text scaling diff --git a/engines/draci/sprite.h b/engines/draci/sprite.h index 44ae8a202b..77e45d6a7c 100644 --- a/engines/draci/sprite.h +++ b/engines/draci/sprite.h @@ -31,6 +31,8 @@ namespace Draci { +enum DrawableType { kDrawableText, kDrawableSprite }; + class Drawable { public: @@ -60,6 +62,8 @@ public: int getDelay() const { return _delay; } virtual Common::Rect getRect(bool scaled = true) const = 0; + + virtual DrawableType getType() const = 0; protected: uint _width; //!< Width of the sprite @@ -105,6 +109,9 @@ public: Common::Rect getRect(bool scaled = true) const; const byte *getBuffer() const { return _data; } + int getPixel(int x, int y) const; + + DrawableType getType() const { return kDrawableSprite; } private: byte *_data; //!< Pointer to a buffer containing raw sprite data (row-wise) @@ -116,7 +123,7 @@ class Text : public Drawable { public: Text(const Common::String &str, Font *font, byte fontColour, int x, int y, uint spacing = 0); - ~Text(); + ~Text() {}; void setText(const Common::String &str); void setColour(byte fontColour); @@ -130,8 +137,10 @@ public: void drawScaled(Surface *surface, bool markDirty = true) const { draw(surface, markDirty); } Common::Rect getRect(bool) const; + DrawableType getType() const { return kDrawableText; } + private: - byte *_text; + Common::String _text; uint _length; uint8 _colour; uint _spacing; |