aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Hesse2011-09-03 12:41:06 +0200
committerSven Hesse2011-09-03 18:00:09 +0200
commit220fc2b59307734a26057fa6446ed13fa2c543a1 (patch)
tree7321ad3607407eaa6a73e7f42bf11c635057b313
parenta4f42017d7a43ae0e8cd7c61d6af746a19c410f5 (diff)
downloadscummvm-rg350-220fc2b59307734a26057fa6446ed13fa2c543a1.tar.gz
scummvm-rg350-220fc2b59307734a26057fa6446ed13fa2c543a1.tar.bz2
scummvm-rg350-220fc2b59307734a26057fa6446ed13fa2c543a1.zip
GOB: Add class ANIObject
Controls an animation stored within an ANI file.
-rw-r--r--engines/gob/aniobject.cpp185
-rw-r--r--engines/gob/aniobject.h99
-rw-r--r--engines/gob/module.mk1
3 files changed, 285 insertions, 0 deletions
diff --git a/engines/gob/aniobject.cpp b/engines/gob/aniobject.cpp
new file mode 100644
index 0000000000..c6a9234eb9
--- /dev/null
+++ b/engines/gob/aniobject.cpp
@@ -0,0 +1,185 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "gob/surface.h"
+#include "gob/anifile.h"
+#include "gob/aniobject.h"
+
+namespace Gob {
+
+ANIObject::ANIObject(const ANIFile &ani) : _ani(&ani), _visible(false),
+ _x(0), _y(0), _background(0), _drawn(false) {
+
+ setAnimation(0);
+ setPosition();
+}
+
+ANIObject::~ANIObject() {
+ delete _background;
+}
+
+void ANIObject::setVisible(bool visible) {
+ _visible = visible;
+}
+
+bool ANIObject::isVisible() const {
+ return _visible;
+}
+
+void ANIObject::setAnimation(uint16 animation) {
+ _animation = animation;
+ _frame = 0;
+}
+
+void ANIObject::setPosition() {
+ if (_animation >= _ani->getAnimationCount())
+ return;
+
+ const ANIFile::Animation &animation = _ani->getAnimationInfo(_animation);
+
+ _x = animation.x;
+ _y = animation.y;
+}
+
+void ANIObject::setPosition(int16 x, int16 y) {
+ _x = x;
+ _y = y;
+}
+
+void ANIObject::getPosition(int16 &x, int16 &y) const {
+ x = _x;
+ y = _y;
+}
+
+void ANIObject::getFramePosition(int16 &x, int16 &y) const {
+ if (_animation >= _ani->getAnimationCount())
+ return;
+
+ const ANIFile::Animation &animation = _ani->getAnimationInfo(_animation);
+ if (_frame >= animation.frameCount)
+ return;
+
+ x = _x + animation.frameAreas[_frame].left;
+ y = _y + animation.frameAreas[_frame].top;
+}
+
+void ANIObject::getFrameSize(int16 &width, int16 &height) const {
+ if (_animation >= _ani->getAnimationCount())
+ return;
+
+ const ANIFile::Animation &animation = _ani->getAnimationInfo(_animation);
+ if (_frame >= animation.frameCount)
+ return;
+
+ width = animation.frameAreas[_frame].right - animation.frameAreas[_frame].left + 1;
+ height = animation.frameAreas[_frame].bottom - animation.frameAreas[_frame].top + 1;
+}
+
+void ANIObject::draw(Surface &dest, int16 &left, int16 &top,
+ int16 &right, int16 &bottom) {
+
+ if (!_visible)
+ return;
+
+ if (!_background) {
+ uint16 width, height;
+
+ _ani->getMaxSize(width, height);
+
+ _background = new Surface(width, height, dest.getBPP());
+ }
+
+ const ANIFile::Animation &animation = _ani->getAnimationInfo(_animation);
+ if (_frame >= animation.frameCount)
+ return;
+
+ const ANIFile::FrameArea &area = animation.frameAreas[_frame];
+
+ _backgroundLeft = CLIP<int16>(area.left + _x, 0, dest.getWidth () - 1);
+ _backgroundTop = CLIP<int16>(area.top + _y, 0, dest.getHeight() - 1);
+ _backgroundRight = CLIP<int16>(area.right + _x, 0, dest.getWidth () - 1);
+ _backgroundBottom = CLIP<int16>(area.bottom + _y, 0, dest.getHeight() - 1);
+
+ _background->blit(dest, _backgroundLeft , _backgroundTop,
+ _backgroundRight, _backgroundBottom, 0, 0);
+
+ _ani->draw(dest, _animation, _frame, _x, _y);
+
+ _drawn = true;
+
+ left = _backgroundLeft;
+ top = _backgroundTop;
+ right = _backgroundRight;
+ bottom = _backgroundBottom;
+}
+
+void ANIObject::clear(Surface &dest, int16 &left, int16 &top,
+ int16 &right, int16 &bottom) {
+
+ if (!_drawn)
+ return;
+
+ const int16 bgRight = _backgroundRight - _backgroundLeft;
+ const int16 bgBottom = _backgroundBottom - _backgroundTop;
+
+ dest.blit(*_background, 0, 0, bgRight, bgBottom, _backgroundLeft, _backgroundTop);
+
+ _drawn = false;
+
+ left = _backgroundLeft;
+ top = _backgroundTop;
+ right = _backgroundRight;
+ bottom = _backgroundBottom;
+}
+
+void ANIObject::advance() {
+ if (_animation >= _ani->getAnimationCount())
+ return;
+
+ const ANIFile::Animation &animation = _ani->getAnimationInfo(_animation);
+
+ _frame = (_frame + 1) % animation.frameCount;
+
+ if (_frame == 0) {
+ _x += animation.deltaX;
+ _y += animation.deltaY;
+ }
+}
+
+uint16 ANIObject::getAnimation() const {
+ return _animation;
+}
+
+uint16 ANIObject::getFrame() const {
+ return _frame;
+}
+
+bool ANIObject::lastFrame() const {
+ if (_animation >= _ani->getAnimationCount())
+ return true;
+
+ const ANIFile::Animation &animation = _ani->getAnimationInfo(_animation);
+
+ return (_frame + 1) >= animation.frameCount;
+}
+
+} // End of namespace Gob
diff --git a/engines/gob/aniobject.h b/engines/gob/aniobject.h
new file mode 100644
index 0000000000..357c2a9bcc
--- /dev/null
+++ b/engines/gob/aniobject.h
@@ -0,0 +1,99 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef GOB_ANIOBJECT_H
+#define GOB_ANIOBJECT_H
+
+#include "common/system.h"
+
+namespace Gob {
+
+class ANIFile;
+class Surface;
+
+/** An ANI object, controlling an animation within an ANI file. */
+class ANIObject {
+public:
+ ANIObject(const ANIFile &ani);
+ virtual ~ANIObject();
+
+ /** Make the object visible/invisible. */
+ void setVisible(bool visible);
+
+ /** Is the object currently visible? */
+ bool isVisible() const;
+
+ /** Set the current position to the animation's default. */
+ void setPosition();
+ /** Set the current position. */
+ void setPosition(int16 x, int16 y);
+
+ /** Return the current position. */
+ void getPosition(int16 &x, int16 &y) const;
+
+ /** Return the current frame position. */
+ void getFramePosition(int16 &x, int16 &y) const;
+ /** Return the current frame size. */
+ void getFrameSize(int16 &width, int16 &height) const;
+
+ /** Set the animation number. */
+ void setAnimation(uint16 animation);
+
+ /** Return the current animation number. */
+ uint16 getAnimation() const;
+ /** Return the current frame number. */
+ uint16 getFrame() const;
+
+ /** Is this the last frame within this animation cycle? */
+ bool lastFrame() const;
+
+ /** Draw the current frame onto the surface and return the affected rectangle. */
+ void draw(Surface &dest, int16 &left, int16 &top, int16 &right, int16 &bottom);
+ /** Draw the current frame from the surface and return the affected rectangle. */
+ void clear(Surface &dest, int16 &left , int16 &top, int16 &right, int16 &bottom);
+
+ /** Advance the animation to the next frame. */
+ virtual void advance();
+
+private:
+ const ANIFile *_ani; ///< The managed ANI file.
+
+ uint16 _animation; ///< The current animation number
+ uint16 _frame; ///< The current frame.
+
+ bool _visible; ///< Is the object currently visible?
+
+ int16 _x; ///< The current X position.
+ int16 _y; ///< The current Y position.
+
+ Surface *_background; ///< The saved background.
+ bool _drawn; ///< Was the animation drawn?
+
+ int16 _backgroundLeft; ///< The left position of the saved background.
+ int16 _backgroundTop; ///< The top of the saved background.
+ int16 _backgroundRight; ///< The right position of the saved background.
+ int16 _backgroundBottom; ///< The bottom position of the saved background.
+};
+
+} // End of namespace Gob
+
+#endif // GOB_ANIOBJECT_H
diff --git a/engines/gob/module.mk b/engines/gob/module.mk
index a2a78bc5c7..d451e250ff 100644
--- a/engines/gob/module.mk
+++ b/engines/gob/module.mk
@@ -2,6 +2,7 @@ MODULE := engines/gob
MODULE_OBJS := \
anifile.o \
+ aniobject.o \
console.o \
dataio.o \
databases.o \