]> git.mxchange.org Git - flightgear.git/blob - src/GUI/new_gui.hxx
6b5b0b9e028b297a93fb61c0f1e35aa582073666
[flightgear.git] / src / GUI / new_gui.hxx
1 // new_gui.hxx - XML-configurable GUI subsystem.
2
3 #ifndef __NEW_GUI_HXX
4 #define __NEW_GUI_HXX 1
5
6 #ifndef __cplusplus
7 # error This library requires C++
8 #endif
9
10 #include <plib/pu.h>
11
12 #include <simgear/compiler.h>   // for SG_USING_STD
13 #include <simgear/misc/props.hxx>
14
15 #include <vector>
16 SG_USING_STD(vector);
17
18 #include <map>
19 SG_USING_STD(map);
20
21 #include <Main/fgfs.hxx>
22 #include <Main/fg_props.hxx>
23 #include <Input/input.hxx>
24
25 class FGMenuBar;
26 class GUIWidget;
27
28
29 /**
30  * Information about a GUI widget.
31  */
32 struct GUIInfo
33 {
34     GUIInfo (GUIWidget * w);
35     virtual ~GUIInfo ();
36
37     GUIWidget * widget;
38     vector <FGBinding *> bindings;
39 };
40
41
42 /**
43  * Top-level GUI widget.
44  */
45 class GUIWidget
46 {
47 public:
48
49
50     /**
51      * Construct a new GUI widget configured by a property tree.
52      */
53     GUIWidget (SGPropertyNode_ptr props);
54
55
56     /**
57      * Destructor.
58      */
59     virtual ~GUIWidget ();
60
61
62     /**
63      * Update the values of all GUI objects with a specific name.
64      *
65      * This method copies from the property to the GUI object.
66      *
67      * @param objectName The name of the GUI object(s) to update.
68      *        Use the empty name for all unnamed objects.
69      */
70     virtual void updateValue (const char * objectName);
71
72
73     /**
74      * Apply the values of all GUI objects with a specific name.
75      *
76      * This method copies from the GUI object to the property.
77      *
78      * @param objectName The name of the GUI object(s) to update.
79      *        Use the empty name for all unnamed objects.
80      */
81     virtual void applyValue (const char * objectName);
82
83
84     /**
85      * Update the values of all GUI objects.
86      *
87      * This method copies from the properties to the GUI objects.
88      */
89     virtual void updateValues ();
90
91
92     /**
93      * Apply the values of all GUI objects.
94      *
95      * This method copies from the GUI objects to the properties.
96      */
97     virtual void applyValues ();
98
99
100 private:
101     GUIWidget (const GUIWidget &); // just for safety
102
103     void display (SGPropertyNode_ptr props);
104     puObject * makeObject (SGPropertyNode * props,
105                            int parentWidth, int parentHeight);
106     void setupObject (puObject * object, SGPropertyNode * props);
107     void setupGroup (puGroup * group, SGPropertyNode * props,
108                      int width, int height, bool makeFrame = false);
109
110     puObject * _object;
111     vector<GUIInfo *> _info;
112     struct PropertyObject {
113         PropertyObject (const char * name,
114                         puObject * object,
115                         SGPropertyNode_ptr node);
116         string name;
117         puObject * object;
118         SGPropertyNode_ptr node;
119     };
120     vector<PropertyObject *> _propertyObjects;
121 };
122
123
124 class NewGUI : public FGSubsystem
125 {
126 public:
127
128     NewGUI ();
129     virtual ~NewGUI ();
130     virtual void init ();
131     virtual void update (double delta_time_sec);
132     virtual void display (const string &name);
133
134     virtual void setCurrentWidget (GUIWidget * widget);
135     virtual GUIWidget * getCurrentWidget ();
136
137     virtual FGMenuBar * getMenuBar ();
138
139
140 private:
141
142     void readDir (const char * path);
143
144     FGMenuBar * _menubar;
145     GUIWidget * _current_widget;
146     map<string,SGPropertyNode_ptr> _widgets;
147
148 };
149
150
151 #endif // __NEW_GUI_HXX
152
153 // end of new_gui.hxx