diff options
author | Max Horn | 2002-12-21 11:57:24 +0000 |
---|---|---|
committer | Max Horn | 2002-12-21 11:57:24 +0000 |
commit | 81dce87a5c17054438042d3af320b00fe46da389 (patch) | |
tree | ff839455218c985dc596d096554637cf03042199 /gui | |
parent | 50f7ffbeb6109eb92461b45678a7514b84ea54a4 (diff) | |
download | scummvm-rg350-81dce87a5c17054438042d3af320b00fe46da389.tar.gz scummvm-rg350-81dce87a5c17054438042d3af320b00fe46da389.tar.bz2 scummvm-rg350-81dce87a5c17054438042d3af320b00fe46da389.zip |
allow for a timed message dialog w/o buttons (still need to add support for multiple buttons with customm labels)
svn-id: r6038
Diffstat (limited to 'gui')
-rw-r--r-- | gui/message.cpp | 37 | ||||
-rw-r--r-- | gui/message.h | 10 |
2 files changed, 33 insertions, 14 deletions
diff --git a/gui/message.cpp b/gui/message.cpp index 352cde117d..d751fb86b8 100644 --- a/gui/message.cpp +++ b/gui/message.cpp @@ -23,13 +23,14 @@ #include "newgui.h" -MessageDialog::MessageDialog(NewGui *gui, const String &message) +MessageDialog::MessageDialog(NewGui *gui, const String &message, uint32 timer, bool showButton) : Dialog(gui, 30, 20, 260, 124) { // First, determine the size the dialog needs. For this we have to break // down the string into lines, and taking the maximum of their widths. // Using this, and accounting for the space the button(s) need, we can set // the real size of the dialog + StringList lines; const char *str = message.c_str(); const char *start = str; int lineWidth, maxlineWidth = 0; @@ -37,7 +38,7 @@ MessageDialog::MessageDialog(NewGui *gui, const String &message) while (*str) { if (*str == '\n') { - lineWidth = addLine(start, str - start); + lineWidth = addLine(lines, start, str - start); if (maxlineWidth < lineWidth) maxlineWidth = lineWidth; start = str + 1; @@ -46,14 +47,17 @@ MessageDialog::MessageDialog(NewGui *gui, const String &message) } // Add the last line - lineWidth = addLine(start, str - start); + lineWidth = addLine(lines, start, str - start); if (maxlineWidth < lineWidth) maxlineWidth = lineWidth; // Calculate the desired dialog size (maxing out at 300*180 for now) _w = maxlineWidth + 20; - lineCount = _lines.size(); - _h = lineCount * kLineHeight + 40; + lineCount = lines.size(); + _h = lineCount * kLineHeight + 16; + if (showButton) + _h += 24; + if (_h > 180) { lineCount = (180 - 34) / kLineHeight; _h = lineCount * kLineHeight + 34; @@ -63,15 +67,28 @@ MessageDialog::MessageDialog(NewGui *gui, const String &message) for (int i = 0; i < lineCount; i++) { new StaticTextWidget(this, 10, 10+i*kLineHeight, maxlineWidth, kLineHeight, - _lines[i], kTextAlignCenter); + lines[i], kTextAlignCenter); } // FIXME - allow for multiple buttons, and return in runModal() which one // was selected. - addButton((_w - kButtonWidth)/2, _h - 24, "OK", kCloseCmd, '\n'); // Confirm dialog + if (showButton) + addButton((_w - kButtonWidth)/2, _h - 24, "OK", kCloseCmd, '\n'); // Confirm dialog + + if (timer) + _timer = _gui->get_time() + timer; + else + _timer = 0; +} + +void MessageDialog::handleTickle() +{ + Dialog::handleTickle(); + if (_timer && _gui->get_time() > _timer) + close(); } -int MessageDialog::addLine(const char *line, int size) +int MessageDialog::addLine(StringList &lines, const char *line, int size) { int width = 0, maxWidth = 0; const char *start = line, *pos = line, *end = start + size; @@ -92,7 +109,7 @@ int MessageDialog::addLine(const char *line, int size) // Add the substring from intervall [start, i-1] tmp = String(start, pos - start); - _lines.push_back(tmp); + lines.push_back(tmp); // Determine the width of the string, and adjust maxWidth accordingly width = _gui->getStringWidth(tmp); @@ -112,7 +129,7 @@ int MessageDialog::addLine(const char *line, int size) if (start < pos) { tmp = String(start, pos - start); - _lines.push_back(tmp); + lines.push_back(tmp); } return maxWidth; } diff --git a/gui/message.h b/gui/message.h index 5b5c3ccea7..c415b905be 100644 --- a/gui/message.h +++ b/gui/message.h @@ -29,12 +29,14 @@ class MessageDialog : public Dialog { typedef ScummVM::String String; typedef ScummVM::StringList StringList; public: - MessageDialog(NewGui *gui, const String &message); + MessageDialog(NewGui *gui, const String &message, uint32 timer = 0, bool showButton = true); + + void handleTickle(); protected: - StringList _lines; - - int addLine(const char *line, int size); + uint32 _timer; + + int addLine(StringList &lines, const char *line, int size); }; #endif |