]> git.mxchange.org Git - flightgear.git/blob - src/GUI/dialog.hxx
Modified Files:
[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 #include <plib/sg.h>
12
13 #include <simgear/compiler.h>   // for SG_USING_STD
14 #include <simgear/props/props.hxx>
15 #include <simgear/misc/sg_path.hxx>
16
17 #undef PUCLASS_LIST
18 #include "puList.hxx"
19
20 #include <vector>
21 SG_USING_STD(vector);
22
23
24 // ugly temproary workaround for plib's lack of user defined class ids  FIXME
25 #define FGCLASS_LIST          0x00000001
26 #define FGCLASS_AIRPORTLIST   0x00000002
27 #define FGCLASS_PROPERTYLIST  0x00000004
28 class GUI_ID { public: GUI_ID(int id) : id(id) {} int id; };
29
30
31
32 class FGDialog;
33 class NewGUI;
34 class FGColor;
35
36
37 /**
38  * An XML-configured dialog box.
39  *
40  * The GUI manager stores only the property tree for the dialog
41  * boxes.  This class creates a PUI dialog box on demand from
42  * the properties in that tree.  The manager recreates the dialog
43  * every time it needs to show it.
44  */
45 class FGDialog
46 {
47 public:
48
49     /**
50      * Construct a new GUI widget configured by a property tree.
51      *
52      * The configuration properties are not part of the main
53      * FlightGear property tree; the GUI manager reads them
54      * from individual configuration files.
55      *
56      * @param props A property tree describing the dialog.
57      */
58     FGDialog (SGPropertyNode * props);
59
60
61     /**
62      * Destructor.
63      */
64     virtual ~FGDialog ();
65
66
67     /**
68      * Update the values of all GUI objects with a specific name,
69      * or all if name is 0 (default).
70      *
71      * This method copies values from the FlightGear property tree to
72      * the GUI object(s).
73      *
74      * @param objectName The name of the GUI object(s) to update.
75      *        Use the empty name for all unnamed objects.
76      */
77     virtual void updateValues (const char * objectName = 0);
78
79
80     /**
81      * Apply the values of all GUI objects with a specific name,
82      * or all if name is 0 (default)
83      *
84      * This method copies values from the GUI object(s) to the
85      * FlightGear property tree.
86      *
87      * @param objectName The name of the GUI object(s) to update.
88      *        Use the empty name for all unnamed objects.
89      */
90     virtual void applyValues (const char * objectName = 0);
91
92
93     /**
94      * Update state.  Called on active dialogs before rendering.
95      */
96     virtual void update ();
97
98 private:
99
100     enum {
101         BACKGROUND = 0x01,
102         FOREGROUND = 0x02,
103         HIGHLIGHT = 0x04,
104         LABEL = 0x08,
105         LEGEND = 0x10,
106         MISC = 0x20,
107         EDITFIELD = 0x40
108     };
109
110     // Private copy constructor to avoid unpleasant surprises.
111     FGDialog (const FGDialog &);
112
113     // Show the dialog.
114     void display (SGPropertyNode * props);
115
116     // Build the dialog or a subobject of it.
117     puObject * makeObject (SGPropertyNode * props,
118                            int parentWidth, int parentHeight);
119
120     // Common configuration for all GUI objects.
121     void setupObject (puObject * object, SGPropertyNode * props);
122
123     // Common configuration for all GUI group objects.
124     void setupGroup (puGroup * group, SGPropertyNode * props,
125                      int width, int height, bool makeFrame = false);
126
127     // Set object colors: the "which" argument defines which color qualities
128     // (PUCOL_LABEL, etc.) should pick up the <color> property.
129     void setColor(puObject * object, SGPropertyNode * props, int which = 0);
130
131     // return key code number for keystring
132     int getKeyCode(const char *keystring);
133
134     // The top-level PUI object.
135     puObject * _object;
136
137     // The GUI subsystem.
138     NewGUI * _gui;
139
140     // The dialog font. Defaults to the global gui font, but can get
141     // overridden by a top level font definition.
142     puFont * _font;
143
144     // The source xml tree, so that we can pass data back, such as the
145     // last position.
146     SGPropertyNode_ptr _props;
147
148     // Nasal module.
149     string _module;
150     SGPropertyNode_ptr _nasal_close;
151
152     // PUI provides no way for userdata to be deleted automatically
153     // with a GUI object, so we have to keep track of all the special
154     // data we allocated and then free it manually when the dialog
155     // closes.
156     vector<void *> _info;
157     struct PropertyObject {
158         PropertyObject (const char * name,
159                         puObject * object,
160                         SGPropertyNode_ptr node);
161         string name;
162         puObject * object;
163         SGPropertyNode_ptr node;
164     };
165     vector<PropertyObject *> _propertyObjects;
166     vector<PropertyObject *> _liveObjects;
167 };
168
169 //
170 // Custom subclass of puPopup to implement "draggable" windows in the
171 // interface.  Note that this is a subclass of puPopup, not
172 // puDialogBox.  Sadly, PUI (mis)uses subclassing to implement a
173 // boolean property: modality.  That means that we can't implement
174 // dragging of both puPopup windows and puDialogBoxes with the same
175 // code.  Rather than duplicate code, I've chosen to implement only
176 // "non-modal dragability" here.  Modal dialog boxes (like the exit
177 // confirmation) are not draggable.
178 //
179 class fgPopup : public puPopup {
180 public:
181     fgPopup(int x, int y, bool d = true) : puPopup(x, y) { _dragging = false; _draggable = d;}
182     int checkHit(int b, int up, int x, int y);
183     int checkKey(int key, int updown);
184     int getHitObjects(puObject *, int x, int y);
185     puObject *getKeyObject(puObject *, int key);
186     puObject *getActiveInputField(puObject *);
187 private:
188     bool _draggable;
189     bool _dragging;
190     int _dX, _dY;
191 };
192
193
194 class fgValueList {
195 public:
196     fgValueList(SGPropertyNode *p);
197     virtual ~fgValueList();
198     virtual void update();
199
200 protected:
201     char **_list;
202
203 private:
204     void make_list();
205     void destroy_list();
206     SGPropertyNode_ptr _props;
207 };
208
209
210 class fgList : public fgValueList, public puList, public GUI_ID {
211 public:
212     fgList(int x1, int y1, int x2, int y2, SGPropertyNode *p, int sw) :
213             fgValueList(p), puList(x1, y1, x2, y2, _list, sw), GUI_ID(FGCLASS_LIST) {}
214     void update();
215 };
216
217 class fgComboBox : public fgValueList, public puaComboBox {
218 public:
219     fgComboBox(int x1, int y1, int x2, int y2, SGPropertyNode *p, bool editable) :
220         fgValueList(p), puaComboBox(x1, y1, x2, y2, _list, editable) {}
221 };
222
223 class fgSelectBox : public fgValueList, public puaSelectBox {
224 public:
225     fgSelectBox(int x1, int y1, int x2, int y2, SGPropertyNode *p) :
226         fgValueList(p), puaSelectBox(x1, y1, x2, y2, _list) {}
227 };
228
229 #endif // __DIALOG_HXX