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