1 // dialog.cxx: implementation of an XML-configurable dialog box.
3 #include <Input/input.hxx>
10 ////////////////////////////////////////////////////////////////////////
12 ////////////////////////////////////////////////////////////////////////
18 action_callback (puObject * object)
20 GUIInfo * info = (GUIInfo *)object->getUserData();
22 (NewGUI *)globals->get_subsystem_mgr()
23 ->get_group(FGSubsystemMgr::INIT)->get_subsystem("gui");
24 gui->setCurrentWidget(info->widget);
25 for (int i = 0; i < info->bindings.size(); i++)
26 info->bindings[i]->fire();
27 gui->setCurrentWidget(0);
32 ////////////////////////////////////////////////////////////////////////
33 // Implementation of GUIInfo.
34 ////////////////////////////////////////////////////////////////////////
36 GUIInfo::GUIInfo (FGDialog * w)
43 for (int i = 0; i < bindings.size(); i++) {
51 ////////////////////////////////////////////////////////////////////////
52 // Implementation of FGDialog.
53 ////////////////////////////////////////////////////////////////////////
55 FGDialog::FGDialog (SGPropertyNode_ptr props)
61 FGDialog::~FGDialog ()
66 for (i = 0; i < _info.size(); i++) {
71 for (i = 0; i < _propertyObjects.size(); i++) {
72 delete _propertyObjects[i];
73 _propertyObjects[i] = 0;
78 FGDialog::updateValue (const char * objectName)
80 for (int i = 0; i < _propertyObjects.size(); i++) {
81 if (_propertyObjects[i]->name == objectName)
82 _propertyObjects[i]->object
83 ->setValue(_propertyObjects[i]->node->getStringValue());
88 FGDialog::applyValue (const char * objectName)
90 for (int i = 0; i < _propertyObjects.size(); i++) {
91 if (_propertyObjects[i]->name == objectName)
92 _propertyObjects[i]->node
93 ->setStringValue(_propertyObjects[i]
94 ->object->getStringValue());
99 FGDialog::updateValues ()
101 for (int i = 0; i < _propertyObjects.size(); i++) {
102 puObject * object = _propertyObjects[i]->object;
103 SGPropertyNode_ptr node = _propertyObjects[i]->node;
104 object->setValue(node->getStringValue());
109 FGDialog::applyValues ()
111 for (int i = 0; i < _propertyObjects.size(); i++) {
112 puObject * object = _propertyObjects[i]->object;
113 SGPropertyNode_ptr node = _propertyObjects[i]->node;
114 node->setStringValue(object->getStringValue());
119 FGDialog::display (SGPropertyNode_ptr props)
122 SG_LOG(SG_GENERAL, SG_ALERT, "This widget is already active");
126 _object = makeObject(props, 1024, 768);
131 SG_LOG(SG_GENERAL, SG_ALERT, "Widget "
132 << props->getStringValue("name", "[unnamed]")
133 << " does not contain a proper GUI definition");
138 FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
140 int width = props->getIntValue("width", parentWidth);
141 int height = props->getIntValue("height", parentHeight);
143 int x = props->getIntValue("x", (parentWidth - width) / 2);
144 int y = props->getIntValue("y", (parentHeight - height) / 2);
146 string type = props->getName();
148 type = props->getStringValue("type");
150 SG_LOG(SG_GENERAL, SG_ALERT, "No type specified for GUI object");
154 if (type == "dialog") {
156 if (props->getBoolValue("modal", false))
157 dialog = new puDialogBox(x, y);
159 dialog = new puPopup(x, y);
160 setupGroup(dialog, props, width, height, true);
162 } else if (type == "group") {
163 puGroup * group = new puGroup(x, y);
164 setupGroup(group, props, width, height, false);
166 } else if (type == "input") {
167 puInput * input = new puInput(x, y, x + width, y + height);
168 setupObject(input, props);
170 } else if (type == "text") {
171 puText * text = new puText(x, y);
172 setupObject(text, props);
174 } else if (type == "button") {
176 const char * legend = props->getStringValue("legend", "[none]");
177 if (props->getBoolValue("one-shot", true))
178 b = new puOneShot(x, y, legend);
180 b = new puButton(x, y, legend);
181 setupObject(b, props);
189 FGDialog::setupObject (puObject * object, SGPropertyNode * props)
191 if (props->hasValue("legend"))
192 object->setLegend(props->getStringValue("legend"));
194 if (props->hasValue("label"))
195 object->setLabel(props->getStringValue("label"));
197 if (props->hasValue("property")) {
198 const char * name = props->getStringValue("name");
201 const char * propname = props->getStringValue("property");
202 SGPropertyNode_ptr node = fgGetNode(propname, true);
203 object->setValue(node->getStringValue());
205 _propertyObjects.push_back(new PropertyObject(name, object, node));
208 vector<SGPropertyNode_ptr> nodes = props->getChildren("binding");
209 if (nodes.size() > 0) {
210 GUIInfo * info = new GUIInfo(this);
212 for (int i = 0; i < nodes.size(); i++)
213 info->bindings.push_back(new FGBinding(nodes[i]));
214 object->setCallback(action_callback);
215 object->setUserData(info);
216 _info.push_back(info);
219 object->makeReturnDefault(props->getBoolValue("default"));
223 FGDialog::setupGroup (puGroup * group, SGPropertyNode * props,
224 int width, int height, bool makeFrame)
226 setupObject(group, props);
229 new puFrame(0, 0, width, height);
231 int nChildren = props->nChildren();
232 for (int i = 0; i < nChildren; i++)
233 makeObject(props->getChild(i), width, height);
239 ////////////////////////////////////////////////////////////////////////
240 // Implementation of FGDialog::PropertyObject.
241 ////////////////////////////////////////////////////////////////////////
243 FGDialog::PropertyObject::PropertyObject (const char * n,
245 SGPropertyNode_ptr p)