aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/support
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-04 00:07:50 -0400
committerPaul Gilbert2016-04-04 00:07:50 -0400
commit56b29987443075faba0495d84eeaf42b443d577f (patch)
tree94c2bbd841ca2cf802d28d61fa6a5ed678ec3b2f /engines/titanic/support
parentebdc773247fb1e6a41f58ee8336986dcdc8e75d6 (diff)
downloadscummvm-rg350-56b29987443075faba0495d84eeaf42b443d577f.tar.gz
scummvm-rg350-56b29987443075faba0495d84eeaf42b443d577f.tar.bz2
scummvm-rg350-56b29987443075faba0495d84eeaf42b443d577f.zip
TITANIC: Further work on STFont character drawing
Diffstat (limited to 'engines/titanic/support')
-rw-r--r--engines/titanic/support/font.cpp82
-rw-r--r--engines/titanic/support/font.h36
-rw-r--r--engines/titanic/support/video_surface.cpp5
-rw-r--r--engines/titanic/support/video_surface.h10
4 files changed, 117 insertions, 16 deletions
diff --git a/engines/titanic/support/font.cpp b/engines/titanic/support/font.cpp
index 6636a84f22..32652588c0 100644
--- a/engines/titanic/support/font.cpp
+++ b/engines/titanic/support/font.cpp
@@ -30,11 +30,9 @@ namespace Titanic {
STFont::STFont() {
_dataPtr = nullptr;
_dataSize = 0;
- _field8 = 0;
- _maxCharWidth = 0;
- _field810 = 0;
- _field814 = 0;
- _field818 = 0;
+ _fontHeight = 0;
+ _dataWidth = 0;
+ _fontR = _fontG = _fontB = 0;
}
STFont::~STFont() {
@@ -48,10 +46,10 @@ void STFont::load(int fontNumber) {
if (!stream)
error("Could not locate the specified font");
- _field8 = stream->readUint32LE();
- _maxCharWidth = stream->readUint32LE();
+ _fontHeight = stream->readUint32LE();
+ _dataWidth = stream->readUint32LE();
for (uint idx = 0; idx < 256; ++idx)
- _chars[idx]._charWidth = stream->readUint32LE();
+ _chars[idx]._width = stream->readUint32LE();
for (uint idx = 0; idx < 256; ++idx)
_chars[idx]._offset = stream->readUint32LE();
@@ -62,6 +60,16 @@ void STFont::load(int fontNumber) {
delete stream;
}
+void STFont::setColor(byte r, byte g, byte b) {
+ _fontR = r;
+ _fontG = g;
+ _fontB = b;
+}
+
+uint16 STFont::getColor() const {
+ return g_system->getScreenFormat().RGBToColor(_fontR, _fontG, _fontB);
+}
+
void STFont::writeString(int maxWidth, const CString &text, int *v1, int *v2) {
warning("TODO: STFont::writeString");
}
@@ -81,11 +89,67 @@ int STFont::stringWidth(const CString &text) const {
// Skip over command parameter bytes
srcP += 4;
} else if (c != '\n') {
- total += _chars[c]._charWidth;
+ total += _chars[c]._width;
}
}
return total;
}
+int STFont::writeChar(CVideoSurface *surface, unsigned char c, const Common::Point &pt, Rect *destRect, Rect *srcRect) {
+ if (c == 233)
+ c = '$';
+
+ Rect tempRect;
+ tempRect.left = _chars[c]._offset;
+ tempRect.right = _chars[c]._offset + _chars[c]._width;
+ tempRect.top = 0;
+ tempRect.bottom = _fontHeight;
+ Point destPos(pt.x + destRect->left, pt.y + destRect->top);
+
+ if (srcRect->isEmpty())
+ srcRect = destRect;
+ if (destPos.y > srcRect->bottom)
+ return -2;
+
+ if ((destPos.y + tempRect.height()) > srcRect->bottom) {
+ tempRect.bottom += tempRect.top - destPos.y;
+ }
+
+ if (destPos.y < srcRect->top) {
+ if ((tempRect.height() + destPos.y) < srcRect->top)
+ return -1;
+
+ tempRect.top += srcRect->top - destPos.y;
+ destPos.y = srcRect->top;
+ }
+
+ if (destPos.x < srcRect->left) {
+ if ((tempRect.width() + destPos.x) < srcRect->left)
+ return -3;
+
+ tempRect.left += srcRect->left - destPos.x;
+ destPos.x = srcRect->left;
+ } else {
+ if ((tempRect.width() + destPos.x) > srcRect->right) {
+ if (destPos.x > srcRect->right)
+ return -4;
+
+ tempRect.right += srcRect->left - destPos.x;
+ }
+ }
+
+ copyRect(surface, destPos, tempRect);
+ return 0;
+}
+
+void STFont::copyRect(CVideoSurface *surface, const Common::Point &pt, Rect &rect) {
+ if (surface->lock()) {
+ uint16 *lineP = surface->getBasePtr(pt.x, pt.y);
+ uint16 color = getColor();
+
+ surface->unlock();
+ }
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/support/font.h b/engines/titanic/support/font.h
index c41f4dc1e0..5ed0b5b7b4 100644
--- a/engines/titanic/support/font.h
+++ b/engines/titanic/support/font.h
@@ -25,24 +25,38 @@
#include "common/scummsys.h"
#include "common/array.h"
+#include "titanic/support/rect.h"
#include "titanic/support/string.h"
namespace Titanic {
+class CVideoSurface;
+
class STFont {
struct CharEntry {
- uint _charWidth;
+ uint _width;
uint _offset;
};
+private:
+ /**
+ * Copys a rectangle representing a character in the font data to
+ * a given destination position in the surface
+ */
+ void copyRect(CVideoSurface *surface, const Common::Point &destPos,
+ Rect &srcRect);
+
+ /**
+ * Write a character
+ */
+ int writeChar(CVideoSurface *surface, unsigned char c,
+ const Common::Point &pt, Rect *destRect, Rect *srcRect);
public:
byte *_dataPtr;
size_t _dataSize;
- int _field8;
- int _maxCharWidth;
+ int _fontHeight;
+ uint _dataWidth;
CharEntry _chars[256];
- int _field810;
- int _field814;
- int _field818;
+ byte _fontR, _fontG, _fontB;
public:
STFont();
~STFont();
@@ -62,6 +76,16 @@ public:
* TODO: Verify this
*/
void writeString(int maxWidth, const CString &text, int *v1, int *v2);
+
+ /**
+ * Sets the font color
+ */
+ void setColor(byte r, byte g, byte b);
+
+ /**
+ * Gets the font color
+ */
+ uint16 getColor() const;
};
} // End of namespace Titanic
diff --git a/engines/titanic/support/video_surface.cpp b/engines/titanic/support/video_surface.cpp
index 6bba24de5f..ebe552a062 100644
--- a/engines/titanic/support/video_surface.cpp
+++ b/engines/titanic/support/video_surface.cpp
@@ -373,4 +373,9 @@ int OSVideoSurface::freeSurface() {
return surfaceSize;
}
+uint16 *OSVideoSurface::getBasePtr(int x, int y) {
+ assert(_rawSurface);
+ return (uint16 *)_rawSurface->getBasePtr(x, y);
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/support/video_surface.h b/engines/titanic/support/video_surface.h
index 1de6a1dd34..da53270122 100644
--- a/engines/titanic/support/video_surface.h
+++ b/engines/titanic/support/video_surface.h
@@ -176,7 +176,10 @@ public:
*/
virtual int freeSurface() { return 0; }
-
+ /**
+ * Get a pointer into the underlying surface
+ */
+ virtual uint16 *getBasePtr(int x, int y) = 0;
/**
* Blit from another surface
@@ -299,6 +302,11 @@ public:
* Frees the underlying surface
*/
virtual int freeSurface();
+
+ /**
+ * Get a pointer into the underlying surface
+ */
+ virtual uint16 *getBasePtr(int x, int y);
};
} // End of namespace Titanic