aboutsummaryrefslogtreecommitdiff
path: root/gui/message.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/message.cpp')
-rw-r--r--gui/message.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/gui/message.cpp b/gui/message.cpp
new file mode 100644
index 0000000000..351b120797
--- /dev/null
+++ b/gui/message.cpp
@@ -0,0 +1,73 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2002 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Header$
+ */
+
+#include "stdafx.h"
+#include "message.h"
+#include "newgui.h"
+
+#include "common/list.h"
+
+
+MessageDialog::MessageDialog(NewGui *gui, const String &message)
+ : 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
+ ScummVM::StringList lines;
+ String tmp;
+ const char *str = message.c_str();
+ const char *start = str;
+ int lineWidth, maxlineWidth = 0;
+
+ while (*str) {
+ if (*str == '\n') {
+ tmp = String(start, str - start);
+ lines.push_back(tmp);
+ lineWidth = _gui->getStringWidth(tmp);
+ if (maxlineWidth < lineWidth)
+ maxlineWidth = lineWidth;
+ start = str + 1;
+ }
+
+ ++str;
+ }
+ if (*start) {
+ tmp = String(start, str - start);
+ lines.push_back(tmp);
+ lineWidth = _gui->getStringWidth(tmp);
+ if (maxlineWidth < lineWidth)
+ maxlineWidth = lineWidth;
+ }
+
+ // TODO - we should probably check for over/underflows here
+ _w = maxlineWidth + 20;
+ _h = lines.size() * kLineHeight + 30;
+ _x = (320 - _w) / 2;
+
+ for (int i = 0; i < lines.size(); i++) {
+ new StaticTextWidget(this, 10, 10+i*kLineHeight, maxlineWidth, kLineHeight,
+ lines[i], kTextAlignCenter);
+ }
+
+ // FIXME - the vertical position has to be adjusted
+ addButton((_w - 54)/2, _h - 20, 54, 16, "OK", kCloseCmd, '\n'); // Confirm dialog
+}