[Scummvm-git-logs] scummvm master -> 87beb98b95cb258d77853502e34c1747acff6771
sev-
sev at scummvm.org
Fri Oct 16 21:59:43 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
87beb98b95 GRAPHICS: Turn set of bool parameters for wordWrap() to a bitfield
Commit: 87beb98b95cb258d77853502e34c1747acff6771
https://github.com/scummvm/scummvm/commit/87beb98b95cb258d77853502e34c1747acff6771
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-10-16T23:52:18+02:00
Commit Message:
GRAPHICS: Turn set of bool parameters for wordWrap() to a bitfield
Changed paths:
engines/bladerunner/subtitles.cpp
graphics/font.cpp
graphics/font.h
diff --git a/engines/bladerunner/subtitles.cpp b/engines/bladerunner/subtitles.cpp
index 4937ae72fe..ce4a6a38ac 100644
--- a/engines/bladerunner/subtitles.cpp
+++ b/engines/bladerunner/subtitles.cpp
@@ -368,7 +368,7 @@ void Subtitles::draw(Graphics::Surface &s) {
if (_currentText != _prevText) {
lines.clear();
_prevText = _currentText;
- _font->wordWrapText(_currentText, kTextMaxWidth, lines, 0, true, true);
+ _font->wordWrapText(_currentText, kTextMaxWidth, lines, 0, Graphics::kWordWrapEvenWidthLines | Graphics::kWordWrapOnExplicitNewLines);
}
int y = s.h - (kMarginBottom + MAX(kPreferedLine, lines.size()) * _font->getFontHeight());
diff --git a/graphics/font.cpp b/graphics/font.cpp
index 8b8e7d0407..8567c0361f 100644
--- a/graphics/font.cpp
+++ b/graphics/font.cpp
@@ -150,7 +150,7 @@ struct WordWrapper {
};
template<class StringType>
-int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Common::Array<StringType> &lines, int initWidth, bool evenWidthLinesModeEnabled, bool wrapOnExplicitNewLines) {
+int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Common::Array<StringType> &lines, int initWidth, uint32 mode) {
WordWrapper<StringType> wrapper(lines);
StringType line;
StringType tmpStr;
@@ -180,7 +180,7 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
// If both are set to true and there are new line characters in the text,
// then "Even Width Lines" mode is disabled.
//
- if (evenWidthLinesModeEnabled) {
+ if (mode & kWordWrapEvenWidthLines) {
// Early loop to get the full width of the text
for (typename StringType::const_iterator x = str.begin(); x != str.end(); ++x) {
typename StringType::unsigned_type c = *x;
@@ -194,10 +194,10 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
}
if (c == '\n') {
- if (!wrapOnExplicitNewLines) {
+ if (!(mode & kWordWrapOnExplicitNewLines)) {
c = ' ';
} else {
- evenWidthLinesModeEnabled = false;
+ mode &= ~kWordWrapEvenWidthLines;
break;
}
}
@@ -211,7 +211,7 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
int targetTotalLinesNumberEWL = 0;
int targetMaxLineWidth = 0;
do {
- if (evenWidthLinesModeEnabled) {
+ if (mode & kWordWrapEvenWidthLines) {
wrapper.clear();
targetTotalLinesNumberEWL += 1;
// We add +2 to the fullTextWidthEWL to account for possible shadow pixels
@@ -240,7 +240,7 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
c = '\n';
}
// if wrapping on explicit new lines is disabled, then new line characters should be treated as a single white space char
- if (!wrapOnExplicitNewLines && c == '\n') {
+ if (!(mode & kWordWrapOnExplicitNewLines) && c == '\n') {
c = ' ';
}
@@ -262,7 +262,7 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
// If we encounter a line break (\n), or if the new space would
// cause the line to overflow: start a new line
- if ((wrapOnExplicitNewLines && c == '\n') || wouldExceedWidth) {
+ if (((mode & kWordWrapOnExplicitNewLines) && c == '\n') || wouldExceedWidth) {
wrapper.add(line, lineWidth);
continue;
}
@@ -307,7 +307,7 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
if (lineWidth > 0) {
wrapper.add(line, lineWidth);
}
- } while (evenWidthLinesModeEnabled
+ } while ((mode & kWordWrapEvenWidthLines)
&& (targetMaxLineWidth > maxWidth));
return wrapper.actualMaxLineWidth;
}
@@ -472,12 +472,12 @@ void Font::drawString(ManagedSurface *dst, const Common::U32String &str, int x,
}
}
-int Font::wordWrapText(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines, int initWidth, bool evenWidthLinesModeEnabled, bool wrapOnExplicitNewLines) const {
- return wordWrapTextImpl(*this, str, maxWidth, lines, initWidth, evenWidthLinesModeEnabled, wrapOnExplicitNewLines);
+int Font::wordWrapText(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines, int initWidth, uint32 mode) const {
+ return wordWrapTextImpl(*this, str, maxWidth, lines, initWidth, mode);
}
-int Font::wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, int initWidth, bool evenWidthLinesModeEnabled, bool wrapOnExplicitNewLines) const {
- return wordWrapTextImpl(*this, str, maxWidth, lines, initWidth, evenWidthLinesModeEnabled, wrapOnExplicitNewLines);
+int Font::wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, int initWidth, uint32 mode) const {
+ return wordWrapTextImpl(*this, str, maxWidth, lines, initWidth, mode);
}
TextAlign convertTextAlignH(TextAlign alignH, bool rtl) {
diff --git a/graphics/font.h b/graphics/font.h
index ef4e056d48..0da5571c3c 100644
--- a/graphics/font.h
+++ b/graphics/font.h
@@ -46,6 +46,13 @@ enum TextAlign {
kTextAlignRight ///< Text should be aligned to the right
};
+/** Word wrapping modes */
+enum WordWrapMode {
+ kWordWrapDefault = 0,
+ kWordWrapEvenWidthLines = 1 << 0, ///< Make the resulting line segments close to the same width
+ kWordWrapOnExplicitNewLines = 1 << 1 ///< Text is wrapped on new lines, otherwise treats them as single white space. Disables kWordWrapEvenWidthLines
+};
+
/**
* Converts virtual text alignments (start + end)
* to actual text alignment (left + right + center) for drawing,
@@ -182,12 +189,11 @@ public:
* @param maxWidth the maximum width a line may have
* @param lines the string list to which the text lines from str are appended
* @param initWidth the starting width of the first line, for partially filled lines (optional)
- * @param evenWidthLinesModeEnabled if enabled, the resulting line segments will be close to the same width (optional)
- * @param wrapOnExplicitNewLines if enabled, forces wrapping on new line characters, otherwise treats them as single white space (optional)
+ * @param mode the wrapping mode. A bitfield of @ref WordWrapMode values
* @return the maximal width of any of the lines added to lines
*/
- int wordWrapText(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines, int initWidth = 0, bool evenWidthLinesModeEnabled = false, bool wrapOnExplicitNewLines = true) const;
- int wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, int initWidth = 0, bool evenWidthLinesModeEnabled = false, bool wrapOnExplicitNewLines = true) const;
+ int wordWrapText(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines, int initWidth = 0, uint32 mode = kWordWrapOnExplicitNewLines) const;
+ int wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, int initWidth = 0, uint32 mode = kWordWrapOnExplicitNewLines) const;
};
More information about the Scummvm-git-logs
mailing list