]> git.mxchange.org Git - flightgear.git/blob - src/GUI/dialog.hxx
Fix typo
[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
16 #include <vector>
17 using std::vector;
18
19
20 // ugly temporary workaround for plib's lack of user defined class ids  FIXME
21 #define FGCLASS_LIST          0x00000001
22 #define FGCLASS_AIRPORTLIST   0x00000002
23 #define FGCLASS_PROPERTYLIST  0x00000004
24 class GUI_ID { public: GUI_ID(int id) : id(id) {} virtual ~GUI_ID() {} int id; };
25
26
27
28 class FGDialog;
29 class NewGUI;
30 class FGColor;
31
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 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     FGDialog (SGPropertyNode * props);
55
56
57     /**
58      * Destructor.
59      */
60     virtual ~FGDialog ();
61
62
63     /**
64      * Update the values of all GUI objects with a specific name,
65      * or all if name is 0 (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 unnamed objects.
72      */
73     virtual void updateValues (const char * objectName = 0);
74
75
76     /**
77      * Apply the values of all GUI objects with a specific name,
78      * or all if name is 0 (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 unnamed objects.
85      */
86     virtual void applyValues (const char * objectName = 0);
87
88
89     /**
90      * Update state.  Called on active dialogs before rendering.
91      */
92     virtual void update ();
93
94 private:
95
96     enum {
97         BACKGROUND = 0x01,
98         FOREGROUND = 0x02,
99         HIGHLIGHT = 0x04,
100         LABEL = 0x08,
101         LEGEND = 0x10,
102         MISC = 0x20,
103         EDITFIELD = 0x40
104     };
105
106     // Private copy constructor to avoid unpleasant surprises.
107     FGDialog (const FGDialog &);
108
109     // Show the dialog.
110     void display (SGPropertyNode * props);
111
112     // Build the dialog or a subobject of it.
113     puObject * makeObject (SGPropertyNode * props,
114                            int parentWidth, int parentHeight);
115
116     // Common configuration for all GUI objects.
117     void setupObject (puObject * object, SGPropertyNode * props);
118
119     // Common configuration for all GUI group objects.
120     void setupGroup (puGroup * group, SGPropertyNode * props,
121                      int width, int height, bool makeFrame = false);
122
123     // Set object colors: the "which" argument defines which color qualities
124     // (PUCOL_LABEL, etc.) should pick up the <color> property.
125     void setColor(puObject * object, SGPropertyNode * props, int which = 0);
126
127     // return key code number for keystring
128     int getKeyCode(const char *keystring);
129
130     // The top-level PUI object.
131     puObject * _object;
132
133     // The GUI subsystem.
134     NewGUI * _gui;
135
136     // The dialog font. Defaults to the global gui font, but can get
137     // overridden by a top level font definition.
138     puFont * _font;
139
140     // The source xml tree, so that we can pass data back, such as the
141     // last position.
142     SGPropertyNode_ptr _props;
143
144     // Nasal module.
145     string _module;
146     SGPropertyNode_ptr _nasal_close;
147
148     // PUI provides no way for userdata to be deleted automatically
149     // with a GUI object, so we have to keep track of all the special
150     // data we allocated and then free it manually when the dialog
151     // closes.
152     vector<void *> _info;
153     struct PropertyObject {
154         PropertyObject (const char * name,
155                         puObject * object,
156                         SGPropertyNode_ptr node);
157         string name;
158         puObject * object;
159         SGPropertyNode_ptr node;
160     };
161     vector<PropertyObject *> _propertyObjects;
162     vector<PropertyObject *> _liveObjects;
163 };
164
165 //
166 // Custom subclass of puPopup to implement "draggable" windows in the
167 // interface.  Note that this is a subclass of puPopup, not
168 // puDialogBox.  Sadly, PUI (mis)uses subclassing to implement a
169 // boolean property: modality.  That means that we can't implement
170 // dragging of both puPopup windows and puDialogBoxes with the same
171 // code.  Rather than duplicate code, I've chosen to implement only
172 // "non-modal dragability" here.  Modal dialog boxes (like the exit
173 // confirmation) are not draggable.
174 //
175 class fgPopup : public puPopup {
176 public:
177     fgPopup(int x, int y, bool r = true, bool d = true) :
178             puPopup(x, y), _draggable(d), _resizable(r), _dragging(false)
179     {}
180     int checkHit(int b, int up, int x, int y);
181     int checkKey(int key, int updown);
182     int getHitObjects(puObject *, int x, int y);
183     puObject *getKeyObject(puObject *, int key);
184     puObject *getActiveInputField(puObject *);
185     void applySize(puObject *);
186 private:
187     enum { LEFT = 1, RIGHT = 2, TOP = 4, BOTTOM = 8 };
188     bool _draggable;
189     bool _resizable;
190     bool _dragging;
191     int _resizing;
192     int _start_cursor;
193     int _cursor;
194     int _dlgX, _dlgY, _dlgW, _dlgH;
195     int _startX, _startY;
196 };
197
198
199 class fgValueList {
200 public:
201     fgValueList(SGPropertyNode *p);
202     virtual ~fgValueList();
203     virtual void update();
204
205 protected:
206     char **_list;
207
208 private:
209     void make_list();
210     void destroy_list();
211     SGPropertyNode_ptr _props;
212 };
213
214
215 class fgList : public fgValueList, public puaList, public GUI_ID {
216 public:
217     fgList(int x1, int y1, int x2, int y2, SGPropertyNode *p, int sw) :
218             fgValueList(p), puaList(x1, y1, x2, y2, _list, sw), GUI_ID(FGCLASS_LIST) {}
219     void update();
220 };
221
222 class fgComboBox : public fgValueList, public puaComboBox {
223 public:
224     fgComboBox(int x1, int y1, int x2, int y2, SGPropertyNode *p, bool editable) :
225         fgValueList(p), puaComboBox(x1, y1, x2, y2, _list, editable) {}
226 };
227
228 class fgSelectBox : public fgValueList, public puaSelectBox {
229 public:
230     fgSelectBox(int x1, int y1, int x2, int y2, SGPropertyNode *p) :
231         fgValueList(p), puaSelectBox(x1, y1, x2, y2, _list) {}
232 };
233
234 #endif // __DIALOG_HXX