diff --git a/changelog b/changelog index da43ee30746..21d9d646cc4 100644 --- a/changelog +++ b/changelog @@ -15,6 +15,7 @@ Version 1.9.3+svn: * Several improvements to the gui2 progress bar. * New add-ons description dialog with further details, including bundled translations. + * Add new gui2 drawing widget. * WML engine: * New [harm_unit] tag for damaging, and eventually killing, units. * [allow_recruit], [disallow_recruit] and [set_recruit] now accept a diff --git a/data/gui/default/widget/drawing_default.cfg b/data/gui/default/widget/drawing_default.cfg new file mode 100644 index 00000000000..5cf2580fc60 --- /dev/null +++ b/data/gui/default/widget/drawing_default.cfg @@ -0,0 +1,14 @@ +#textdomain wesnoth-lib +### +### Definition of a drawing. +### + +[drawing_definition] + id = "default" + description = "The default drawing." + + [resolution] + [/resolution] + +[/drawing_definition] + diff --git a/po/wesnoth-lib/POTFILES.in b/po/wesnoth-lib/POTFILES.in index ba6622e1fe7..e4d1f4ae52c 100644 --- a/po/wesnoth-lib/POTFILES.in +++ b/po/wesnoth-lib/POTFILES.in @@ -12,6 +12,7 @@ src/gui/auxiliary/log.cpp src/gui/auxiliary/tips.cpp src/gui/auxiliary/widget_definition/button.cpp src/gui/auxiliary/widget_definition.cpp +src/gui/auxiliary/widget_definition/drawing.cpp src/gui/auxiliary/widget_definition/horizontal_scrollbar.cpp src/gui/auxiliary/widget_definition/image.cpp src/gui/auxiliary/widget_definition/label.cpp @@ -34,6 +35,7 @@ src/gui/auxiliary/widget_definition/tree_view.cpp src/gui/auxiliary/widget_definition/vertical_scrollbar.cpp src/gui/auxiliary/widget_definition/window.cpp src/gui/auxiliary/window_builder/button.cpp +src/gui/auxiliary/window_builder/drawing.cpp src/gui/auxiliary/window_builder/control.cpp src/gui/auxiliary/window_builder.cpp src/gui/auxiliary/window_builder/helper.cpp @@ -86,6 +88,7 @@ src/gui/dialogs/unit_create.cpp src/gui/dialogs/wml_message.cpp src/gui/widgets/button.cpp src/gui/widgets/container.cpp +src/gui/widgets/drawing.cpp src/gui/widgets/control.cpp src/gui/widgets/debug.cpp src/gui/widgets/generator.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 42a505a2e0b..ab7be0b57b6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -354,6 +354,7 @@ set(wesnoth-main_SRC gui/auxiliary/tips.cpp gui/auxiliary/widget_definition.cpp gui/auxiliary/widget_definition/button.cpp + gui/auxiliary/widget_definition/drawing.cpp gui/auxiliary/widget_definition/horizontal_scrollbar.cpp gui/auxiliary/widget_definition/image.cpp gui/auxiliary/widget_definition/label.cpp @@ -376,6 +377,7 @@ set(wesnoth-main_SRC gui/auxiliary/widget_definition/vertical_scrollbar.cpp gui/auxiliary/widget_definition/window.cpp gui/auxiliary/window_builder/button.cpp + gui/auxiliary/window_builder/drawing.cpp gui/auxiliary/window_builder/control.cpp gui/auxiliary/window_builder/helper.cpp gui/auxiliary/window_builder/horizontal_listbox.cpp @@ -431,6 +433,7 @@ set(wesnoth-main_SRC gui/dialogs/unit_create.cpp gui/dialogs/wml_message.cpp gui/widgets/button.cpp + gui/widgets/drawing.cpp gui/widgets/control.cpp gui/widgets/container.cpp gui/widgets/debug.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 1a6fc6a91ff..cd66e9d156c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -125,6 +125,7 @@ wesnoth_source = \ gui/auxiliary/tips.cpp \ gui/auxiliary/widget_definition.cpp \ gui/auxiliary/widget_definition/button.cpp \ + gui/auxiliary/widget_definition/drawing.cpp \ gui/auxiliary/widget_definition/horizontal_scrollbar.cpp \ gui/auxiliary/widget_definition/image.cpp \ gui/auxiliary/widget_definition/label.cpp \ @@ -147,6 +148,7 @@ wesnoth_source = \ gui/auxiliary/widget_definition/vertical_scrollbar.cpp \ gui/auxiliary/widget_definition/window.cpp \ gui/auxiliary/window_builder/button.cpp \ + gui/auxiliary/window_builder/drawing.cpp \ gui/auxiliary/window_builder/control.cpp \ gui/auxiliary/window_builder/helper.cpp \ gui/auxiliary/window_builder/horizontal_listbox.cpp \ @@ -202,6 +204,7 @@ wesnoth_source = \ gui/dialogs/unit_create.cpp \ gui/dialogs/wml_message.cpp \ gui/widgets/button.cpp \ + gui/widgets/drawing.cpp \ gui/widgets/control.cpp \ gui/widgets/container.cpp \ gui/widgets/debug.cpp \ diff --git a/src/SConscript b/src/SConscript index 0d6bfbd786e..033692747fd 100644 --- a/src/SConscript +++ b/src/SConscript @@ -294,6 +294,7 @@ wesnoth_sources = Split(""" gui/auxiliary/tips.cpp gui/auxiliary/widget_definition.cpp gui/auxiliary/widget_definition/button.cpp + gui/auxiliary/widget_definition/drawing.cpp gui/auxiliary/widget_definition/horizontal_scrollbar.cpp gui/auxiliary/widget_definition/image.cpp gui/auxiliary/widget_definition/label.cpp @@ -316,6 +317,7 @@ wesnoth_sources = Split(""" gui/auxiliary/widget_definition/tree_view.cpp gui/auxiliary/widget_definition/window.cpp gui/auxiliary/window_builder/button.cpp + gui/auxiliary/window_builder/drawing.cpp gui/auxiliary/window_builder/control.cpp gui/auxiliary/window_builder/helper.cpp gui/auxiliary/window_builder/horizontal_listbox.cpp @@ -371,6 +373,7 @@ wesnoth_sources = Split(""" gui/dialogs/unit_create.cpp gui/dialogs/wml_message.cpp gui/widgets/button.cpp + gui/widgets/drawing.cpp gui/widgets/control.cpp gui/widgets/container.cpp gui/widgets/generator.cpp diff --git a/src/gui/auxiliary/widget_definition/drawing.cpp b/src/gui/auxiliary/widget_definition/drawing.cpp new file mode 100644 index 00000000000..75fbccdb6fe --- /dev/null +++ b/src/gui/auxiliary/widget_definition/drawing.cpp @@ -0,0 +1,60 @@ +/* $Id$ */ +/* + Copyright (C) 2010 by Mark de Wever + 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 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. + + See the COPYING file for more details. +*/ + +#define GETTEXT_DOMAIN "wesnoth-lib" + +#include "gui/auxiliary/widget_definition/drawing.hpp" + +#include "gui/auxiliary/log.hpp" + +namespace gui2 { + +tdrawing_definition::tdrawing_definition(const config& cfg) + : tcontrol_definition(cfg) +{ + DBG_GUI_P << "Parsing drawing " << id << '\n'; + + load_resolutions(cfg); +} + +tdrawing_definition::tresolution::tresolution(const config& cfg) + : tresolution_definition_(cfg) +{ +/*WIKI + * @page = GUIWidgetDefinitionWML + * @order = 1_drawing + * + * == Drawing == + * + * @macro = drawing_description + * + * The definition of a drawing. The widget normally has no event interaction + * so only one state is defined. This + * + * The following states exist: + * * state_enabled, the drawing is enabled. The state is a dummy since the + * things really drawn are placed in the window instance. + */ + /* + * Note the order should be the same as the enum tstate in drawing.hpp. + * Normally the [draw] section is in the config, but for this widget the + * original draw section is ignored, so send a dummy. + */ + static const config dummy("draw"); + state.push_back(tstate_definition(dummy)); +} + +} // namespace gui2 + diff --git a/src/gui/auxiliary/widget_definition/drawing.hpp b/src/gui/auxiliary/widget_definition/drawing.hpp new file mode 100644 index 00000000000..3f462eed385 --- /dev/null +++ b/src/gui/auxiliary/widget_definition/drawing.hpp @@ -0,0 +1,38 @@ +/* $Id$ */ +/* + Copyright (C) 2010 by Mark de Wever + 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 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. + + See the COPYING file for more details. +*/ + +#ifndef GUI_AUXILIARY_WIDGET_DEFINITION_DRAWING_HPP_INCLUDED +#define GUI_AUXILIARY_WIDGET_DEFINITION_DRAWING_HPP_INCLUDED + +#include "gui/auxiliary/widget_definition.hpp" + +namespace gui2 { + +struct tdrawing_definition + : public tcontrol_definition +{ + explicit tdrawing_definition(const config& cfg); + + struct tresolution + : public tresolution_definition_ + { + explicit tresolution(const config& cfg); + }; +}; + +} // namespace gui2 + +#endif + diff --git a/src/gui/auxiliary/window_builder.cpp b/src/gui/auxiliary/window_builder.cpp index 3f4b322b5c3..8d35a179040 100644 --- a/src/gui/auxiliary/window_builder.cpp +++ b/src/gui/auxiliary/window_builder.cpp @@ -35,6 +35,7 @@ #include "gui/auxiliary/window_builder/scroll_label.hpp" #include "gui/auxiliary/window_builder/minimap.hpp" #include "gui/auxiliary/window_builder/button.hpp" +#include "gui/auxiliary/window_builder/drawing.hpp" #endif #include "gui/widgets/settings.hpp" #include "gui/widgets/window.hpp" @@ -108,6 +109,7 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg) TRY(scroll_label); TRY(minimap); TRY(button); + TRY(drawing); #undef TRY #endif diff --git a/src/gui/auxiliary/window_builder/drawing.cpp b/src/gui/auxiliary/window_builder/drawing.cpp new file mode 100644 index 00000000000..88d9a36a81f --- /dev/null +++ b/src/gui/auxiliary/window_builder/drawing.cpp @@ -0,0 +1,97 @@ +/* $Id$ */ +/* + Copyright (C) 2010 by Mark de Wever + 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 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. + + See the COPYING file for more details. +*/ + +#define GETTEXT_DOMAIN "wesnoth-lib" + +#include "gui/auxiliary/window_builder/drawing.hpp" + +#include "config.hpp" +#include "gui/auxiliary/log.hpp" +#include "gui/widgets/drawing.hpp" + +namespace gui2 { + +namespace implementation { + +tbuilder_drawing::tbuilder_drawing(const config& cfg) + : tbuilder_control(cfg) + , width_(cfg["width"]) + , height_(cfg["height"]) + , draw_(cfg.child("draw")) +{ + assert(!draw_.empty()); +} + +twidget* tbuilder_drawing::build() const +{ + tdrawing* widget = new tdrawing(); + + init_control(widget); + + const game_logic::map_formula_callable& size = + get_screen_size_variables(); + + const unsigned width = width_(size); + const unsigned height = height_(size); + + if(width || height) { + widget->set_best_size(tpoint(width, height)); + } + + widget->set_drawing(draw_); + + DBG_GUI_G << "Window builder: placed drawing '" + << id << "' with definition '" + << definition << "'.\n"; + + return widget; +} + +} // namespace implementation + +} // namespace gui2 + +/*WIKI_MACRO + * @start_macro = drawing_description + * + * A drawing is widget with a fixed size and gives access to the + * canvas of the widget in the window instance. This allows special + * display only widgets. + * @end_macro + */ + + +/*WIKI + * @page = GUIWidgetInstanceWML + * @order = 2_drawing + * + * == Spacer == + * + * @macro = drawing_description + * + * If either the width or the height is not zero the drawing functions as a + * fixed size drawing. + * + * @begin{table}{config} + * width & f_unsigned & 0 & The width of the drawing. $ + * height & f_unsigned & 0 & The height of the drawing. $ + * draw & config & & The config containing the drawing. $ + * @end{table} + * + * The variable available are the same as for the window resolution see + * http://www.wesnoth.org/wiki/GUIToolkitWML#Resolution_2 for the list of + * items. + */ + diff --git a/src/gui/auxiliary/window_builder/drawing.hpp b/src/gui/auxiliary/window_builder/drawing.hpp new file mode 100644 index 00000000000..33ff8dc852e --- /dev/null +++ b/src/gui/auxiliary/window_builder/drawing.hpp @@ -0,0 +1,49 @@ +/* $Id$ */ +/* + Copyright (C) 2010 by Mark de Wever + 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 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. + + See the COPYING file for more details. +*/ + +#ifndef GUI_AUXILIARY_WINDOW_BUILDER_DRAWING_HPP_INCLUDED +#define GUI_AUXILIARY_WINDOW_BUILDER_DRAWING_HPP_INCLUDED + +#include "config.hpp" +#include "gui/auxiliary/window_builder/control.hpp" + +namespace gui2 { + +namespace implementation { + +struct tbuilder_drawing + : public tbuilder_control +{ + explicit tbuilder_drawing(const config& cfg); + + twidget* build () const; + +private: + /** The width of the widget. */ + tformula width_; + + /** The height of the widget. */ + tformula height_; + + /** Config containing what to draw on the widgets canvas. */ + config draw_; +}; + +} // namespace implementation + +} // namespace gui2 + +#endif + diff --git a/src/gui/widgets/drawing.cpp b/src/gui/widgets/drawing.cpp new file mode 100644 index 00000000000..6847ca342ee --- /dev/null +++ b/src/gui/widgets/drawing.cpp @@ -0,0 +1,42 @@ +/* $Id$ */ +/* + Copyright (C) 2010 by Mark de Wever + 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 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. + + See the COPYING file for more details. +*/ + +#define GETTEXT_DOMAIN "wesnoth-lib" + +#include "gui/widgets/drawing.hpp" + +#include "gui/auxiliary/widget_definition/drawing.hpp" +#include "gui/auxiliary/window_builder/drawing.hpp" +#include "gui/widgets/settings.hpp" + +#include + +namespace gui2 { + +REGISTER_WIDGET(drawing) + +void tdrawing::set_drawing(const ::config& cfg) +{ + canvas().front().set_cfg(cfg); +} + +const std::string& tdrawing::get_control_type() const +{ + static const std::string type = "drawing"; + return type; +} + +} // namespace gui2 + diff --git a/src/gui/widgets/drawing.hpp b/src/gui/widgets/drawing.hpp new file mode 100644 index 00000000000..0d5d5a58e39 --- /dev/null +++ b/src/gui/widgets/drawing.hpp @@ -0,0 +1,92 @@ +/* $Id$ */ +/* + Copyright (C) 2010 by Mark de Wever + 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 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. + + See the COPYING file for more details. +*/ + +#ifndef GUI_WIDGETS_DRAWING_HPP_INCLUDED +#define GUI_WIDGETS_DRAWING_HPP_INCLUDED + +#include "gui/widgets/control.hpp" + +namespace gui2 { + +/** + * A widget to draw upon. + * + * This widget has a fixed size like the spacer, but allows the user to + * manual draw items. The widget is display only. + */ +class tdrawing + : public tcontrol +{ +public: + tdrawing() + : tcontrol(COUNT) + , best_size_(0, 0) + { + } + + /***** ***** ***** ***** layout functions ***** ***** ***** *****/ + +private: + /** Inherited from tcontrol. */ + tpoint calculate_best_size() const + { + return best_size_ != tpoint(0, 0) + ? best_size_ : tcontrol::calculate_best_size(); + } +public: + + void set_drawing(const ::config& cfg); + + /***** ***** ***** ***** Inherited ***** ***** ***** *****/ + + /** Inherited from tcontrol. */ + void set_active(const bool) {} + + /** Inherited from tcontrol. */ + bool get_active() const { return true; } + + /** Inherited from tcontrol. */ + unsigned get_state() const { return 0; } + + /** Inherited from tcontrol. */ + bool disable_click_dismiss() const { return false; } + + /***** ***** ***** setters / getters for members ***** ****** *****/ + + void set_best_size(const tpoint& best_size) { best_size_ = best_size; } + +private: + + /** + * Possible states of the widget. + * + * Note the order of the states must be the same as defined in + * settings.hpp. + */ + enum tstate { ENABLED, COUNT }; + + /** When we're used as a fixed size item, this holds the best size. */ + tpoint best_size_; + + /** Inherited from tcontrol. */ + const std::string& get_control_type() const; +}; + + +} // namespace gui2 + +#endif + +