2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-09-26 11:44:02 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2002-09-26 11:44:02 +00:00
|
|
|
*/
|
|
|
|
|
2003-11-01 20:52:41 +00:00
|
|
|
#include "common/str.h"
|
2005-05-15 17:01:32 +00:00
|
|
|
#include "common/system.h"
|
2020-08-26 15:26:50 +00:00
|
|
|
#include "common/translation.h"
|
2003-11-02 14:50:53 +00:00
|
|
|
#include "gui/message.h"
|
2010-11-16 10:19:01 +00:00
|
|
|
#include "gui/gui-manager.h"
|
2008-11-12 12:58:33 +00:00
|
|
|
#include "gui/ThemeEval.h"
|
2003-11-02 14:50:53 +00:00
|
|
|
#include "gui/widget.h"
|
2002-09-26 11:44:02 +00:00
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2003-01-02 10:36:17 +00:00
|
|
|
enum {
|
2021-08-17 19:31:54 +00:00
|
|
|
kDefaultCmd = 'DFLT',
|
|
|
|
kAltCmd = 'ALTC'
|
2003-01-02 10:36:17 +00:00
|
|
|
};
|
2002-09-26 11:44:02 +00:00
|
|
|
|
2008-11-12 12:53:53 +00:00
|
|
|
|
2020-02-03 13:14:34 +00:00
|
|
|
|
2003-11-02 14:50:53 +00:00
|
|
|
// TODO: The default button should be visibly distinct from the alternate button
|
|
|
|
|
2021-08-17 20:18:33 +00:00
|
|
|
void MessageDialog::init(const Common::U32String &message,
|
|
|
|
const Common::U32String &defaultButton,
|
2021-08-17 20:19:10 +00:00
|
|
|
const Common::U32StringArray &altButtons,
|
2021-08-17 20:18:33 +00:00
|
|
|
Graphics::TextAlign alignment,
|
|
|
|
const char *url) {
|
2020-08-26 15:26:50 +00:00
|
|
|
_url = url;
|
|
|
|
|
2005-05-15 17:01:32 +00:00
|
|
|
const int screenW = g_system->getOverlayWidth();
|
|
|
|
const int screenH = g_system->getOverlayHeight();
|
|
|
|
|
2008-11-12 12:58:33 +00:00
|
|
|
int buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0);
|
|
|
|
int buttonHeight = g_gui.xmlEval()->getVar("Globals.Button.Height", 0);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2002-09-26 11:44:02 +00:00
|
|
|
// 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
|
2020-06-13 16:42:25 +00:00
|
|
|
Common::Array<Common::U32String> lines;
|
2021-08-17 20:19:10 +00:00
|
|
|
int lineCount;
|
2021-08-18 21:36:59 +00:00
|
|
|
const int horizontalMargin = 10;
|
|
|
|
int maxlineWidth = g_gui.getFont().wordWrapText(message, screenW - 2 * horizontalMargin - 20, lines);
|
2021-08-17 20:19:10 +00:00
|
|
|
const int buttonCount = altButtons.size() + 1;
|
|
|
|
const int buttonSpacing = 10;
|
|
|
|
const int buttonsTotalWidth = buttonCount * buttonWidth + (buttonCount - 1) * buttonSpacing;
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2002-11-10 14:53:28 +00:00
|
|
|
// Calculate the desired dialog size (maxing out at 300*180 for now)
|
2021-08-18 21:36:59 +00:00
|
|
|
_w = MAX(maxlineWidth, buttonsTotalWidth) + 2 * horizontalMargin;
|
2010-10-10 10:32:58 +00:00
|
|
|
|
2002-12-21 11:57:24 +00:00
|
|
|
lineCount = lines.size();
|
2005-05-15 17:01:32 +00:00
|
|
|
|
|
|
|
_h = 16;
|
2021-08-17 20:19:10 +00:00
|
|
|
if (!defaultButton.empty() || !altButtons.empty())
|
2005-05-16 10:26:20 +00:00
|
|
|
_h += buttonHeight + 8;
|
2002-12-21 11:57:24 +00:00
|
|
|
|
2005-05-15 17:01:32 +00:00
|
|
|
// Limit the number of lines so that the dialog still fits on the screen.
|
2005-06-03 12:33:03 +00:00
|
|
|
if (lineCount > (screenH - 20 - _h) / kLineHeight) {
|
|
|
|
lineCount = (screenH - 20 - _h) / kLineHeight;
|
2002-11-10 14:53:28 +00:00
|
|
|
}
|
2005-06-03 12:33:03 +00:00
|
|
|
_h += lineCount * kLineHeight;
|
2005-05-15 17:01:32 +00:00
|
|
|
|
|
|
|
// Center the dialog
|
|
|
|
_x = (screenW - _w) / 2;
|
|
|
|
_y = (screenH - _h) / 2;
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2005-05-15 17:01:32 +00:00
|
|
|
// Each line is represented by one static text item.
|
2002-11-10 14:53:28 +00:00
|
|
|
for (int i = 0; i < lineCount; i++) {
|
2021-08-18 21:36:59 +00:00
|
|
|
new StaticTextWidget(this, horizontalMargin, 10 + i * kLineHeight, maxlineWidth, kLineHeight, lines[i], alignment);
|
2002-09-26 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-17 20:19:10 +00:00
|
|
|
// Assume defaultButton is always given
|
|
|
|
int buttonPos = (_w - buttonsTotalWidth) / 2;
|
2003-01-02 10:36:17 +00:00
|
|
|
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 12:36:37 +00:00
|
|
|
if (!defaultButton.empty()) {
|
|
|
|
// Confirm dialog
|
2021-08-17 20:19:10 +00:00
|
|
|
new ButtonWidget(this, buttonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight, defaultButton, Common::U32String(), kDefaultCmd, Common::ASCII_RETURN);
|
|
|
|
buttonPos += buttonWidth + buttonSpacing;
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 12:36:37 +00:00
|
|
|
}
|
2003-01-02 10:36:17 +00:00
|
|
|
|
2021-08-17 20:19:10 +00:00
|
|
|
int buttonHotKey = altButtons.size() == 1 ? Common::ASCII_ESCAPE : 0;
|
|
|
|
for (size_t i = 0, total = altButtons.size(); i < total; ++i) {
|
|
|
|
new ButtonWidget(this, buttonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight, altButtons[i], Common::U32String(), kAltCmd + i, buttonHotKey);
|
|
|
|
buttonHotKey = 0;
|
|
|
|
buttonPos += buttonWidth + buttonSpacing;
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 12:36:37 +00:00
|
|
|
}
|
2002-09-26 11:44:02 +00:00
|
|
|
}
|
2002-11-19 01:36:47 +00:00
|
|
|
|
2021-08-17 20:18:33 +00:00
|
|
|
MessageDialog::MessageDialog(const Common::U32String &message,
|
|
|
|
const Common::U32String &defaultButton,
|
|
|
|
const Common::U32String &altButton,
|
|
|
|
Graphics::TextAlign alignment,
|
|
|
|
const char *url)
|
2020-08-21 08:20:43 +00:00
|
|
|
: Dialog(30, 20, 260, 124) {
|
|
|
|
|
2021-08-17 20:19:10 +00:00
|
|
|
init(message, defaultButton,
|
|
|
|
altButton.empty() ? Common::U32StringArray() : Common::U32StringArray(1, altButton),
|
|
|
|
alignment, url);
|
2020-08-21 08:20:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-17 20:18:33 +00:00
|
|
|
MessageDialog::MessageDialog(const Common::String &message,
|
|
|
|
const Common::String &defaultButton,
|
|
|
|
const Common::String &altButton,
|
|
|
|
Graphics::TextAlign alignment,
|
|
|
|
const char *url)
|
2020-06-16 19:57:23 +00:00
|
|
|
: Dialog(30, 20, 260, 124) {
|
|
|
|
|
2021-08-17 20:19:10 +00:00
|
|
|
init(Common::U32String(message), Common::U32String(defaultButton),
|
|
|
|
altButton.empty() ? Common::U32StringArray() : Common::U32StringArray(1, Common::U32String(altButton)),
|
|
|
|
alignment, url);
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageDialog::MessageDialog(const Common::U32String &message,
|
|
|
|
const Common::U32String &defaultButton,
|
|
|
|
const Common::U32StringArray &altButtons,
|
|
|
|
Graphics::TextAlign alignment)
|
|
|
|
: Dialog(30, 20, 260, 124) {
|
|
|
|
|
|
|
|
init(message, defaultButton, altButtons, alignment, nullptr);
|
2020-06-16 19:57:23 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void MessageDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
2021-08-17 19:31:54 +00:00
|
|
|
if (cmd == kDefaultCmd) {
|
2004-08-11 21:49:58 +00:00
|
|
|
setResult(kMessageOK);
|
2003-01-02 10:36:17 +00:00
|
|
|
close();
|
2021-08-17 20:19:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cmd >= kAltCmd) {
|
2020-08-26 15:26:50 +00:00
|
|
|
if (_url) {
|
|
|
|
if (g_system->hasFeature(OSystem::kFeatureOpenUrl))
|
|
|
|
g_system->openUrl(_url);
|
|
|
|
|
|
|
|
setResult(kMessageOK);
|
|
|
|
} else {
|
2021-08-17 20:19:10 +00:00
|
|
|
setResult(kMessageAlt + cmd - kAltCmd);
|
2020-08-26 15:26:50 +00:00
|
|
|
}
|
2003-01-02 10:36:17 +00:00
|
|
|
close();
|
|
|
|
} else {
|
|
|
|
Dialog::handleCommand(sender, cmd, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-13 16:42:25 +00:00
|
|
|
TimedMessageDialog::TimedMessageDialog(const Common::U32String &message, uint32 duration)
|
2020-11-15 18:15:58 +00:00
|
|
|
: MessageDialog(message, Common::U32String(), Common::U32String()) {
|
2010-03-11 23:41:28 +00:00
|
|
|
_timer = g_system->getMillis() + duration;
|
2003-11-01 20:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TimedMessageDialog::handleTickle() {
|
|
|
|
MessageDialog::handleTickle();
|
2010-03-11 23:41:28 +00:00
|
|
|
if (g_system->getMillis() > _timer)
|
2003-11-01 20:52:41 +00:00
|
|
|
close();
|
|
|
|
}
|
2003-11-10 23:40:48 +00:00
|
|
|
|
2020-08-29 09:05:47 +00:00
|
|
|
MessageDialogWithURL::MessageDialogWithURL(const Common::U32String &message, const char *url, const Common::U32String &defaultButton, Graphics::TextAlign alignment)
|
|
|
|
: MessageDialog(message, defaultButton, _("Open URL"), alignment, url) {
|
|
|
|
}
|
|
|
|
|
2020-08-26 15:26:50 +00:00
|
|
|
MessageDialogWithURL::MessageDialogWithURL(const Common::String &message, const char *url, const char *defaultButton, Graphics::TextAlign alignment)
|
2020-08-29 09:05:47 +00:00
|
|
|
: MessageDialog(Common::U32String(message), Common::U32String(defaultButton), _("Open URL"), alignment, url) {
|
2020-08-26 15:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|