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>
25 * An XML-configured dialog box.
27 * The GUI manager stores only the property tree for the dialog
28 * boxes. This class creates a PUI dialog box on demand from
29 * the properties in that tree. The manager recreates the dialog
30 * every time it needs to show it.
37 * Construct a new GUI widget configured by a property tree.
39 * The configuration properties are not part of the main
40 * FlightGear property tree; the GUI manager reads them
41 * from individual configuration files.
43 * @param props A property tree describing the dialog.
45 FGDialog (SGPropertyNode * props);
55 * Update the values of all GUI objects with a specific name.
57 * This method copies values from the FlightGear property tree to
60 * @param objectName The name of the GUI object(s) to update.
61 * Use the empty name for all unnamed objects.
63 virtual void updateValue (const char * objectName);
67 * Apply the values of all GUI objects with a specific name.
69 * This method copies values from the GUI object(s) to the
70 * FlightGear property tree.
72 * @param objectName The name of the GUI object(s) to update.
73 * Use the empty name for all unnamed objects.
75 virtual void applyValue (const char * objectName);
79 * Update the values of all GUI objects.
81 * This method copies values from the FlightGear property tree to
84 virtual void updateValues ();
88 * Apply the values of all GUI objects.
90 * This method copies from the GUI objects to the FlightGear
91 * property tree properties.
93 virtual void applyValues ();
97 * Update state. Called on active dialogs before rendering.
99 virtual void update ();
103 // Private copy constructor to avoid unpleasant surprises.
104 FGDialog (const FGDialog &);
107 void display (SGPropertyNode * props);
109 // Build the dialog or a subobject of it.
110 puObject * makeObject (SGPropertyNode * props,
111 int parentWidth, int parentHeight);
113 // Common configuration for all GUI objects.
114 void setupObject (puObject * object, SGPropertyNode * props);
116 // Common configuration for all GUI group objects.
117 void setupGroup (puGroup * group, SGPropertyNode * props,
118 int width, int height, sgVec4 color,
119 bool makeFrame = false);
121 // Read color properties and merge them into color vector.
122 void getColor(const SGPropertyNode * prop, sgVec4 color);
124 // The top-level PUI object.
127 // PUI provides no way for userdata to be deleted automatically
128 // with a GUI object, so we have to keep track of all the special
129 // data we allocated and then free it manually when the dialog
131 vector<void *> _info;
132 struct PropertyObject {
133 PropertyObject (const char * name,
135 SGPropertyNode_ptr node);
138 SGPropertyNode_ptr node;
140 vector<PropertyObject *> _propertyObjects;
141 vector<PropertyObject *> _liveObjects;
143 // PUI doesn't copy arrays, so we have to allocate string arrays
144 // and then keep pointers so that we can delete them when the
146 char ** make_char_array (int size);
147 vector<char **> _char_arrays;
155 // Custom subclass of puPopup to implement "draggable" windows in the
156 // interface. Note that this is a subclass of puPopup, not
157 // puDialogBox. Sadly, PUI (mis)uses subclassing to implement a
158 // boolean property: modality. That means that we can't implement
159 // dragging of both puPopup windows and puDialogBoxes with the same
160 // code. Rather than duplicate code, I've chosen to implement only
161 // "non-modal dragability" here. Modal dialog boxes (like the exit
162 // confirmation) are not draggable.
164 class fgPopup : public puPopup {
166 fgPopup(int x, int y, bool d = true) : puPopup(x, y) { _dragging = false; _draggable = d;}
167 int checkHit(int b, int up, int x, int y);
168 int getHitObjects(puObject *, int x, int y);
175 #endif // __DIALOG_HXX