]> git.mxchange.org Git - flightgear.git/blob - src/GUI/FGPUIDialog.hxx
Launcher: Maintain aircraft selection better
[flightgear.git] / src / GUI / FGPUIDialog.hxx
1 // FGPUIDialog.hxx - XML-configured dialog box.
2
3 #ifndef FG_PUI_DIALOG_HXX
4 #define FG_PUI_DIALOG_HXX 1
5
6 #include "dialog.hxx"
7
8 #include <plib/puAux.h>
9
10 #include <simgear/props/props.hxx>
11 #include <simgear/misc/sg_path.hxx>
12 #include <simgear/props/condition.hxx>
13
14 #include <vector>
15
16
17 // ugly temporary workaround for plib's lack of user defined class ids  FIXME
18 #define FGCLASS_LIST          0x00000001
19 #define FGCLASS_AIRPORTLIST   0x00000002
20 #define FGCLASS_PROPERTYLIST  0x00000004
21 #define FGCLASS_WAYPOINTLIST  0x00000008
22 #define FGCLASS_LOGLIST       0x00000010
23
24 class GUI_ID { public: GUI_ID(int id) : id(id) {} virtual ~GUI_ID() {} int id; };
25
26
27
28 class NewGUI;
29 class FGColor;
30 class puObject;
31 class puFont;
32
33 /**
34  * An XML-configured dialog box.
35  *
36  * The GUI manager stores only the property tree for the dialog
37  * boxes.  This class creates a PUI dialog box on demand from
38  * the properties in that tree.  The manager recreates the dialog
39  * every time it needs to show it.
40  */
41 class FGPUIDialog : public FGDialog
42 {
43 public:
44
45     /**
46      * Construct a new GUI widget configured by a property tree.
47      *
48      * The configuration properties are not part of the main
49      * FlightGear property tree; the GUI manager reads them
50      * from individual configuration files.
51      *
52      * @param props A property tree describing the dialog.
53      */
54     FGPUIDialog (SGPropertyNode * props);
55
56
57     /**
58      * Destructor.
59      */
60     virtual ~FGPUIDialog ();
61
62
63     /**
64      * Update the values of all GUI objects with a specific name,
65      * or all if an empty name is given (default).
66      *
67      * This method copies values from the FlightGear property tree to
68      * the GUI object(s).
69      *
70      * @param objectName The name of the GUI object(s) to update.
71      *        Use the empty name for all objects.
72      */
73     virtual void updateValues(const std::string& objectName = "");
74
75
76     /**
77      * Apply the values of all GUI objects with a specific name,
78      * or all if an empty name is given (default).
79      *
80      * This method copies values from the GUI object(s) to the
81      * FlightGear property tree.
82      *
83      * @param objectName The name of the GUI object(s) to update.
84      *        Use the empty name for all objects.
85      */
86     virtual void applyValues(const std::string& objectName = "");
87
88
89     /**
90      * Update state.  Called on active dialogs before rendering.
91      */
92     virtual void update ();
93
94     /**
95      * Recompute the dialog's layout
96      */
97     void relayout();
98     
99     
100     void setNeedsLayout() {
101       _needsRelayout = true;
102     }
103     
104     class ActiveWidget
105     {
106     public:
107         virtual void update() = 0;
108     };
109 private:
110
111     enum {
112         BACKGROUND = 0x01,
113         FOREGROUND = 0x02,
114         HIGHLIGHT = 0x04,
115         LABEL = 0x08,
116         LEGEND = 0x10,
117         MISC = 0x20,
118         EDITFIELD = 0x40
119     };
120
121     // Show the dialog.
122     void display (SGPropertyNode * props);
123
124     // Build the dialog or a subobject of it.
125     puObject * makeObject (SGPropertyNode * props,
126                            int parentWidth, int parentHeight);
127
128     // Common configuration for all GUI objects.
129     void setupObject (puObject * object, SGPropertyNode * props);
130
131     // Common configuration for all GUI group objects.
132     void setupGroup (puGroup * group, SGPropertyNode * props,
133                      int width, int height, bool makeFrame = false);
134
135     // Set object colors: the "which" argument defines which color qualities
136     // (PUCOL_LABEL, etc.) should pick up the <color> property.
137     void setColor(puObject * object, SGPropertyNode * props, int which = 0);
138
139     // return key code number for keystring
140     int getKeyCode(const char *keystring);
141
142     /**
143      * Apply layout sizes to a tree of puObjects
144      */
145     void applySize(puObject *object);
146
147     // The top-level PUI object.
148     puObject * _object;
149
150     // The GUI subsystem.
151     NewGUI * _gui;
152
153     // The dialog font. Defaults to the global gui font, but can get
154     // overridden by a top level font definition.
155     puFont * _font;
156
157     // The source xml tree, so that we can pass data back, such as the
158     // last position.
159     SGPropertyNode_ptr _props;
160
161     bool _needsRelayout;
162
163     // Nasal module.
164     std::string _module;
165     SGPropertyNode_ptr _nasal_close;
166
167     // PUI provides no way for userdata to be deleted automatically
168     // with a GUI object, so we have to keep track of all the special
169     // data we allocated and then free it manually when the dialog
170     // closes.
171     std::vector<void *> _info;
172     struct PropertyObject {
173         PropertyObject (const char * name,
174                         puObject * object,
175                         SGPropertyNode_ptr node);
176         std::string name;
177         puObject * object;
178         SGPropertyNode_ptr node;
179     };
180     std::vector<PropertyObject *> _propertyObjects;
181     std::vector<PropertyObject *> _liveObjects;
182     
183     class ConditionalObject : public SGConditional
184     {
185     public:
186       ConditionalObject(const std::string& aName, puObject* aPu) :
187         _name(aName),
188         _pu(aPu)
189       { ; }
190     
191       void update(FGPUIDialog* aDlg);
192     
193     private:
194       const std::string _name;
195       puObject* _pu;      
196     };
197     
198     typedef SGSharedPtr<ConditionalObject> ConditionalObjectRef;
199     std::vector<ConditionalObjectRef> _conditionalObjects;
200     
201     std::vector<ActiveWidget*> _activeWidgets;
202 };
203
204 #endif // __DIALOG_HXX