1 // dialog.hxx - XML-configured dialog box.
7 # error This library requires C++
13 #include <simgear/compiler.h> // for SG_USING_STD
14 #include <simgear/props/props.hxx>
15 #include <simgear/misc/sg_path.hxx>
27 * An XML-configured dialog box.
29 * The GUI manager stores only the property tree for the dialog
30 * boxes. This class creates a PUI dialog box on demand from
31 * the properties in that tree. The manager recreates the dialog
32 * every time it needs to show it.
39 * Construct a new GUI widget configured by a property tree.
41 * The configuration properties are not part of the main
42 * FlightGear property tree; the GUI manager reads them
43 * from individual configuration files.
45 * @param props A property tree describing the dialog.
47 FGDialog (SGPropertyNode * props);
57 * Update the values of all GUI objects with a specific name.
59 * This method copies values from the FlightGear property tree to
62 * @param objectName The name of the GUI object(s) to update.
63 * Use the empty name for all unnamed objects.
65 virtual void updateValue (const char * objectName);
69 * Apply the values of all GUI objects with a specific name.
71 * This method copies values from the GUI object(s) to the
72 * FlightGear property tree.
74 * @param objectName The name of the GUI object(s) to update.
75 * Use the empty name for all unnamed objects.
77 virtual void applyValue (const char * objectName);
81 * Update the values of all GUI objects.
83 * This method copies values from the FlightGear property tree to
86 virtual void updateValues ();
90 * Apply the values of all GUI objects.
92 * This method copies from the GUI objects to the FlightGear
93 * property tree properties.
95 virtual void applyValues ();
99 * Update state. Called on active dialogs before rendering.
101 virtual void update ();
114 // Private copy constructor to avoid unpleasant surprises.
115 FGDialog (const FGDialog &);
118 void display (SGPropertyNode * props);
120 // Build the dialog or a subobject of it.
121 puObject * makeObject (SGPropertyNode * props,
122 int parentWidth, int parentHeight);
124 // Common configuration for all GUI objects.
125 void setupObject (puObject * object, SGPropertyNode * props);
127 // Common configuration for all GUI group objects.
128 void setupGroup (puGroup * group, SGPropertyNode * props,
129 int width, int height, bool makeFrame = false);
131 // Set object colors: the "which" argument defines which color qualities
132 // (PUCOL_LABEL, etc.) should pick up the <color> property.
133 void setColor(puObject * object, SGPropertyNode * props, int which = 0);
135 // The top-level PUI object.
138 // The GUI subsystem.
141 // PUI provides no way for userdata to be deleted automatically
142 // with a GUI object, so we have to keep track of all the special
143 // data we allocated and then free it manually when the dialog
145 vector<void *> _info;
146 struct PropertyObject {
147 PropertyObject (const char * name,
149 SGPropertyNode_ptr node);
152 SGPropertyNode_ptr node;
154 vector<PropertyObject *> _propertyObjects;
155 vector<PropertyObject *> _liveObjects;
157 // PUI doesn't copy arrays, so we have to allocate string arrays
158 // and then keep pointers so that we can delete them when the
160 char ** make_char_array (int size);
161 vector<char **> _char_arrays;
167 // Custom subclass of puPopup to implement "draggable" windows in the
168 // interface. Note that this is a subclass of puPopup, not
169 // puDialogBox. Sadly, PUI (mis)uses subclassing to implement a
170 // boolean property: modality. That means that we can't implement
171 // dragging of both puPopup windows and puDialogBoxes with the same
172 // code. Rather than duplicate code, I've chosen to implement only
173 // "non-modal dragability" here. Modal dialog boxes (like the exit
174 // confirmation) are not draggable.
176 class fgPopup : public puPopup {
178 fgPopup(int x, int y, bool d = true) : puPopup(x, y) { _dragging = false; _draggable = d;}
179 int checkHit(int b, int up, int x, int y);
180 int getHitObjects(puObject *, int x, int y);
187 #endif // __DIALOG_HXX