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