Move gui2::tbuilder_slider to its own file.

This commit is contained in:
Mark de Wever 2009-07-04 12:37:31 +00:00
parent 78a18c071a
commit 0ecb029bca
8 changed files with 184 additions and 108 deletions

View file

@ -15,6 +15,7 @@ src/gui/auxiliary/window_builder/label.cpp
src/gui/auxiliary/window_builder/listbox.cpp
src/gui/auxiliary/window_builder/minimap.cpp
src/gui/auxiliary/window_builder/menubar.cpp
src/gui/auxiliary/window_builder/slider.cpp
src/gui/auxiliary/window_builder/spacer.cpp
src/gui/auxiliary/window_builder/text_box.cpp
src/gui/auxiliary/window_builder/panel.cpp

View file

@ -273,6 +273,7 @@ SET(wesnoth-main_SRC
gui/auxiliary/window_builder/listbox.cpp
gui/auxiliary/window_builder/minimap.cpp
gui/auxiliary/window_builder/menubar.cpp
gui/auxiliary/window_builder/slider.cpp
gui/auxiliary/window_builder/spacer.cpp
gui/auxiliary/window_builder/text_box.cpp
gui/auxiliary/window_builder/panel.cpp

View file

@ -98,6 +98,7 @@ wesnoth_source = \
gui/auxiliary/window_builder/listbox.cpp \
gui/auxiliary/window_builder/minimap.cpp \
gui/auxiliary/window_builder/menubar.cpp \
gui/auxiliary/window_builder/slider.cpp \
gui/auxiliary/window_builder/spacer.cpp \
gui/auxiliary/window_builder/text_box.cpp \
gui/auxiliary/window_builder/panel.cpp \

View file

@ -254,6 +254,7 @@ wesnoth_sources = Split("""
gui/auxiliary/window_builder/listbox.cpp
gui/auxiliary/window_builder/minimap.cpp
gui/auxiliary/window_builder/menubar.cpp
gui/auxiliary/window_builder/slider.cpp
gui/auxiliary/window_builder/spacer.cpp
gui/auxiliary/window_builder/text_box.cpp
gui/auxiliary/window_builder/panel.cpp

View file

@ -28,6 +28,7 @@
#include "gui/auxiliary/window_builder/listbox.hpp"
#include "gui/auxiliary/window_builder/minimap.hpp"
#include "gui/auxiliary/window_builder/menubar.hpp"
#include "gui/auxiliary/window_builder/slider.hpp"
#include "gui/auxiliary/window_builder/spacer.hpp"
#include "gui/auxiliary/window_builder/text_box.hpp"
#include "gui/auxiliary/window_builder/panel.hpp"
@ -502,62 +503,6 @@ twidget* tbuilder_scroll_label::build() const
return widget;
}
tbuilder_slider::tbuilder_slider(const config& cfg) :
implementation::tbuilder_control(cfg),
best_slider_length_(lexical_cast_default<unsigned>(cfg["best_slider_length"])),
minimum_value_(lexical_cast_default<int>(cfg["minimum_value"])),
maximum_value_(lexical_cast_default<int>(cfg["maximum_value"])),
step_size_(lexical_cast_default<unsigned>(cfg["step_size"])),
value_(lexical_cast_default<unsigned>(cfg["value"])),
minimum_value_label_(cfg["minimum_value_label"]),
maximum_value_label_(cfg["maximum_value_label"]),
value_labels_()
{
/*WIKI
* @page = GUIWidgetInstanceWML
* @order = 3_slider
*
* == Slider ==
*
* @start_table = config
* best_slider_length (unsigned = 0)
* The best length for the sliding part.
* minimum_value (int = 0) The minimum value the slider can have.
* maximum_value (int = 0) The maximum value the slider can have.
*
* step_size (unsigned = 0) The number of items the slider's value
* increases with one step.
* value (int = 0) The value of the slider.
*
* minimum_value_label (t_string = "")
* If the minimum value is chosen there
* might be the need for a special value (eg
* off). When this key has a value that value
* will be shown if the minimum is selected.
* maximum_value_label (t_string = "")
* If the maximum value is chosen there
* might be the need for a special value (eg
* unlimited)). When this key has a value
* that value will be shown if the maximum is
* selected.
* value_labels ([]) It might be the labels need to be shown
* are not a linear number sequence eg (0.5,
* 1, 2, 4) in that case for all items this
* section can be filled with the values,
* which should be the same number of items
* as the items in the slider. NOTE if this
* option is used, 'minimum_value_label' and
* 'maximum_value_label' are ignored.
* @end_table
*/
const config &labels = cfg.child("value_labels");
if (!labels) return;
foreach (const config &label, labels.child_range("value")) {
value_labels_.push_back(label["label"]);
}
}
tbuilder_scrollbar_panel::tbuilder_scrollbar_panel(const config& cfg)
: implementation::tbuilder_control(cfg)
, vertical_scrollbar_mode(
@ -658,35 +603,6 @@ twidget* tbuilder_scrollbar_panel::build() const
return scrollbar_panel;
}
twidget* tbuilder_slider::build() const
{
tslider* slider = new tslider();
init_control(slider);
slider->set_best_slider_length(best_slider_length_);
slider->set_maximum_value(maximum_value_);
slider->set_minimum_value(minimum_value_);
slider->set_step_size(step_size_);
slider->set_value(value_);
if(!value_labels_.empty()) {
VALIDATE(value_labels_.size() == slider->get_item_count(),
_("The number of value_labels and values don't match."));
slider->set_value_labels(value_labels_);
} else {
slider->set_minimum_value_label(minimum_value_label_);
slider->set_maximum_value_label(maximum_value_label_);
}
DBG_GUI_G << "Window builder: placed slider '" << id << "' with defintion '"
<< definition << "'.\n";
return slider;
}
twidget* tbuilder_toggle_button::build() const
{
ttoggle_button *toggle_button = new ttoggle_button();

View file

@ -0,0 +1,126 @@
/* $Id$ */
/*
Copyright (C) 2008 - 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/auxiliary/window_builder/slider.hpp"
#include "config.hpp"
#include "foreach.hpp"
#include "gettext.hpp"
#include "gui/auxiliary/log.hpp"
#include "gui/widgets/slider.hpp"
#include "wml_exception.hpp"
namespace gui2 {
namespace implementation {
tbuilder_slider::tbuilder_slider(const config& cfg)
: implementation::tbuilder_control(cfg)
, best_slider_length_(lexical_cast_default<unsigned>(
cfg["best_slider_length"]))
, minimum_value_(lexical_cast_default<int>(cfg["minimum_value"]))
, maximum_value_(lexical_cast_default<int>(cfg["maximum_value"]))
, step_size_(lexical_cast_default<unsigned>(cfg["step_size"]))
, value_(lexical_cast_default<unsigned>(cfg["value"]))
, minimum_value_label_(cfg["minimum_value_label"])
, maximum_value_label_(cfg["maximum_value_label"])
, value_labels_()
{
const config &labels = cfg.child("value_labels");
if(!labels) {
return;
}
foreach(const config &label, labels.child_range("value")) {
value_labels_.push_back(label["label"]);
}
}
twidget* tbuilder_slider::build() const
{
tslider* widget = new tslider();
init_control(widget);
widget->set_best_slider_length(best_slider_length_);
widget->set_maximum_value(maximum_value_);
widget->set_minimum_value(minimum_value_);
widget->set_step_size(step_size_);
widget->set_value(value_);
if(!value_labels_.empty()) {
VALIDATE(value_labels_.size() == widget->get_item_count(),
_("The number of value_labels and values don't match."));
widget->set_value_labels(value_labels_);
} else {
widget->set_minimum_value_label(minimum_value_label_);
widget->set_maximum_value_label(maximum_value_label_);
}
DBG_GUI_G << "Window builder: placed slider '"
<< id << "' with defintion '"
<< definition << "'.\n";
return widget;
}
} // namespace implementation
} // namespace gui2
/*WIKI
* @page = GUIWidgetInstanceWML
* @order = 3_slider
*
* == Slider ==
*
* @start_table = config
* best_slider_length (unsigned = 0)
* The best length for the sliding part.
* minimum_value (int = 0) The minimum value the slider can have.
* maximum_value (int = 0) The maximum value the slider can have.
*
* step_size (unsigned = 0) The number of items the slider's value
* increases with one step.
* value (int = 0) The value of the slider.
*
* minimum_value_label (t_string = "")
* If the minimum value is chosen there
* might be the need for a special value
* (eg off). When this key has a value
* that value will be shown if the minimum
* is selected.
* maximum_value_label (t_string = "")
* If the maximum value is chosen there
* might be the need for a special value
* (eg unlimited)). When this key has a
* value that value will be shown if the
* maximum is
* selected.
* value_labels ([]) It might be the labels need to be shown
* are not a linear number sequence eg
* (0.5, 1, 2, 4) in that case for all
* items this section can be filled with
* the values, which should be the same
* number of items as the items in the
* slider. NOTE if this option is used,
* 'minimum_value_label' and
* 'maximum_value_label' are ignored.
* @end_table
*/

View file

@ -0,0 +1,53 @@
/* $Id$ */
/*
Copyright (C) 2008 - 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_AUXILIARY_WINDOW_BUILDER_SLIDER_HPP_INCLUDED
#define GUI_AUXILIARY_WINDOW_BUILDER_SLIDER_HPP_INCLUDED
#include "gui/auxiliary/window_builder/control.hpp"
#include "tstring.hpp"
#include <vector>
namespace gui2 {
namespace implementation {
struct tbuilder_slider
: public tbuilder_control
{
tbuilder_slider(const config& cfg);
twidget* build () const;
private:
unsigned best_slider_length_;
int minimum_value_;
int maximum_value_;
unsigned step_size_;
int value_;
t_string minimum_value_label_;
t_string maximum_value_label_;
std::vector<t_string> value_labels_;
};
} // namespace implementation
} // namespace gui2
#endif

View file

@ -74,29 +74,6 @@ public:
std::vector<string_map> data;
};
struct tbuilder_slider : public implementation::tbuilder_control
{
private:
tbuilder_slider();
public:
tbuilder_slider(const config& cfg);
twidget* build () const;
private:
unsigned best_slider_length_;
int minimum_value_;
int maximum_value_;
unsigned step_size_;
int value_;
t_string minimum_value_label_;
t_string maximum_value_label_;
std::vector<t_string> value_labels_;
};
struct tbuilder_scroll_label : public implementation::tbuilder_control
{
public: