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
32namespace Graphics {
33
34class Font;
35class ManagedSurface;
36
37} // End of namespace Graphics
38
39namespace MTropolis {
40
41class Runtime;
42class Window;
43
45public:
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
53private:
54 Common::HashMap<uint32, Common::String> _assetIDToSubtitleSet;
56};
57
59public:
61
62 Common::ErrorCode load(const Common::String &filePath);
63
64 const Common::String *findSubtitleSetForModifierGUID(uint32 guid) const;
65
66private:
68};
69
71public:
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
79private:
82};
83
85public:
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
117private:
120};
121
122
128};
129
131public:
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
139private:
140 Common::U32String _text;
141 Common::U32String _speaker;
142 uint _slot;
143 double _position;
144};
145
147public:
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
160private:
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
183public:
184 SubtitlePlayer(Runtime *runtime, const Common::String &subtitleSetID, const SubtitleTables &tables);
186
187 void update(uint64 prevTime, uint64 newTime);
188 void stop();
189
190private:
191 void triggerSubtitleLine(const SubtitleLineTable::LineData &line);
192
194
197
199 Runtime *_runtime;
200};
201
202} // End of namespace MTropolis
203
204#endif
Definition: ptr.h:159
Definition: str.h:59
Definition: ustr.h:57
Definition: runtime.h:1575
Definition: subtitles.h:44
Definition: subtitles.h:130
Definition: subtitles.h:84
Definition: subtitles.h:58
Definition: subtitles.h:182
Definition: subtitles.h:146
Definition: subtitles.h:70
Definition: render.h:93
ErrorCode
Definition: error.h:47
Definition: formatinfo.h:28
Definition: actions.h:25
Definition: subtitles.h:102
Definition: subtitles.h:90
Definition: subtitles.h:123