SCUMM: Center text better in Mac Loom (bug #12984)

Measure the whole string before dividing the length by 2 to get the
low-res width of the string. Before, each character width was divided
which led to rounding errors. The result is better, but not pixel
perfect. I'm not sure what I'm still getting wrong.
This commit is contained in:
Torbjörn Andersson 2021-10-13 14:31:55 +02:00 committed by Torbjörn Andersson
parent fb3b9d2c1d
commit 4cf42c6dac
2 changed files with 22 additions and 2 deletions

View File

@ -538,7 +538,7 @@ int CharsetRenderer::getStringWidth(int arg, const byte *text, uint strLenMax) {
if (arg == 1)
break;
while (text[pos++] == ' ')
;
;
continue;
}
if (chr == 10 || chr == 21 || chr == 12 || chr == 13) {
@ -1666,6 +1666,25 @@ void CharsetRendererMac::setCurID(int32 id) {
_curId = id;
}
int CharsetRendererMac::getStringWidth(int arg, const byte *text, uint strLenMax) {
int pos = 0;
int width = 0;
int chr;
while ((chr = text[pos++]) != 0) {
// The only control codes I've seen in use are line breaks in
// Loom. In Indy 3, I haven't seen anything at all like it.
if (chr == 255) {
chr = text[pos++];
if (chr == 1) // 'Newline'
break;
}
width += _macFonts[_curId].getCharWidth(chr);
}
return width / 2;
}
// HACK: Usually, we want the approximate width and height in the unscaled
// graphics resolution. But for font 1 in Indiana Jones and the Last
// crusade we want the actual dimensions for drawing the text boxes.

View File

@ -97,7 +97,7 @@ public:
virtual void printChar(int chr, bool ignoreCharsetMask) = 0;
virtual void drawChar(int chr, Graphics::Surface &s, int x, int y) {}
int getStringWidth(int a, const byte *str, uint strLenMax = 100000);
virtual int getStringWidth(int arg, const byte *text, uint strLenMax = 100000);
void addLinebreaks(int a, byte *str, int pos, int maxwidth);
void translateColor();
@ -294,6 +294,7 @@ public:
~CharsetRendererMac() override;
void setCurID(int32 id) override;
int getStringWidth(int arg, const byte *text, uint strLenMax = 100000);
int getFontHeight() override;
int getCharWidth(uint16 chr) override;
void printChar(int chr, bool ignoreCharsetMask) override;