gui/auxiliary/window_builder/scrollbar_panel.cpp

Go to the documentation of this file.
00001 /* $Id: scrollbar_panel.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2008 - 2012 by Mark de Wever <koraq@xs4all.nl>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017 
00018 #include "gui/auxiliary/window_builder/scrollbar_panel.hpp"
00019 
00020 #include "config.hpp"
00021 #include "gettext.hpp"
00022 #include "gui/auxiliary/log.hpp"
00023 #include "gui/auxiliary/widget_definition/scrollbar_panel.hpp"
00024 #include "gui/auxiliary/window_builder/helper.hpp"
00025 #include "gui/widgets/scrollbar_panel.hpp"
00026 #include "wml_exception.hpp"
00027 
00028 namespace gui2 {
00029 
00030 namespace implementation {
00031 
00032 tbuilder_scrollbar_panel::tbuilder_scrollbar_panel(const config& cfg)
00033     : tbuilder_control(cfg)
00034     , vertical_scrollbar_mode(
00035             get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
00036     , horizontal_scrollbar_mode(
00037             get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
00038     , grid(NULL)
00039 {
00040     const config &definition = cfg.child("definition");
00041 
00042     VALIDATE(definition, _("No list defined."));
00043     grid = new tbuilder_grid(definition);
00044     assert(grid);
00045 }
00046 
00047 twidget* tbuilder_scrollbar_panel::build() const
00048 {
00049     tscrollbar_panel *widget = new tscrollbar_panel();
00050 
00051     init_control(widget);
00052 
00053     widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
00054     widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
00055 
00056     DBG_GUI_G << "Window builder: placed scrollbar_panel '"
00057             << id << "' with definition '"
00058             << definition << "'.\n";
00059 
00060     boost::intrusive_ptr<
00061             const tscrollbar_panel_definition::tresolution> conf =
00062                 boost::dynamic_pointer_cast
00063                     <const tscrollbar_panel_definition::tresolution>
00064                         (widget->config());
00065     assert(conf);
00066 
00067     widget->init_grid(conf->grid);
00068     widget->finalize_setup();
00069 
00070     /*** Fill the content grid. ***/
00071     tgrid* content_grid = widget->content_grid();
00072     assert(content_grid);
00073 
00074     const unsigned rows = grid->rows;
00075     const unsigned cols = grid->cols;
00076 
00077     content_grid->set_rows_cols(rows, cols);
00078 
00079     for(unsigned x = 0; x < rows; ++x) {
00080         content_grid->set_row_grow_factor(x, grid->row_grow_factor[x]);
00081         for(unsigned y = 0; y < cols; ++y) {
00082 
00083             if(x == 0) {
00084                 content_grid->set_column_grow_factor(y
00085                         , grid->col_grow_factor[y]);
00086             }
00087 
00088             twidget* widget = grid->widgets[x * cols + y]->build();
00089             content_grid->set_child(widget
00090                     , x
00091                     , y
00092                     , grid->flags[x * cols + y]
00093                     , grid->border_size[x * cols + y]);
00094         }
00095     }
00096 
00097     return widget;
00098 }
00099 
00100 } // namespace implementation
00101 
00102 } // namespace gui2
00103 
00104 /*WIKI
00105  * @page = GUIWidgetInstanceWML
00106  * @order = 2_scrollbar_panel
00107  *
00108  * == Scrollbar panel ==
00109  * @begin{parent}{name="gui/window/resolution/grid/row/column/"}
00110  * @begin{tag}{name="scrollbar_panel"}{min="0"}{max="-1"}{super="generic/widget_instance"}
00111  * Instance of a scrollbar_panel.
00112  *
00113  * List with the scrollbar_panel specific variables:
00114  * @begin{table}{config}
00115  *     vertical_scrollbar_mode & scrollbar_mode & initial_auto &
00116  *                                     Determines whether or not to show the
00117  *                                     scrollbar. $
00118  *     horizontal_scrollbar_mode & scrollbar_mode & initial_auto &
00119  *                                     Determines whether or not to show the
00120  *                                     scrollbar. $
00121  *
00122  *     definition & section & &        This defines how a scrollbar_panel item
00123  *                                     looks. It must contain the grid
00124  *                                     definition for 1 row of the list. $
00125  *
00126  * @end{table}
00127  * @begin{tag}{name="definition"}{min=0}{max=1}{super="gui/window/resolution/grid"}
00128  * @end{tag}{name="definition"}
00129  * @end{tag}{name="scrollbar_panel"}
00130  * @end{parent}{name="gui/window/resolution/grid/row/column/"}
00131  */
00132 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:42 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs