mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-02 23:26:44 +00:00
VIDEO: Initial code for drawing subtitles on overlay
This commit is contained in:
parent
9cb80bc9fb
commit
af8c37db9d
@ -21,9 +21,12 @@
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/file.h"
|
||||
#include "common/system.h"
|
||||
|
||||
#include "graphics/fonts/ttf.h"
|
||||
#include "graphics/font.h"
|
||||
#include "graphics/fontman.h"
|
||||
#include "graphics/surface.h"
|
||||
|
||||
#include "video/subtitles.h"
|
||||
|
||||
@ -222,9 +225,11 @@ Common::String SRTParser::getSubtitle(uint32 timestamp) {
|
||||
}
|
||||
|
||||
Subtitles::Subtitles() : _loaded(false), _font(nullptr) {
|
||||
_surface = new Graphics::Surface();
|
||||
}
|
||||
|
||||
Subtitles::~Subtitles() {
|
||||
delete _surface;
|
||||
}
|
||||
|
||||
void Subtitles::loadFont(const char *fontname, int height) {
|
||||
@ -253,4 +258,37 @@ void Subtitles::loadSRTFile(const char *fname) {
|
||||
_loaded = _srtParser.parseFile(fname);
|
||||
}
|
||||
|
||||
void Subtitles::setBBox(const Common::Rect bbox) {
|
||||
_bbox = bbox;
|
||||
|
||||
_surface->create(_bbox.width(), _bbox.height(), g_system->getOverlayFormat());
|
||||
}
|
||||
|
||||
|
||||
void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
|
||||
if (!_loaded)
|
||||
return;
|
||||
|
||||
Common::String subtitle = _srtParser.getSubtitle(timestamp);
|
||||
|
||||
if (!force && subtitle == _prevSubtitle)
|
||||
return;
|
||||
|
||||
_prevSubtitle = subtitle;
|
||||
|
||||
Common::Array<Common::String> lines;
|
||||
|
||||
int maxlineWidth = _font->wordWrapText(subtitle, _bbox.width(), lines);
|
||||
|
||||
int y = _bbox.top;
|
||||
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
_font->drawString(_surface, lines[i], _bbox.left, y, _bbox.width(), _color);
|
||||
|
||||
y += _font->getFontHeight();
|
||||
}
|
||||
|
||||
g_system->copyRectToOverlay(_surface->getPixels(), _surface->pitch, _bbox.left, _bbox.right, _bbox.width(), _bbox.height());
|
||||
}
|
||||
|
||||
} // End of namespace Video
|
||||
|
@ -24,9 +24,11 @@
|
||||
|
||||
#include "common/str.h"
|
||||
#include "common/array.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
namespace Graphics {
|
||||
class Font;
|
||||
struct Surface;
|
||||
}
|
||||
|
||||
namespace Video {
|
||||
@ -63,6 +65,9 @@ public:
|
||||
|
||||
void loadSRTFile(const char *fname);
|
||||
void loadFont(const char *fontname, int height = 30);
|
||||
void setBBox(const Common::Rect bbox);
|
||||
void setColor(int color) { _color = color; }
|
||||
void drawSubtitle(uint32 timestamp, bool force = false);
|
||||
|
||||
private:
|
||||
SRTParser _srtParser;
|
||||
@ -70,6 +75,14 @@ private:
|
||||
|
||||
const Graphics::Font *_font;
|
||||
int _fontHeight;
|
||||
|
||||
Graphics::Surface *_surface;
|
||||
|
||||
Common::Rect _bbox;
|
||||
Common::Rect _dirtyRect;
|
||||
|
||||
Common::String _prevSubtitle;
|
||||
uint32 _color;
|
||||
};
|
||||
|
||||
} // End of namespace Video
|
||||
|
Loading…
Reference in New Issue
Block a user