From 90e6ff9d8a2dab45ddaba2713831d47264493fa0 Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Fri, 3 Jul 2009 17:39:13 +0000 Subject: Added support for mirrored sprites. svn-id: r42067 --- engines/draci/sprite.cpp | 39 ++++++++++++++++++++++++++++++--------- engines/draci/sprite.h | 4 ++++ 2 files changed, 34 insertions(+), 9 deletions(-) (limited to 'engines') diff --git a/engines/draci/sprite.cpp b/engines/draci/sprite.cpp index 45f4c40e05..b417afc0ed 100644 --- a/engines/draci/sprite.cpp +++ b/engines/draci/sprite.cpp @@ -61,7 +61,8 @@ Sprite::Sprite(byte *raw_data, uint16 width, uint16 height, uint x, uint y, _x = x; _y = y; _z = z; - + _mirror = false; + _data = new byte[width * height]; memcpy(_data, raw_data, width * height); @@ -82,7 +83,8 @@ Sprite::Sprite(byte *sprite_data, uint16 length, uint x, uint y, uint z, _x = x; _y = y; _z = z; - + _mirror = false; + Common::MemoryReadStream reader(sprite_data, length); _width = reader.readUint16LE(); @@ -102,6 +104,14 @@ Sprite::~Sprite() { delete[] _data; } +void Sprite::setMirrorOn() { + _mirror = true; +} + +void Sprite::setMirrorOff() { + _mirror = false; +} + /** * @brief Draws the sprite to a Draci::Surface * @param surface Pointer to a Draci::Surface @@ -113,14 +123,25 @@ void Sprite::draw(Surface *surface, bool markDirty) const { byte *src = _data; // Blit the sprite to the surface - for (unsigned int i = 0; i < _height; ++i) { - for(unsigned int j = 0; j < _width; ++j, ++src) { - - // Don't blit if the pixel is transparent on the target surface - if (*src != surface->getTransparentColour()) - dst[j] = *src; + for (int i = 0; i < _height; ++i) { + + // Draw the sprite mirrored if the _mirror flag is set + if (_mirror) { + for(int j = _width - 1; j >= 0; --j, ++src) { + + // Don't blit if the pixel is transparent on the target surface + if (*src != surface->getTransparentColour()) + dst[j] = *src; + } + } else { + for(int j = 0; j < _width; ++j, ++src) { + + // Don't blit if the pixel is transparent on the target surface + if (*src != surface->getTransparentColour()) + dst[j] = *src; + } } - + dst += surface->pitch; } diff --git a/engines/draci/sprite.h b/engines/draci/sprite.h index c0572f085c..191d20ca9e 100644 --- a/engines/draci/sprite.h +++ b/engines/draci/sprite.h @@ -84,11 +84,15 @@ public: ~Sprite(); void draw(Surface *surface, bool markDirty = true) const; + + void setMirrorOn(); + void setMirrorOff(); const byte *getBuffer() const { return _data; } private: byte *_data; //!< Pointer to a buffer containing raw sprite data (row-wise) + bool _mirror; }; class Text : public Drawable { -- cgit v1.2.3