aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/graphics/text32.cpp
diff options
context:
space:
mode:
authorFilippos Karapetis2011-10-08 17:16:58 +0300
committerFilippos Karapetis2011-10-08 17:19:00 +0300
commit4ad2ebd9959a8413c0d00cd7498ac4166edfe886 (patch)
treea663c3cae3cdecd205b38c950cb888a3b24e6db5 /engines/sci/graphics/text32.cpp
parent2ffdd0d3b7d06d072c11db06cb4017d9948b205b (diff)
downloadscummvm-rg350-4ad2ebd9959a8413c0d00cd7498ac4166edfe886.tar.gz
scummvm-rg350-4ad2ebd9959a8413c0d00cd7498ac4166edfe886.tar.bz2
scummvm-rg350-4ad2ebd9959a8413c0d00cd7498ac4166edfe886.zip
SCI2+: Some groundwork for kTextSize()
The old behavior is currently hacked in inside kernelTextSize(), as the top of the subtitles frame is wrong if kTextWidth() is properly working...
Diffstat (limited to 'engines/sci/graphics/text32.cpp')
-rw-r--r--engines/sci/graphics/text32.cpp94
1 files changed, 90 insertions, 4 deletions
diff --git a/engines/sci/graphics/text32.cpp b/engines/sci/graphics/text32.cpp
index 21372f1502..f13a56fa17 100644
--- a/engines/sci/graphics/text32.cpp
+++ b/engines/sci/graphics/text32.cpp
@@ -74,7 +74,7 @@ void GfxText32::createTextBitmap(reg_t textObject) {
}
// TODO: Finish this!
-void GfxText32::drawTextBitmap(reg_t textObject, uint16 textX, uint16 textY, uint16 w) {
+void GfxText32::drawTextBitmap(reg_t textObject, uint16 textX, uint16 textY, uint16 planeWidth) {
uint32 textId = (textObject.segment << 16) | textObject.offset;
if (!_textCache.contains(textId))
@@ -90,11 +90,19 @@ void GfxText32::drawTextBitmap(reg_t textObject, uint16 textX, uint16 textY, uin
const char *txt = entry->text.c_str();
int16 charCount;
+ uint16 maxWidth = (planeWidth > 0) ? planeWidth : _screen->getWidth() - textX;
while (*txt) {
- charCount = GetLongest(txt, w, font);
- if (charCount == 0)
- break;
+ charCount = GetLongest(txt, maxWidth, font);
+ if (charCount == 0) {
+ // If the text does not fit inside the given plane, use the
+ // whole screen.
+ // TODO/FIXME: Is this really needed? Perhaps some other
+ // functionality is missing instead?
+ charCount = GetLongest(txt, _screen->getWidth() - textX, font);
+ if (charCount == 0)
+ break;
+ }
uint16 curX = textX;
@@ -235,4 +243,82 @@ int16 GfxText32::GetLongest(const char *text, int16 maxWidth, GfxFont *font) {
return maxChars;
}
+void GfxText32::kernelTextSize(const char *text, int16 font, int16 maxWidth, int16 *textWidth, int16 *textHeight) {
+ Common::Rect rect(0, 0, 0, 0);
+ Size(rect, text, font, maxWidth);
+ *textWidth = rect.width();
+ *textHeight = rect.height();
+
+ // TODO: Setting textWidth properly changes the subtitle plane top to 0.
+ // I have no idea why, so we currently hack in the old behavior here.
+ *textWidth = 0;
+ *textHeight = 0;
+}
+
+void GfxText32::StringWidth(const char *str, GuiResourceId fontId, int16 &textWidth, int16 &textHeight) {
+ Width(str, 0, (int16)strlen(str), fontId, textWidth, textHeight, true);
+}
+
+void GfxText32::Width(const char *text, int16 from, int16 len, GuiResourceId fontId, int16 &textWidth, int16 &textHeight, bool restoreFont) {
+ uint16 curChar;
+ textWidth = 0; textHeight = 0;
+
+ GfxFont *font = _cache->getFont(fontId);
+
+ if (font) {
+ text += from;
+ while (len--) {
+ curChar = (*(const byte *)text++);
+ switch (curChar) {
+ case 0x0A:
+ case 0x0D:
+ case 0x9781: // this one is used by SQ4/japanese as line break as well
+ textHeight = MAX<int16> (textHeight, font->getHeight());
+ break;
+ case 0x7C:
+ warning("Code processing isn't implemented in SCI32");
+ break;
+ default:
+ textHeight = MAX<int16> (textHeight, font->getHeight());
+ textWidth += font->getCharWidth(curChar);
+ break;
+ }
+ }
+ }
+}
+
+int16 GfxText32::Size(Common::Rect &rect, const char *text, GuiResourceId fontId, int16 maxWidth) {
+ int16 charCount;
+ int16 maxTextWidth = 0, textWidth;
+ int16 totalHeight = 0, textHeight;
+
+ rect.top = rect.left = 0;
+ GfxFont *font = _cache->getFont(fontId);
+
+ if (maxWidth < 0) { // force output as single line
+ StringWidth(text, fontId, textWidth, textHeight);
+ rect.bottom = textHeight;
+ rect.right = textWidth;
+ } else {
+ // rect.right=found widest line with RTextWidth and GetLongest
+ // rect.bottom=num. lines * GetPointSize
+ rect.right = (maxWidth ? maxWidth : 192);
+ const char *curPos = text;
+ while (*curPos) {
+ charCount = GetLongest(curPos, rect.right, font);
+ if (charCount == 0)
+ break;
+ Width(curPos, 0, charCount, fontId, textWidth, textHeight, false);
+ maxTextWidth = MAX(textWidth, maxTextWidth);
+ totalHeight += textHeight;
+ curPos += charCount;
+ while (*curPos == ' ')
+ curPos++; // skip over breaking spaces
+ }
+ rect.bottom = totalHeight;
+ rect.right = maxWidth ? maxWidth : MIN(rect.right, maxTextWidth);
+ }
+ return rect.right;
+}
+
} // End of namespace Sci