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