FlightGear next
new_gui.hxx
Go to the documentation of this file.
1/*
2 * SPDX-FileName: new_gui.hxx
3 * SPDX-FileComment: XML-configured GUI subsystem.
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#pragma once
8
9#include <simgear/props/props.hxx>
10#include <simgear/structure/subsystem_mgr.hxx>
11#include <simgear/misc/sg_path.hxx>
12
13#include <map>
14#include <memory> // for unique_ptr on some systems
15#include <cstring> // for strcmp in lstr() (in this header, alas)
16
17class FGMenuBar;
18class FGDialog;
19class FGColor;
20
30class NewGUI : public SGSubsystem
31{
32public:
33 using FGDialogRef = SGSharedPtr<FGDialog>;
34
38 NewGUI ();
39
43 virtual ~NewGUI ();
44
45 // Subsystem API.
46 void bind() override;
47 void init() override;
48 void reinit() override;
49 void shutdown() override;
50 void unbind() override;
51 void update(double delta_time_sec) override;
52 void postinit() override;
53
54 // Subsystem identification.
55 static const char* staticSubsystemClassId() { return "gui"; }
56
60 virtual void redraw ();
61
72 virtual void newDialog (SGPropertyNode* node);
73
86 virtual bool showDialog (const std::string &name);
87
94 virtual bool toggleDialog (const std::string &name);
95
96
105 virtual bool closeActiveDialog ();
106
113 virtual bool closeDialog (const std::string &name);
114
120 virtual SGPropertyNode_ptr getDialogProperties (const std::string &name);
121
125 virtual FGMenuBar * getMenuBar ();
126
133 virtual void setActiveDialog (FGDialog * dialog);
134
141
142
148 virtual FGDialogRef getDialog(const std::string& name);
149
150
151 virtual FGColor *getColor (const char * name) const {
152 _citt_t it = _colors.find(name);
153 return (it != _colors.end()) ? it->second : NULL;
154 }
155 virtual FGColor *getColor (const std::string &name) const {
156 _citt_t it = _colors.find(name.c_str());
157 return (it != _colors.end()) ? it->second : NULL;
158 }
159
160protected:
166 virtual bool getMenuBarVisible () const;
167
173 virtual void setMenuBarVisible (bool visible);
174
175 virtual void setStyle ();
176
184 virtual void reset (bool reload);
185
186 bool getMenuBarOverlapHide() const;
187 void setMenuBarOverlapHide(bool hide);
188
189private:
190 void createMenuBarImplementation();
191 // Assign an element of _dialog_metadata.
192 void setDialogMetadata(const std::string& name, const SGPath& xmlFilepath,
193 const std::string& translationDomain = "core");
194
195 typedef std::map<std::string, FGColor*> ColourDict;
196 ColourDict _colors;
197 typedef ColourDict::iterator _itt_t;
198 typedef ColourDict::const_iterator _citt_t;
199 void clear_colors();
200
201 // Read all the configuration files in a directory. The translation domain
202 // may be overridden from each dialog XML definition.
203 void readDir(const SGPath& path, const std::string& translationDomain);
204
205 std::unique_ptr<FGMenuBar> _menubar;
206 FGDialogRef _active_dialog;
207
208
209 typedef std::map<std::string, FGDialogRef> DialogDict;
210 DialogDict _active_dialogs;
211
212 struct DialogMetadata {
213 DialogMetadata(const SGPath& xmlFilePath,
214 const std::string& translationDomain);
215
216 SGPath xmlFilePath;
217 std::string translationDomain;
218 };
219
220 typedef std::map<std::string, DialogMetadata> DialogMetadataDict;
221 // For each dialog name, this gives a path to the XML PropertyList file
222 // that defines the dialog contents and the domain used for fetching
223 // translations of text elements of the dialog (labels, etc.).
224 DialogMetadataDict _dialog_metadata;
225
226 // cache of loaded dialog proeprties
227 typedef std::map<std::string,SGPropertyNode_ptr> NameDialogDict;
228 NameDialogDict _dialog_props;
229};
An XML-configured dialog box.
Definition dialog.hxx:21
XML-configured menu bar interface.
Definition menubar.hxx:19
void shutdown() override
Definition new_gui.cxx:157
void unbind() override
Definition new_gui.cxx:251
virtual SGPropertyNode_ptr getDialogProperties(const std::string &name)
Get dialog property tree's root node.
Definition new_gui.cxx:384
virtual bool closeDialog(const std::string &name)
Close a named dialog, if it is open.
Definition new_gui.cxx:369
static const char * staticSubsystemClassId()
Definition new_gui.hxx:55
SGSharedPtr< FGDialog > FGDialogRef
Definition new_gui.hxx:33
void init() override
Definition new_gui.cxx:116
virtual void setMenuBarVisible(bool visible)
Show or hide the menubar.
Definition new_gui.cxx:454
void setMenuBarOverlapHide(bool hide)
Definition new_gui.cxx:471
virtual FGDialogRef getActiveDialog()
Get the dialog currently active, if any.
Definition new_gui.cxx:432
virtual void reset(bool reload)
Used by reinit() and redraw() to close all dialogs and to apply current GUI colors.
Definition new_gui.cxx:212
void bind() override
Definition new_gui.cxx:246
void update(double delta_time_sec) override
Definition new_gui.cxx:272
void reinit() override
Definition new_gui.cxx:169
virtual bool showDialog(const std::string &name)
Display a dialog box.
Definition new_gui.cxx:281
void postinit() override
Definition new_gui.cxx:255
virtual bool toggleDialog(const std::string &name)
Toggle display of a dialog box.
Definition new_gui.cxx:324
virtual void redraw()
Redraw the GUI picking up new GUI colors.
Definition new_gui.cxx:176
virtual FGMenuBar * getMenuBar()
Return a pointer to the current menubar.
Definition new_gui.cxx:438
virtual void setStyle()
Definition new_gui.cxx:579
virtual bool getMenuBarVisible() const
Test if the menubar is visible.
Definition new_gui.cxx:444
virtual ~NewGUI()
Destructor.
Definition new_gui.cxx:68
virtual FGColor * getColor(const char *name) const
Definition new_gui.hxx:151
virtual FGColor * getColor(const std::string &name) const
Definition new_gui.hxx:155
virtual void setActiveDialog(FGDialog *dialog)
Ignore this method.
Definition new_gui.cxx:423
virtual bool closeActiveDialog()
Close the currenty active dialog.
Definition new_gui.cxx:337
bool getMenuBarOverlapHide() const
Definition new_gui.cxx:465
virtual void newDialog(SGPropertyNode *node)
Creates a new dialog box, using the same property format as the gui/dialogs configuration files.
Definition new_gui.cxx:479
virtual FGDialogRef getDialog(const std::string &name)
Get the named dialog if active.
Definition new_gui.cxx:413
NewGUI()
Constructor.
Definition new_gui.cxx:64
const char * name