From 2eee488e364460772dcb8a85962f6c210810587b Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 15 Oct 2014 20:49:59 +0200 Subject: [PATCH] WINTERMUTE: Do some refactoring over a bunch of attrs in VideoSubtitle Conflicts: engines/wintermute/video/video_subtitler.cpp --- engines/wintermute/video/video_subtitle.cpp | 23 ++++++++++---------- engines/wintermute/video/video_subtitle.h | 11 ++++++---- engines/wintermute/video/video_subtitler.cpp | 16 +++++++------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/engines/wintermute/video/video_subtitle.cpp b/engines/wintermute/video/video_subtitle.cpp index 5be22de5923..bcaa2931241 100644 --- a/engines/wintermute/video/video_subtitle.cpp +++ b/engines/wintermute/video/video_subtitle.cpp @@ -32,25 +32,26 @@ namespace Wintermute { ////////////////////////////////////////////////////////////////////////// VideoSubtitle::VideoSubtitle(BaseGame *inGame): BaseClass(inGame) { - _text = NULL; _startFrame = _endFrame = 0; } ////////////////////////////////////////////////////////////////////////// -VideoSubtitle::VideoSubtitle(BaseGame *inGame, char *text, long startFrame, long endFrame): BaseClass(inGame) { - _text = new char[strlen(text) + 1]; - strcpy(_text, text); - _gameRef->expandStringByStringTable(&_text); +VideoSubtitle::VideoSubtitle(BaseGame *inGame, char *text, const long &startFrame, const long &endFrame): BaseClass(inGame) { + _gameRef->expandStringByStringTable(&text); + _text = Common::String(text); _startFrame = startFrame; _endFrame = endFrame; } +long VideoSubtitle::getStartFrame() { + return _startFrame; +} -////////////////////////////////////////////////////////////////////////// -VideoSubtitle::~VideoSubtitle() { - if (_text) { - delete [] _text; - _text = NULL; - } +long VideoSubtitle::getEndFrame() { + return _endFrame; +} + +Common::String VideoSubtitle::getText() { + return _text; } } diff --git a/engines/wintermute/video/video_subtitle.h b/engines/wintermute/video/video_subtitle.h index 6d629b34d02..5df1348465e 100644 --- a/engines/wintermute/video/video_subtitle.h +++ b/engines/wintermute/video/video_subtitle.h @@ -35,12 +35,15 @@ namespace Wintermute { class VideoSubtitle : public BaseClass { public: + VideoSubtitle(BaseGame *inGame); + VideoSubtitle(BaseGame *inGame, char *text, const long &startFrame, const long &endFrame); + long getEndFrame(); + long getStartFrame(); + Common::String getText(); +private: long _endFrame; long _startFrame; - char *_text; - VideoSubtitle(BaseGame *inGame); - VideoSubtitle(BaseGame *inGame, char *text, long startFrame, long endFrame); - virtual ~VideoSubtitle(); + Common::String _text; }; } diff --git a/engines/wintermute/video/video_subtitler.cpp b/engines/wintermute/video/video_subtitler.cpp index 06b8bab1f42..a1294dd3d4e 100644 --- a/engines/wintermute/video/video_subtitler.cpp +++ b/engines/wintermute/video/video_subtitler.cpp @@ -186,8 +186,8 @@ bool VideoSubtitler::loadSubtitles(const char *filename, const char *subtitleFil bool VideoSubtitler::display() { if (_showSubtitle) { BaseFont *font = _gameRef->getVideoFont() ? _gameRef->getVideoFont() : _gameRef->getSystemFont(); - int textHeight = font->getTextHeight((byte *)_subtitles[_currentSubtitle]->_text, _gameRef->_renderer->getWidth()); - font->drawText((byte *)_subtitles[_currentSubtitle]->_text, + int textHeight = font->getTextHeight((byte *)_subtitles[_currentSubtitle]->getText().c_str(), _gameRef->_renderer->getWidth()); + font->drawText((byte *)_subtitles[_currentSubtitle]->getText().c_str(), 0, (_gameRef->_renderer->getHeight() - textHeight - 5), (_gameRef->_renderer->getWidth(), TAL_CENTER)); @@ -208,11 +208,11 @@ bool VideoSubtitler::update(long frame) { _showSubtitle = false; - bool overdue = (frame > _subtitles[_currentSubtitle]->_endFrame); + bool overdue = (frame > _subtitles[_currentSubtitle]->getEndFrame()); bool hasNext = (_currentSubtitle + 1 < _subtitles.size()); bool nextStarted = false; if (hasNext) { - nextStarted = (_subtitles[_currentSubtitle + 1]->_startFrame <= frame); + nextStarted = (_subtitles[_currentSubtitle + 1]->getStartFrame() <= frame); } while (_currentSubtitle < _subtitles.size() && @@ -228,22 +228,22 @@ bool VideoSubtitler::update(long frame) { _currentSubtitle++; - overdue = (frame > _subtitles[_currentSubtitle]->_endFrame); + overdue = (frame > _subtitles[_currentSubtitle]->getEndFrame()); hasNext = (_currentSubtitle + 1 < _subtitles.size()); if (hasNext) { - nextStarted = (_subtitles[_currentSubtitle + 1]->_startFrame <= frame); + nextStarted = (_subtitles[_currentSubtitle + 1]->getStartFrame() <= frame); } else { nextStarted = false; } } - bool currentValid = (_subtitles[_currentSubtitle]->_endFrame != 0); + bool currentValid = (_subtitles[_currentSubtitle]->getEndFrame() != 0); /* * No idea why we do this check, carried over from Mnemonic's code. * Possibly a workaround for buggy subtitles or some kind of sentinel? :-\ */ - bool currentStarted = frame >= _subtitles[_currentSubtitle]->_startFrame; + bool currentStarted = frame >= _subtitles[_currentSubtitle]->getStartFrame(); if (currentStarted && !overdue && currentValid) { _showSubtitle = true;