ScummVM API documentation
sprite.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 #ifndef MEDIASTATION_SPRITE_H
23 #define MEDIASTATION_SPRITE_H
24 
25 #include "common/rect.h"
26 #include "common/array.h"
27 
28 #include "mediastation/asset.h"
29 #include "mediastation/datafile.h"
30 #include "mediastation/bitmap.h"
31 #include "mediastation/mediascript/scriptvalue.h"
32 #include "mediastation/mediascript/scriptconstants.h"
33 
34 namespace MediaStation {
35 
36 struct SpriteClip {
37  uint id = 0;
38  uint firstFrameIndex = 0;
39  uint lastFrameIndex = 0;
40 };
41 
43 public:
44  SpriteFrameHeader(Chunk &chunk);
45 
46  uint _index;
47  Common::Point _boundingBox;
48 };
49 
50 class SpriteFrame : public Bitmap {
51 public:
52  SpriteFrame(Chunk &chunk, SpriteFrameHeader *header);
53  virtual ~SpriteFrame() override;
54 
55  uint32 left();
56  uint32 top();
57  Common::Point topLeft();
58  Common::Rect boundingBox();
59  uint32 index();
60 
61 private:
62  SpriteFrameHeader *_bitmapHeader = nullptr;
63 };
64 
65 // Sprites are somewhat like movies, but they strictly show one frame at a time
66 // and don't have sound. They are intended for background/recurrent animations.
67 class Sprite : public SpatialEntity {
68 friend class Context;
69 
70 public:
71  Sprite() : SpatialEntity(kAssetTypeSprite) {};
72  ~Sprite();
73 
74  virtual void process() override;
75  virtual void draw(const Common::Array<Common::Rect> &dirtyRegion) override;
76 
77  virtual void readParameter(Chunk &chunk, AssetHeaderSectionType paramType) override;
78  virtual ScriptValue callMethod(BuiltInMethod methodId, Common::Array<ScriptValue> &args) override;
79 
80  virtual bool isVisible() const override { return _isVisible; }
81 
82  virtual void readChunk(Chunk &chunk) override;
83 
84 private:
85  static const uint DEFAULT_CLIP_ID = 1200;
86  uint _loadType = 0;
87  uint _frameRate = 0;
88  uint _frameCount = 0;
91  bool _isPlaying = false;
92  uint _currentFrameIndex = 0;
93  uint _nextFrameTime = 0;
94  SpriteClip _activeClip;
95 
96  void play();
97  void stop();
98  void setCurrentClip(uint clipId);
99 
100  bool activateNextFrame();
101  bool activatePreviousFrame();
102 
103  void dirtyIfVisible();
104  void setCurrentFrameToInitial();
105  void setCurrentFrameToFinal();
106 
107  void scheduleNextFrame();
108  void scheduleNextTimerEvent();
109  void postMovieEndEventIfNecessary();
110  void setVisibility(bool visibility);
111 
112  void updateFrameState();
113  void timerEvent();
114 };
115 
116 } // End of namespace MediaStation
117 
118 #endif
Definition: sprite.h:42
Definition: sprite.h:50
Definition: asset.h:167
Definition: asset.h:32
Definition: context.h:58
Definition: datafile.h:103
Definition: bitmap.h:41
Definition: rect.h:524
Definition: bitmap.h:50
Definition: sprite.h:36
Definition: hashmap.h:85
Definition: rect.h:144
Definition: sprite.h:67
Definition: scriptvalue.h:36