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 VIDEO_SUBTITLES_H
23 #define VIDEO_SUBTITLES_H
24 
25 #include "common/str.h"
26 #include "common/array.h"
27 #include "common/rect.h"
28 
29 namespace Graphics {
30 class Font;
31 struct Surface;
32 }
33 
34 namespace Video {
35 
36 struct SRTEntry {
37  uint seq;
38  uint32 start;
39  uint32 end;
40 
41  Common::String text;
42 
43  SRTEntry(uint seq_, uint32 start_, uint32 end_, Common::String text_) {
44  seq = seq_; start = start_; end = end_; text = text_;
45  }
46 };
47 
48 class SRTParser {
49 public:
50  SRTParser();
51  ~SRTParser();
52 
53  void cleanup();
54  bool parseFile(const Common::Path &fname);
55  Common::String getSubtitle(uint32 timestamp) const;
56 
57 private:
59 };
60 
61 class Subtitles {
62 public:
63  Subtitles();
64  ~Subtitles();
65 
66  void loadSRTFile(const Common::Path &fname);
67  void close() { _loaded = false; _subtitle.clear(); _fname.clear(); _srtParser.cleanup(); }
68  void setFont(const char *fontname, int height = 18);
69  void setBBox(const Common::Rect bbox);
70  void setColor(byte r, byte g, byte b);
71  void setPadding(uint16 horizontal, uint16 vertical);
72  bool drawSubtitle(uint32 timestamp, bool force = false) const;
73  bool isLoaded() const { return _loaded || _subtitleDev; }
74 
75 private:
76  void renderSubtitle() const;
77 
78  SRTParser _srtParser;
79  bool _loaded;
80  bool _subtitleDev;
81  bool _overlayHasAlpha;
82 
83  const Graphics::Font *_font;
84  int _fontHeight;
85 
86  Graphics::Surface *_surface;
87 
88  mutable Common::Rect _drawRect;
89  Common::Rect _requestedBBox;
90  mutable Common::Rect _realBBox;
91  mutable int16 _lastOverlayWidth, _lastOverlayHeight;
92 
93  Common::Path _fname;
94  mutable Common::String _subtitle;
95  uint32 _color;
96  uint32 _blackColor;
97  uint32 _transparentColor;
98  uint16 _hPad;
99  uint16 _vPad;
100 };
101 
102 } // End of namespace Video
103 
104 #endif
Definition: str.h:59
Definition: font.h:83
Definition: surface.h:67
Definition: array.h:52
Definition: rect.h:144
Definition: path.h:52
Definition: subtitles.h:61
Definition: formatinfo.h:28
Definition: subtitles.h:36
Definition: subtitles.h:48
Definition: avi_frames.h:36