[Scummvm-cvs-logs] CVS: scummvm/gui message.cpp,NONE,1.1 message.h,NONE,1.1 ListWidget.h,1.3,1.4 newgui.cpp,1.15,1.16 newgui.h,1.10,1.11
Max Horn
fingolfin at users.sourceforge.net
Thu Sep 26 04:45:03 CEST 2002
Update of /cvsroot/scummvm/scummvm/gui
In directory usw-pr-cvs1:/tmp/cvs-serv32207/gui
Modified Files:
ListWidget.h newgui.cpp newgui.h
Added Files:
message.cpp message.h
Log Message:
added simple message dialog
--- NEW FILE: message.cpp ---
/* 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: /cvsroot/scummvm/scummvm/gui/message.cpp,v 1.1 2002/09/26 11:44:02 fingolfin Exp $
*/
#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
}
--- NEW FILE: message.h ---
/* 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: /cvsroot/scummvm/scummvm/gui/message.h,v 1.1 2002/09/26 11:44:02 fingolfin Exp $
*/
#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
Index: ListWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ListWidget.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ListWidget.h 8 Sep 2002 16:00:12 -0000 1.3
+++ ListWidget.h 26 Sep 2002 11:44:02 -0000 1.4
@@ -32,11 +32,6 @@
kListNumberingOne = 1
};
-// Height of a signle entry line
-enum {
- kLineHeight = 11
-};
-
// Some special commands
enum {
kListItemDoubleClickedCmd = 'LIdb', // 'data' will be item index
Index: newgui.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- newgui.cpp 24 Sep 2002 23:45:25 -0000 1.15
+++ newgui.cpp 26 Sep 2002 11:44:02 -0000 1.16
@@ -401,11 +401,12 @@
}
}
-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 @@
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]);
}
}
Index: newgui.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- newgui.h 24 Sep 2002 23:45:25 -0000 1.10
+++ newgui.h 26 Sep 2002 11:44:02 -0000 1.11
@@ -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 @@
// 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 @@
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);
};
More information about the Scummvm-git-logs
mailing list