gui/auxiliary/window_builder/slider.cpp

Go to the documentation of this file.
00001 /* $Id: slider.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/slider.hpp"
00019 
00020 #include "config.hpp"
00021 #include "foreach.hpp"
00022 #include "gettext.hpp"
00023 #include "gui/auxiliary/log.hpp"
00024 #include "gui/widgets/slider.hpp"
00025 #include "wml_exception.hpp"
00026 
00027 namespace gui2 {
00028 
00029 namespace implementation {
00030 
00031 tbuilder_slider::tbuilder_slider(const config& cfg)
00032     : implementation::tbuilder_control(cfg)
00033     , best_slider_length_(cfg["best_slider_length"])
00034     , minimum_value_(cfg["minimum_value"])
00035     , maximum_value_(cfg["maximum_value"])
00036     , step_size_(cfg["step_size"])
00037     , value_(cfg["value"])
00038     , minimum_value_label_(cfg["minimum_value_label"].t_str())
00039     , maximum_value_label_(cfg["maximum_value_label"].t_str())
00040     , value_labels_()
00041 {
00042     const config& labels = cfg.child("value_labels");
00043     if(!labels) {
00044         return;
00045     }
00046 
00047     foreach(const config& label, labels.child_range("value")) {
00048         value_labels_.push_back(label["label"]);
00049     }
00050 }
00051 
00052 twidget* tbuilder_slider::build() const
00053 {
00054     tslider* widget = new tslider();
00055 
00056     init_control(widget);
00057 
00058     widget->set_best_slider_length(best_slider_length_);
00059     widget->set_maximum_value(maximum_value_);
00060     widget->set_minimum_value(minimum_value_);
00061     widget->set_step_size(step_size_);
00062     widget->set_value(value_);
00063 
00064     if(!value_labels_.empty()) {
00065         VALIDATE(value_labels_.size() == widget->get_item_count()
00066                 , _("The number of value_labels and values don't match."));
00067 
00068         widget->set_value_labels(value_labels_);
00069 
00070     } else {
00071         widget->set_minimum_value_label(minimum_value_label_);
00072         widget->set_maximum_value_label(maximum_value_label_);
00073     }
00074 
00075     DBG_GUI_G << "Window builder: placed slider '"
00076             << id << "' with definition '"
00077             << definition << "'.\n";
00078 
00079     return widget;
00080 }
00081 
00082 } // namespace implementation
00083 
00084 } // namespace gui2
00085 
00086 /*WIKI_MACRO
00087  * @begin{macro}{slider_description}
00088  * A slider is a control that can select a value by moving a grip on a groove.
00089  * @end{macro}
00090  */
00091 
00092 /*WIKI
00093  * @page = GUIWidgetInstanceWML
00094  * @order = 3_slider
00095  * @begin{parent}{name="gui/window/resolution/grid/row/column/"}
00096  * @begin{tag}{name="slider"}{min="0"}{max="-1"}{super="generic/widget_instance"}
00097  * == Slider ==
00098  *
00099  * @macro = slider_description
00100  *
00101  * @begin{table}{config}
00102  *     best_slider_length & unsigned & 0 &
00103  *                                    The best length for the sliding part. $
00104  *     minimum_value & int & 0 &        The minimum value the slider can have. $
00105  *     maximum_value & int & 0 &        The maximum value the slider can have. $
00106  *
00107  *     step_size & unsigned & 0 &       The number of items the slider's value
00108  *                                    increases with one step. $
00109  *     value & int & 0 &                The value of the slider. $
00110  *
00111  *     minimum_value_label & t_string & "" &
00112  *                                    If the minimum value is chosen there
00113  *                                    might be the need for a special value
00114  *                                    (eg off). When this key has a value
00115  *                                    that value will be shown if the minimum
00116  *                                    is selected. $
00117  *     maximum_value_label & t_string & "" &
00118  *                                    If the maximum value is chosen there
00119  *                                    might be the need for a special value
00120  *                                    (eg unlimited)). When this key has a
00121  *                                    value that value will be shown if the
00122  *                                    maximum is selected. $
00123  *     value_labels & [] &              It might be the labels need to be shown
00124  *                                    are not a linear number sequence eg
00125  *                                    (0.5, 1, 2, 4) in that case for all
00126  *                                    items this section can be filled with
00127  *                                    the values, which should be the same
00128  *                                    number of items as the items in the
00129  *                                    slider. NOTE if this option is used,
00130  *                                    'minimum_value_label' and
00131  *                                    'maximum_value_label' are ignored. $
00132  * @end{table}
00133  * @end{tag}{name="slider"}
00134  * @end{parent}{name="gui/window/resolution/grid/row/column/"}
00135  */
00136 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:55 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs