aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorMax Horn2002-11-21 13:20:27 +0000
committerMax Horn2002-11-21 13:20:27 +0000
commitfa312d3746a5d3755d5916c275c53ad6e6b08692 (patch)
treefa7fc59ff2aa91c5a5c9745bcbb18b99558b39d9 /gui
parent7a5063f086075d19892ee78156f2711afcc899d6 (diff)
downloadscummvm-rg350-fa312d3746a5d3755d5916c275c53ad6e6b08692.tar.gz
scummvm-rg350-fa312d3746a5d3755d5916c275c53ad6e6b08692.tar.bz2
scummvm-rg350-fa312d3746a5d3755d5916c275c53ad6e6b08692.zip
center dialog vertically, too; split overlong lines at whitespaces if posible
svn-id: r5661
Diffstat (limited to 'gui')
-rw-r--r--gui/message.cpp43
1 files changed, 26 insertions, 17 deletions
diff --git a/gui/message.cpp b/gui/message.cpp
index 8dc9931a9c..352cde117d 100644
--- a/gui/message.cpp
+++ b/gui/message.cpp
@@ -53,12 +53,13 @@ MessageDialog::MessageDialog(NewGui *gui, const String &message)
// Calculate the desired dialog size (maxing out at 300*180 for now)
_w = maxlineWidth + 20;
lineCount = _lines.size();
- _h = lineCount * kLineHeight + 34;
+ _h = lineCount * kLineHeight + 40;
if (_h > 180) {
lineCount = (180 - 34) / kLineHeight;
_h = lineCount * kLineHeight + 34;
}
_x = (320 - _w) / 2;
+ _y = (200 - _h) / 2;
for (int i = 0; i < lineCount; i++) {
new StaticTextWidget(this, 10, 10+i*kLineHeight, maxlineWidth, kLineHeight,
@@ -73,36 +74,44 @@ MessageDialog::MessageDialog(NewGui *gui, const String &message)
int MessageDialog::addLine(const char *line, int size)
{
int width = 0, maxWidth = 0;
- const char *start = line;
+ const char *start = line, *pos = line, *end = start + size;
String tmp;
- for (int i = 0; i < size; ++i) {
- int w = _gui->getCharWidth(*line);
+ while (pos < end) {
+ int w = _gui->getCharWidth(*pos);
- // Check if we exceed the maximum line width, if so, split the line
- // TODO - we could make this more clever by trying to split at
- // non-letters, e.g. at space/slash/dot
+ // Check if we exceed the maximum line width, if so, split the line.
+ // If possible we split at whitespaces.
if (width + w > 280) {
- if (maxWidth < width)
- maxWidth = width;
+ // Scan backward till we find a space or we get back to the start
+ const char *newPos = pos;
+ while (newPos > start && !isspace(*newPos))
+ newPos--;
+ if (newPos > start)
+ pos = newPos;
// Add the substring from intervall [start, i-1]
- tmp = String(start, line - start);
+ tmp = String(start, pos - start);
_lines.push_back(tmp);
- start = line;
- width = w;
- } else
+ // Determine the width of the string, and adjust maxWidth accordingly
+ width = _gui->getStringWidth(tmp);
+ if (maxWidth < width)
+ maxWidth = width;
+
+ start = pos;
+ width = 0;
+ } else {
width += w;
-
- line++;
+ pos++;
+ }
}
if (maxWidth < width)
maxWidth = width;
- if (start < line) {
- tmp = String(start, line - start);
+ if (start < pos) {
+ tmp = String(start, pos - start);
_lines.push_back(tmp);
}
return maxWidth;