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