Add a builder for a viewport.
It allows to use a viewport in a grid. It's now also possible to own the widget in the viewport. The code is used to experiment with a different approach of the implementation of a listbox.
This commit is contained in:
parent
60b4a2d8ab
commit
036f932414
9 changed files with 166 additions and 0 deletions
|
@ -1743,6 +1743,18 @@
|
|||
max="1"
|
||||
super="generic/widget_instance"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="viewport"
|
||||
min="0"
|
||||
max="-1"
|
||||
super="generic/widget_instance"
|
||||
[tag]
|
||||
name="widget"
|
||||
min="1"
|
||||
max="1"
|
||||
super="gui/window/resolution/grid/row/column"
|
||||
[/tag]
|
||||
[/tag]
|
||||
[link]
|
||||
name="gui/window/resolution/grid"
|
||||
[/link]
|
||||
|
|
|
@ -65,6 +65,7 @@ src/gui/auxiliary/window_builder/toggle_button.cpp
|
|||
src/gui/auxiliary/window_builder/toggle_panel.cpp
|
||||
src/gui/auxiliary/window_builder/tree_view.cpp
|
||||
src/gui/auxiliary/window_builder/vertical_scrollbar.cpp
|
||||
src/gui/auxiliary/window_builder/viewport.cpp
|
||||
src/gui/dialogs/addon_connect.cpp
|
||||
src/gui/dialogs/addon/description.cpp
|
||||
src/gui/dialogs/addon_list.cpp
|
||||
|
|
|
@ -473,6 +473,7 @@ set(wesnoth-main_SRC
|
|||
gui/auxiliary/window_builder/toggle_panel.cpp
|
||||
gui/auxiliary/window_builder/tree_view.cpp
|
||||
gui/auxiliary/window_builder/vertical_scrollbar.cpp
|
||||
gui/auxiliary/window_builder/viewport.cpp
|
||||
gui/dialogs/addon/description.cpp
|
||||
gui/dialogs/addon/uninstall_list.cpp
|
||||
gui/dialogs/addon_connect.cpp
|
||||
|
|
|
@ -317,6 +317,7 @@ wesnoth_sources = Split("""
|
|||
gui/auxiliary/window_builder/toggle_panel.cpp
|
||||
gui/auxiliary/window_builder/tree_view.cpp
|
||||
gui/auxiliary/window_builder/vertical_scrollbar.cpp
|
||||
gui/auxiliary/window_builder/viewport.cpp
|
||||
gui/dialogs/addon/description.cpp
|
||||
gui/dialogs/addon/uninstall_list.cpp
|
||||
gui/dialogs/addon_connect.cpp
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "gui/auxiliary/window_builder/button.hpp"
|
||||
#include "gui/auxiliary/window_builder/drawing.hpp"
|
||||
#include "gui/auxiliary/window_builder/password_box.hpp"
|
||||
#include "gui/auxiliary/window_builder/viewport.hpp"
|
||||
#endif
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
|
@ -170,6 +171,10 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
|
|||
if(const config &c = cfg.child("grid")) {
|
||||
return new tbuilder_grid(c);
|
||||
}
|
||||
|
||||
if(const config& viewport = cfg.child("viewport")) {
|
||||
return new implementation::tbuilder_viewport(viewport);
|
||||
}
|
||||
/*
|
||||
* This is rather odd, when commented out the classes no longer seem to be in
|
||||
* the executable, no real idea why, except maybe of an overzealous optimizer
|
||||
|
|
67
src/gui/auxiliary/window_builder/viewport.cpp
Normal file
67
src/gui/auxiliary/window_builder/viewport.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2012 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/viewport.hpp"
|
||||
|
||||
#include "gui/widgets/viewport.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
namespace implementation {
|
||||
|
||||
tbuilder_viewport::tbuilder_viewport(const config& cfg)
|
||||
: tbuilder_widget(cfg)
|
||||
, widget(create_builder_widget(cfg.child("widget", "[viewport]")))
|
||||
{
|
||||
}
|
||||
|
||||
twidget* tbuilder_viewport::build() const
|
||||
{
|
||||
return tviewport::build(*this);
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
||||
/*WIKI_MACRO
|
||||
* @begin{macro}{viewport_description}
|
||||
*
|
||||
* A viewport is an special widget used to view only a part of the
|
||||
* widget it `holds'.
|
||||
* @end{macro}
|
||||
*/
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWidgetInstanceWML
|
||||
* @order = 2_viewport
|
||||
* @begin{parent}{name="gui/window/resolution/grid/row/column/"}
|
||||
* @begin{tag}{name="viewport"}{min=0}{max=-1}{super="generic/widget_instance"}
|
||||
* @begin{tag}{name="widget"}{min="1"}{max="1"}{super="gui/window/resolution/grid/row/column"}
|
||||
* == Label ==
|
||||
*
|
||||
* @macro = viewport_description
|
||||
*
|
||||
* List with the label specific variables:
|
||||
* @begin{table}{config}
|
||||
* widget & section & & Holds a single widget like a grid cell.$
|
||||
* @end{table}
|
||||
* @end{tag}{name="widget"}
|
||||
* @end{tag}{name="viewport"}
|
||||
* @end{parent}{name="gui/window/resolution/grid/row/column/"}
|
||||
*/
|
41
src/gui/auxiliary/window_builder/viewport.hpp
Normal file
41
src/gui/auxiliary/window_builder/viewport.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2012 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_VIEWPORT_HPP_INCLUDED
|
||||
#define GUI_AUXILIARY_WINDOW_BUILDER_VIEWPORT_HPP_INCLUDED
|
||||
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
namespace implementation {
|
||||
|
||||
struct tbuilder_viewport
|
||||
: public tbuilder_widget
|
||||
{
|
||||
explicit tbuilder_viewport(const config& cfg);
|
||||
|
||||
twidget* build() const;
|
||||
|
||||
tbuilder_widget_ptr widget;
|
||||
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
#include "utils/const_clone.tpp"
|
||||
#include "gui/auxiliary/window_builder/viewport.hpp"
|
||||
|
||||
#define LOG_SCOPE_HEADER "tviewport [" + id() + "] " + __func__
|
||||
#define LOG_HEADER LOG_SCOPE_HEADER + ':'
|
||||
|
@ -84,10 +85,30 @@ struct tviewport_implementation
|
|||
|
||||
tviewport::tviewport(twidget& widget)
|
||||
: widget_(widget)
|
||||
, owns_widget_(false)
|
||||
{
|
||||
widget_.set_parent(this);
|
||||
}
|
||||
|
||||
tviewport::tviewport(const implementation::tbuilder_viewport& builder)
|
||||
: twidget(builder)
|
||||
, widget_(*builder.widget->build())
|
||||
, owns_widget_(true)
|
||||
{
|
||||
}
|
||||
|
||||
tviewport::~tviewport()
|
||||
{
|
||||
if(owns_widget_) {
|
||||
delete &widget_;
|
||||
}
|
||||
}
|
||||
|
||||
tviewport* tviewport::build(const implementation::tbuilder_viewport& builder)
|
||||
{
|
||||
return new tviewport(builder);
|
||||
}
|
||||
|
||||
void tviewport::place(const tpoint& origin, const tpoint& size)
|
||||
{
|
||||
twidget::place(origin, size);
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
|
||||
namespace gui2 {
|
||||
|
||||
namespace implementation {
|
||||
class tbuilder_viewport;
|
||||
} // namespace implementation
|
||||
|
||||
class tgrid;
|
||||
|
||||
class tviewport
|
||||
|
@ -28,8 +32,19 @@ class tviewport
|
|||
friend struct tviewport_implementation;
|
||||
public:
|
||||
|
||||
/** @deprecated use the second overload. */
|
||||
explicit tviewport(twidget& widget);
|
||||
|
||||
private:
|
||||
|
||||
explicit tviewport(const implementation::tbuilder_viewport& builder);
|
||||
|
||||
public:
|
||||
|
||||
static tviewport* build(const implementation::tbuilder_viewport& builder);
|
||||
|
||||
~tviewport();
|
||||
|
||||
/** Inherited from twidget. */
|
||||
void place(const tpoint& origin, const tpoint& size);
|
||||
|
||||
|
@ -75,6 +90,8 @@ private:
|
|||
|
||||
twidget& widget_;
|
||||
|
||||
bool owns_widget_;
|
||||
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
|
Loading…
Add table
Reference in a new issue