Skip to content

Commit

Permalink
XEEN: Fixes for text display
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jan 1, 2015
1 parent 4a953b0 commit fb6e805
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
50 changes: 41 additions & 9 deletions engines/xeen/font.cpp
Expand Up @@ -76,22 +76,24 @@ Common::String FontSurface::writeString(const Common::String &s, const Common::R
assert(_fontData);

for (;;) {
const char *msgStartP = _displayString;
_msgWraps = false;

// Get the size of the string that can be displayed on the likne
int xp = _fontJustify ? bounds.left : _writePos.x;
// Get the size of the string that can be displayed on the line
int xp = _fontJustify == JUSTIFY_CENTER ? bounds.left : _writePos.x;
while (!getNextCharWidth(xp)) {
if (xp >= bounds.right) {
--_displayString;
_msgWraps = true;
break;
}
}

// Get the end point of the text that can be displayed
const char *displayEnd = _displayString;
_displayString = s.c_str();
_displayString = msgStartP;

if (*displayEnd && _fontJustify != JUSTIFY_RIGHT && xp >= bounds.right) {
if (_msgWraps && _fontJustify != JUSTIFY_RIGHT && xp >= bounds.right) {
// Need to handle justification of text
// First, move backwards to find the end of the previous word
// for a convenient point to break the line at
Expand All @@ -116,6 +118,34 @@ Common::String FontSurface::writeString(const Common::String &s, const Common::R
}
}

// Justification adjustment
if (_fontJustify != JUSTIFY_NONE) {
// Figure out the width of the selected portion of the string
int totalWidth = 0;
while (!getNextCharWidth(totalWidth)) {
if (_displayString > displayEnd && *displayEnd == ' ') {
// Don't include any ending space as part of the total
totalWidth -= _fontReduced ? 4 : 5;
}
}

// Reset starting position back to the start of the string portion
_displayString = msgStartP;

if (_fontJustify == JUSTIFY_RIGHT) {
// Right aligned
if (_writePos.x == bounds.left)
_writePos.x = bounds.right;
_writePos.x -= totalWidth + 1;
} else {
// Center aligned
if (_writePos.x == bounds.left)
_writePos.x = (bounds.left + bounds.right + 1 - totalWidth) / 2;
else
_writePos.x = (_writePos.x * 2 - totalWidth) / 2;
}
}

// Main character display loop
while (_displayString <= displayEnd) {
char c = getNextChar();
Expand Down Expand Up @@ -195,26 +225,28 @@ Common::String FontSurface::writeString(const Common::String &s, const Common::R
if (newLine(bounds))
break;
} else if (c == 11) {
// Skip y position
// Set y position
int yp = fontAtoi();
_writePos.y = MIN(bounds.top + yp, (int)bounds.bottom);
} else if (c == 12) {
// Set text colors
int idx = fontAtoi();
int idx = fontAtoi(2);
if (idx < 0)
idx = 0;
setTextColor(idx);
} else if (c < ' ') {
// Invalid command
displayEnd = nullptr;
// End of string or invalid command
_displayString = nullptr;
break;
} else {
// Standard character - write it out
writeChar(c);
}
}

if (_displayString > displayEnd && _fontJustify != JUSTIFY_RIGHT && _msgWraps
if (!_displayString)
break;
if ( _displayString > displayEnd && _fontJustify != JUSTIFY_RIGHT && _msgWraps
&& newLine(bounds))
break;
}
Expand Down
4 changes: 2 additions & 2 deletions engines/xeen/menus.cpp
Expand Up @@ -362,9 +362,9 @@ void WorldOptionsMenu::showContents(SpriteResource &title1, bool waitFlag) {
title1.draw(screen._windows[0], 0);
screen._windows[28].frame();

screen._windows[28].writeString("\r\x01\x03c\fdMight and Magic Options\n"
screen._windows[28].writeString("\x0D\x01\003c\014dMight and Magic Options\n"
"World of Xeen\x02\n"
"117Copyright (c) 1993 NWC, Inc.\n"
"\v117Copyright (c) 1993 NWC, Inc.\n"
"All Rights Reserved\x01");

for (uint btnIndex = 0; btnIndex < _buttons.size(); ++btnIndex) {
Expand Down
3 changes: 2 additions & 1 deletion engines/xeen/screen.cpp
Expand Up @@ -259,7 +259,8 @@ void Screen::update() {
}

void Screen::addDirtyRect(const Common::Rect &r) {
assert(r.isValidRect() && r.width() > 0 && r.height() > 0);
assert(r.isValidRect() && r.width() > 0 && r.height() > 0
&& r.right <= SCREEN_WIDTH && r.bottom <= SCREEN_HEIGHT);
_dirtyRects.push_back(r);
}

Expand Down

0 comments on commit fb6e805

Please sign in to comment.