[Scummvm-cvs-logs] CVS: scummvm/gui message.cpp,1.6,1.7 message.h,1.2,1.3

Max Horn fingolfin at users.sourceforge.net
Sat Dec 21 04:21:06 CET 2002


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv26174

Modified Files:
	message.cpp message.h 
Log Message:
allow for a timed message dialog w/o buttons (still need to add support for multiple buttons with customm labels)

Index: message.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/message.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- message.cpp	21 Nov 2002 13:20:27 -0000	1.6
+++ message.cpp	21 Dec 2002 11:57:24 -0000	1.7
@@ -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 @@
 	
 	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 @@
 	}
 
 	// 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 @@
 	
 	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;
 }
 
-int MessageDialog::addLine(const char *line, int size)
+void MessageDialog::handleTickle()
+{
+	Dialog::handleTickle();
+	if (_timer && _gui->get_time() > _timer)
+		close();
+}
+
+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 @@
 			
 			// 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 @@
 
 	if (start < pos) {
 		tmp = String(start, pos - start);
-		_lines.push_back(tmp);
+		lines.push_back(tmp);
 	}
 	return maxWidth;
 }

Index: message.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/message.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- message.h	10 Nov 2002 14:53:28 -0000	1.2
+++ message.h	21 Dec 2002 11:57:24 -0000	1.3
@@ -29,12 +29,14 @@
 	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





More information about the Scummvm-git-logs mailing list