WINTERMUTE: Do some refactoring over a bunch of attrs in VideoSubtitle

Conflicts:
	engines/wintermute/video/video_subtitler.cpp
This commit is contained in:
Tobia Tesan 2014-10-15 20:49:59 +02:00
parent f2441da3da
commit 2eee488e36
3 changed files with 27 additions and 23 deletions

View File

@ -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;
}
}

View File

@ -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;
};
}

View File

@ -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;