16 #define GETTEXT_DOMAIN "wesnoth-lib"
35 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
36 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
46 , best_slider_length_(builder.best_slider_length)
49 , minimum_value_label_()
50 , maximum_value_label_()
51 , value_label_generator_()
52 , current_item_mouse_position_(0, 0)
71 const auto conf = cast_config_to<slider_definition>();
86 if(value == old_value) {
94 <<
" old_value=" << old_value
96 <<
" desired_value=" << value
126 const auto conf = cast_config_to<slider_definition>();
128 return conf->positioner_length;
133 const auto conf = cast_config_to<slider_definition>();
135 return conf->left_offset;
140 const auto conf = cast_config_to<slider_definition>();
142 return conf->right_offset;
147 rect positioner_rect(
157 const unsigned x =
static_cast<std::size_t
>(
coordinate.
x);
158 const unsigned y =
static_cast<std::size_t
>(
coordinate.
y);
207 if(key == SDLK_DOWN || key == SDLK_LEFT) {
209 }
else if(key == SDLK_UP || key == SDLK_RIGHT) {
221 update_current_item_mouse_position();
238 assert(
static_cast<int>(value_labels.size()) == max);
239 assert(item_position < max && item_position >= 0);
240 return value_labels[item_position];
257 VALIDATE(min_value <= max_value,
"invalid slider data");
262 int diff = max_value - min_value;
300 load_resolutions<resolution>(cfg);
305 , positioner_length(cfg[
"minimum_positioner_length"].to_unsigned())
306 , left_offset(cfg[
"left_offset"].to_unsigned())
307 , right_offset(cfg[
"right_offset"].to_unsigned())
322 builder_slider::builder_slider(
const config& cfg)
324 , best_slider_length(cfg[
"best_slider_length"].to_unsigned())
325 , minimum_value_(cfg[
"minimum_value"].to_int())
326 , maximum_value_(cfg[
"maximum_value"].to_int())
327 , step_size_(cfg[
"step_size"].to_int(1))
328 , value_(cfg[
"value"].to_int())
329 , minimum_value_label_(cfg[
"minimum_value_label"].t_str())
330 , maximum_value_label_(cfg[
"maximum_value_label"].t_str())
338 for(
const auto&
label : labels->child_range(
"value")) {
345 auto widget = std::make_unique<slider>(*
this);
355 _(
"The number of value_labels and values don’t match."));
364 DBG_GUI_G <<
"Window builder: placed slider '" <<
id <<
"' with definition '" <<
definition <<
"'.";
A config object defines a single node in a WML file, with access to child nodes.
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
Base class for a scroll bar.
virtual void update_canvas() override
See styled_widget::update_canvas.
@ ITEM_FORWARD
Go one item towards the end.
@ ITEM_BACKWARDS
Go one item towards the begin.
unsigned get_positioner_offset() const
unsigned get_slider_position() const
void signal_handler_left_button_down(const event::ui_event event, bool &handled)
void slider_set_item_last(const unsigned item_last)
void set_slider_position(int item_position)
Note the position isn't guaranteed to be the wanted position the step size is honored.
void scroll(const scroll_mode scroll)
Sets the item position.
unsigned get_positioner_length() const
void set_step_size(int step_size)
virtual void child_callback_positioner_moved() override
Inherited from scrollbar_base.
t_string maximum_value_label_
When the slider shows the maximum value can show a special text.
void handle_key_decrease(bool &handled)
Handlers for keyboard input.
unsigned best_slider_length_
The best size for the slider part itself, if 0 ignored.
unsigned offset_before() const override
Inherited from scrollbar_base.
void signal_handler_sdl_key_down(const event::ui_event event, bool &handled, const SDL_Keycode key)
Signal handlers:
int minimum_value_
The minimum value the slider holds.
virtual int get_minimum_value() const override
Inherited from integer_selector.
int on_bar(const point &coordinate) const override
Inherited from scrollbar_base.
void handle_key_increase(bool &handled)
virtual void set_value(int value) override
Inherited from integer_selector.
virtual point calculate_best_size() const override
See widget::calculate_best_size.
virtual int get_maximum_value() const override
Inherited from integer_selector.
void set_value_range(int min_value, int max_value)
virtual int get_value() const override
Inherited from integer_selector.
label_generator value_label_generator_
Function to output custom value labels for the slider.
int get_item_count() const
t_string get_value_label() const
Returns the label shown for the current value.
int positioner_length() const override
Inherited from scrollbar_base.
t_string minimum_value_label_
When the slider shows the minimum value can show a special text.
bool on_positioner(const point &coordinate) const override
Inherited from scrollbar_base.
void signal_handler_left_button_up(const event::ui_event event, bool &handled)
virtual void update_canvas() override
Inherited from scrollbar_base.
void set_value_labels(const std::vector< t_string > &value_labels)
unsigned offset_after() const override
Inherited from scrollbar_base.
void keyboard_capture(widget *widget)
static std::string _(const char *str)
Define the common log macros for the gui toolkit.
#define log_scope2(domain, description)
General math utility functions.
int rounded_division(int a, int b)
ui_event
The event sent to the dispatcher.
std::string sound_slider_adjust
static t_string default_value_label_generator(const std::vector< t_string > &value_labels, int item_position, int max)
lg::log_domain log_gui_layout("gui/layout")
Contains the implementation details for lexical_cast and shouldn't be used directly.
void play_UI_sound(const std::string &files)
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
Contains the SDL_Rect helper code.
This file contains the settings handling of the widget library.
virtual std::unique_ptr< widget > build() const override
std::vector< t_string > value_labels_
t_string maximum_value_label_
t_string minimum_value_label_
std::vector< state_definition > state
resolution(const config &cfg)
unsigned positioner_length
slider_definition(const config &cfg)
An abstract description of a rectangle with integer coordinates.
bool contains(int x, int y) const
Whether the given point lies within the rectangle.
std::string missing_mandatory_wml_tag(const std::string §ion, const std::string &tag)
Returns a standard message for a missing wml child (tag).
std::string missing_mandatory_wml_key(const std::string §ion, const std::string &key, const std::string &primary_key, const std::string &primary_value)
Returns a standard message for a missing wml key (attribute).
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE_WML_CHILD(cfg, key, message)
#define VALIDATE(cond, message)
The macro to use for the validation of WML.