The Battle for Wesnoth  1.19.7+dev
gui_definition.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
3  by Mark de Wever <koraq@xs4all.nl>
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 #pragma once
17 
18 #include "gui/auxiliary/tips.hpp"
21 
22 #include <map>
23 
24 class config;
25 
26 namespace gui2
27 {
28 /**
29  * A GUI theme definition.
30  *
31  * Each theme defines the appearance and layout of widgets and windows. At least one theme
32  * (the default) must exist for the game to run. That theme is expected to contain at least
33  * one default definition for each widget type and a layout for each window recorded in the
34  * static registry. Do note that a widget type may have any number of definitions defined
35  * per theme, but a window may only have one layout.
36  *
37  * Non-default themes may omit a default widget definition or a window layout, in which case
38  * the game will fall back on the default definition (for widgets) or the layout (for windows)
39  * specified in the default theme.
40  *
41  * Each widget definition and window layout may also define different variations of itself
42  * to be used based on the current game resolution.
43  *
44  * As of December 2017 only the default theme is provided.
45  */
47 {
48 public:
49  /** Private ctor. Use create to initialize a new definition. */
50  explicit gui_definition(const config& cfg);
51 
52  using widget_definition_map_t = std::map<std::string, styled_widget_definition_ptr>;
53 
54  /** Map of each widget type, by id, and a sub-map of each of the type's definitions, also by id. */
55  std::map<std::string, widget_definition_map_t> widget_types;
56 
57  /** Map of all known windows (the builder class builds a window). */
58  std::map<std::string, builder_window> window_types;
59 
60  /** Activates this GUI. */
61  void activate() const;
62 
64  return description_;
65  }
66 
67 private:
68  std::string id_;
69 
71 
72  std::chrono::milliseconds popup_show_delay_;
73  std::chrono::milliseconds popup_show_time_;
74  std::chrono::milliseconds help_show_time_;
75  std::chrono::milliseconds double_click_time_;
76  std::chrono::milliseconds repeat_button_repeat_time_;
77 
78  std::string sound_button_click_;
81  std::string sound_slider_adjust_;
82 
84 
85  std::vector<game_tip> tips_;
86 };
87 
88 using gui_theme_map_t = std::map<std::string, gui_definition>;
89 
90 /** Map of all known GUIs. */
91 extern gui_theme_map_t guis;
92 
93 /** Iterator pointing to the current GUI. */
95 
96 /** Iterator pointing to the default GUI. */
98 
99 /**
100  * Returns the appropriate config data for a widget instance fom the active
101  * GUI definition.
102  *
103  * @param control_type The widget type.
104  * @param definition The definition ID.
105  *
106  * @returns A pointer to the specified definition data struct
107  * for the widget type, accounting for the current
108  * screen resolution.
109  */
110 resolution_definition_ptr get_control(const std::string& control_type, const std::string& definition);
111 
112 /** Helper struct to signal that get_window_builder failed. */
113 struct window_builder_invalid_id : std::exception
114 {
115 };
116 
117 /**
118  * Returns an reference to the requested builder.
119  *
120  * The builder is determined by the @p type and the current screen resolution.
121  *
122  * @pre There is a valid builder for @p type at the
123  * current resolution.
124  *
125  * @throws window_builder_invalid_id
126  * When the precondition is violated.
127  *
128  * @param type The type of builder window to get.
129  *
130  * @returns An iterator to the requested builder.
131  */
133 
134 /** Adds a widget definition to the default GUI. */
135 bool add_single_widget_definition(const std::string& widget_type,
136  const std::string& definition_id,
137  const config& cfg);
138 
139 /** Removes a widget definition from the default GUI. */
140 void remove_single_widget_definition(const std::string& widget_type,
141  const std::string& definition_id);
142 
143 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
A GUI theme definition.
std::map< std::string, builder_window > window_types
Map of all known windows (the builder class builds a window).
std::chrono::milliseconds popup_show_time_
std::map< std::string, widget_definition_map_t > widget_types
Map of each widget type, by id, and a sub-map of each of the type's definitions, also by id.
std::vector< game_tip > tips_
std::chrono::milliseconds repeat_button_repeat_time_
std::chrono::milliseconds double_click_time_
std::map< std::string, styled_widget_definition_ptr > widget_definition_map_t
std::string sound_toggle_button_click_
std::chrono::milliseconds popup_show_delay_
std::string sound_slider_adjust_
std::string sound_toggle_panel_click_
gui_definition(const config &cfg)
Private ctor.
std::string sound_button_click_
std::chrono::milliseconds help_show_time_
void activate() const
Activates this GUI.
Generic file dialog.
bool add_single_widget_definition(const std::string &widget_type, const std::string &definition_id, const config &cfg)
Adds a widget definition to the default GUI.
void remove_single_widget_definition(const std::string &widget_type, const std::string &definition_id)
Removes a widget definition from the default GUI.
std::shared_ptr< resolution_definition > resolution_definition_ptr
const builder_window::window_resolution & get_window_builder(const std::string &type)
Returns an reference to the requested builder.
gui_theme_map_t guis
Map of all known GUIs.
std::map< std::string, gui_definition > gui_theme_map_t
gui_theme_map_t::iterator current_gui
Iterator pointing to the current GUI.
gui_theme_map_t::iterator default_gui
Iterator pointing to the default GUI.
resolution_definition_ptr get_control(const std::string &control_type, const std::string &definition)
Returns the appropriate config data for a widget instance fom the active GUI definition.
std::string::const_iterator iterator
Definition: tokenizer.hpp:25
Helper struct to signal that get_window_builder failed.