aboutsummaryrefslogtreecommitdiff
path: root/gui/message.cpp
blob: a2b890785c05338b8004bdec841156e4f08e6de7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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;
	}

	// Add in the last line
	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 + 34;
	_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 - 24, 54, 16, "OK", kCloseCmd, '\n');	// Confirm dialog
}