Add a new image widget and optionally use it in the message dialog.

This commit is contained in:
Mark de Wever 2008-09-22 21:22:54 +00:00
parent f87ffceada
commit d3751f85ea
13 changed files with 157 additions and 21 deletions

View file

@ -24,7 +24,8 @@ Version 1.5.4+svn:
* Added a new scroll label widget.
* Allowed usage of wildcards (? and *) in friend and ignore lists.
* Allowed usage of lists in /friend, /ignore and /remove commands. (feature
#7492)
#7492)
* Added a new image widget.
* WML engine:
* New command, [store_time_of_day], makes it possible to store ToD info
in a WML array/container.

View file

@ -329,31 +329,69 @@
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "title"
definition = "title"
[/label]
[grid]
[/column]
[row]
[/row]
[column]
vertical_alignment = "top"
[row]
grow_factor = 1
[image]
id = "image"
definition = "default"
[/image]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[/column]
[scroll_label]
id = "label"
definition = "default"
[/scroll_label]
[column]
grow_factor = 1
vertical_alignment = "top"
horizontal_alignment = "left"
[grid]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "title"
definition = "title"
[/label]
[/column]
[/row]
[row]
grow_factor = 1
[column]
border = "all"
border_size = 5
vertical_alignment = "top"
horizontal_alignment = "left"
[scroll_label]
id = "label"
definition = "default"
[/scroll_label]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/column]

View file

@ -20,6 +20,7 @@ src/gui/widgets/container.cpp
src/gui/widgets/event_handler.cpp
src/gui/widgets/grid.cpp
src/gui/widgets/helper.cpp
src/gui/widgets/image.cpp
src/gui/widgets/label.cpp
src/gui/widgets/listbox.cpp
src/gui/widgets/menubar.cpp

View file

