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