From dab4ce1f7bc5c72f9f90bc0de8553e4b4e945624 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 3 Dec 2014 02:38:06 +0200 Subject: ZVISION: Move the subtitle class --- engines/zvision/graphics/subtitles.cpp | 108 ++++++++++++++++++++++ engines/zvision/graphics/subtitles.h | 54 +++++++++++ engines/zvision/module.mk | 2 +- engines/zvision/scripting/sidefx/music_node.h | 2 +- engines/zvision/scripting/sidefx/syncsound_node.h | 2 +- engines/zvision/subtitles/subtitles.cpp | 108 ---------------------- engines/zvision/subtitles/subtitles.h | 54 ----------- engines/zvision/video/video.cpp | 2 +- 8 files changed, 166 insertions(+), 166 deletions(-) create mode 100644 engines/zvision/graphics/subtitles.cpp create mode 100644 engines/zvision/graphics/subtitles.h delete mode 100644 engines/zvision/subtitles/subtitles.cpp delete mode 100644 engines/zvision/subtitles/subtitles.h diff --git a/engines/zvision/graphics/subtitles.cpp b/engines/zvision/graphics/subtitles.cpp new file mode 100644 index 0000000000..784721562a --- /dev/null +++ b/engines/zvision/graphics/subtitles.cpp @@ -0,0 +1,108 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "zvision/graphics/render_manager.h" +#include "zvision/graphics/subtitles.h" +#include "zvision/core/search_manager.h" +#include "zvision/text/text.h" + +namespace ZVision { + +Subtitle::Subtitle(ZVision *engine, const Common::String &subname) : + _engine(engine), + _areaId(-1), + _subId(-1) { + Common::File file; + if (_engine->getSearchManager()->openFile(file, subname)) { + while (!file.eos()) { + Common::String str = file.readLine(); + if (str.lastChar() == '~') + str.deleteLastChar(); + + if (str.matchString("*Initialization*", true)) { + // Not used + } else if (str.matchString("*Rectangle*", true)) { + int32 x1, y1, x2, y2; + sscanf(str.c_str(), "%*[^:]:%d %d %d %d", &x1, &y1, &x2, &y2); + Common::Rect rct = Common::Rect(x1, y1, x2, y2); + _areaId = _engine->getRenderManager()->createSubArea(rct); + } else if (str.matchString("*TextFile*", true)) { + char filename[64]; + sscanf(str.c_str(), "%*[^:]:%s", filename); + Common::File txt; + if (_engine->getSearchManager()->openFile(txt, filename)) { + while (!txt.eos()) { + Common::String txtline = readWideLine(txt); + sub curSubtitle; + curSubtitle.start = -1; + curSubtitle.stop = -1; + curSubtitle.subStr = txtline; + + _subs.push_back(curSubtitle); + } + txt.close(); + } + } else { + int32 st; + int32 en; + int32 sb; + if (sscanf(str.c_str(), "%*[^:]:(%d,%d)=%d", &st, &en, &sb) == 3) { + if (sb <= (int32)_subs.size()) { + _subs[sb].start = st; + _subs[sb].stop = en; + } + } + } + } + } +} + +Subtitle::~Subtitle() { + if (_areaId != -1) + _engine->getRenderManager()->deleteSubArea(_areaId); + + _subs.clear(); +} + +void Subtitle::process(int32 time) { + int16 j = -1; + for (uint16 i = 0; i < _subs.size(); i++) + if (time >= _subs[i].start && time <= _subs[i].stop) { + j = i; + break; + } + + if (j == -1 && _subId != -1) { + if (_areaId != -1) + _engine->getRenderManager()->updateSubArea(_areaId, ""); + _subId = -1; + } + + if (j != -1 && j != _subId) { + if (_subs[j].subStr.size()) + if (_areaId != -1) + _engine->getRenderManager()->updateSubArea(_areaId, _subs[j].subStr); + _subId = j; + } +} + +} // End of namespace ZVision diff --git a/engines/zvision/graphics/subtitles.h b/engines/zvision/graphics/subtitles.h new file mode 100644 index 0000000000..c3da6583a4 --- /dev/null +++ b/engines/zvision/graphics/subtitles.h @@ -0,0 +1,54 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef ZVISION_SUBTITLES_H +#define ZVISION_SUBTITLES_H + +#include "zvision/zvision.h" + +namespace ZVision { + +class ZVision; + +class Subtitle { +public: + Subtitle(ZVision *engine, const Common::String &subname); + ~Subtitle(); + + void process(int32 time); +private: + ZVision *_engine; + int32 _areaId; + int16 _subId; + + struct sub { + int start; + int stop; + Common::String subStr; + }; + + Common::Array _subs; +}; + +} + +#endif diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index e2beeb593d..045eb5264a 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -17,6 +17,7 @@ MODULE_OBJS := \ graphics/effects/wave.o \ graphics/render_manager.o \ graphics/render_table.o \ + graphics/subtitles.o \ graphics/truetype_font.o \ scripting/actions.o \ scripting/control.o \ @@ -41,7 +42,6 @@ MODULE_OBJS := \ scripting/sidefx/timer_node.o \ scripting/sidefx/ttytext_node.o \ sound/zork_raw.o \ - subtitles/subtitles.o \ text/string_manager.o \ text/text.o \ utility/clock.o \ diff --git a/engines/zvision/scripting/sidefx/music_node.h b/engines/zvision/scripting/sidefx/music_node.h index 954e2f474e..c89345f0d0 100644 --- a/engines/zvision/scripting/sidefx/music_node.h +++ b/engines/zvision/scripting/sidefx/music_node.h @@ -25,7 +25,7 @@ #include "audio/mixer.h" #include "zvision/scripting/sidefx.h" -#include "zvision/subtitles/subtitles.h" +#include "zvision/graphics/subtitles.h" namespace Common { class String; diff --git a/engines/zvision/scripting/sidefx/syncsound_node.h b/engines/zvision/scripting/sidefx/syncsound_node.h index c16ffebe7f..7cd02a8aef 100644 --- a/engines/zvision/scripting/sidefx/syncsound_node.h +++ b/engines/zvision/scripting/sidefx/syncsound_node.h @@ -25,7 +25,7 @@ #include "audio/mixer.h" #include "zvision/scripting/sidefx.h" -#include "zvision/subtitles/subtitles.h" +#include "zvision/graphics/subtitles.h" namespace Common { class String; diff --git a/engines/zvision/subtitles/subtitles.cpp b/engines/zvision/subtitles/subtitles.cpp deleted file mode 100644 index d36eb24923..0000000000 --- a/engines/zvision/subtitles/subtitles.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "zvision/subtitles/subtitles.h" -#include "zvision/graphics/render_manager.h" -#include "zvision/core/search_manager.h" -#include "zvision/text/text.h" - -namespace ZVision { - -Subtitle::Subtitle(ZVision *engine, const Common::String &subname) : - _engine(engine), - _areaId(-1), - _subId(-1) { - Common::File file; - if (_engine->getSearchManager()->openFile(file, subname)) { - while (!file.eos()) { - Common::String str = file.readLine(); - if (str.lastChar() == '~') - str.deleteLastChar(); - - if (str.matchString("*Initialization*", true)) { - // Not used - } else if (str.matchString("*Rectangle*", true)) { - int32 x1, y1, x2, y2; - sscanf(str.c_str(), "%*[^:]:%d %d %d %d", &x1, &y1, &x2, &y2); - Common::Rect rct = Common::Rect(x1, y1, x2, y2); - _areaId = _engine->getRenderManager()->createSubArea(rct); - } else if (str.matchString("*TextFile*", true)) { - char filename[64]; - sscanf(str.c_str(), "%*[^:]:%s", filename); - Common::File txt; - if (_engine->getSearchManager()->openFile(txt, filename)) { - while (!txt.eos()) { - Common::String txtline = readWideLine(txt); - sub curSubtitle; - curSubtitle.start = -1; - curSubtitle.stop = -1; - curSubtitle.subStr = txtline; - - _subs.push_back(curSubtitle); - } - txt.close(); - } - } else { - int32 st; - int32 en; - int32 sb; - if (sscanf(str.c_str(), "%*[^:]:(%d,%d)=%d", &st, &en, &sb) == 3) { - if (sb <= (int32)_subs.size()) { - _subs[sb].start = st; - _subs[sb].stop = en; - } - } - } - } - } -} - -Subtitle::~Subtitle() { - if (_areaId != -1) - _engine->getRenderManager()->deleteSubArea(_areaId); - - _subs.clear(); -} - -void Subtitle::process(int32 time) { - int16 j = -1; - for (uint16 i = 0; i < _subs.size(); i++) - if (time >= _subs[i].start && time <= _subs[i].stop) { - j = i; - break; - } - - if (j == -1 && _subId != -1) { - if (_areaId != -1) - _engine->getRenderManager()->updateSubArea(_areaId, ""); - _subId = -1; - } - - if (j != -1 && j != _subId) { - if (_subs[j].subStr.size()) - if (_areaId != -1) - _engine->getRenderManager()->updateSubArea(_areaId, _subs[j].subStr); - _subId = j; - } -} - -} // End of namespace ZVision diff --git a/engines/zvision/subtitles/subtitles.h b/engines/zvision/subtitles/subtitles.h deleted file mode 100644 index c3da6583a4..0000000000 --- a/engines/zvision/subtitles/subtitles.h +++ /dev/null @@ -1,54 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef ZVISION_SUBTITLES_H -#define ZVISION_SUBTITLES_H - -#include "zvision/zvision.h" - -namespace ZVision { - -class ZVision; - -class Subtitle { -public: - Subtitle(ZVision *engine, const Common::String &subname); - ~Subtitle(); - - void process(int32 time); -private: - ZVision *_engine; - int32 _areaId; - int16 _subId; - - struct sub { - int start; - int stop; - Common::String subStr; - }; - - Common::Array _subs; -}; - -} - -#endif diff --git a/engines/zvision/video/video.cpp b/engines/zvision/video/video.cpp index 25125ec2fb..36b5f9b921 100644 --- a/engines/zvision/video/video.cpp +++ b/engines/zvision/video/video.cpp @@ -29,7 +29,7 @@ #include "zvision/zvision.h" #include "zvision/utility/clock.h" #include "zvision/graphics/render_manager.h" -#include "zvision/subtitles/subtitles.h" +#include "zvision/graphics/subtitles.h" namespace ZVision { -- cgit v1.2.3