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>
24 * An XML-configured dialog box.
26 * The GUI manager stores only the property tree for the dialog
27 * boxes. This class creates a PUI dialog box on demand from
28 * the properties in that tree. The manager recreates the dialog
29 * every time it needs to show it.
36 * Construct a new GUI widget configured by a property tree.
38 * The configuration properties are not part of the main
39 * FlightGear property tree; the GUI manager reads them
40 * from individual configuration files.
42 * @param props A property tree describing the dialog.
44 FGDialog (SGPropertyNode * props);
54 * Update the values of all GUI objects with a specific name.
56 * This method copies values from the FlightGear property tree to
59 * @param objectName The name of the GUI object(s) to update.
60 * Use the empty name for all unnamed objects.
62 virtual void updateValue (const char * objectName);
66 * Apply the values of all GUI objects with a specific name.
68 * This method copies values from the GUI object(s) to the
69 * FlightGear property tree.
71 * @param objectName The name of the GUI object(s) to update.
72 * Use the empty name for all unnamed objects.
74 virtual void applyValue (const char * objectName);
78 * Update the values of all GUI objects.
80 * This method copies values from the FlightGear property tree to
83 virtual void updateValues ();
87 * Apply the values of all GUI objects.
89 * This method copies from the GUI objects to the FlightGear
90 * property tree properties.
92 virtual void applyValues ();
96 * Update state. Called on active dialogs before rendering.
98 virtual void update ();
102 // Private copy constructor to avoid unpleasant surprises.
103 FGDialog (const FGDialog &);
106 void display (SGPropertyNode * props);
108 // Build the dialog or a subobject of it.
109 puObject * makeObject (SGPropertyNode * props,
110 int parentWidth, int parentHeight);
112 // Common configuration for all GUI objects.
113 void setupObject (puObject * object, SGPropertyNode * props);
115 // Common configuration for all GUI group objects.
116 void setupGroup (puGroup * group, SGPropertyNode * props,
117 int width, int height, sgVec4 color,
118 bool makeFrame = false);
120 // The top-level PUI object.
123 // PUI provides no way for userdata to be deleted automatically
124 // with a GUI object, so we have to keep track of all the special
125 // data we allocated and then free it manually when the dialog
127 vector<void *> _info;
128 struct PropertyObject {
129 PropertyObject (const char * name,
131 SGPropertyNode_ptr node);
134 SGPropertyNode_ptr node;
136 vector<PropertyObject *> _propertyObjects;
137 vector<PropertyObject *> _liveObjects;
139 // PUI doesn't copy arrays, so we have to allocate string arrays
140 // and then keep pointers so that we can delete them when the
142 char ** make_char_array (int size);
143 vector<char **> _char_arrays;
147 // Custom subclass of puPopup to implement "draggable" windows in the
148 // interface. Note that this is a subclass of puPopup, not
149 // puDialogBox. Sadly, PUI (mis)uses subclassing to implement a
150 // boolean property: modality. That means that we can't implement
151 // dragging of both puPopup windows and puDialogBoxes with the same
152 // code. Rather than duplicate code, I've chosen to implement only
153 // "non-modal dragability" here. Modal dialog boxes (like the exit
154 // confirmation) are not draggable.
156 class fgPopup : public puPopup {
158 fgPopup(int x, int y, bool d = true) : puPopup(x, y) { _dragging = false; _draggable = d;}
159 int checkHit(int b, int up, int x, int y);
160 int getHitObjects(puObject *, int x, int y);
167 #endif // __DIALOG_HXX