The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
scrollbar_panel.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
20 #include "gui/widgets/settings.hpp"
22 
23 #include "gettext.hpp"
24 #include "wml_exception.hpp"
25 
26 #include "utils/functional.hpp"
27 
28 namespace gui2
29 {
30 
31 // ------------ WIDGET -----------{
32 
33 REGISTER_WIDGET(scrollbar_panel)
34 
35 bool tscrollbar_panel::get_active() const
36 {
37  return true;
38 }
39 
41 {
42  return 0;
43 }
44 
46 {
47  static const std::string type = "scrollbar_panel";
48  return type;
49 }
50 
51 void tscrollbar_panel::set_self_active(const bool /*active*/)
52 {
53  /* DO NOTHING */
54 }
55 
56 // }---------- DEFINITION ---------{
57 
59  : tcontrol_definition(cfg)
60 {
61  DBG_GUI_P << "Parsing scrollbar panel " << id << '\n';
62 
63  load_resolutions<tresolution>(cfg);
64 }
65 
66 /*WIKI
67  * @page = GUIWidgetDefinitionWML
68  * @order = 1_scrollbar_panel
69  *
70  * == Scrollbar panel ==
71  *
72  * @begin{parent}{name="gui/"}
73  * @begin{tag}{name="scrollbar_panel_definition"}{min=0}{max=-1}{super="generic/widget_definition"}
74  * @begin{tag}{name="resolution"}{min=0}{max=-1}{super="gui/window_definition/resolution"}
75  * The definition of a panel with scrollbars. A panel is a container holding
76  * other elements in its grid. A panel is always enabled and can't be
77  * disabled. Instead it uses the states as layers to draw on.
78  *
79  * @begin{table}{config}
80  * grid & grid & & A grid containing the widgets for main
81  * widget. $
82  * @end{table}
83  * The following layers exist:
84  * * background, the background of the panel.
85  * * foreground, the foreground of the panel.
86  *
87  * @end{tag}{name="resolution"}
88  * @end{tag}{name="scrollbar_panel_definition"}
89  * @end{parent}{name="gui/"}
90  */
93 {
94  // The panel needs to know the order.
95  state.push_back(tstate_definition(cfg.child("background")));
96  state.push_back(tstate_definition(cfg.child("foreground")));
97 
98  const config& child = cfg.child("grid");
99  VALIDATE(child, _("No grid defined."));
100 
101  grid = new tbuilder_grid(child);
102 }
103 
104 // }---------- BUILDER -----------{
105 
106 /*WIKI
107  * @page = GUIWidgetInstanceWML
108  * @order = 2_scrollbar_panel
109  *
110  * == Scrollbar panel ==
111  * @begin{parent}{name="gui/window/resolution/grid/row/column/"}
112  * @begin{tag}{name="scrollbar_panel"}{min="0"}{max="-1"}{super="generic/widget_instance"}
113  * Instance of a scrollbar_panel.
114  *
115  * List with the scrollbar_panel specific variables:
116  * @begin{table}{config}
117  * vertical_scrollbar_mode & scrollbar_mode & initial_auto &
118  * Determines whether or not to show the
119  * scrollbar. $
120  * horizontal_scrollbar_mode & scrollbar_mode & initial_auto &
121  * Determines whether or not to show the
122  * scrollbar. $
123  *
124  * definition & section & & This defines how a scrollbar_panel item
125  * looks. It must contain the grid
126  * definition for 1 row of the list. $
127  *
128  * @end{table}
129  * @begin{tag}{name="definition"}{min=0}{max=1}{super="gui/window/resolution/grid"}
130  * @end{tag}{name="definition"}
131  * @end{tag}{name="scrollbar_panel"}
132  * @end{parent}{name="gui/window/resolution/grid/row/column/"}
133  */
134 
135 namespace implementation
136 {
137 
138 tbuilder_scrollbar_panel::tbuilder_scrollbar_panel(const config& cfg)
139  : tbuilder_control(cfg)
140  , vertical_scrollbar_mode(
141  get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
142  , horizontal_scrollbar_mode(
143  get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
144  , grid(nullptr)
145 {
146  const config& definition = cfg.child("definition");
147 
148  VALIDATE(definition, _("No list defined."));
149  grid = new tbuilder_grid(definition);
150  assert(grid);
151 }
152 
154 {
155  tscrollbar_panel* widget = new tscrollbar_panel();
156 
157  init_control(widget);
158 
161 
162  DBG_GUI_G << "Window builder: placed scrollbar_panel '" << id
163  << "' with definition '" << definition << "'.\n";
164 
166  = boost::dynamic_pointer_cast<const tscrollbar_panel_definition::
167  tresolution>(
168  widget->config());
169  assert(conf);
170 
171  widget->init_grid(conf->grid);
172  widget->finalize_setup();
173 
174  /*** Fill the content grid. ***/
175  tgrid* content_grid = widget->content_grid();
176  assert(content_grid);
177 
178  const unsigned rows = grid->rows;
179  const unsigned cols = grid->cols;
180 
181  content_grid->set_rows_cols(rows, cols);
182 
183  for(unsigned x = 0; x < rows; ++x) {
184  content_grid->set_row_grow_factor(x, grid->row_grow_factor[x]);
185  for(unsigned y = 0; y < cols; ++y) {
186 
187  if(x == 0) {
188  content_grid->set_column_grow_factor(y,
189  grid->col_grow_factor[y]);
190  }
191 
192  twidget* widget = grid->widgets[x * cols + y]->build();
193  content_grid->set_child(widget,
194  x,
195  y,
196  grid->flags[x * cols + y],
197  grid->border_size[x * cols + y]);
198  }
199  }
200 
201  return widget;
202 }
203 
204 } // namespace implementation
205 
206 // }------------ END --------------
207 
208 } // namespace gui2
#define DBG_GUI_P
Definition: log.hpp:69
tscrollbar_container::tscrollbar_mode horizontal_scrollbar_mode
tscrollbar_container::tscrollbar_mode vertical_scrollbar_mode
void set_row_grow_factor(const unsigned row, const unsigned factor)
Sets the grow factor for a row.
Definition: grid.hpp:81
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
Base container class.
Definition: grid.hpp:29
tresolution_definition_ptr config()
Definition: control.hpp:299
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
tscrollbar_container::tscrollbar_mode get_scrollbar_mode(const std::string &scrollbar_mode)
Returns the scrollbar mode flags.
Definition: helper.cpp:114
Base class of a resolution, contains the common keys for a resolution.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
void init_control(tcontrol *control) const
Definition: control.cpp:675
std::string definition
Parameters for the control.
Definition: control.hpp:530
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
void set_vertical_scrollbar_mode(const tscrollbar_mode scrollbar_mode)
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
This file contains the settings handling of the widget library.
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
void set_column_grow_factor(const unsigned column, const unsigned factor)
Sets the grow factor for a column.
Definition: grid.hpp:96
void init_grid(const boost::intrusive_ptr< tbuilder_grid > &grid_builder)
Initializes and builds the grid.
Definition: container.cpp:209
Contains the state info for a resolution.
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
tscrollbar_panel_definition(const config &cfg)
virtual unsigned get_state() const override
See tcontrol::get_state.
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
void set_horizontal_scrollbar_mode(const tscrollbar_mode scrollbar_mode)
void set_rows_cols(const unsigned rows, const unsigned cols)
Wrapper to set_rows and set_cols.
Definition: grid.cpp:679
std::vector< tstate_definition > state
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:658
Base class for all widgets.
Definition: widget.hpp:49
void set_child(twidget *widget, const unsigned row, const unsigned col, const unsigned flags, const unsigned border_size)
Sets a child in the grid.
Definition: grid.cpp:69
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
#define DBG_GUI_G
Definition: log.hpp:41
virtual void set_self_active(const bool active) override
See tcontainer_::set_self_active.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Visible container to hold multiple widgets.
Contains the implementation details for lexical_cast and shouldn't be used directly.