ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

Drawable.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 // Based on code by omergilad.
00024 
00025 #ifndef GUI_ANIMATION_DRAWABLE_H
00026 #define GUI_ANIMATION_DRAWABLE_H
00027 
00028 #include "common/ptr.h"
00029 #include "graphics/transparent_surface.h"
00030 
00031 #include "gui/animation/Animation.h"
00032 
00033 namespace GUI {
00034 
00035 class Animation;
00036 typedef Common::SharedPtr<Animation> AnimationPtr;
00037 
00038 class Drawable {
00039 public:
00040     Drawable() :
00041         _bitmap(NULL), _positionX(0), _positionY(0), _width(0), _height(0), _alpha(1),
00042         _usingSnapshot(false), _shouldCenter(false) {
00043         _displayRatio = 1.0;
00044     }
00045 
00046     virtual ~Drawable() {
00047         if (_usingSnapshot)
00048             delete _bitmap;
00049     }
00050 
00051     void updateAnimation(long currentTime) {
00052         if (_animation.get() != NULL) {
00053             _animation->update(this, currentTime);
00054         }
00055     }
00056 
00057     bool isAnimationFinished() {
00058         if (_animation.get() != NULL)
00059             return _animation->isFinished();
00060 
00061         return false;
00062     }
00063 
00064     float getAlpha() const { return _alpha; }
00065     void setAlpha(float alpha) { _alpha = alpha; }
00066     AnimationPtr getAnimation() const { return _animation; }
00067     void setAnimation(AnimationPtr animation) { _animation = animation; }
00068     Graphics::TransparentSurface *getBitmap() const { return _bitmap; }
00069     void setBitmap(Graphics::TransparentSurface *bitmap) { _bitmap = bitmap; }
00070     float getPositionX() const { return _positionX; }
00071     void setPositionX(float positionX) { _positionX = positionX; }
00072     float getPositionY() const { return _positionY; }
00073     void setPositionY(float positionY) { _positionY = positionY; }
00074     virtual float getWidth() const { return _width; }
00075     void setWidth(float width) { _width = width; }
00076 
00077     virtual float getHeight() const {
00078         if (_height == 0)
00079             return getWidth() * _bitmap->getRatio() * _displayRatio;
00080 
00081         return _height;
00082     }
00083 
00084     void setHeight(float height) { _height = height; }
00085     void setDisplayRatio(float ratio) { _displayRatio = ratio; }
00086     inline bool shouldCenter() const { return _shouldCenter; }
00087     void setShouldCenter(bool shouldCenter) { _shouldCenter = shouldCenter; }
00088 
00089 protected:
00090     bool _usingSnapshot;
00091 
00092 private:
00093     Graphics::TransparentSurface *_bitmap;
00094     float _positionX;
00095     float _positionY;
00096     float _width;
00097     float _height;
00098     float _alpha;
00099     bool _shouldCenter;
00100     AnimationPtr _animation;
00101 
00102     float _displayRatio;
00103 };
00104 
00105 typedef Common::SharedPtr<Drawable> DrawablePtr;
00106 
00107 } // End of namespace GUI
00108 
00109 #endif /* GUI_ANIMATION_DRAWABLE_H */


Generated on Sat May 18 2019 05:01:00 for ResidualVM by doxygen 1.7.1
curved edge   curved edge