ScummVM API documentation
subtitles.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 MTROPOLIS_SUBTITLES_H
23 #define MTROPOLIS_SUBTITLES_H
24 
25 #include "common/array.h"
26 #include "common/error.h"
27 #include "common/str.h"
28 #include "common/hash-str.h"
29 #include "common/hashmap.h"
30 #include "common/ptr.h"
31 
32 namespace Graphics {
33 
34 class Font;
35 class ManagedSurface;
36 
37 } // End of namespace Graphics
38 
39 namespace MTropolis {
40 
41 class Runtime;
42 class Window;
43 
45 public:
47 
48  Common::ErrorCode load(const Common::String &filePath);
49 
50  const Common::String *findSubtitleSetForAssetID(uint32 assetID) const;
51  const Common::String *findSubtitleSetForAssetName(const Common::String &assetName) const;
52 
53 private:
54  Common::HashMap<uint32, Common::String> _assetIDToSubtitleSet;
56 };
57 
59 public:
61 
62  Common::ErrorCode load(const Common::String &filePath);
63 
64  const Common::String *findSubtitleSetForModifierGUID(uint32 guid) const;
65 
66 private:
67  Common::HashMap<uint32, Common::String> _guidToSubtitleSet;
68 };
69 
71 public:
73 
74  Common::ErrorCode load(const Common::String &filePath);
75 
76  const Common::Array<Common::String> &getSpeakers() const;
77  uint getSpeakerID(const Common::String &speakerName) const;
78 
79 private:
82 };
83 
85 public:
87 
88  Common::ErrorCode load(const Common::String &filePath, const SubtitleSpeakerTable &speakerTable);
89 
90  struct LineRange {
91  LineRange();
92 
93  uint linesStart;
94  uint numLines;
95  };
96 
97  enum LineClass {
98  kLineClassDefault,
99  kLineClassGameplay,
100  };
101 
102  struct LineData {
103  LineData();
104 
105  uint32 timeOffsetMSec;
106  uint slot;
107  uint durationMSec;
108  Common::String textUTF8;
109  uint speakerID;
110  LineClass lineClass;
111  double position;
112  };
113 
114  const Common::Array<LineData> &getAllLines() const;
115  const LineRange *getLinesForSubtitleSetID(const Common::String &subtitleSetID) const;
116 
117 private:
120 };
121 
122 
128 };
129 
131 public:
132  SubtitleDisplayItem(const Common::String &text, const Common::String &speaker, uint slot, double position);
133 
134  const Common::U32String &getText() const;
135  const Common::U32String &getSpeaker() const;
136  uint getSlot() const;
137  double getPosition() const;
138 
139 private:
140  Common::U32String _text;
141  Common::U32String _speaker;
142  uint _slot;
143  double _position;
144 };
145 
147 public:
148  explicit SubtitleRenderer(bool enableGameplaySubtitles);
149 
150  void addDisplayItem(const Common::SharedPtr<SubtitleDisplayItem> &item, uint duration);
151  void removeDisplayItem(const SubtitleDisplayItem *item, bool immediately);
152 
153  bool update(uint64 currentTime); // Updates the subtitle player, returns true if any changes occurred since last update
154 
155  void composite(Window &window) const;
156  bool isDirty() const;
157 
158  bool isGameplaySubtitlesEnabled() const;
159 
160 private:
161  struct DisplayItem {
162  DisplayItem();
163 
166  uint64 expireTime;
167  };
168 
169  void render();
170  static void splitLines(const Common::U32String &str, Common::Array<Common::U32String> &outLines);
171 
172  Common::Array<DisplayItem> _displayItems;
173 
175  uint64 _lastTime;
176  uint _nonImmediateDisappearTime;
177  int _fontHeight;
178  bool _isDirty;
179  bool _enableGameplaySubtitles;
180 };
181 
183 public:
184  SubtitlePlayer(Runtime *runtime, const Common::String &subtitleSetID, const SubtitleTables &tables);
185  ~SubtitlePlayer();
186 
187  void update(uint64 prevTime, uint64 newTime);
188  void stop();
189 
190 private:
191  void triggerSubtitleLine(const SubtitleLineTable::LineData &line);
192 
194 
197 
198  SubtitleLineTable::LineRange _lineRange;
199  Runtime *_runtime;
200 };
201 
202 } // End of namespace MTropolis
203 
204 #endif
Definition: subtitles.h:44
Definition: str.h:59
Definition: subtitles.h:146
Definition: subtitles.h:90
ErrorCode
Definition: error.h:47
Definition: runtime.h:1594
Definition: subtitles.h:182
Definition: render.h:93
Definition: subtitles.h:130
Definition: ustr.h:57
Definition: subtitles.h:123
Definition: formatinfo.h:28
Definition: subtitles.h:70
Definition: subtitles.h:84
Definition: actions.h:25
Definition: subtitles.h:58
Definition: ptr.h:159
Definition: subtitles.h:102