aboutsummaryrefslogtreecommitdiff
path: root/engines/drascula/graphics.cpp
diff options
context:
space:
mode:
authorThierry Crozat2016-04-13 21:08:17 +0100
committerThierry Crozat2016-04-13 21:08:31 +0100
commit323549316decba7460edb346a950890b26585ccc (patch)
treea8679acd3d6baaf9f52e6a572a1fcef65df4e111 /engines/drascula/graphics.cpp
parentb4a3c06d911c488c8afc10ea3405b1d8ac053ef3 (diff)
downloadscummvm-rg350-323549316decba7460edb346a950890b26585ccc.tar.gz
scummvm-rg350-323549316decba7460edb346a950890b26585ccc.tar.bz2
scummvm-rg350-323549316decba7460edb346a950890b26585ccc.zip
DRASCULA: Improve text centering
When splitting strings into several lines to fit on the screen the original engine could result in lines with one character beyond the right edge of the screen, which in practice would be drawn on the next line on its own, aligned to the left (and not centered). This commits adds a check to avoid this situation. So although it now behaves slightly differently than the original engine this is for the better.
Diffstat (limited to 'engines/drascula/graphics.cpp')
-rw-r--r--engines/drascula/graphics.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/engines/drascula/graphics.cpp b/engines/drascula/graphics.cpp
index 4ed949cc99..01bd267158 100644
--- a/engines/drascula/graphics.cpp
+++ b/engines/drascula/graphics.cpp
@@ -319,12 +319,27 @@ int DrasculaEngine::print_abc_opc(const char *said, int screenY, int game) {
}
bool DrasculaEngine::textFitsCentered(char *text, int x) {
- int halfLen = (strlen(text) / 2) * CHAR_WIDTH;
+ int textLen = strlen(text);
+ int halfLen = (textLen / 2) * CHAR_WIDTH;
- // See comment in centerText()
+ //if (x > 160)
+ // x = 315 - x;
+ //return (halfLen <= x);
+
+ // The commented out code above is what the original engine is doing. Instead of testing the
+ // upper bound if x is greater than 160 it takes the complement to 315 and test only the lower
+ // bounds.
+ // Also note that since it does an integer division to compute the half length of the string,
+ // in the case where the string has an odd number of characters there is one more character to
+ // the right than to the left. If the string center is beyond 160, this is taken care of by
+ // taking the complement to 315 instead of 320. But if the string center is close to the screen
+ // center, but not greater than 160, this can lead to the string being accepted despite having
+ // one character beyond the right edge of the screen.
+ // In ScummVM we therefore also test the right edge, which leads to differences
+ // with the original engine, but for the better.
if (x > 160)
- x = 315 - x;
- return (halfLen <= x);
+ return (315 - x - halfLen >= 0);
+ return (x - halfLen >= 0 && x + halfLen + (textLen % 2) * CHAR_WIDTH <= 320);
}
void DrasculaEngine::centerText(const char *message, int textX, int textY) {
@@ -337,13 +352,7 @@ void DrasculaEngine::centerText(const char *message, int textX, int textY) {
// return (x - halfLen >= 0 && x + halfLen <= 319);
// The engines does things differently though. It tries to clips text at 315 instead of 319.
- // And instead of testing the upper bound if x is greater than 160 it takes the complement to 315
- // and test only the lower bounds. However since 160 is not the middle of 315, we end up having
- // text that can go beyond 315 (up to 320) if x is in [159, 160].
- // Also note that if the numbers of characters is odd, there is one more character to the right
- // than to the left as it computes the half length with an integer division by two BEFORE multiplying
- // by CHAR_WIDTH. Thus in theory we may end up with one character out of the screen!
- // Be faithfull to the original and do the same though.
+ // See also the comment in textFitsCentered().
textX = CLIP<int>(textX, 60, 255);