The Battle for Wesnoth  1.19.5+dev
edit_label.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2024
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 
20 #include "gui/widgets/text_box.hpp"
21 #include "gui/widgets/window.hpp"
22 
23 #include <functional>
24 
25 namespace gui2::dialogs
26 {
27 
28 REGISTER_DIALOG(editor_edit_label)
29 
31  bool& immutable,
32  bool& visible_fog,
33  bool& visible_shroud,
34  color_t& color,
35  std::string& category)
36  : modal_dialog(window_id())
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  add_to_tab_order(find_widget<text_box>("label", false, true));
52  add_to_tab_order(find_widget<text_box>("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
double g
Definition: astarsearch.cpp:63
virtual void pre_show() override
Actions to be taken before showing the window.
Definition: edit_label.cpp:49
void register_color_component(std::string widget_id, uint8_t color_t::*component)
Definition: edit_label.cpp:55
int load_color_component(uint8_t color_t::*component)
Definition: edit_label.cpp:61
color_t & color_store
The execute function.
Definition: edit_label.hpp:51
void save_color_component(uint8_t color_t::*component, const int value)
Definition: edit_label.cpp:65
Abstract base class for all modal dialogs.
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.
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
Definition: window.cpp:1225
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(editor_edit_unit)
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59
#define b