[Scummvm-git-logs] scummvm master -> b611b1dd4e4e219e683c38d5b1a5a0c1dad8037f
aquadran
noreply at scummvm.org
Sun Nov 22 06:44:08 UTC 2026
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
b611b1dd4e GRIM: Fix margin on speech near the window edges
Commit: b611b1dd4e4e219e683c38d5b1a5a0c1dad8037f
https://github.com/scummvm/scummvm/commit/b611b1dd4e4e219e683c38d5b1a5a0c1dad8037f
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2026-11-22T07:44:04+01:00
Commit Message:
GRIM: Fix margin on speech near the window edges
The original engines for Grim and EMI use the width of the widest word
to decide how much padding to use
Fixes #11790
Changed paths:
engines/grim/textobject.cpp
engines/grim/textobject.h
diff --git a/engines/grim/textobject.cpp b/engines/grim/textobject.cpp
index a0d59b0f6d4..ba2c73afd52 100644
--- a/engines/grim/textobject.cpp
+++ b/engines/grim/textobject.cpp
@@ -163,6 +163,26 @@ void TextObject::invalidate() {
}
}
+template <typename S>
+int TextObject::getWidestWord(const S &msg, const Font *font) {
+ int widest = 0;
+ int width = 0;
+ bool inWord = false;
+ for (uint i = 0; i < msg.size(); i++) {
+ const typename S::value_type c = msg[i];
+ if (c == '\n' || (c == ' ' && inWord)) {
+ widest = MAX(widest, width);
+ width = 0;
+ inWord = false;
+ continue;
+ }
+ if (c != ' ')
+ inWord = true;
+ width += font->getCharKernedWidth(c);
+ }
+ return MAX(widest, width);
+}
+
template <typename S>
void TextObject::setupTextReal(S msg, Common::String (*convert)(const S &s)) {
S message;
@@ -186,16 +206,16 @@ void TextObject::setupTextReal(S msg, Common::String (*convert)(const S &s)) {
// format the output message to incorporate line wrapping
// (if necessary) for the text object
const int SCREEN_WIDTH = _width ? _width : 640;
- const int SCREEN_MARGIN = SCREEN_WIDTH / 10;
+ const int SCREEN_MARGIN = 40;
// If the speaker is too close to the edge of the screen we have to make
// some room for the subtitles.
if (_isSpeech) {
- if (_x < SCREEN_MARGIN) {
- _x = SCREEN_MARGIN;
- } else if (SCREEN_WIDTH - _x < SCREEN_MARGIN) {
- _x = SCREEN_WIDTH - SCREEN_MARGIN;
- }
+ const int halfWidth = getWidestWord(msg, _font) / 2;
+ if (_x - halfWidth < SCREEN_MARGIN)
+ _x = halfWidth + SCREEN_MARGIN;
+ if (_x + halfWidth > SCREEN_WIDTH - SCREEN_MARGIN)
+ _x = SCREEN_WIDTH - halfWidth - SCREEN_MARGIN;
}
// The maximum width for any line of text is determined by the justification
diff --git a/engines/grim/textobject.h b/engines/grim/textobject.h
index 52e7aa7e283..ecde5d4b69a 100644
--- a/engines/grim/textobject.h
+++ b/engines/grim/textobject.h
@@ -149,6 +149,8 @@ protected:
int _stackLevel;
private:
+ template <typename S>
+ int getWidestWord(const S &msg, const Font *font);
template <typename S>
void setupTextReal(S msg, Common::String (*convert)(const S &s));
};
More information about the Scummvm-git-logs
mailing list