Add a new transient dialog.

This commit is contained in:
Mark de Wever 2009-05-22 19:08:34 +00:00
parent bf20b5c1dc
commit a01857f746
11 changed files with 218 additions and 0 deletions

View file

@ -8,6 +8,7 @@ Version 1.7.0+svn:
* Added unit tests for the new widgets
* Improved the layout algorithm not to show scrollbars when they make the
situation worse
* Add a new transient message dialog
* Miscellaneous and bugfixes:
* Add strict compilation to cmake
* Let cmake also use the CXXFLAGS and CFLAGS environment variables

View file

@ -0,0 +1,58 @@
#textdomain wesnoth-lib
###
### In game transient message dialog.
###
[window]
id = "transient_message"
description = "A transient message on a semi-transparent dialog."
[resolution]
definition = "message"
easy_close = "true"
[grid]
[row]
[column]
border = "all"
border_size = 5
vertical_alignment = "top"
horizontal_alignment = "left"
[label]
id = "title"
definition = "title"
[/label]
[/column]
[/row]
[row]
[column]
border = "all"
border_size = 5
vertical_alignment = "top"
horizontal_alignment = "left"
[label]
id = "message"
definition = "wml_message"
[/label]
[/column]
[/row]
[/grid]
[/resolution]
[/window]

View file

@ -19,6 +19,7 @@ src/gui/dialogs/mp_connect.cpp
src/gui/dialogs/mp_create_game.cpp
src/gui/dialogs/mp_method_selection.cpp
src/gui/dialogs/title_screen.cpp
src/gui/dialogs/transient_message.cpp
src/gui/dialogs/wml_message.cpp
src/gui/widgets/button.cpp
src/gui/widgets/control.cpp

View file

@ -261,6 +261,7 @@ SET(wesnoth-main_SRC
gui/dialogs/mp_method_selection.cpp
gui/dialogs/mp_cmd_wrapper.cpp
gui/dialogs/title_screen.cpp
gui/dialogs/transient_message.cpp
gui/dialogs/wml_message.cpp
gui/widgets/button.cpp
gui/widgets/control.cpp

View file

@ -91,6 +91,7 @@ wesnoth_source = \
gui/dialogs/mp_method_selection.cpp \
gui/dialogs/mp_cmd_wrapper.cpp \
gui/dialogs/title_screen.cpp \
gui/dialogs/transient_message.cpp \
gui/dialogs/wml_message.cpp \
gui/widgets/button.cpp \
gui/widgets/control.cpp \

View file

@ -246,6 +246,7 @@ wesnoth_sources = Split("""
gui/dialogs/mp_method_selection.cpp
gui/dialogs/mp_cmd_wrapper.cpp
gui/dialogs/title_screen.cpp
gui/dialogs/transient_message.cpp
gui/dialogs/wml_message.cpp
gui/widgets/button.cpp
gui/widgets/control.cpp

View file

@ -0,0 +1,58 @@
/* $Id$ */
/*
Copyright (C) 2009 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/transient_message.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/window.hpp"
namespace gui2 {
twindow* ttransient_message::build_window(CVideo& video)
{
return build(video, get_id(TRANSIENT_MESSAGE));
}
void ttransient_message::pre_show(CVideo& /*video*/, twindow& window)
{
tlabel* title =
dynamic_cast<tlabel*>(window.find_widget("title", false));
VALIDATE(title, missing_widget("title"));
title->set_label(title_);
title->set_markup_mode(title_markup_mode_);
tlabel* message =
dynamic_cast<tlabel*>(window.find_widget("message", false));
VALIDATE(message, missing_widget("message"));
message->set_label(message_);
message->set_markup_mode(message_markup_mode_);
message->set_can_wrap(true);
}
void show_transient_message(CVideo& video, const std::string& title,
const std::string& message,
const tcontrol::tmarkup_mode message_markup_mode,
const tcontrol::tmarkup_mode title_markup_mode)
{
ttransient_message dlg(title, title_markup_mode,
message, message_markup_mode);
dlg.show(video);
}
} // namespace gui2

View file

@ -0,0 +1,83 @@
/* $Id$ */
/*
Copyright (C) 2009 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef GUI_DIALOGS_TRANSIENT_MESSAGE_HPP_INCLUDED
#define GUI_DIALOGS_TRANSIENT_MESSAGE_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
#include "gui/widgets/control.hpp"
namespace gui2 {
/** Shows a transient message. */
class ttransient_message
: public tdialog
{
public:
ttransient_message(const std::string& title,
const tcontrol::tmarkup_mode title_markup_mode,
const std::string& message,
const tcontrol::tmarkup_mode message_markup_mode)
: title_(title)
, title_markup_mode_(title_markup_mode)
, message_(message)
, message_markup_mode_(message_markup_mode)
{}
protected:
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
private:
/** The title for the dialog. */
std::string title_;
/** The markup mode for the title. */
tcontrol::tmarkup_mode title_markup_mode_;
/** The message to show to the user. */
std::string message_;
/** The markup mode for the message. */
tcontrol::tmarkup_mode message_markup_mode_;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
};
/**
* Shows a transient message to the user.
*
* This shows a dialog with a short message which can be dismissed with a
* single click.
*
* @note The message _should_ be small enough to fit on the window, the test
* can contain newlines and will wrap when needed.
*
* @param video The video which contains the surface to draw
* upon.
* @param title The title of the dialog.
* @param message The message to show in the dialog.
* @param message_markup_mode The markup mode used for the title.
* @param title_markup_mod The markup mode used for the title.
*/
void show_transient_message(CVideo& video, const std::string& title,
const std::string& message,
const tcontrol::tmarkup_mode message_markup_mode = tcontrol::NO_MARKUP,
const tcontrol::tmarkup_mode title_markup_mode = tcontrol::NO_MARKUP);
} // namespace gui2
#endif

View file

@ -80,6 +80,7 @@ static void fill_window_types()
window_type_list[WML_MESSAGE_LEFT] = "wml_message_left";
window_type_list[WML_MESSAGE_RIGHT] = "wml_message_right";
window_type_list[MESSAGE] = "message";
window_type_list[TRANSIENT_MESSAGE] = "transient_message";
window_type_list[MP_CONNECT] = "mp_connect";
window_type_list[MP_METHOD_SELECTION] = "mp_method_selection";
window_type_list[MP_SERVER_LIST] = "mp_server_list";

View file

@ -42,6 +42,7 @@ enum twindow_type {
CAMPAIGN_SELECTION, /**< The campaign selection dialog. */
LANGUAGE_SELECTION, /**< The language selection dialog. */
MESSAGE, /**< A generic message dialog. */
TRANSIENT_MESSAGE, /**< A transient message dialog. */
WML_MESSAGE_LEFT, /**<
* A WML message dialog with the portrait on
* the left side.

View file

@ -39,6 +39,7 @@
#include "gui/dialogs/mp_method_selection.hpp"
#include "gui/dialogs/mp_cmd_wrapper.hpp"
#include "gui/dialogs/title_screen.hpp"
#include "gui/dialogs/transient_message.hpp"
#include "gui/dialogs/wml_message.hpp"
#include "gui/widgets/helper.hpp"
#include "gui/widgets/settings.hpp"
@ -333,6 +334,17 @@ struct twrapper<gui2::teditor_settings>
}
};
template<>
struct twrapper<gui2::ttransient_message>
{
static gui2::ttransient_message* create()
{
return new gui2::ttransient_message(
"Title", gui2::tcontrol::NO_MARKUP,
"Message", gui2::tcontrol::NO_MARKUP);
}
};
template<>
struct twrapper<gui2::twml_message_left>
{