From 58e5e0069f82c9319fd9c6f6987f98886c3b9f67 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 26 Sep 2002 11:44:02 +0000 Subject: added simple message dialog svn-id: r5020 --- gui/ListWidget.h | 5 ---- gui/message.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gui/message.h | 35 +++++++++++++++++++++++++++ gui/newgui.cpp | 17 ++++++------- gui/newgui.h | 13 ++++++++-- 5 files changed, 128 insertions(+), 15 deletions(-) create mode 100644 gui/message.cpp create mode 100644 gui/message.h (limited to 'gui') diff --git a/gui/ListWidget.h b/gui/ListWidget.h index c778b2e807..106e61ceb6 100644 --- a/gui/ListWidget.h +++ b/gui/ListWidget.h @@ -32,11 +32,6 @@ enum { kListNumberingOne = 1 }; -// Height of a signle entry line -enum { - kLineHeight = 11 -}; - // Some special commands enum { kListItemDoubleClickedCmd = 'LIdb', // 'data' will be item index 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 +} diff --git a/gui/message.h b/gui/message.h new file mode 100644 index 0000000000..136d96be98 --- /dev/null +++ b/gui/message.h @@ -0,0 +1,35 @@ +/* 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$ + */ + +#ifndef MESSAGE_DIALOG_H +#define MESSAGE_DIALOG_H + +#include "dialog.h" +#include "common/str.h" + +class MessageDialog : public Dialog { + typedef ScummVM::String String; +public: + MessageDialog(NewGui *gui, const String &message); + +protected: +}; + +#endif diff --git a/gui/newgui.cpp b/gui/newgui.cpp index 7adfa1aaea..dbdf9d170d 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -401,11 +401,12 @@ void NewGui::drawChar(const char chr, int xx, int yy, int16 color) } } -int NewGui::getStringWidth(const char *str) +int NewGui::getStringWidth(const String &str) { int space = 0; - while (*str) - space += getCharWidth(*str++); + + for (int i = 0; i < str.size(); ++i) + space += getCharWidth(str[i]); return space; } @@ -414,17 +415,17 @@ int NewGui::getCharWidth(char c) return guifont[c+6]; } -void NewGui::drawString(const char *str, int x, int y, int w, int16 color, int align) +void NewGui::drawString(const String &str, int x, int y, int w, int16 color, int align) { int width = getStringWidth(str); if (align == kTextAlignCenter) x = x + (w - width - 1)/2; else if (align == kTextAlignRight) x = x + w - width; - while (*str) { - drawChar(*str, x, y, color); - x += getCharWidth(*str); - str++; + + for (int i = 0; i < str.size(); ++i) { + drawChar(str[i], x, y, color); + x += getCharWidth(str[i]); } } diff --git a/gui/newgui.h b/gui/newgui.h index b1ce4daeea..455904026d 100644 --- a/gui/newgui.h +++ b/gui/newgui.h @@ -23,12 +23,20 @@ #include "scummsys.h" #include "system.h" // For events +#include "common/str.h" class Dialog; #define hline(x, y, x2, color) line(x, y, x2, y, color); #define vline(x, y, y2, color) line(x, y, x, y2, color); +// Height of a single text line +enum { + kLineHeight = 11 +}; + + +// Text alignment modes for drawString() enum { kTextAlignLeft, kTextAlignCenter, @@ -59,6 +67,7 @@ public: // This class hopefully will replace the old Gui class completly one day class NewGui { friend class Dialog; + typedef ScummVM::String String; public: // Main entry for the GUI: this will start an event loop that keeps running @@ -123,9 +132,9 @@ public: void frameRect(int x, int y, int w, int h, int16 color); void addDirtyRect(int x, int y, int w, int h); void drawChar(char c, int x, int y, int16 color); - int getStringWidth(const char *str); + int getStringWidth(const String &str); int getCharWidth(char c); - void drawString(const char *str, int x, int y, int w, int16 color, int align = kTextAlignLeft); + void drawString(const String &str, int x, int y, int w, int16 color, int align = kTextAlignLeft); void drawBitmap(uint32 bitmap[8], int x, int y, int16 color); }; -- cgit v1.2.3