ScummVM API documentation
subtitle_manager.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 ZVISION_SUBTITLES_H
23 #define ZVISION_SUBTITLES_H
24 
25 #include "audio/mixer.h"
26 #include "zvision/zvision.h"
27 #include "zvision/common/focus_list.h"
28 
29 namespace ZVision {
30 
31 class ZVision;
32 
33 class Subtitle {
34  friend class SubtitleManager;
35 public:
36  Subtitle(ZVision *engine, const Common::Path &subname, bool vob = false); // For scripted subtitles
37  Subtitle(ZVision *engine, const Common::String &str, const Common::Rect &textArea); // For other text messages
38  virtual ~Subtitle();
39  bool update(int32 count); // Return true if necessary to redraw
40  virtual bool selfUpdate() {
41  return false;
42  }
43 
44 protected:
45  virtual bool process(int32 deltatime); // Return true if to be deleted
46  ZVision *_engine;
47  Common::Rect _textArea;
48  int16 _timer; // Always in milliseconds; countdown to deletion
49  bool _toDelete;
50  bool _redraw;
51 
52  int16 _lineId;
53  struct Line {
54  int start;
55  int stop;
56  Common::String subStr;
57  };
58  // NB: start & stop do not always use the same units between different instances of this struct!
59  // Sound effect & music subtitles use milliseconds
60  // Video subtitle timings are specified in video frames at 15fps, i.e. in multiples of 66.6' milliseconds!
61  // AVI videos run at 15fps and can have frames counted directly
62  // DVD videos in VOB format run at 29.97 fps and must be converted to work with the subtitle files, which were made for AVI.
63 
64  Common::Array<Line> _lines;
65 };
66 
67 class AutomaticSubtitle : public Subtitle {
68 public:
69  AutomaticSubtitle(ZVision *engine, const Common::Path &subname, Audio::SoundHandle handle); // For scripted audio subtitles
70  ~AutomaticSubtitle() {}
71 
72 private:
73  bool process(int32 deltatime); // Return true if to be deleted
74  bool selfUpdate(); // Return true if necessary to redraw
75  Audio::SoundHandle _handle;
76 };
77 
79 public:
80  SubtitleManager(ZVision *engine, const ScreenLayout layout, const Graphics::PixelFormat pixelFormat, bool doubleFPS);
81  ~SubtitleManager();
82 private:
83  ZVision *_engine;
84  OSystem *_system;
85  RenderManager *_renderManager;
86  const Graphics::PixelFormat _pixelFormat;
87  const Common::Point _textOffset; // Position vector of text area origin relative to working window origin
88  const Common::Rect _textArea;
89  bool _redraw;
90  bool _doubleFPS;
91  // Internal subtitle ID counter
92  uint16 _subId;
93 
95 
96  // Subtitle list
97  SubtitleMap _subsList;
98  // Subtitle focus history
99  FocusList<uint16> _subsFocus;
100 
101 public:
102  // Update all subtitle objects' deletion timers, delete expired subtitles, & redraw most recent. Does NOT update any subtitle's count value or displayed string!
103  void process(int32 deltatime); // deltatime is always milliseconds
104  // Update counter value of referenced subtitle id & set current line to display, if any.
105  void update(int32 count, uint16 subid); // Count is milliseconds for sound & music; frames for video playback.
106 
107  const Common::Point &getTextOffset() const {
108  return _textOffset;
109  }
110 
111  // Create subtitle object and return ID
112  uint16 create(const Common::Path &subname, bool vob = false);
113  uint16 create(const Common::Path &subname, Audio::SoundHandle handle); // NB this creates an automatic subtitle
114  uint16 create(const Common::String &str);
115 
116  // Delete subtitle object by ID
117  void destroy(uint16 id);
118  void destroy(uint16 id, int16 delay);
119 
120  bool askQuestion(const Common::String &str, bool streaming = false, bool safeDefault = false);
121  void delayedMessage(const Common::String &str, uint16 milsecs);
122  void timedMessage(const Common::String &str, uint16 milsecs);
123  void showDebugMsg(const Common::String &msg, int16 delay = 3000);
124 };
125 
126 }
127 
128 #endif
Definition: str.h:59
Definition: pixelformat.h:138
Definition: subtitle_manager.h:67
Definition: rect.h:524
Definition: path.h:52
Definition: zvision.h:72
Definition: focus_list.h:27
Definition: mixer.h:49
Definition: subtitle_manager.h:33
Definition: subtitle_manager.h:53
Definition: rect.h:144
Definition: subtitle_manager.h:78
Definition: render_manager.h:48
Definition: system.h:163