[Scummvm-cvs-logs] SF.net SVN: scummvm:[42836] scummvm/branches/gsoc2009-draci/engines/draci

dkasak13 at users.sourceforge.net dkasak13 at users.sourceforge.net
Mon Jul 27 06:18:45 CEST 2009


Revision: 42836
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42836&view=rev
Author:   dkasak13
Date:     2009-07-27 04:18:44 +0000 (Mon, 27 Jul 2009)

Log Message:
-----------
* Added AnimationManager::addText() for adding text animations
* Added AnimationManager::getTopAnimationID(x, y) which returns the ID of the top layer animation located on a point
* Added Animation::getScale{X,Y}()
* Fixed a few bugs related to animations sometimes having no frames

Modified Paths:
--------------
    scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp
    scummvm/branches/gsoc2009-draci/engines/draci/animation.h

Modified: scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp	2009-07-27 04:14:59 UTC (rev 42835)
+++ scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp	2009-07-27 04:18:44 UTC (rev 42836)
@@ -213,6 +213,14 @@
 	_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 @@
 
 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 @@
 
 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 @@
 	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 @@
 	_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;
 }
+			
+}

Modified: scummvm/branches/gsoc2009-draci/engines/draci/animation.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/animation.h	2009-07-27 04:14:59 UTC (rev 42835)
+++ scummvm/branches/gsoc2009-draci/engines/draci/animation.h	2009-07-27 04:18:44 UTC (rev 42836)
@@ -34,7 +34,7 @@
   * 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 @@
 	void setIndex(int index);
 
 	void setScaleFactors(double scaleX, double scaleY);
+	double getScaleX();
+	double getScaleY();
 
 	void markDirtyRect(Surface *surface);
 
@@ -126,6 +128,7 @@
 	~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 @@
 	int getLastIndex();
 	void deleteAfterIndex(int index);
 
+	int getTopAnimationID(int x, int y);
+
 private:
 	void sortAnimations();	
 	void insertAnimation(Animation *anim);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list