The Battle for Wesnoth  1.19.0-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 
63 private:
64  std::string id_;
65 
67 
69  unsigned popup_show_time_;
70  unsigned help_show_time_;
73 
74  std::string sound_button_click_;
77  std::string sound_slider_adjust_;
78 
80 
81  std::vector<game_tip> tips_;
82 };
83 
84 using gui_theme_map_t = std::map<std::string, gui_definition>;
85 
86 /** Map of all known GUIs. */
87 extern gui_theme_map_t guis;
88 
89 /** Iterator pointing to the current GUI. */
91 
92 /** Iterator pointing to the default GUI. */
94 
95 /**
96  * Returns the appropriate config data for a widget instance fom the active
97  * GUI definition.
98  *
99  * @param control_type The widget type.
100  * @param definition The definition ID.
101  *
102  * @returns A pointer to the specified definition data struct
103  * for the widget type, accounting for the current
104  * screen resolution.
105  */
106 resolution_definition_ptr get_control(const std::string& control_type, const std::string& definition);
107 
108 /** Helper struct to signal that get_window_builder failed. */
109 struct window_builder_invalid_id : std::exception
110 {
111 };
112 
113 /**
114  * Returns an reference to the requested builder.
115  *
116  * The builder is determined by the @p type and the current screen resolution.
117  *
118  * @pre There is a valid builder for @p type at the
119  * current resolution.
120  *
121  * @throws window_builder_invalid_id
122  * When the precondition is violated.
123  *
124  * @param type The type of builder window to get.
125  *
126  * @returns An iterator to the requested builder.
127  */
129 
130 /** Adds a widget definition to the default GUI. */
131 bool add_single_widget_definition(const std::string& widget_type,
132  const std::string& definition_id,
133  const config& cfg);
134 
135 /** Removes a widget definition from the default GUI. */
136 void remove_single_widget_definition(const std::string& widget_type,
137  const std::string& definition_id);
138 
139 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
A GUI theme definition.
std::map< std::string, builder_window > window_types
Map of all known windows (the builder class builds a window).
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.
unsigned repeat_button_repeat_time_
std::vector< game_tip > tips_
std::map< std::string, styled_widget_definition_ptr > widget_definition_map_t
std::string sound_toggle_button_click_
std::string sound_slider_adjust_
std::string sound_toggle_panel_click_
gui_definition(const config &cfg)
Private ctor.
std::string sound_button_click_
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.