@ -244,6 +244,7 @@ SET(wesnoth-main_SRC
gui/widgets/event_handler.cpp
gui/widgets/grid.cpp
gui/widgets/helper.cpp
gui/widgets/image.cpp
gui/widgets/label.cpp
gui/widgets/listbox.cpp
gui/widgets/menubar.cpp

View file

@ -87,6 +87,7 @@ wesnoth_source = \
gui/widgets/event_handler.cpp \
gui/widgets/grid.cpp \
gui/widgets/helper.cpp \
gui/widgets/image.cpp \
gui/widgets/label.cpp \
gui/widgets/listbox.cpp \
gui/widgets/menubar.cpp \

View file

@ -220,6 +220,7 @@ wesnoth_sources = Split("""
gui/widgets/event_handler.cpp
gui/widgets/grid.cpp
gui/widgets/helper.cpp
gui/widgets/image.cpp
gui/widgets/label.cpp
gui/widgets/listbox.cpp
gui/widgets/menubar.cpp

View file

@ -14,6 +14,7 @@
#include "gui/dialogs/message.hpp"
#include "gui/widgets/image.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/widget.hpp"
#include "gui/widgets/window.hpp"
@ -42,6 +43,12 @@ void tmessage::pre_show(CVideo& /*video*/, twindow& window)
title->set_label(title_);
timage* image =
dynamic_cast<timage*>(window.find_widget("image", false));
VALIDATE(image, missing_widget("image"));
image->set_label(image_);
tcontrol* label =
dynamic_cast<tcontrol*>(window.find_widget("label", false));
VALIDATE(label, missing_widget("label"));

View file

@ -37,12 +37,21 @@ public:
void set_title(const std::string& title) { title_ = title; }
void set_image(const std::string& image) { image_ = image; }
void set_message(const std::string& message) { message_ = message; }
private:
/** The title for the dialog. */
std::string title_;
/**
* The image which is shown in the dialog.
*
* This image can be an icon or portrait or any other image.
*/
std::string image_;
/** The message to show to the user. */
std::string message_;

View file

@ -20,7 +20,7 @@
#include "gui/widgets/canvas.hpp"
#include "config.hpp"
#include "image.hpp"
#include "../../image.hpp"
#include "gettext.hpp"
#include "gui/widgets/formula.hpp"
#include "gui/widgets/helper.hpp"

View file

@ -188,6 +188,7 @@ const std::string& tgui_definition::read(const config& cfg)
* <span id="widget_list"></span>List of available widgets:
* @start_table = widget_definition
* button_definition A push button.
* image_definition An image.
* menubar_definition A menubar which is used in menus and the
* tabbar in a tabcontrol.
* minimap_definition A minimap to show the gamemap, this only
@ -231,6 +232,7 @@ const std::string& tgui_definition::read(const config& cfg)
/***** Control definitions *****/
load_definitions<tbutton_definition>("button", cfg.get_children("button_definition"));
load_definitions<timage_definition>("image", cfg.get_children("image_definition"));
load_definitions<tlabel_definition>("label", cfg.get_children("label_definition"));
load_definitions<tlistbox_definition>("listbox", cfg.get_children("listbox_definition"));
load_definitions<tmenubar_definition>("menubar", cfg.get_children("menubar_definition"));
@ -524,6 +526,35 @@ tbutton_definition::tresolution::tresolution(const config& cfg) :
state.push_back(tstate_definition(cfg.child("state_focussed")));
}
timage_definition::timage_definition(const config& cfg) :
tcontrol_definition(cfg)
{
DBG_G_P << "Parsing image " << id << '\n';
load_resolutions<tresolution>(cfg.get_children("resolution"));
}
timage_definition::tresolution::tresolution(const config& cfg) :
tresolution_definition_(cfg)
{
/*WIKI
* @page = GUIToolkitWML
* @order = 1_widget_image
*
* == Image ==
*
* The definition of an image. The label field of the widget is used as the
* name of file to show.
*
* The following states exist:
* * state_enabled, the image is enabled.
*
*/
// Note the order should be the same as the enum tstate is image.hpp.
state.push_back(tstate_definition(cfg.child("state_enabled")));
}
tlabel_definition::tlabel_definition(const config& cfg) :
tcontrol_definition(cfg)
{

View file

@ -149,6 +149,17 @@ struct tbutton_definition : public tcontrol_definition
};
struct timage_definition : public tcontrol_definition
{
timage_definition(const config& cfg);
struct tresolution : public tresolution_definition_
{
tresolution(const config& cfg);
};
};
struct tlabel_definition : public tcontrol_definition
{

View file

@ -17,6 +17,7 @@
#include "foreach.hpp"
#include "gettext.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/image.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/minimap.hpp"
@ -185,6 +186,8 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
if(cfg.child("button")) {
return new tbuilder_button(*(cfg.child("button")));
} else if(cfg.child("image")) {
return new tbuilder_image(*(cfg.child("image")));
} else if(cfg.child("label")) {
return new tbuilder_label(*(cfg.child("label")));
} else if(cfg.child("listbox")) {
@ -443,6 +446,7 @@ tbuilder_grid::tbuilder_grid(const config& cfg) :
*
* The widget is one of the following items:
* * button a button.
* * image an image.
* * grid a grid, this is used to nest items.
* * label a label.
* * listbox a listbox.
@ -621,6 +625,18 @@ twidget* tbuilder_button::build() const
return button;
}
twidget* tbuilder_image::build() const
{
timage* widget = new timage();
init_control(widget);
DBG_G << "Window builder: placed image '" << id << "' with defintion '"
<< definition << "'.\n";
return widget;
}
tbuilder_gridcell::tbuilder_gridcell(const config& cfg) :
tbuilder_widget(cfg),
flags(read_flags(cfg)),

View file

@ -62,6 +62,25 @@ private:
int retval_;
};
struct tbuilder_image : public tbuilder_control
{
/*WIKI
* @page = GUIToolkitWML
* @order = 3_widget_image
*
* == Image ==
*
* An image has no extra fields.
*/
tbuilder_image(const config& cfg)
: tbuilder_control(cfg)
{
}
twidget* build () const;
};
/**
* A temporary helper class.
*