Implement the new scrollbar panel widget.

The widget isn't used yet, but will be for the campaign dialog.
This commit is contained in:
Mark de Wever 2009-06-02 19:41:15 +00:00
parent af522cbcf0
commit c60186f971
12 changed files with 340 additions and 0 deletions

View file

@ -0,0 +1,73 @@
#textdomain wesnoth-lib
###
### Default definition of a scrollbar panel.
###
[scrollbar_panel_definition]
id = "default"
description = "The scrollbar default panel, we basically are an 'invisible' grid at the moment."
[resolution]
[background]
[draw]
[/draw]
[/background]
[foreground]
[draw]
[/draw]
[/foreground]
[grid]
[row]
grow_factor = 1
[column]
grow_factor = 1
# Needed since the widget is replaced with a dummy.
horizontal_grow = "true"
vertical_grow = "true"
[grid]
id = "_content_grid"
[/grid]
[/column]
[column]
{GUI__VERTICAL_SCROLLBAR_GRID}
[/column]
[/row]
[row]
[column]
{GUI__HORIZONTAL_SCROLLBAR_GRID}
[/column]
[column]
[spacer]
[/spacer]
[/column]
[/row]
[/grid]
[/resolution]
[/scrollbar_panel_definition]

View file

@ -40,6 +40,7 @@ src/gui/widgets/panel.cpp
src/gui/widgets/password_box.cpp
src/gui/widgets/scroll_label.cpp
src/gui/widgets/scrollbar_container.cpp
src/gui/widgets/scrollbar_panel.cpp
src/gui/widgets/scrollbar.cpp
src/gui/widgets/settings.cpp
src/gui/widgets/slider.cpp

View file

