Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

@eriktorbjorn
Copy link
Member

@eriktorbjorn eriktorbjorn commented Oct 13, 2021

This is an attempt, albeit not yet quite successful, at addressing the text centering issues described in https://bugs.scummvm.org/ticket/12984

The theory is that the main problem is that ScummVM currently measures the width of a string by dividing the width of every character in the string by two (to get the low-resolution width), and taking the sum of that.

With this change, it adds the high-resolution width of all the character widths, and then divides that sum by two.

To do this, I had to make getStringWidth() a virtual function so that each character renderer define their own. I don't know if this is the best way to do it, since that means each character renderer has to handle escape sequences in the strings if they want to define their own. But if only one single character renderer has to define its own, and it's a really simple one... well, maybe that's not so bad after all?

How simple is it? Well, I played through all of Loom and only saw it use 255 + 1 to indicate line break. In Indy 3 (which I only played a few bits of) I didn't see any escape sequences at all.

Unfortunately, while the result seems to be an improvement in general, there are still places where it's not pixel perfect and I have no idea why. I'm attaching a series of screenshots to demonstrate, and will add a comment about the observed results. (I recommend opening the pictures in separate browser tabs to make it easier to compare them.)

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.
@@ -538,7 +538,7 @@ int CharsetRenderer::getStringWidth(int arg, const byte *text, uint strLenMax) {
if (arg == 1)
break;
while (text[pos++] == ' ')
;
;
Copy link
Contributor

@einstein95 einstein95 Oct 13, 2021

accidental whitespace?

Copy link
Member Author

@eriktorbjorn eriktorbjorn Oct 13, 2021

No, I thought the original indentation looked wrong with the semicolon at the same indentation level as the "while".

Though based on https://wiki.scummvm.org/index.php/Code_Formatting_Conventions I should have added a set of empty braces instead, so I guess I'll go ahead and do that...

@eriktorbjorn
Copy link
Member Author

@eriktorbjorn eriktorbjorn commented Oct 13, 2021

Screenshot from Mac emulator. Interestingly, it seems the bottom pixels of the "y" in the "Refer to your ..." line are truncated. ScummVM does not have this glitch.
original-00000

Screenshot from unmodified ScummVM. Only the text "EXPERT" is in the correct position
scummvm-00000

Screenshot from ScummVM after this change. Everything is in the correct position except the "Select a Proficiency ..." line, which is a bit too far to the right.
scummvm-new-00000

@eriktorbjorn
Copy link
Member Author

@eriktorbjorn eriktorbjorn commented Oct 13, 2021

Screenshot from Mac emulator. Again, the "y" in the bottom row is slightly truncated.
original-00001

Screenshot from unmodified ScummVM. Only "Beat" is in the correct position.
scummvm-00001

Screenshot from ScummVM after this change. Everything appears to be in the correct position.
scummvm-new-00001

@eriktorbjorn
Copy link
Member Author

@eriktorbjorn eriktorbjorn commented Oct 13, 2021

Screenshot from Mac emulator.
original-00002

Screenshot from unmodified ScummVM. Both lines are in the wrong position.
scummvm-00002

Screenshot from ScummVM after this change. Both lines are still in the wrong position, but perhaps by a little less? The second line is in the same position as before the change.
scummvm-new-00002

@eriktorbjorn
Copy link
Member Author

@eriktorbjorn eriktorbjorn commented Oct 13, 2021

Screenshot from Mac emulator.
original-00003

Screenshot from unmodified ScummVM. Text is already correctly positioned.
scummvm-00003

Screenshot from ScummVM after this change. Text is still correctly positioned.
scummvm-new-00003

@eriktorbjorn
Copy link
Member Author

@eriktorbjorn eriktorbjorn commented Oct 13, 2021

Screenshot from Mac emulator.
original-00004

Screenshot from unmodified ScummVM. "It's trying to open!" and "egg" are out of place. The color of the note names is wrong, as is the text shadowing for them. I've seen that problem in the past. I don't know what's causing either of them.
scummvm-00004

Screenshot from ScummVM after this change. All text is in the correct place. The other issues remain.
scummvm-new-00004

@eriktorbjorn
Copy link
Member Author

@eriktorbjorn eriktorbjorn commented Oct 13, 2021

Screenshot from Mac emulator.
original-00005

Screenshot from unmodified ScummVM. The text looks correct.
scummvm-00005

Screenshot from ScummVM after this change. Everything still looks correct.
scummvm-new-00005

@eriktorbjorn
Copy link
Member Author

@eriktorbjorn eriktorbjorn commented Oct 13, 2021

Screenshot from Mac emulator. The original has incorrect spacing between letters, which makes it hard to say what's right or wrong.
original-00006

Screenshot from unmodified ScummVM.
scummvm-00006

Screenshot from ScummVM after this change. The leftmost character of each line appears in the same position as in the original, which could be seen as an improvement over unmodified ScummVM.
scummvm-new-00006

@eriktorbjorn
Copy link
Member Author

@eriktorbjorn eriktorbjorn commented Oct 13, 2021

Screenshot from Mac emulator. The original has incorrect spacing between letters, which makes it hard to say what's right or wrong.
original-00007

Screenshot from unmodified ScummVM. Only "1938" appears in the same position as the original.
scummvm-00007

Screenshot from ScummVM after this change. The leftmost character of each line appears in the same position as in the original, which could be seen as an improvement over unmodified ScummVM.
scummvm-new-00007

@eriktorbjorn
Copy link
Member Author

@eriktorbjorn eriktorbjorn commented Oct 13, 2021

Screenshot from Mac emulator. The original has incorrect spacing between letters, which makes it hard to say what's right or wrong.
original-00008

Screenshot from unmodified ScummVM. The leftmost characters all appear in the same position as in the original.
scummvm-00008

Screenshot from ScummVM after this change. Nothing has changed compared to before the change.
scummvm-new-00008

It's mandatory in our code formatting conventions.
As far as I know, that's the only game that uses the Nut charset
renderer.
@eriktorbjorn
Copy link
Member Author

@eriktorbjorn eriktorbjorn commented Oct 14, 2021

Ideas that don't work:

  • Always rounding up when dividing by two. This fixes the positions of some texts, but messes up others.
  • Counting linebreaks as adding 1 to the width. This fixes the position of some texts, but messes up others.

Observation: The real width of the string will be divided by two twice: Once by getStringWidth(), and once by the code that centers the text. That means that there are several possible widths that would result in the same offset position. But I couldn't find any way to take advantage of that either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants