ScummVM API documentation
Drawable.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 // Based on code by omergilad.
23 
24 #ifndef GUI_ANIMATION_DRAWABLE_H
25 #define GUI_ANIMATION_DRAWABLE_H
26 
27 #include "common/ptr.h"
28 #include "graphics/managed_surface.h"
29 
30 #include "gui/animation/Animation.h"
31 
32 namespace GUI {
33 
34 class Animation;
35 typedef Common::SharedPtr<Animation> AnimationPtr;
36 
37 class Drawable {
38 public:
39  Drawable() :
40  _bitmap(NULL), _positionX(0), _positionY(0), _width(0), _height(0), _alpha(1),
41  _usingSnapshot(false), _shouldCenter(false) {
42  _displayRatio = 1.0;
43  }
44 
45  virtual ~Drawable() {
46  if (_usingSnapshot)
47  delete _bitmap;
48  }
49 
50  void updateAnimation(long currentTime) {
51  if (_animation.get() != NULL) {
52  _animation->update(this, currentTime);
53  }
54  }
55 
56  bool isAnimationFinished() {
57  if (_animation.get() != NULL)
58  return _animation->isFinished();
59 
60  return false;
61  }
62 
63  float getAlpha() const { return _alpha; }
64  void setAlpha(float alpha) { _alpha = alpha; }
65  AnimationPtr getAnimation() const { return _animation; }
66  void setAnimation(AnimationPtr animation) { _animation = animation; }
67  Graphics::ManagedSurface *getBitmap() const { return _bitmap; }
68  void setBitmap(Graphics::ManagedSurface *bitmap) { _bitmap = bitmap; }
69  float getPositionX() const { return _positionX; }
70  void setPositionX(float positionX) { _positionX = positionX; }
71  float getPositionY() const { return _positionY; }
72  void setPositionY(float positionY) { _positionY = positionY; }
73  virtual float getWidth() const { return _width; }
74  void setWidth(float width) { _width = width; }
75 
76  virtual float getHeight() const {
77  if (_height == 0 && _bitmap && _bitmap->w && _bitmap->h)
78  return getWidth() * _displayRatio * _bitmap->h / _bitmap->w;
79 
80  return _height;
81  }
82 
83  void setHeight(float height) { _height = height; }
84  void setDisplayRatio(float ratio) { _displayRatio = ratio; }
85  inline bool shouldCenter() const { return _shouldCenter; }
86  void setShouldCenter(bool shouldCenter) { _shouldCenter = shouldCenter; }
87 
88 protected:
89  bool _usingSnapshot;
90 
91 private:
92  Graphics::ManagedSurface *_bitmap;
93  float _positionX;
94  float _positionY;
95  float _width;
96  float _height;
97  float _alpha;
98  bool _shouldCenter;
99  AnimationPtr _animation;
100 
101  float _displayRatio;
102 };
103 
105 
106 } // End of namespace GUI
107 
108 #endif /* GUI_ANIMATION_DRAWABLE_H */
Definition: managed_surface.h:51
int16 & w
Definition: managed_surface.h:117
Definition: system.h:46
PointerType get() const
Definition: ptr.h:229
int16 & h
Definition: managed_surface.h:118
Definition: Drawable.h:37