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();
21 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
22 gui->setCurrentWidget(info->widget);
23 for (int i = 0; i < info->bindings.size(); i++)
24 info->bindings[i]->fire();
25 gui->setCurrentWidget(0);
30 ////////////////////////////////////////////////////////////////////////
31 // Implementation of GUIInfo.
32 ////////////////////////////////////////////////////////////////////////
34 GUIInfo::GUIInfo (FGDialog * w)
41 for (int i = 0; i < bindings.size(); i++) {
49 ////////////////////////////////////////////////////////////////////////
50 // Implementation of FGDialog.
51 ////////////////////////////////////////////////////////////////////////
53 FGDialog::FGDialog (SGPropertyNode_ptr props)
59 FGDialog::~FGDialog ()
64 for (i = 0; i < _info.size(); i++) {
69 for (i = 0; i < _propertyObjects.size(); i++) {
70 delete _propertyObjects[i];
71 _propertyObjects[i] = 0;
76 FGDialog::updateValue (const char * objectName)
78 for (int i = 0; i < _propertyObjects.size(); i++) {
79 if (_propertyObjects[i]->name == objectName)
80 _propertyObjects[i]->object
81 ->setValue(_propertyObjects[i]->node->getStringValue());
86 FGDialog::applyValue (const char * objectName)
88 for (int i = 0; i < _propertyObjects.size(); i++) {
89 if (_propertyObjects[i]->name == objectName)
90 _propertyObjects[i]->node
91 ->setStringValue(_propertyObjects[i]
92 ->object->getStringValue());
97 FGDialog::updateValues ()
99 for (int i = 0; i < _propertyObjects.size(); i++) {
100 puObject * object = _propertyObjects[i]->object;
101 SGPropertyNode_ptr node = _propertyObjects[i]->node;
102 object->setValue(node->getStringValue());
107 FGDialog::applyValues ()
109 for (int i = 0; i < _propertyObjects.size(); i++) {
110 puObject * object = _propertyObjects[i]->object;
111 SGPropertyNode_ptr node = _propertyObjects[i]->node;
112 node->setStringValue(object->getStringValue());
117 FGDialog::display (SGPropertyNode_ptr props)
120 SG_LOG(SG_GENERAL, SG_ALERT, "This widget is already active");
124 _object = makeObject(props, 1024, 768);
129 SG_LOG(SG_GENERAL, SG_ALERT, "Widget "
130 << props->getStringValue("name", "[unnamed]")
131 << " does not contain a proper GUI definition");
136 FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
138 int width = props->getIntValue("width", parentWidth);
139 int height = props->getIntValue("height", parentHeight);
141 int x = props->getIntValue("x", (parentWidth - width) / 2);
142 int y = props->getIntValue("y", (parentHeight - height) / 2);
144 string type = props->getName();
146 type = props->getStringValue("type");
148 SG_LOG(SG_GENERAL, SG_ALERT, "No type specified for GUI object");
152 if (type == "dialog") {
154 if (props->getBoolValue("modal", false))
155 dialog = new puDialogBox(x, y);
157 dialog = new puPopup(x, y);
158 setupGroup(dialog, props, width, height, true);
160 } else if (type == "group") {
161 puGroup * group = new puGroup(x, y);
162 setupGroup(group, props, width, height, false);
164 } else if (type == "input") {
165 puInput * input = new puInput(x, y, x + width, y + height);
166 setupObject(input, props);
168 } else if (type == "text") {
169 puText * text = new puText(x, y);
170 setupObject(text, props);
172 } else if (type == "button") {
174 const char * legend = props->getStringValue("legend", "[none]");
175 if (props->getBoolValue("one-shot", true))
176 b = new puOneShot(x, y, legend);
178 b = new puButton(x, y, legend);
179 setupObject(b, props);
187 FGDialog::setupObject (puObject * object, SGPropertyNode * props)
189 if (props->hasValue("legend"))
190 object->setLegend(props->getStringValue("legend"));
192 if (props->hasValue("label"))
193 object->setLabel(props->getStringValue("label"));
195 if (props->hasValue("property")) {
196 const char * name = props->getStringValue("name");
199 const char * propname = props->getStringValue("property");
200 SGPropertyNode_ptr node = fgGetNode(propname, true);
201 object->setValue(node->getStringValue());
203 _propertyObjects.push_back(new PropertyObject(name, object, node));
206 vector<SGPropertyNode_ptr> nodes = props->getChildren("binding");
207 if (nodes.size() > 0) {
208 GUIInfo * info = new GUIInfo(this);
210 for (int i = 0; i < nodes.size(); i++)
211 info->bindings.push_back(new FGBinding(nodes[i]));
212 object->setCallback(action_callback);
213 object->setUserData(info);
214 _info.push_back(info);
217 object->makeReturnDefault(props->getBoolValue("default"));
221 FGDialog::setupGroup (puGroup * group, SGPropertyNode * props,
222 int width, int height, bool makeFrame)
224 setupObject(group, props);
227 new puFrame(0, 0, width, height);
229 int nChildren = props->nChildren();
230 for (int i = 0; i < nChildren; i++)
231 makeObject(props->getChild(i), width, height);
237 ////////////////////////////////////////////////////////////////////////
238 // Implementation of FGDialog::PropertyObject.
239 ////////////////////////////////////////////////////////////////////////
241 FGDialog::PropertyObject::PropertyObject (const char * n,
243 SGPropertyNode_ptr p)