aboutsummaryrefslogtreecommitdiff
path: root/engines/draci/animation.cpp
diff options
context:
space:
mode:
authorDenis Kasak2009-07-20 17:25:57 +0000
committerDenis Kasak2009-07-20 17:25:57 +0000
commita2a71cb8fbdbf1426d73c6f09f315abf04cfcbb9 (patch)
tree9775895526760b51efd16912422aacb122859368 /engines/draci/animation.cpp
parent18301b6f78fd6d7eb77b5055129b71d2b8dce270 (diff)
downloadscummvm-rg350-a2a71cb8fbdbf1426d73c6f09f315abf04cfcbb9.tar.gz
scummvm-rg350-a2a71cb8fbdbf1426d73c6f09f315abf04cfcbb9.tar.bz2
scummvm-rg350-a2a71cb8fbdbf1426d73c6f09f315abf04cfcbb9.zip
* Added scaling support
* Made the dragon scale when it is in different parts of the room * Added getters for relative coordinates (Animation::getRelativeX() and Animation::getRelativeY()) * Commented Game::loop() and Sprite::draw*() methods in more detail svn-id: r42627
Diffstat (limited to 'engines/draci/animation.cpp')
-rw-r--r--engines/draci/animation.cpp70
1 files changed, 64 insertions, 6 deletions
diff --git a/engines/draci/animation.cpp b/engines/draci/animation.cpp
index b5f0d6b806..3faa85ac63 100644
--- a/engines/draci/animation.cpp
+++ b/engines/draci/animation.cpp
@@ -33,6 +33,8 @@ Animation::Animation(DraciEngine *vm) : _vm(vm) {
_z = 0;
_relX = 0;
_relY = 0;
+ _scaleX = 1.0;
+ _scaleY = 1.0;
setPlaying(false);
_looping = false;
_tick = _vm->_system->getMillis();
@@ -50,7 +52,14 @@ bool Animation::isLooping() {
void Animation::setRelative(int relx, int rely) {
// Delete the previous frame
- Common::Rect frameRect = _frames[_currentFrame]->getRect();
+ Common::Rect frameRect;
+
+ if (isScaled()) {
+ frameRect = getFrame()->getScaledRect(_scaleX, _scaleY);
+ } else {
+ frameRect = getFrame()->getRect();
+ }
+
frameRect.translate(_relX, _relY);
_vm->_screen->getSurface()->markDirtyRect(frameRect);
@@ -58,6 +67,24 @@ void Animation::setRelative(int relx, int rely) {
_relY = rely;
}
+void Animation::setScaling(double scalex, double scaley) {
+
+ _scaleX = scalex;
+ _scaleY = scaley;
+}
+
+bool Animation::isScaled() const {
+ return !(_scaleX == 1.0 && _scaleY == 1.0);
+}
+
+double Animation::getScaleX() const {
+ return _scaleX;
+}
+
+double Animation::getScaleY() const {
+ return _scaleY;
+}
+
void Animation::setLooping(bool looping) {
_looping = looping;
debugC(7, kDraciAnimationDebugLevel, "Setting looping to %d on animation %d",
@@ -72,7 +99,13 @@ void Animation::nextFrame(bool force) {
Drawable *frame = _frames[_currentFrame];
- Common::Rect frameRect = frame->getRect();
+ Common::Rect frameRect;
+
+ if (isScaled()) {
+ frameRect = frame->getScaledRect(_scaleX, _scaleY);
+ } else {
+ frameRect = frame->getRect();
+ }
// Translate rectangle to compensate for relative coordinates
frameRect.translate(_relX, _relY);
@@ -111,19 +144,29 @@ void Animation::drawFrame(Surface *surface) {
return;
if (_id == kOverlayImage) {
- _frames[_currentFrame]->draw(surface, false);
+ _frames[_currentFrame]->drawScaled(surface, _scaleX, _scaleY, false);
}
else {
Drawable *ptr = _frames[_currentFrame];
+
int x = ptr->getX();
int y = ptr->getY();
+
+ // Take account relative coordinates
int newX = x + _relX;
int newY = y + _relY;
+ // Translate the frame to those relative coordinates
ptr->setX(newX);
ptr->setY(newY);
- ptr->draw(surface, true);
+ // Draw frame
+ if (isScaled())
+ ptr->drawScaled(surface, _scaleX, _scaleY, true);
+ else
+ ptr->drawScaled(surface, _scaleX, _scaleY, true);
+
+ // Revert back to old coordinates
ptr->setX(x);
ptr->setY(y);
}
@@ -145,6 +188,14 @@ uint Animation::getZ() {
return _z;
}
+int Animation::getRelativeX() {
+ return _relX;
+}
+
+int Animation::getRelativeY() {
+ return _relY;
+}
+
bool Animation::isPlaying() {
return _playing;
}
@@ -208,8 +259,15 @@ void AnimationManager::stop(int id) {
Animation *anim = getAnimation(id);
// Clean up the last frame that was drawn before stopping
- Common::Rect frameRect = anim->getFrame()->getRect();
- frameRect.translate(anim->_relX, anim->_relY);
+ Common::Rect frameRect;
+
+ if (anim->isScaled()) {
+ frameRect = anim->getFrame()->getScaledRect(anim->getScaleX(), anim->getScaleY());
+ } else {
+ frameRect = anim->getFrame()->getRect();
+ }
+
+ frameRect.translate(anim->getRelativeX(), anim->getRelativeY());
_vm->_screen->getSurface()->markDirtyRect(frameRect);
if (anim) {