The Battle for Wesnoth  1.17.0-dev
edit_label.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2021
3  by Fabian Müller <fabianmueller5@gmx.de>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
19 
21 #include "gui/widgets/settings.hpp"
22 #include "gui/widgets/text_box.hpp"
23 #include "gui/widgets/window.hpp"
24 
25 #include <functional>
26 
27 namespace gui2::dialogs
28 {
29 
30 REGISTER_DIALOG(editor_edit_label)
31 
33  bool& immutable,
34  bool& visible_fog,
35  bool& visible_shroud,
36  color_t& color,
37  std::string& category)
38  : color_store(color)
39 {
40  register_text("label", true, text, true);
41  register_text("category", true, category, false);
42  register_bool("immutable_toggle", true, immutable);
43  register_bool("visible_fog_toggle", true, visible_fog);
44  register_bool("visible_shroud_toggle", true, visible_shroud);
45  register_color_component("slider_red", &color_t::r);
46  register_color_component("slider_green", &color_t::g);
47  register_color_component("slider_blue", &color_t::b);
48 }
49 
51 {
52  win.add_to_tab_order(find_widget<text_box>(&win, "label", false, true));
53  win.add_to_tab_order(find_widget<text_box>(&win, "category", false, true));
54 }
55 
56 void editor_edit_label::register_color_component(std::string widget_id, uint8_t color_t::* component) {
57  register_integer(widget_id, true,
58  std::bind(&editor_edit_label::load_color_component, this, component),
59  std::bind(&editor_edit_label::save_color_component, this, component, std::placeholders::_1));
60 }
61 
63  return color_store.*component;
64 }
65 
66 void editor_edit_label::save_color_component(uint8_t color_t::* component, const int value) {
67  color_store.*component = value;
68 }
69 } // namespace dialogs
int load_color_component(uint8_t color_t::*component)
Definition: edit_label.cpp:62
void register_color_component(std::string widget_id, uint8_t color_t::*component)
Definition: edit_label.cpp:56
This file contains the window object, this object is a top level container which has the event manage...
STL namespace.
This file contains the settings handling of the widget library.
field_integer * register_integer(const std::string &id, const bool mandatory, const std::function< int()> callback_load_value=nullptr, const std::function< void(int)> callback_save_value=nullptr)
Creates a new integer field.
Dialog for editing gamemap labels.
Definition: edit_label.hpp:34
uint8_t r
Red value.
Definition: color.hpp:178
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: edit_label.cpp:50
color_t & color_store
The execute function.
Definition: edit_label.hpp:62
void save_color_component(uint8_t color_t::*component, const int value)
Definition: edit_label.cpp:66
uint8_t g
Green value.
Definition: color.hpp:181
uint8_t b
Blue value.
Definition: color.hpp:184
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
Definition: window.cpp:1294
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65