The Battle for Wesnoth  1.19.0-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 
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  : modal_dialog(window_id())
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
double g
Definition: astarsearch.cpp:63
Dialog for editing gamemap labels.
Definition: edit_label.hpp:34
void register_color_component(std::string widget_id, uint8_t color_t::*component)
Definition: edit_label.cpp:56
int load_color_component(uint8_t color_t::*component)
Definition: edit_label.cpp:62
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:66
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: edit_label.cpp:50
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.
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:63
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
Definition: window.cpp:1239
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