@ -289,6 +289,7 @@ SET(wesnoth-main_SRC
gui/widgets/spacer.cpp
gui/widgets/scroll_label.cpp
gui/widgets/scrollbar_container.cpp
gui/widgets/scrollbar_panel.cpp
gui/widgets/scrollbar.cpp
gui/widgets/text.cpp
gui/widgets/text_box.cpp

View file

@ -113,6 +113,7 @@ wesnoth_source = \
gui/widgets/scroll_label.cpp \
gui/widgets/scrollbar.cpp \
gui/widgets/scrollbar_container.cpp \
gui/widgets/scrollbar_panel.cpp \
gui/widgets/slider.cpp \
gui/widgets/spacer.cpp \
gui/widgets/text.cpp \

View file

@ -266,6 +266,7 @@ wesnoth_sources = Split("""
gui/widgets/settings.cpp
gui/widgets/scroll_label.cpp
gui/widgets/scrollbar_container.cpp
gui/widgets/scrollbar_panel.cpp
gui/widgets/scrollbar.cpp
gui/widgets/slider.cpp
gui/widgets/spacer.cpp

View file

@ -30,6 +30,7 @@
#include "gui/widgets/multi_page.hpp"
#include "gui/widgets/password_box.hpp"
#include "gui/widgets/scroll_label.hpp"
#include "gui/widgets/scrollbar_panel.hpp"
#include "gui/widgets/slider.hpp"
#include "gui/widgets/spacer.hpp"
#include "gui/widgets/text_box.hpp"
@ -186,6 +187,7 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
TRY(multi_page);
TRY(panel);
TRY(scroll_label);
TRY(scrollbar_panel);
TRY(slider);
TRY(spacer);
TRY(text_box);
@ -1146,6 +1148,105 @@ tbuilder_slider::tbuilder_slider(const config& cfg) :
}
}
tbuilder_scrollbar_panel::tbuilder_scrollbar_panel(const config& cfg)
: tbuilder_control(cfg)
, vertical_scrollbar_mode(
get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
, horizontal_scrollbar_mode(
get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
, grid(0)
{
/*WIKI
* @page = GUIWidgetInstanceWML
* @order = 2_scrollbar_panel
*
* == Scrollbar panel ==
*
* Instance of a scrollbar_panel.
*
* List with the scrollbar_panel specific variables:
* @start_table = config
* vertical_scrollbar_mode (scrollbar_mode = auto | initial_auto)
* Determines whether or not to show the
* scrollbar. The default of initial_auto
* is used when --new-widgets is used.
* In the future the default will be
* auto.
* horizontal_scrollbar_mode (scrollbar_mode = auto | initial_auto)
* Determines whether or not to show the
* scrollbar. The default of initial_auto
* is used when --new-widgets is used.
* In the future the default will be
* initial_auto.
*
* definition (section) This defines how a scrollbar_panel item
* looks. It must contain the grid
* definition for 1 row of the list.
*
* @end_table
*
*/
const config &definition = cfg.child("definition");
VALIDATE(definition, _("No list defined."));
grid = new tbuilder_grid(definition);
assert(grid);
}
twidget* tbuilder_scrollbar_panel::build() const
{
tscrollbar_panel *scrollbar_panel = new tscrollbar_panel();
init_control(scrollbar_panel);
scrollbar_panel->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
scrollbar_panel->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
DBG_GUI_G << "Window builder: placed scrollbar_panel '" << id << "' with defintion '"
<< definition << "'.\n";
boost::intrusive_ptr<
const tscrollbar_panel_definition::tresolution> conf =
boost::dynamic_pointer_cast
<const tscrollbar_panel_definition::tresolution>
(scrollbar_panel->config());
assert(conf);
conf->grid->build(&scrollbar_panel->grid());
scrollbar_panel->finalize_setup();
/*** Fill the content grid. ***/
tgrid* content_grid = scrollbar_panel->content_grid();
assert(content_grid);
const unsigned rows = grid->rows;
const unsigned cols = grid->cols;
content_grid->set_rows_cols(rows, cols);
for(unsigned x = 0; x < rows; ++x) {
content_grid->set_row_grow_factor(x, grid->row_grow_factor[x]);
for(unsigned y = 0; y < cols; ++y) {
if(x == 0) {
content_grid->set_col_grow_factor(y
, grid->col_grow_factor[y]);
}
twidget* widget = grid->widgets[x * cols + y]->build();
content_grid->set_child(widget
, x
, y
, grid->flags[x * cols + y]
, grid->border_size[x * cols + y]);
}
}
return scrollbar_panel;
}
twidget* tbuilder_slider::build() const
{
tslider* slider = new tslider();

View file

@ -292,6 +292,24 @@ private:
bool auto_hide_scrollbar_;
};
struct tbuilder_scrollbar_panel
: public tbuilder_control
{
private:
tbuilder_scrollbar_panel();
public:
tbuilder_scrollbar_panel(const config& cfg);
twidget* build () const;
tscrollbar_container::tscrollbar_mode
vertical_scrollbar_mode,
horizontal_scrollbar_mode;
tbuilder_grid_ptr grid;
};
struct tbuilder_spacer : public tbuilder_control
{

View file

@ -36,6 +36,7 @@ class tscrollbar_container
friend class tdebug_layout_graph;
friend struct tbuilder_scroll_label;
friend struct tbuilder_scrollbar_panel;
friend class tlistbox;
friend struct tscrollbar_container_implementation;

View file

@ -0,0 +1,22 @@
/* $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/widgets/scrollbar_panel.hpp"
namespace gui2 {
} // namespace gui2

View file

@ -0,0 +1,65 @@
/* $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_WIDGETS_SCROLLBAR_PANEL_HPP_INCLUDED
#define GUI_WIDGETS_SCROLLBAR_PANEL_HPP_INCLUDED
#include "gui/widgets/scrollbar_container.hpp"
namespace gui2 {
/**
* Visible container to hold multiple widgets.
*
* This widget can draw items beyond the widgets it holds and in front of
* them. A panel is always active so these functions return dummy values.
*/
class tscrollbar_panel
: public tscrollbar_container
{
friend class tbuilder_scrollbar_panel;
public:
/**
* Constructor.
*
* @param canvas_count The canvas count for tcontrol.
*/
tscrollbar_panel(const unsigned canvas_count = 2) :
tscrollbar_container(canvas_count)
{
}
/** Inherited from tcontrol. */
bool get_active() const { return true; }
/** Inherited from tcontrol. */
unsigned get_state() const { return 0; }
private:
/** Inherited from tcontrol. */
const std::string& get_control_type() const
{ static const std::string type = "scrollbar_panel"; return type; }
/** Inherited from tcontainer_. */
void set_self_active(const bool /*active*/) {}
};
} // namespace gui2
#endif

View file

@ -271,6 +271,7 @@ const std::string& tgui_definition::read(const config& cfg)
load_definitions<tmulti_page_definition>("multi_page", cfg);
load_definitions<tpanel_definition>("panel", cfg);
load_definitions<tscroll_label_definition>("scroll_label", cfg);
load_definitions<tscrollbar_panel_definition>("scrollbar_panel", cfg);
load_definitions<tslider_definition>("slider", cfg);
load_definitions<tspacer_definition>("spacer", cfg);
load_definitions<ttext_box_definition>("text_box", cfg);
@ -953,6 +954,48 @@ tscroll_label_definition::tresolution::tresolution(const config& cfg) :
grid = new tbuilder_grid(child);
}
tscrollbar_panel_definition::tscrollbar_panel_definition(const config& cfg)
: tcontrol_definition(cfg)
{
DBG_GUI_P << "Parsing scrollbar panel " << id << '\n';
load_resolutions<tresolution>(cfg);
}
tscrollbar_panel_definition::tresolution::tresolution(const config& cfg)
: tresolution_definition_(cfg)
{
/*WIKI
* @page = GUIWidgetDefinitionWML
* @order = 1_scrollbar_panel
*
* == Scrollbar panel ==
*
* The definition of a panel with scrollbars. A panel is a container hold
* other elements in it's grid. A panel is always enabled and can't be
* disabled. Instead it uses the states as layers to draw on.
*
* @start_table = config
* grid (grid) A grid containing the widgets for main
* widget.
* @end_table
*
* The following layers exist:
* * background, the background of the panel.
* * foreground, the foreground of the panel.
*/
// The panel needs to know the order.
state.push_back(tstate_definition(cfg.child("background")));
state.push_back(tstate_definition(cfg.child("foreground")));
const config &child = cfg.child("grid");
VALIDATE(child, _("No grid defined."));
grid = new tbuilder_grid(child);
}
tslider_definition::tslider_definition(const config& cfg) :
tcontrol_definition(cfg)
{

View file

@ -284,6 +284,19 @@ struct tscroll_label_definition : public tcontrol_definition
};
};
struct tscrollbar_panel_definition : public tcontrol_definition
{
tscrollbar_panel_definition(const config& cfg);
struct tresolution : public tresolution_definition_
{
tresolution(const config& cfg);
tbuilder_grid_ptr grid;
};
};
struct tslider_definition : public tcontrol_definition
{
tslider_definition(const config& cfg);