aboutsummaryrefslogtreecommitdiff
path: root/engines/draci
diff options
context:
space:
mode:
Diffstat (limited to 'engines/draci')
-rw-r--r--engines/draci/animation.cpp106
-rw-r--r--engines/draci/animation.h7
2 files changed, 112 insertions, 1 deletions
diff --git a/engines/draci/animation.cpp b/engines/draci/animation.cpp
index 83a21ee543..cb4035a475 100644
--- a/engines/draci/animation.cpp
+++ b/engines/draci/animation.cpp
@@ -213,6 +213,14 @@ void Animation::setScaleFactors(double scaleX, double scaleY) {
_scaleY = scaleY;
}
+double Animation::getScaleX() {
+ return _scaleX;
+}
+
+double Animation::getScaleY() {
+ return _scaleY;
+}
+
void Animation::addFrame(Drawable *frame) {
_frames.push_back(frame);
}
@@ -227,6 +235,11 @@ void Animation::setIndex(int index) {
Drawable *Animation::getFrame(int frameNum) {
+ // If there are no frames stored, return NULL
+ if (_frames.size() == 0) {
+ return NULL;
+ }
+
// If no argument is passed, return the current frame
if (frameNum == kCurrentFrame) {
return _frames[_currentFrame];
@@ -241,6 +254,13 @@ uint Animation::getFramesNum() {
void Animation::deleteFrames() {
+ // If there are no frames to delete, return
+ if (_frames.size() == 0) {
+ return;
+ }
+
+ markDirtyRect(_vm->_screen->getSurface());
+
for (int i = getFramesNum() - 1; i >= 0; --i) {
delete _frames[i];
_frames.pop_back();
@@ -263,6 +283,19 @@ Animation *AnimationManager::addAnimation(int id, uint z, bool playing) {
return anim;
}
+Animation *AnimationManager::addText(int id, bool playing) {
+
+ Animation *anim = new Animation(_vm, kIgnoreIndex);
+
+ anim->setID(id);
+ anim->setZ(256);
+ anim->setPlaying(playing);
+
+ insertAnimation(anim);
+
+ return anim;
+}
+
void AnimationManager::play(int id) {
Animation *anim = getAnimation(id);
@@ -461,4 +494,77 @@ void AnimationManager::deleteAfterIndex(int index) {
_lastIndex = index;
}
+int AnimationManager::getTopAnimationID(int x, int y) {
+
+ Common::List<Animation *>::iterator it;
+
+ // The default return value if no animations were found on these coordinates (not even overlays)
+ // i.e. the black background shows through so treat it as an overlay
+ int retval = kOverlayImage;
+
+ // Get transparent colour for the current screen
+ const int transparent = _vm->_screen->getSurface()->getTransparentColour();
+
+ for (it = _animations.reverse_begin(); it != _animations.end(); --it) {
+
+ Animation *anim = *it;
+
+ // If the animation is not playing, ignore it
+ if (!anim->isPlaying()) {
+ continue;
+ }
+
+ Drawable *frame = anim->getFrame();
+
+ if (frame == NULL) {
+ continue;
+ }
+
+ int oldX = frame->getX();
+ int oldY = frame->getY();
+
+ // Take account relative coordinates
+ int newX = oldX + anim->getRelativeX();
+ int newY = oldY + anim->getRelativeY();
+
+ // Translate the frame to those relative coordinates
+ frame->setX(newX);
+ frame->setY(newY);
+
+ // Save scaled width and height
+ int scaledWidth = frame->getScaledWidth();
+ int scaledHeight = frame->getScaledHeight();
+
+ // Take into account per-animation scaling and adjust the current frames dimensions
+ if (anim->getScaleX() != 1.0 || anim->getScaleY() != 1.0)
+ frame->setScaled(scaledWidth * anim->getScaleX(), scaledHeight * anim->getScaleY());
+
+ if (frame->getRect().contains(x, y)) {
+
+ if (frame->getType() == kDrawableText) {
+
+ retval = anim->getID();
+
+ } else if (frame->getType() == kDrawableSprite &&
+ reinterpret_cast<Sprite *>(frame)->getPixel(x, y) != transparent) {
+
+ retval = anim->getID();
+ }
+ }
+
+ // Revert back to old coordinates
+ frame->setX(oldX);
+ frame->setY(oldY);
+
+ // Revert back to old dimensions
+ frame->setScaled(scaledWidth, scaledHeight);
+
+ // Found an animation
+ if (retval != kOverlayImage)
+ break;
+ }
+
+ return retval;
+}
+
}
diff --git a/engines/draci/animation.h b/engines/draci/animation.h
index 5229972543..66b16647bd 100644
--- a/engines/draci/animation.h
+++ b/engines/draci/animation.h
@@ -34,7 +34,7 @@ namespace Draci {
* Animation IDs for those animations that don't have their IDs
* specified in the data files.
*/
-enum { kOverlayImage = -1, kWalkingMapOverlay = -2, kUnused = -3 };
+enum { kOverlayImage = -1, kWalkingMapOverlay = -2, kTitleText = -3, kUnused = -4 };
/**
* Default argument to Animation::getFrame() that makes it return
@@ -84,6 +84,8 @@ public:
void setIndex(int index);
void setScaleFactors(double scaleX, double scaleY);
+ double getScaleX();
+ double getScaleY();
void markDirtyRect(Surface *surface);
@@ -126,6 +128,7 @@ public:
~AnimationManager() { deleteAll(); }
Animation *addAnimation(int id, uint z, bool playing = false);
+ Animation *addText(int id, bool playing = false);
void addOverlay(Drawable *overlay, uint z);
void play(int id);
@@ -142,6 +145,8 @@ public:
int getLastIndex();
void deleteAfterIndex(int index);
+ int getTopAnimationID(int x, int y);
+
private:
void sortAnimations();
void insertAnimation(Animation *anim);