Add drawing widget.
This widget allows to customize drawing the widget in the window definition. The widget has, like the spacer a fixed best size.
This commit is contained in:
parent
22f7e80164
commit
119349b09e
13 changed files with 407 additions and 0 deletions
|
@ -15,6 +15,7 @@ Version 1.9.3+svn:
|
||||||
* Several improvements to the gui2 progress bar.
|
* Several improvements to the gui2 progress bar.
|
||||||
* New add-ons description dialog with further details, including bundled
|
* New add-ons description dialog with further details, including bundled
|
||||||
translations.
|
translations.
|
||||||
|
* Add new gui2 drawing widget.
|
||||||
* WML engine:
|
* WML engine:
|
||||||
* New [harm_unit] tag for damaging, and eventually killing, units.
|
* New [harm_unit] tag for damaging, and eventually killing, units.
|
||||||
* [allow_recruit], [disallow_recruit] and [set_recruit] now accept a
|
* [allow_recruit], [disallow_recruit] and [set_recruit] now accept a
|
||||||
|
|
14
data/gui/default/widget/drawing_default.cfg
Normal file
14
data/gui/default/widget/drawing_default.cfg
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#textdomain wesnoth-lib
|
||||||
|
###
|
||||||
|
### Definition of a drawing.
|
||||||
|
###
|
||||||
|
|
||||||
|
[drawing_definition]
|
||||||
|
id = "default"
|
||||||
|
description = "The default drawing."
|
||||||
|
|
||||||
|
[resolution]
|
||||||
|
[/resolution]
|
||||||
|
|
||||||
|
[/drawing_definition]
|
||||||
|
|
|
@ -12,6 +12,7 @@ src/gui/auxiliary/log.cpp
|
||||||
src/gui/auxiliary/tips.cpp
|
src/gui/auxiliary/tips.cpp
|
||||||
src/gui/auxiliary/widget_definition/button.cpp
|
src/gui/auxiliary/widget_definition/button.cpp
|
||||||
src/gui/auxiliary/widget_definition.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/horizontal_scrollbar.cpp
|
||||||
src/gui/auxiliary/widget_definition/image.cpp
|
src/gui/auxiliary/widget_definition/image.cpp
|
||||||
src/gui/auxiliary/widget_definition/label.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/vertical_scrollbar.cpp
|
||||||
src/gui/auxiliary/widget_definition/window.cpp
|
src/gui/auxiliary/widget_definition/window.cpp
|
||||||
src/gui/auxiliary/window_builder/button.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/control.cpp
|
||||||
src/gui/auxiliary/window_builder.cpp
|
src/gui/auxiliary/window_builder.cpp
|
||||||
src/gui/auxiliary/window_builder/helper.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/dialogs/wml_message.cpp
|
||||||
src/gui/widgets/button.cpp
|
src/gui/widgets/button.cpp
|
||||||
src/gui/widgets/container.cpp
|
src/gui/widgets/container.cpp
|
||||||
|
src/gui/widgets/drawing.cpp
|
||||||
src/gui/widgets/control.cpp
|
src/gui/widgets/control.cpp
|
||||||
src/gui/widgets/debug.cpp
|
src/gui/widgets/debug.cpp
|
||||||
src/gui/widgets/generator.cpp
|
src/gui/widgets/generator.cpp
|
||||||
|
|
|
@ -354,6 +354,7 @@ set(wesnoth-main_SRC
|
||||||
gui/auxiliary/tips.cpp
|
gui/auxiliary/tips.cpp
|
||||||
gui/auxiliary/widget_definition.cpp
|
gui/auxiliary/widget_definition.cpp
|
||||||
gui/auxiliary/widget_definition/button.cpp
|
gui/auxiliary/widget_definition/button.cpp
|
||||||
|
gui/auxiliary/widget_definition/drawing.cpp
|
||||||
gui/auxiliary/widget_definition/horizontal_scrollbar.cpp
|
gui/auxiliary/widget_definition/horizontal_scrollbar.cpp
|
||||||
gui/auxiliary/widget_definition/image.cpp
|
gui/auxiliary/widget_definition/image.cpp
|
||||||
gui/auxiliary/widget_definition/label.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/vertical_scrollbar.cpp
|
||||||
gui/auxiliary/widget_definition/window.cpp
|
gui/auxiliary/widget_definition/window.cpp
|
||||||
gui/auxiliary/window_builder/button.cpp
|
gui/auxiliary/window_builder/button.cpp
|
||||||
|
gui/auxiliary/window_builder/drawing.cpp
|
||||||
gui/auxiliary/window_builder/control.cpp
|
gui/auxiliary/window_builder/control.cpp
|
||||||
gui/auxiliary/window_builder/helper.cpp
|
gui/auxiliary/window_builder/helper.cpp
|
||||||
gui/auxiliary/window_builder/horizontal_listbox.cpp
|
gui/auxiliary/window_builder/horizontal_listbox.cpp
|
||||||
|
@ -431,6 +433,7 @@ set(wesnoth-main_SRC
|
||||||
gui/dialogs/unit_create.cpp
|
gui/dialogs/unit_create.cpp
|
||||||
gui/dialogs/wml_message.cpp
|
gui/dialogs/wml_message.cpp
|
||||||
gui/widgets/button.cpp
|
gui/widgets/button.cpp
|
||||||
|
gui/widgets/drawing.cpp
|
||||||
gui/widgets/control.cpp
|
gui/widgets/control.cpp
|
||||||
gui/widgets/container.cpp
|
gui/widgets/container.cpp
|
||||||
gui/widgets/debug.cpp
|
gui/widgets/debug.cpp
|
||||||
|
|
|
@ -125,6 +125,7 @@ wesnoth_source = \
|
||||||
gui/auxiliary/tips.cpp \
|
gui/auxiliary/tips.cpp \
|
||||||
gui/auxiliary/widget_definition.cpp \
|
gui/auxiliary/widget_definition.cpp \
|
||||||
gui/auxiliary/widget_definition/button.cpp \
|
gui/auxiliary/widget_definition/button.cpp \
|
||||||
|
gui/auxiliary/widget_definition/drawing.cpp \
|
||||||
gui/auxiliary/widget_definition/horizontal_scrollbar.cpp \
|
gui/auxiliary/widget_definition/horizontal_scrollbar.cpp \
|
||||||
gui/auxiliary/widget_definition/image.cpp \
|
gui/auxiliary/widget_definition/image.cpp \
|
||||||
gui/auxiliary/widget_definition/label.cpp \
|
gui/auxiliary/widget_definition/label.cpp \
|
||||||
|
@ -147,6 +148,7 @@ wesnoth_source = \
|
||||||
gui/auxiliary/widget_definition/vertical_scrollbar.cpp \
|
gui/auxiliary/widget_definition/vertical_scrollbar.cpp \
|
||||||
gui/auxiliary/widget_definition/window.cpp \
|
gui/auxiliary/widget_definition/window.cpp \
|
||||||
gui/auxiliary/window_builder/button.cpp \
|
gui/auxiliary/window_builder/button.cpp \
|
||||||
|
gui/auxiliary/window_builder/drawing.cpp \
|
||||||
gui/auxiliary/window_builder/control.cpp \
|
gui/auxiliary/window_builder/control.cpp \
|
||||||
gui/auxiliary/window_builder/helper.cpp \
|
gui/auxiliary/window_builder/helper.cpp \
|
||||||
gui/auxiliary/window_builder/horizontal_listbox.cpp \
|
gui/auxiliary/window_builder/horizontal_listbox.cpp \
|
||||||
|
@ -202,6 +204,7 @@ wesnoth_source = \
|
||||||
gui/dialogs/unit_create.cpp \
|
gui/dialogs/unit_create.cpp \
|
||||||
gui/dialogs/wml_message.cpp \
|
gui/dialogs/wml_message.cpp \
|
||||||
gui/widgets/button.cpp \
|
gui/widgets/button.cpp \
|
||||||
|
gui/widgets/drawing.cpp \
|
||||||
gui/widgets/control.cpp \
|
gui/widgets/control.cpp \
|
||||||
gui/widgets/container.cpp \
|
gui/widgets/container.cpp \
|
||||||
gui/widgets/debug.cpp \
|
gui/widgets/debug.cpp \
|
||||||
|
|
|
@ -294,6 +294,7 @@ wesnoth_sources = Split("""
|
||||||
gui/auxiliary/tips.cpp
|
gui/auxiliary/tips.cpp
|
||||||
gui/auxiliary/widget_definition.cpp
|
gui/auxiliary/widget_definition.cpp
|
||||||
gui/auxiliary/widget_definition/button.cpp
|
gui/auxiliary/widget_definition/button.cpp
|
||||||
|
gui/auxiliary/widget_definition/drawing.cpp
|
||||||
gui/auxiliary/widget_definition/horizontal_scrollbar.cpp
|
gui/auxiliary/widget_definition/horizontal_scrollbar.cpp
|
||||||
gui/auxiliary/widget_definition/image.cpp
|
gui/auxiliary/widget_definition/image.cpp
|
||||||
gui/auxiliary/widget_definition/label.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/tree_view.cpp
|
||||||
gui/auxiliary/widget_definition/window.cpp
|
gui/auxiliary/widget_definition/window.cpp
|
||||||
gui/auxiliary/window_builder/button.cpp
|
gui/auxiliary/window_builder/button.cpp
|
||||||
|
gui/auxiliary/window_builder/drawing.cpp
|
||||||
gui/auxiliary/window_builder/control.cpp
|
gui/auxiliary/window_builder/control.cpp
|
||||||
gui/auxiliary/window_builder/helper.cpp
|
gui/auxiliary/window_builder/helper.cpp
|
||||||
gui/auxiliary/window_builder/horizontal_listbox.cpp
|
gui/auxiliary/window_builder/horizontal_listbox.cpp
|
||||||
|
@ -371,6 +373,7 @@ wesnoth_sources = Split("""
|
||||||
gui/dialogs/unit_create.cpp
|
gui/dialogs/unit_create.cpp
|
||||||
gui/dialogs/wml_message.cpp
|
gui/dialogs/wml_message.cpp
|
||||||
gui/widgets/button.cpp
|
gui/widgets/button.cpp
|
||||||
|
gui/widgets/drawing.cpp
|
||||||
gui/widgets/control.cpp
|
gui/widgets/control.cpp
|
||||||
gui/widgets/container.cpp
|
gui/widgets/container.cpp
|
||||||
gui/widgets/generator.cpp
|
gui/widgets/generator.cpp
|
||||||
|
|
60
src/gui/auxiliary/widget_definition/drawing.cpp
Normal file
60
src/gui/auxiliary/widget_definition/drawing.cpp
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/*
|
||||||
|
Copyright (C) 2010 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 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<tresolution>(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
|
||||||
|
|
38
src/gui/auxiliary/widget_definition/drawing.hpp
Normal file
38
src/gui/auxiliary/widget_definition/drawing.hpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/*
|
||||||
|
Copyright (C) 2010 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 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
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "gui/auxiliary/window_builder/scroll_label.hpp"
|
#include "gui/auxiliary/window_builder/scroll_label.hpp"
|
||||||
#include "gui/auxiliary/window_builder/minimap.hpp"
|
#include "gui/auxiliary/window_builder/minimap.hpp"
|
||||||
#include "gui/auxiliary/window_builder/button.hpp"
|
#include "gui/auxiliary/window_builder/button.hpp"
|
||||||
|
#include "gui/auxiliary/window_builder/drawing.hpp"
|
||||||
#endif
|
#endif
|
||||||
#include "gui/widgets/settings.hpp"
|
#include "gui/widgets/settings.hpp"
|
||||||
#include "gui/widgets/window.hpp"
|
#include "gui/widgets/window.hpp"
|
||||||
|
@ -108,6 +109,7 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
|
||||||
TRY(scroll_label);
|
TRY(scroll_label);
|
||||||
TRY(minimap);
|
TRY(minimap);
|
||||||
TRY(button);
|
TRY(button);
|
||||||
|
TRY(drawing);
|
||||||
#undef TRY
|
#undef TRY
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
97
src/gui/auxiliary/window_builder/drawing.cpp
Normal file
97
src/gui/auxiliary/window_builder/drawing.cpp
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/*
|
||||||
|
Copyright (C) 2010 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 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.
|
||||||
|
*/
|
||||||
|
|
49
src/gui/auxiliary/window_builder/drawing.hpp
Normal file
49
src/gui/auxiliary/window_builder/drawing.hpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/*
|
||||||
|
Copyright (C) 2010 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 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<unsigned> width_;
|
||||||
|
|
||||||
|
/** The height of the widget. */
|
||||||
|
tformula<unsigned> height_;
|
||||||
|
|
||||||
|
/** Config containing what to draw on the widgets canvas. */
|
||||||
|
config draw_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace implementation
|
||||||
|
|
||||||
|
} // namespace gui2
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
42
src/gui/widgets/drawing.cpp
Normal file
42
src/gui/widgets/drawing.cpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/*
|
||||||
|
Copyright (C) 2010 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 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 <boost/bind.hpp>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
92
src/gui/widgets/drawing.hpp
Normal file
92
src/gui/widgets/drawing.hpp
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/*
|
||||||
|
Copyright (C) 2010 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 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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue