diff options
Diffstat (limited to 'engines/titanic/support')
-rw-r--r-- | engines/titanic/support/credit_text.cpp | 110 | ||||
-rw-r--r-- | engines/titanic/support/credit_text.h | 6 | ||||
-rw-r--r-- | engines/titanic/support/direct_draw.cpp | 12 | ||||
-rw-r--r-- | engines/titanic/support/direct_draw.h | 6 | ||||
-rw-r--r-- | engines/titanic/support/files_manager.cpp | 9 | ||||
-rw-r--r-- | engines/titanic/support/files_manager.h | 7 | ||||
-rw-r--r-- | engines/titanic/support/font.cpp | 61 | ||||
-rw-r--r-- | engines/titanic/support/font.h | 6 | ||||
-rw-r--r-- | engines/titanic/support/mouse_cursor.cpp | 8 | ||||
-rw-r--r-- | engines/titanic/support/mouse_cursor.h | 7 | ||||
-rw-r--r-- | engines/titanic/support/screen_manager.cpp | 23 | ||||
-rw-r--r-- | engines/titanic/support/screen_manager.h | 20 | ||||
-rw-r--r-- | engines/titanic/support/string_parser.cpp | 97 | ||||
-rw-r--r-- | engines/titanic/support/string_parser.h | 76 | ||||
-rw-r--r-- | engines/titanic/support/video_surface.cpp | 14 |
15 files changed, 409 insertions, 53 deletions
diff --git a/engines/titanic/support/credit_text.cpp b/engines/titanic/support/credit_text.cpp index 0e9715aaa6..009c3f4944 100644 --- a/engines/titanic/support/credit_text.cpp +++ b/engines/titanic/support/credit_text.cpp @@ -28,7 +28,7 @@ namespace Titanic { CCreditText::CCreditText() : _screenManagerP(nullptr), _field14(0), _ticks(0), _fontHeight(1), _objectP(nullptr), _totalHeight(0), _field40(0), _field44(0), _field48(0), _field4C(0), _field50(0), - _field54(0), _field58(0), _field5C(0) { + _field54(0), _field58(0), _counter(0) { } void CCreditText::clear() { @@ -52,7 +52,7 @@ void CCreditText::load(CGameObject *obj, CScreenManager *screenManager, _field50 = 0; _field54 = 0; _field58 = 0; - _field5C = 0; + _counter = 0; } void CCreditText::setup() { @@ -87,8 +87,11 @@ void CCreditText::setup() { } _groups.push_back(group); + if (hasDots) + handleDots(group); } + _screenManagerP->setFontNumber(oldFontNumber); _groupIt = _groups.begin(); _lineIt = (*_groupIt)->_lines.begin(); _totalHeight = _objectP->getBounds().height() + _fontHeight * 2; @@ -147,7 +150,108 @@ void CCreditText::handleDots(CCreditLineGroup *group) { } bool CCreditText::draw() { - return false; + if (_groupIt == _groups.end()) + return false; + + if (++_counter > 200) { + _field44 += _field50; + _field48 += _field54; + _field4C += _field58; + _field50 = g_vm->getRandomNumber(63) + 192 - _field44; + _field54 = g_vm->getRandomNumber(63) + 192 - _field48; + _field58 = g_vm->getRandomNumber(63) + 192 - _field4C; + _counter = 0; + } + + // Positioning adjustment, changing lines and/or group if necessary + int yDiff = (int)(g_vm->_events->getTicksCount() - _ticks) / 22 - _field40; + while (yDiff > 0) { + if (_totalHeight > 0) { + if (yDiff < _totalHeight) { + _totalHeight -= yDiff; + _field40 += yDiff; + yDiff = 0; + } else { + yDiff -= _totalHeight; + _field40 += _totalHeight; + _totalHeight = 0; + } + } else { + if (yDiff < _fontHeight) + break; + + ++_lineIt; + yDiff -= _fontHeight; + _field40 += _fontHeight; + + if (_lineIt == (*_groupIt)->_lines.end()) { + // Move to next line group + ++_groupIt; + if (_groupIt == _groups.end()) + // Reached end of groups + return false; + + _lineIt = (*_groupIt)->_lines.begin(); + _totalHeight = _fontHeight * 3 / 2; + } + } + } + + int oldFontNumber = _screenManagerP->setFontNumber(3); + CCreditLineGroups::iterator groupIt = _groupIt; + CCreditLines::iterator lineIt = _lineIt; + + Point textPos; + for (textPos.y = _rect.top + _totalHeight; textPos.y <= _rect.bottom; + textPos.y += _fontHeight) { + int textR = _field44 + _field50 * _counter / 200; + int textG = _field48 + _field54 * _counter / 200; + int textB = _field4C + _field58 * _counter / 200; + + // Single iteration loop to figure out RGB values for the line + do { + int percent = 0; + if (textPos.y < (_rect.top + 2 * _fontHeight)) { + percent = (textPos.y - _rect.top) * 100 / (_fontHeight * 2); + if (percent < 0) + percent = 0; + } else { + int bottom = _rect.bottom - 2 * _fontHeight; + if (textPos.y < bottom) + break; + + percent = (_rect.bottom - textPos.y) * 100 + / (_fontHeight * 2); + } + + // Adjust the RGB to the specified percentage intensity + textR = textR * percent / 100; + textG = textG * percent / 100; + textB = textB * percent / 100; + } while (0); + + // Write out the line + _screenManagerP->setFontColor(textR, textG, textB); + textPos.x = _rect.left + (_rect.width() - (*lineIt)->_lineWidth) / 2; + _screenManagerP->writeString(SURFACE_BACKBUFFER, textPos, + _rect, (*lineIt)->_line, (*lineIt)->_lineWidth); + + // Move to next line + ++lineIt; + if (lineIt == (*groupIt)->_lines.end()) { + ++groupIt; + if (groupIt == _groups.end()) + // Finished all lines + break; + + lineIt = (*groupIt)->_lines.begin(); + textPos.y += _fontHeight * 3 / 2; + } + } + + _objectP->makeDirty(); + _screenManagerP->setFontNumber(oldFontNumber); + return true; } } // End of namespace Titanic diff --git a/engines/titanic/support/credit_text.h b/engines/titanic/support/credit_text.h index ec8fc22cda..3e5bfca0c2 100644 --- a/engines/titanic/support/credit_text.h +++ b/engines/titanic/support/credit_text.h @@ -68,11 +68,11 @@ public: int _field14; CCreditLineGroups _groups; uint _ticks; - uint _fontHeight; + int _fontHeight; CGameObject *_objectP; CCreditLineGroups::iterator _groupIt; CCreditLines::iterator _lineIt; - uint _totalHeight; + int _totalHeight; int _field40; int _field44; int _field48; @@ -80,7 +80,7 @@ public: int _field50; int _field54; int _field58; - int _field5C; + int _counter; public: CCreditText(); diff --git a/engines/titanic/support/direct_draw.cpp b/engines/titanic/support/direct_draw.cpp index 6958896077..3cec9377bb 100644 --- a/engines/titanic/support/direct_draw.cpp +++ b/engines/titanic/support/direct_draw.cpp @@ -75,18 +75,6 @@ void DirectDrawManager::initVideo(int width, int height, int bpp, int numBackSur } } -void DirectDrawManager::setResolution() { - // TODO -} - -void DirectDrawManager::proc2() { - -} - -void DirectDrawManager::proc3() { - -} - void DirectDrawManager::initFullScreen() { debugC(ERROR_BASIC, kDebugGraphics, "Creating surfaces"); _directDraw.setDisplayMode(_directDraw._width, _directDraw._height, diff --git a/engines/titanic/support/direct_draw.h b/engines/titanic/support/direct_draw.h index 85c344c600..4b5596896a 100644 --- a/engines/titanic/support/direct_draw.h +++ b/engines/titanic/support/direct_draw.h @@ -78,12 +78,6 @@ public: */ void initVideo(int width, int height, int bpp, int numBackSurfaces); - void setResolution(); - - void proc2(); - - void proc3(); - /** * Initializes the surfaces in windowed mode */ diff --git a/engines/titanic/support/files_manager.cpp b/engines/titanic/support/files_manager.cpp index 89e0a1d10e..3ee17e9769 100644 --- a/engines/titanic/support/files_manager.cpp +++ b/engines/titanic/support/files_manager.cpp @@ -104,8 +104,9 @@ void CFilesManager::loadDrive() { resetView(); } -void CFilesManager::debug(CScreenManager *screenManager) { - warning("TODO: CFilesManager::debug"); +void CFilesManager::insertCD(CScreenManager *screenManager) { + // We not support running game directly from the original CDs, + // so this method can remain stubbed } void CFilesManager::resetView() { @@ -115,10 +116,6 @@ void CFilesManager::resetView() { } } -void CFilesManager::fn4(const CString &name) { - warning("TODO: CFilesManager::fn4"); -} - void CFilesManager::preload(const CString &name) { // We don't currently do any preloading of resources } diff --git a/engines/titanic/support/files_manager.h b/engines/titanic/support/files_manager.h index ec0c7fc008..c530b05ece 100644 --- a/engines/titanic/support/files_manager.h +++ b/engines/titanic/support/files_manager.h @@ -84,15 +84,16 @@ public: */ void loadDrive(); - void debug(CScreenManager *screenManager); + /** + * Shows a dialog for inserting a new CD + */ + void insertCD(CScreenManager *screenManager); /** * Resets the view being displayed */ void resetView(); - void fn4(const CString &name); - /** * Preloads and caches a file for access shortly */ diff --git a/engines/titanic/support/font.cpp b/engines/titanic/support/font.cpp index 69c0efe504..e519237c3b 100644 --- a/engines/titanic/support/font.cpp +++ b/engines/titanic/support/font.cpp @@ -179,6 +179,67 @@ int STFont::writeString(CVideoSurface *surface, const Rect &rect1, const Rect &d return endP ? endP - str.c_str() : 0; } +void STFont::writeString(CVideoSurface *surface, const Point &destPos, Rect &clipRect, + const CString &str, int lineWidth) { + if (!_fontHeight || !_dataPtr || str.empty()) + return; + if (!lineWidth) + // No line width specified, so get in the width + lineWidth = stringWidth(str); + + Rect textRect(0, 0, lineWidth, _fontHeight); + Point textPt = destPos; + + // Perform clipping as necessary if the text will fall outside clipping area + if (textPt.y > clipRect.bottom) + return; + + if ((textPt.y + textRect.height()) > clipRect.bottom) + textRect.bottom = textRect.top - textPt.y + clipRect.bottom; + + if (textPt.y < clipRect.top) { + if ((textPt.y + textRect.height()) < clipRect.top) + return; + + textRect.top += clipRect.top - textPt.y; + textPt.y = clipRect.top; + } + + // Iterate through each character of the string + for (const byte *srcP = (const byte *)str.c_str(); *srcP; ++srcP) { + byte c = *srcP; + if (c == 0xE9) + c = '$'; + + // Form a rect of the area of the next character to draw + Rect charRect(_chars[c]._offset, textRect.top, + _chars[c]._offset + _chars[c]._width, textRect.bottom); + + if (textPt.x < clipRect.left) { + // Character is either partially or entirely left off-screen + if ((textPt.x + charRect.width()) < clipRect.left) { + textPt.x += _chars[c]._width; + continue; + } + + // Partially clipped on left-hand side + charRect.left = clipRect.left - textPt.x; + textPt.x = clipRect.left; + } else if ((textPt.x + charRect.width()) > clipRect.right) { + if (textPt.x > clipRect.right) + // Now entirely off right-hand side, so stop drawing + break; + + // Partially clipped on right-hand side + charRect.right += clipRect.right - textPt.x - charRect.width(); + } + + // At this point, we know we've got to draw at least part of a character, + // and have figured out the area of the character to draw + copyRect(surface, textPt, charRect); + } +} + WriteCharacterResult STFont::writeChar(CVideoSurface *surface, unsigned char c, const Point &pt, const Rect &destRect, const Rect *srcRect) { if (c == 233) diff --git a/engines/titanic/support/font.h b/engines/titanic/support/font.h index 591fb4661c..6c4fe8e9c3 100644 --- a/engines/titanic/support/font.h +++ b/engines/titanic/support/font.h @@ -99,6 +99,12 @@ public: int yOffset, const CString &str, CTextCursor *textCursor); /** + * Write a string to the specified surface + */ + void writeString(CVideoSurface *surface, const Point &destPos, Rect &clipRect, + const CString &str, int lineWidth = 0); + + /** * Get the text area a string will fit into * @param str String * @param maxWidth Maximum width in pixels diff --git a/engines/titanic/support/mouse_cursor.cpp b/engines/titanic/support/mouse_cursor.cpp index 068267cb18..d342e6cccb 100644 --- a/engines/titanic/support/mouse_cursor.cpp +++ b/engines/titanic/support/mouse_cursor.cpp @@ -67,7 +67,6 @@ CMouseCursor::~CMouseCursor() { void CMouseCursor::loadCursorImages() { const CResourceKey key("ycursors.avi"); - g_vm->_filesManager->fn4(key.getString()); // Iterate through getting each cursor for (int idx = 0; idx < NUM_CURSORS; ++idx) { @@ -128,8 +127,11 @@ void CMouseCursor::unlockE4() { CScreenManager::_screenManagerPtr->_inputHandler->decLockCount(); } -void CMouseCursor::saveState(int v1, int v2, int v3) { - // TODO +void CMouseCursor::setPosition(const Point &pt, double rate) { + assert(rate >= 0.0 && rate <= 1.0); + + // TODO: Figure out use of the rate parameter + g_system->warpMouse(pt.x, pt.y); } } // End of namespace Titanic diff --git a/engines/titanic/support/mouse_cursor.h b/engines/titanic/support/mouse_cursor.h index 7a81ad43fa..74fb1f6113 100644 --- a/engines/titanic/support/mouse_cursor.h +++ b/engines/titanic/support/mouse_cursor.h @@ -24,8 +24,8 @@ #define TITANIC_MOUSE_CURSOR_H #include "common/scummsys.h" -#include "common/rect.h" #include "graphics/managed_surface.h" +#include "titanic/support/rect.h" namespace Titanic { @@ -105,7 +105,10 @@ public: void lockE4(); void unlockE4(); - void saveState(int v1, int v2, int v3); + /** + * Sets the mouse to a new position + */ + void setPosition(const Point &pt, double rate); }; diff --git a/engines/titanic/support/screen_manager.cpp b/engines/titanic/support/screen_manager.cpp index b0d852104c..bcf43fc8cb 100644 --- a/engines/titanic/support/screen_manager.cpp +++ b/engines/titanic/support/screen_manager.cpp @@ -239,10 +239,25 @@ int OSScreenManager::writeString(int surfaceNum, const Rect &destRect, yOffset, str, textCursor); } -int OSScreenManager::writeString(int surfaceNum, const Rect &srcRect, - const Rect &destRect, const CString &str, CTextCursor *textCursor) { - // TODO - return 0; +void OSScreenManager::writeString(int surfaceNum, const Point &destPos, + const Rect &clipRect, const CString &str, int lineWidth) { + CVideoSurface *surface; + Rect bounds; + + if (surfaceNum >= 0 && surfaceNum < (int)_backSurfaces.size()) { + surface = _backSurfaces[surfaceNum]._surface; + bounds = _backSurfaces[surfaceNum]._bounds; + } else if (surfaceNum == -1) { + surface = _frontRenderSurface; + bounds = Rect(0, 0, surface->getWidth(), surface->getHeight()); + } else { + return; + } + + Rect destRect = clipRect; + destRect.constrain(bounds); + + _fonts[_fontNumber].writeString(surface, destPos, destRect, str, lineWidth); } void OSScreenManager::setFontColor(byte r, byte g, byte b) { diff --git a/engines/titanic/support/screen_manager.h b/engines/titanic/support/screen_manager.h index 0736f1393c..cad6901b02 100644 --- a/engines/titanic/support/screen_manager.h +++ b/engines/titanic/support/screen_manager.h @@ -140,13 +140,13 @@ public: /** * Write a string * @param surfaceNum Destination surface - * @param srcRect Drawing area - * @param destRect Bounds of dest surface + * @param destPos Position to start writing text at + * @param clipRect Clipping area to constrain text to * @param str Line or lines to write - * @param textCursor Optional text cursor pointer + * @param maxWidth Maximum allowed line width */ - virtual int writeString(int surfaceNum, const Rect &srcRect, - const Rect &destRect, const CString &str, CTextCursor *textCursor) = 0; + virtual void writeString(int surfaceNum, const Point &destPos, + const Rect &clipRect, const CString &str, int maxWidth) = 0; /** * Set the font color @@ -322,13 +322,13 @@ public: /** * Write a string * @param surfaceNum Destination surface - * @param srcRect Drawing area - * @param destRect Bounds of dest surface + * @param destPos Position to start writing text at + * @param clipRect Clipping area to constrain text to * @param str Line or lines to write - * @param textCursor Optional text cursor pointer + * @param lineWidth Width in pixels of the string, if known. */ - virtual int writeString(int surfaceNum, const Rect &srcRect, - const Rect &destRect, const CString &str, CTextCursor *textCursor); + virtual void writeString(int surfaceNum, const Point &destPos, + const Rect &clipRect, const CString &str, int lineWidth = 0); /** * Set the font color diff --git a/engines/titanic/support/string_parser.cpp b/engines/titanic/support/string_parser.cpp new file mode 100644 index 0000000000..496440a973 --- /dev/null +++ b/engines/titanic/support/string_parser.cpp @@ -0,0 +1,97 @@ +/* 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 "titanic/support/string_parser.h" +#include "common/util.h" + +namespace Titanic { + +void CStringParser::skipSeperators(const CString &seperatorChars) { + for (; _index < size(); ++_index) { + char c = (*this)[_index]; + if (seperatorChars.indexOf(c) == -1) + break; + } +} + +bool CStringParser::parse(CString &resultStr, const CString &seperatorChars, bool allowQuotes) { + if (_index >= size()) + return false; + + resultStr.clear(); + bool quoteFlag = false; + while (_index < size()) { + char c = (*this)[_index]; + if (!quoteFlag && seperatorChars.indexOf(c) >= 0) + break; + + if (allowQuotes) { + if (quoteFlag) { + if (c == '"') { + // End of quoted string + ++_index; + break; + } + } else { + if (c == '"') { + // Start of quoted string + ++_index; + quoteFlag = true; + continue; + } + } + } + + resultStr += c; + ++_index; + } + + return true; +} + +uint CStringParser::readInt() { + // Get digits from the string + CString numStr; + while (Common::isDigit(currentChar())) + numStr += getNextChar(); + + // Throw a wobbly if there wasn't a number + if (numStr.empty()) + error("ReadInt(): No number to read"); + + return atoi(numStr.c_str()); +} + +char CStringParser::currentChar() const { + return (_index >= size()) ? '\0' : (*this)[_index]; +} + +char CStringParser::getNextChar() { + return (_index >= size()) ? '\0' : (*this)[_index++]; +} + +void CStringParser::skipSpaces() { + while (_index < size() && Common::isSpace(currentChar())) + ++_index; +} + +} // End of namespace Titanic diff --git a/engines/titanic/support/string_parser.h b/engines/titanic/support/string_parser.h new file mode 100644 index 0000000000..f89caacfb5 --- /dev/null +++ b/engines/titanic/support/string_parser.h @@ -0,0 +1,76 @@ +/* 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 TITANIC_STRING_PARSER_H +#define TITANIC_STRING_PARSER_H + +#include "titanic/support/string.h" + +namespace Titanic { + +class CStringParser : public CString { +private: + uint _index; +private: + /** + * Gets the character at the current index + */ + char currentChar() const; + + /** + * Gets the next character, and increments the parsing index + */ + char getNextChar(); + + /** + * Skips over any spaces + */ + void skipSpaces(); +public: + CStringParser() : CString(), _index(0) {} + CStringParser(const CString &str) : CString(str), _index(0) {} + + /** + * Skips over any specified seperator characters in our string + * at the current index + */ + void skipSeperators(const CString &seperatorChars); + + /** + * Parses out a string from a source string at the current index + * @param resultStr String to hold the resulting sring + * @param seperatorChras List of characters that seperate string values + * @param allowQuotes If true, handles double-quoted substrings + * @returns True if a string entry was extracted + */ + bool parse(CString &resultStr, const CString &seperatorChars, bool allowQuotes = false); + + /** + * Reads an integer from the string + */ + uint readInt(); + +}; + +} // End of namespace Titanic + +#endif /* TITANIC_STRING_PARSER_H */ diff --git a/engines/titanic/support/video_surface.cpp b/engines/titanic/support/video_surface.cpp index 594f660937..b5f668793a 100644 --- a/engines/titanic/support/video_surface.cpp +++ b/engines/titanic/support/video_surface.cpp @@ -163,7 +163,19 @@ void CVideoSurface::blitRect2(const Rect &srcRect, const Rect &destRect, CVideoS } void CVideoSurface::movieBlitRect(const Rect &srcRect, const Rect &destRect, CVideoSurface *src) { - // TODO + if (lock()) { + if (src->lock()) { + Graphics::ManagedSurface *srcSurface = src->_rawSurface; + Graphics::ManagedSurface *destSurface = _rawSurface; + + // TODO: Handle the transparency mode correctly + destSurface->blitFrom(*srcSurface, srcRect, Point(srcRect.left, srcRect.top)); + + src->unlock(); + } + + unlock(); + } } uint CVideoSurface::getTransparencyColor() { |