aboutsummaryrefslogtreecommitdiff
path: root/engines/draci
diff options
context:
space:
mode:
authorDenis Kasak2009-07-04 18:29:01 +0000
committerDenis Kasak2009-07-04 18:29:01 +0000
commita06509f3c255b89c322975fcfcc620735789122b (patch)
tree8466fac1fced466f8632189f51c38f7bc1e6830a /engines/draci
parent0888e8a6da350c88c8e69f02963203772c7ea33b (diff)
downloadscummvm-rg350-a06509f3c255b89c322975fcfcc620735789122b.tar.gz
scummvm-rg350-a06509f3c255b89c322975fcfcc620735789122b.tar.bz2
scummvm-rg350-a06509f3c255b89c322975fcfcc620735789122b.zip
* Removed tracking of Z coordinates in Drawable since it's not used
* Made columnwise parameter mandatory * Made Sprite coordinates signed (the engine sometimes uses negative coordinates) * Prevented overflow when drawing sprites in some cases svn-id: r42100
Diffstat (limited to 'engines/draci')
-rw-r--r--engines/draci/sprite.cpp39
-rw-r--r--engines/draci/sprite.h22
2 files changed, 32 insertions, 29 deletions
diff --git a/engines/draci/sprite.cpp b/engines/draci/sprite.cpp
index 4461a743f5..39a33438ae 100644
--- a/engines/draci/sprite.cpp
+++ b/engines/draci/sprite.cpp
@@ -53,14 +53,15 @@ static void transformToRows(byte *img, uint16 width, uint16 height) {
/**
* Constructor for loading sprites from a raw data buffer, one byte per pixel.
- */
-Sprite::Sprite(byte *raw_data, uint16 width, uint16 height, uint x, uint y,
- uint z, bool columnwise) : _data(NULL) {
+ */
+Sprite::Sprite(byte *raw_data, uint16 width, uint16 height, int x, int y,
+ bool columnwise) : _data(NULL) {
+
_width = width;
_height = height;
_x = x;
_y = y;
- _z = z;
+
_mirror = false;
_data = new byte[width * height];
@@ -73,22 +74,22 @@ Sprite::Sprite(byte *raw_data, uint16 width, uint16 height, uint x, uint y,
}
}
-
/**
* Constructor for loading sprites from a sprite-formatted buffer, one byte per
* pixel.
*/
-Sprite::Sprite(byte *sprite_data, uint16 length, uint x, uint y, uint z,
- bool columnwise) : _data(NULL) {
+Sprite::Sprite(byte *sprite_data, uint16 length, int x, int y, bool columnwise)
+ : _data(NULL) {
+
_x = x;
_y = y;
- _z = z;
+
_mirror = false;
Common::MemoryReadStream reader(sprite_data, length);
- _width = reader.readUint16LE();
- _height = reader.readUint16LE();
+ _width = reader.readSint16LE();
+ _height = reader.readSint16LE();
_data = new byte[_width * _height];
@@ -122,19 +123,27 @@ void Sprite::draw(Surface *surface, bool markDirty) const {
byte *dst = (byte *)surface->getBasePtr(_x, _y);
byte *src = _data;
+ // Determine how many pixels to draw horizontally (to prevent overflow)
+ int xSpaceLeft = surface->w - _x - 1;
+ int xPixelsToDraw = (_width < xSpaceLeft) ? _width : xSpaceLeft;
+
+ // Determine how many pixels to draw vertically
+ int ySpaceLeft = surface->h - _y - 1;
+ int yPixelsToDraw = (_height < ySpaceLeft) ? _height : ySpaceLeft;
+
// Blit the sprite to the surface
- for (int i = 0; i < _height; ++i) {
+ for (int i = 0; i < yPixelsToDraw; ++i) {
// Draw the sprite mirrored if the _mirror flag is set
if (_mirror) {
- for(int j = _width - 1; j >= 0; --j, ++src) {
+ for (int j = xPixelsToDraw - 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) {
+ for (int j = 0; j < xPixelsToDraw; ++j, ++src) {
// Don't blit if the pixel is transparent on the target surface
if (*src != surface->getTransparentColour())
@@ -142,6 +151,7 @@ void Sprite::draw(Surface *surface, bool markDirty) const {
}
}
+ src += _width - xPixelsToDraw;
dst += surface->pitch;
}
@@ -157,13 +167,12 @@ Common::Rect Sprite::getRect() const {
}
Text::Text(const Common::String &str, Font *font, byte fontColour,
- uint x, uint y, uint z, uint spacing) {
+ int x, int y, uint spacing) {
uint len = str.size();
_length = len;
_x = x;
_y = y;
- _z = z;
_text = new byte[len];
memcpy(_text, str.c_str(), len);
diff --git a/engines/draci/sprite.h b/engines/draci/sprite.h
index 6af4e8ca1e..3e881914ca 100644
--- a/engines/draci/sprite.h
+++ b/engines/draci/sprite.h
@@ -43,21 +43,18 @@ public:
virtual uint16 getWidth() { return _width; }
virtual uint16 getHeight() { return _height; }
- virtual uint getX() { return _x; }
- virtual uint getY() { return _y; }
- virtual uint getZ() { return _z; }
+ virtual int getX() { return _x; }
+ virtual int getY() { return _y; }
- virtual void setX(uint x) { _x = x; }
- virtual void setY(uint y) { _y = y; }
- virtual void setZ(uint z) { _z = z; }
+ virtual void setX(int x) { _x = x; }
+ virtual void setY(int y) { _y = y; }
virtual Common::Rect getRect() const = 0;
private:
uint16 _width; //!< Width of the sprite
uint16 _height; //!< Height of the sprite
- uint _x, _y; //!< Sprite coordinates
- uint _z; //!< Sprite depth position
+ int _x, _y; //!< Sprite coordinates
};
/**
@@ -76,12 +73,10 @@ private:
class Sprite : public Drawable {
public:
- Sprite(byte *raw_data, uint16 width, uint16 height, uint x, uint y,
- uint z, bool columnwise = true);
+ Sprite(byte *raw_data, uint16 width, uint16 height, int x, int y, bool columnwise);
- Sprite(byte *sprite_data, uint16 length, uint x, uint y,
- uint z, bool columnwise = true);
+ Sprite(byte *sprite_data, uint16 length, int x, int y, bool columnwise);
~Sprite();
@@ -90,7 +85,6 @@ public:
void setMirrorOn();
void setMirrorOff();
-
virtual Common::Rect getRect() const;
const byte *getBuffer() const { return _data; }
@@ -103,7 +97,7 @@ class Text : public Drawable {
public:
Text(const Common::String &str, Font *font, byte fontColour,
- uint x, uint y, uint z, uint spacing = 0);
+ int x, int y, uint spacing = 0);
~Text();
void setText(const Common::String &str);