The Battle for Wesnoth  1.15.1+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 "utils/functional.hpp"
25 
26 namespace gui2
27 {
28 namespace dialogs
29 {
30 
31 /*WIKI
32  * @page = GUIWindowDefinitionWML
33  * @order = 2_edit_label
34  *
35  * == Edit label ==
36  *
37  * Dialog for editing gamemap labels.
38  *
39  * @begin{table}{dialog_widgets}
40  *
41  * title & & label & m &
42  * Dialog title label. $
43  *
44  * label & & text_box & m &
45  * Input field for the map label. $
46  *
47  * team_only_toggle & & toggle_button & m &
48  * Checkbox for whether to make the label visible to the player's team
49  * only or not. $
50  *
51  * @end{table}
52  */
53 
54 REGISTER_DIALOG(editor_edit_label)
55 
57  bool& immutable,
58  bool& visible_fog,
59  bool& visible_shroud,
60  color_t& color,
61  std::string& category)
62  : color_store(color)
63 {
64  // std::string text = label.text();
65  // bool immutable = label.immutable();
66 
67 
68  // std::string label = old_label ? old_label->text() : "";
69  // std::string team_name = old_label ? old_label->team_name() : "";
70  // bool visible_shroud = old_label ? old_label->visible_in_shroud() :
71  // false;
72  // bool visible_fog = old_label ? old_label->visible_in_fog() :
73  // true;
74  // bool immutable = old_label ? old_label->immutable() :
75  // true;
76 
77  register_text("label", true, text, true);
78  register_text("category", true, category, false);
79  register_bool("immutable_toggle", true, immutable);
80  register_bool("visible_fog_toggle", true, visible_fog);
81  register_bool("visible_shroud_toggle", true, visible_shroud);
82  register_color_component("slider_red", &color_t::r);
83  register_color_component("slider_green", &color_t::g);
84  register_color_component("slider_blue", &color_t::b);
85 }
86 
88 {
89  win.add_to_tab_order(find_widget<text_box>(&win, "label", false, true));
90  win.add_to_tab_order(find_widget<text_box>(&win, "category", false, true));
91 }
92 
93 void editor_edit_label::register_color_component(std::string widget_id, uint8_t color_t::* component) {
94  register_integer(widget_id, true,
95  std::bind(&editor_edit_label::load_color_component, this, component),
96  std::bind(&editor_edit_label::save_color_component, this, component, _1));
97 }
98 
100  return color_store.*component;
101 }
102 
103 void editor_edit_label::save_color_component(uint8_t color_t::* component, const int value) {
104  color_store.*component = value;
105 }
106 } // namespace dialogs
107 } // namespace gui2
int load_color_component(uint8_t color_t::*component)
Definition: edit_label.cpp:99
void register_color_component(std::string widget_id, uint8_t color_t::*component)
Definition: edit_label.cpp:93
This file contains the window object, this object is a top level container which has the event manage...
STL namespace.
Generic file dialog.
Definition: field-fwd.hpp:22
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.
uint8_t r
Red value.
Definition: color.hpp:177
Various uncategorised dialogs.
virtual void pre_show(window &window) override
Inherited from modal_dialog.
Definition: edit_label.cpp:87
color_t & color_store
The execute function.
Definition: edit_label.hpp:48
void save_color_component(uint8_t color_t::*component, const int value)
Definition: edit_label.cpp:103
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:1300
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63