]> git.mxchange.org Git - flightgear.git/blob - src/GUI/dialog.hxx
Add aubmodels to AI objects
[flightgear.git] / src / GUI / dialog.hxx
1 // dialog.hxx - XML-configured dialog box.
2
3 #ifndef __DIALOG_HXX
4 #define __DIALOG_HXX 1
5
6 #ifndef __cplusplus
7 # error This library requires C++
8 #endif
9
10 #include <plib/puAux.h>
11
12 #include <simgear/compiler.h>   // for SG_USING_STD
13 #include <simgear/props/props.hxx>
14 #include <simgear/misc/sg_path.hxx>
15 #include <simgear/props/condition.hxx>
16
17 #include <vector>
18 using std::vector;
19
20
21 // ugly temporary workaround for plib's lack of user defined class ids  FIXME
22 #define FGCLASS_LIST          0x00000001
23 #define FGCLASS_AIRPORTLIST   0x00000002
24 #define FGCLASS_PROPERTYLIST  0x00000004
25 #define FGCLASS_WAYPOINTLIST  0x00000008
26
27 class GUI_ID { public: GUI_ID(int id) : id(id) {} virtual ~GUI_ID() {} int id; };
28
29
30
31 class FGDialog;
32 class NewGUI;
33 class FGColor;
34
35
36 /**
37  * An XML-configured dialog box.
38  *
39  * The GUI manager stores only the property tree for the dialog
40  * boxes.  This class creates a PUI dialog box on demand from
41  * the properties in that tree.  The manager recreates the dialog
42  * every time it needs to show it.
43  */
44 class FGDialog
45 {
46 public:
47
48     /**
49      * Construct a new GUI widget configured by a property tree.
50      *
51      * The configuration properties are not part of the main
52      * FlightGear property tree; the GUI manager reads them
53      * from individual configuration files.
54      *
55      * @param props A property tree describing the dialog.
56      */
57     FGDialog (SGPropertyNode * props);
58
59
60     /**
61      * Destructor.
62      */
63     virtual ~FGDialog ();
64
65
66     /**
67      * Update the values of all GUI objects with a specific name,
68      * or all if name is 0 (default).
69      *
70      * This method copies values from the FlightGear property tree to
71      * the GUI object(s).
72      *
73      * @param objectName The name of the GUI object(s) to update.
74      *        Use the empty name for all unnamed objects.
75      */
76     virtual void updateValues (const char * objectName = 0);
77
78
79     /**
80      * Apply the values of all GUI objects with a specific name,
81      * or all if name is 0 (default)
82      *
83      * This method copies values from the GUI object(s) to the
84      * FlightGear property tree.
85      *
86      * @param objectName The name of the GUI object(s) to update.
87      *        Use the empty name for all unnamed objects.
88      */
89     virtual void applyValues (const char * objectName = 0);
90
91
92     /**
93      * Update state.  Called on active dialogs before rendering.
94      */
95     virtual void update ();
96
97     /**
98      * Recompute the dialog's layout
99      */
100     void relayout();
101     
102     
103     void setNeedsLayout() {
104       _needsRelayout = true;
105     }
106 private:
107
108     enum {
109         BACKGROUND = 0x01,
110         FOREGROUND = 0x02,
111         HIGHLIGHT = 0x04,
112         LABEL = 0x08,
113         LEGEND = 0x10,
114         MISC = 0x20,
115         EDITFIELD = 0x40
116     };
117
118     // Private copy constructor to avoid unpleasant surprises.
119     FGDialog (const FGDialog &);
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     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     vector<PropertyObject *> _propertyObjects;
181     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(FGDialog* aDlg);
192     
193     private:
194       const std::string _name;
195       puObject* _pu;      
196     };
197     
198     typedef SGSharedPtr<ConditionalObject> ConditionalObjectRef;
199     vector<ConditionalObjectRef> _conditionalObjects;
200 };
201
202 //
203 // Custom subclass of puPopup to implement "draggable" windows in the
204 // interface.  Note that this is a subclass of puPopup, not
205 // puDialogBox.  Sadly, PUI (mis)uses subclassing to implement a
206 // boolean property: modality.  That means that we can't implement
207 // dragging of both puPopup windows and puDialogBoxes with the same
208 // code.  Rather than duplicate code, I've chosen to implement only
209 // "non-modal dragability" here.  Modal dialog boxes (like the exit
210 // confirmation) are not draggable.
211 //
212 class fgPopup : public puPopup {
213 public:
214     fgPopup(int x, int y, bool r = true, bool d = true) :
215             puPopup(x, y), _draggable(d), _resizable(r), _dragging(false)
216     {}
217     int checkHit(int b, int up, int x, int y);
218     int checkKey(int key, int updown);
219     int getHitObjects(puObject *, int x, int y);
220     puObject *getKeyObject(puObject *, int key);
221     puObject *getActiveInputField(puObject *);
222     void applySize(puObject *);
223 private:
224     enum { LEFT = 1, RIGHT = 2, TOP = 4, BOTTOM = 8 };
225     bool _draggable;
226     bool _resizable;
227     bool _dragging;
228     int _resizing;
229     int _start_cursor;
230     int _cursor;
231     int _dlgX, _dlgY, _dlgW, _dlgH;
232     int _startX, _startY;
233 };
234
235
236 class fgValueList {
237 public:
238     fgValueList(SGPropertyNode *p);
239     virtual ~fgValueList();
240     virtual void update();
241
242 protected:
243     char **_list;
244
245 private:
246     void make_list();
247     void destroy_list();
248     SGPropertyNode_ptr _props;
249 };
250
251
252 class fgList : public fgValueList, public puaList, public GUI_ID {
253 public:
254     fgList(int x1, int y1, int x2, int y2, SGPropertyNode *p, int sw) :
255             fgValueList(p), puaList(x1, y1, x2, y2, _list, sw), GUI_ID(FGCLASS_LIST) {}
256     void update();
257 };
258
259 class fgComboBox : public fgValueList, public puaComboBox {
260 public:
261     fgComboBox(int x1, int y1, int x2, int y2, SGPropertyNode *p, bool editable) :
262         fgValueList(p), puaComboBox(x1, y1, x2, y2, _list, editable) {}
263         
264     void update();
265 };
266
267 class fgSelectBox : public fgValueList, public puaSelectBox {
268 public:
269     fgSelectBox(int x1, int y1, int x2, int y2, SGPropertyNode *p) :
270         fgValueList(p), puaSelectBox(x1, y1, x2, y2, _list) {}
271 };
272
273 #endif // __DIALOG_HXX