aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-26 22:18:21 -0400
committerPaul Gilbert2016-07-10 16:12:05 -0400
commit34c32e38e2659406e3556f752fcada8491860e92 (patch)
treec9f2e355504d97376cf8437133415a7f0a606dc6 /engines
parentb114c768cd592462794d4fa2a397473cf146656c (diff)
downloadscummvm-rg350-34c32e38e2659406e3556f752fcada8491860e92.tar.gz
scummvm-rg350-34c32e38e2659406e3556f752fcada8491860e92.tar.bz2
scummvm-rg350-34c32e38e2659406e3556f752fcada8491860e92.zip
TITANIC: More font logic, beginnings of text cursor
Diffstat (limited to 'engines')
-rw-r--r--engines/titanic/game_manager.cpp2
-rw-r--r--engines/titanic/pet_control/pet_text.cpp7
-rw-r--r--engines/titanic/pet_control/pet_text.h3
-rw-r--r--engines/titanic/support/font.cpp59
-rw-r--r--engines/titanic/support/font.h6
-rw-r--r--engines/titanic/support/screen_manager.cpp13
-rw-r--r--engines/titanic/support/screen_manager.h24
-rw-r--r--engines/titanic/support/text_cursor.cpp12
-rw-r--r--engines/titanic/support/text_cursor.h54
9 files changed, 157 insertions, 23 deletions
diff --git a/engines/titanic/game_manager.cpp b/engines/titanic/game_manager.cpp
index 31bb4278e1..a82488e44e 100644
--- a/engines/titanic/game_manager.cpp
+++ b/engines/titanic/game_manager.cpp
@@ -142,7 +142,7 @@ void CGameManager::update() {
CScreenManager *screenManager = CScreenManager::_screenManagerPtr;
CTextCursor *textCursor = screenManager->_textCursor;
if (textCursor && textCursor->_active)
- _bounds.extend(textCursor->getBounds());
+ _bounds.extend(textCursor->getCursorBounds());
// Set the surface bounds
screenManager->setSurfaceBounds(SURFACE_BACKBUFFER, _bounds);
diff --git a/engines/titanic/pet_control/pet_text.cpp b/engines/titanic/pet_control/pet_text.cpp
index 7f5a5eaed9..77019d7f2d 100644
--- a/engines/titanic/pet_control/pet_text.cpp
+++ b/engines/titanic/pet_control/pet_text.cpp
@@ -30,7 +30,7 @@ CPetText::CPetText(uint count) :
_backR(0xff), _backG(0xff), _backB(0xff),
_textR(0), _textG(0), _textB(200),
_fontNumber2(0), _field64(0), _field68(0), _field6C(0),
- _hasBorder(true), _field74(0), _field78(0), _field7C(0) {
+ _hasBorder(true), _field74(0), _textCursor(nullptr), _field7C(0) {
setupArrays(count);
}
@@ -140,9 +140,8 @@ void CPetText::draw(CScreenManager *screenManager) {
tempRect.grow(-2);
screenManager->setFontNumber(_fontNumber2);
-// int var14 = 0;
-// screenManager->writeLines(0, &var14, _field74, )
- warning("TODO: CPetText_Draw");
+ screenManager->writeString(0, tempRect, _field74, _lines, _textCursor);
+
screenManager->setFontNumber(_fontNumber1);
}
diff --git a/engines/titanic/pet_control/pet_text.h b/engines/titanic/pet_control/pet_text.h
index 35d48974dd..6ce1903166 100644
--- a/engines/titanic/pet_control/pet_text.h
+++ b/engines/titanic/pet_control/pet_text.h
@@ -25,6 +25,7 @@
#include "titanic/support/simple_file.h"
#include "titanic/support/screen_manager.h"
+#include "titanic/support/text_cursor.h"
namespace Titanic {
@@ -57,7 +58,7 @@ private:
int _field6C;
bool _hasBorder;
int _field74;
- int _field78;
+ CTextCursor *_textCursor;
int _field7C;
private:
void setupArrays(int count);
diff --git a/engines/titanic/support/font.cpp b/engines/titanic/support/font.cpp
index 819eaadb33..c6fd871e78 100644
--- a/engines/titanic/support/font.cpp
+++ b/engines/titanic/support/font.cpp
@@ -127,11 +127,60 @@ int STFont::stringWidth(const CString &text) const {
return total;
}
-int STFont::writeString(CVideoSurface *surface, const Point &pt, const CString &str) {
- return 0;
+int STFont::writeString(CVideoSurface *surface, const Rect &rect1, const Rect &destRect,
+ int val1, const CString &str, CTextCursor *textCursor) {
+ if (!_fontHeight || !_dataPtr)
+ return -1;
+
+ Point textSize;
+ Rect destBounds = destRect;
+ destBounds.constrain(rect1);
+ if (destBounds.isEmpty())
+ return -1;
+
+ const char *endP = nullptr;
+ const char *strEndP = str.c_str() + str.size() - 1;
+ for (const char *srcP = str.c_str(); *srcP; ++srcP) {
+ if (*srcP == TEXTCMD_26) {
+ srcP += 3;
+ } else if (*srcP == TEXTCMD_SET_COLOR) {
+ // Change the color used for characters
+ byte r = *++srcP;
+ byte g = *++srcP;
+ byte b = *++srcP;
+ ++srcP;
+ setColor(r, g, b);
+ } else {
+ if (*srcP == ' ') {
+ // Check fo rline wrapping
+ checkLineWrap(textSize, rect1.width(), srcP);
+ if (!*srcP)
+ return endP - str.c_str();
+ }
+
+ if (*srcP != '\n') {
+ int result = writeChar(surface, *srcP, textSize, rect1, &destBounds);
+ if (result == -2)
+ return endP - str.c_str();
+ else if (!result)
+ endP = srcP;
+ }
+
+ if (srcP < strEndP)
+ extendBounds(textSize, *srcP, rect1.width());
+ }
+ }
+
+ if (textCursor && textCursor->get54() == -2) {
+ Point cursorPos(rect1.left + textSize.x, rect1.top + textSize.y);
+ textCursor->setPos(cursorPos);
+ }
+
+ return endP - str.c_str();
}
-int STFont::writeChar(CVideoSurface *surface, unsigned char c, const Point &pt, Rect *destRect, Rect *srcRect) {
+int STFont::writeChar(CVideoSurface *surface, unsigned char c, const Point &pt,
+ const Rect &destRect, const Rect *srcRect) {
if (c == 233)
c = '$';
@@ -140,10 +189,10 @@ int STFont::writeChar(CVideoSurface *surface, unsigned char c, const Point &pt,
tempRect.right = _chars[c]._offset + _chars[c]._width;
tempRect.top = 0;
tempRect.bottom = _fontHeight;
- Point destPos(pt.x + destRect->left, pt.y + destRect->top);
+ Point destPos(pt.x + destRect.left, pt.y + destRect.top);
if (srcRect->isEmpty())
- srcRect = destRect;
+ srcRect = &destRect;
if (destPos.y > srcRect->bottom)
return -2;
diff --git a/engines/titanic/support/font.h b/engines/titanic/support/font.h
index 087680e933..f2d7c471d9 100644
--- a/engines/titanic/support/font.h
+++ b/engines/titanic/support/font.h
@@ -27,6 +27,7 @@
#include "common/array.h"
#include "titanic/support/rect.h"
#include "titanic/support/string.h"
+#include "titanic/support/text_cursor.h"
namespace Titanic {
@@ -51,7 +52,7 @@ private:
* Write a character
*/
int writeChar(CVideoSurface *surface, unsigned char c,
- const Common::Point &pt, Rect *destRect, Rect *srcRect);
+ const Common::Point &pt, const Rect &destRect, const Rect *srcRect);
/**
* Extends a passed text area by the space required for
@@ -87,7 +88,8 @@ public:
/**
* Write a string to the specified surface
*/
- int writeString(CVideoSurface *surface, const Point &pt, const CString &str);
+ int writeString(CVideoSurface *surface, const Rect &rect1, const Rect &destRect,
+ int val1, const CString &str, CTextCursor *textCursor);
/**
* Get the text area a string will fit into
diff --git a/engines/titanic/support/screen_manager.cpp b/engines/titanic/support/screen_manager.cpp
index b467c8593d..3005bdd446 100644
--- a/engines/titanic/support/screen_manager.cpp
+++ b/engines/titanic/support/screen_manager.cpp
@@ -201,7 +201,16 @@ void OSScreenManager::blitFrom(SurfaceNum surfaceNum, CVideoSurface *src,
}
void OSScreenManager::proc12() {}
-void OSScreenManager::proc13() {}
+
+int OSScreenManager::writeString(int surfaceNum, const Rect &destRect,
+ int val1, const CString &str, CTextCursor *textCursor) {
+ if (_backSurfaces.empty())
+ return -1;
+
+ return _fonts[_fontNumber].writeString(_backSurfaces[surfaceNum]._surface,
+ destRect, _backSurfaces[surfaceNum]._bounds, val1, str, textCursor);
+}
+
void OSScreenManager::proc14() {}
void OSScreenManager::setFontColor(byte r, byte g, byte b) {
@@ -273,7 +282,7 @@ void OSScreenManager::loadCursors() {
showCursor();
if (!_textCursor) {
- _textCursor = new CTextCursor();
+ _textCursor = new CTextCursor(this);
}
}
diff --git a/engines/titanic/support/screen_manager.h b/engines/titanic/support/screen_manager.h
index b1e949ad58..7fe60d20b7 100644
--- a/engines/titanic/support/screen_manager.h
+++ b/engines/titanic/support/screen_manager.h
@@ -106,7 +106,17 @@ public:
const Rect *srcRect = nullptr) = 0;
virtual void proc12() = 0;
- virtual void proc13() = 0;
+
+ /**
+ * Write a string
+ * @param surfaceNum Destination surface
+ * @param destRect Bounds within dest surface
+ * @param str Line or lines to write
+ * @param textCursor Optional text cursor pointer
+ */
+ virtual int writeString(int surfaceNum, const Rect &destRect, int val1,
+ const CString &str, CTextCursor *textCursor) = 0;
+
virtual void proc14() = 0;
/**
@@ -226,7 +236,17 @@ public:
const Rect *srcRect = nullptr);
virtual void proc12();
- virtual void proc13();
+
+ /**
+ * Write a string
+ * @param surfaceNum Destination surface
+ * @param destRect Bounds within dest surface
+ * @param str Line or lines to write
+ * @param textCursor Optional text cursor pointer
+ */
+ virtual int writeString(int surfaceNum, const Rect &destRect,
+ int val1, const CString &str, CTextCursor *textCursor);
+
virtual void proc14();
/**
diff --git a/engines/titanic/support/text_cursor.cpp b/engines/titanic/support/text_cursor.cpp
index fd0c1d22dd..2f2ee8af8c 100644
--- a/engines/titanic/support/text_cursor.cpp
+++ b/engines/titanic/support/text_cursor.cpp
@@ -22,15 +22,19 @@
#include "common/textconsole.h"
#include "titanic/support/text_cursor.h"
+#include "titanic/support/screen_manager.h"
namespace Titanic {
-CTextCursor::CTextCursor() : _active(false) {
+CTextCursor::CTextCursor(CScreenManager *screenManager) :
+ _screenManager(screenManager), _priorTicks(300), _active(false),
+ _field24(0), _size(2, 10), _field38(0), _field3C(0),
+ _field44(0), _field48(0), _field4C(0), _field54(-1) {
+ screenManager->createSurface(10, 10);
}
-Rect CTextCursor::getBounds() {
- warning("CTextCursor::getBounds");
- return Rect();
+CTextCursor::~CTextCursor() {
+ delete _surface;
}
} // End of namespace Titanic
diff --git a/engines/titanic/support/text_cursor.h b/engines/titanic/support/text_cursor.h
index b6480673eb..d9dbce0988 100644
--- a/engines/titanic/support/text_cursor.h
+++ b/engines/titanic/support/text_cursor.h
@@ -28,13 +28,63 @@
namespace Titanic {
+class CScreenManager;
+class CVideoSurface;
+
class CTextCursor {
+private:
+ CScreenManager *_screenManager;
+ Point _pos;
+ Rect _bounds;
+ uint _priorTicks;
+ int _field24;
+ Point _size;
+ int _field38;
+ int _field3C;
+ int _field44;
+ int _field48;
+ int _field4C;
+ CVideoSurface *_surface;
+ int _field54;
public:
bool _active;
public:
- CTextCursor();
+ CTextCursor(CScreenManager *screenManager);
+ ~CTextCursor();
+
+ /**
+ * Sets the position of the cursor
+ */
+ void setPos(const Point &pt) { _pos = pt; }
+
+ /**
+ * Sets the size of the cursor
+ */
+ void setSize(const Point &size) { _size = size; }
+
+ /**
+ * Returns the bounds for the cursor
+ */
+ Rect getCursorBounds() const {
+ return Rect(_pos.x, _pos.y, _pos.x + _size.x, _pos.y + _size.y);
+ }
+
+ /**
+ * Set bounds
+ */
+ void setBounds(const Rect &r) { _bounds = r; }
+
+ /**
+ * Clear the bounds
+ */
+ void clearBounds() { _bounds.clear(); }
+
+ /**
+ * Set the prior ticks
+ */
+ void setTicks(uint ticks) { _priorTicks = ticks; }
- Rect getBounds();
+ int get54() const { return _field54; }
};
} // End of namespace Titanic