]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/dialog.cxx
Make sure that all elapsed time gets passed to update when a subsystem
[flightgear.git] / src / GUI / dialog.cxx
index 525ffb3ec87e6ecade8e4b2636f0e5d292890663..de22f948fe0c4bede213b56167868b0ce19c565f 100644 (file)
 // Callbacks.
 ////////////////////////////////////////////////////////////////////////
 
+/**
+ * User data for a GUI object.
+ */
+struct GUIInfo
+{
+    GUIInfo (FGDialog * d);
+    virtual ~GUIInfo ();
+
+    FGDialog * dialog;
+    vector <FGBinding *> bindings;
+};
+
+
 /**
  * Action callback.
  */
@@ -19,10 +32,14 @@ action_callback (puObject * object)
 {
     GUIInfo * info = (GUIInfo *)object->getUserData();
     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
-    gui->setCurrentWidget(info->widget);
-    for (int i = 0; i < info->bindings.size(); i++)
+    gui->setActiveDialog(info->dialog);
+    int nBindings = info->bindings.size();
+    for (int i = 0; i < nBindings; i++) {
         info->bindings[i]->fire();
-    gui->setCurrentWidget(0);
+        if (gui->getActiveDialog() == 0)
+            break;
+    }
+    gui->setActiveDialog(0);
 }
 
 
@@ -79,8 +96,8 @@ copy_from_pui (puObject * object, SGPropertyNode * node)
 // Implementation of GUIInfo.
 ////////////////////////////////////////////////////////////////////////
 
-GUIInfo::GUIInfo (FGDialog * w)
-    : widget(w)
+GUIInfo::GUIInfo (FGDialog * d)
+    : dialog(d)
 {
 }
 
@@ -98,7 +115,7 @@ GUIInfo::~GUIInfo ()
 // Implementation of FGDialog.
 ////////////////////////////////////////////////////////////////////////
 
-FGDialog::FGDialog (SGPropertyNode_ptr props)
+FGDialog::FGDialog (SGPropertyNode * props)
     : _object(0)
 {
     display(props);
@@ -106,14 +123,29 @@ FGDialog::FGDialog (SGPropertyNode_ptr props)
 
 FGDialog::~FGDialog ()
 {
-    delete _object;
+    puDeleteObject(_object);
 
     int i;
+
+                                // Delete all the arrays we made
+                                // and were forced to keep around
+                                // because PUI won't do its own
+                                // memory management.
+    for (i = 0; i < _char_arrays.size(); i++) {
+        for (int j = 0; _char_arrays[i][j] != 0; j++)
+            free(_char_arrays[i][j]); // added with strdup
+        delete _char_arrays[i];
+    }
+
+                                // Delete all the info objects we
+                                // were forced to keep around because
+                                // PUI cannot delete its own user data.
     for (i = 0; i < _info.size(); i++) {
-        delete _info[i];
+        delete (GUIInfo *)_info[i];
         _info[i] = 0;
     }
 
+                                // Finally, delete the property links.
     for (i = 0; i < _propertyObjects.size(); i++) {
         delete _propertyObjects[i];
         _propertyObjects[i] = 0;
@@ -157,7 +189,7 @@ FGDialog::applyValues ()
 }
 
 void
-FGDialog::display (SGPropertyNode_ptr props)
+FGDialog::display (SGPropertyNode * props)
 {
     if (_object != 0) {
         SG_LOG(SG_GENERAL, SG_ALERT, "This widget is already active");
@@ -186,11 +218,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
 
     string type = props->getName();
     if (type == "")
-        type = props->getStringValue("type");
-    if (type == "") {
-        SG_LOG(SG_GENERAL, SG_ALERT, "No type specified for GUI object");
-        return 0;
-    }
+        type = "dialog";
 
     if (type == "dialog") {
         puPopup * dialog;
@@ -226,6 +254,32 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
             b = new puButton(x, y, legend);
         setupObject(b, props);
         return b;
+    } else if (type == "combo") {
+        vector<SGPropertyNode_ptr> value_nodes = props->getChildren("value");
+        char ** entries = make_char_array(value_nodes.size());
+        for (int i = 0, j = value_nodes.size() - 1;
+             i < value_nodes.size();
+             i++, j--)
+            entries[i] = strdup((char *)value_nodes[i]->getStringValue());
+        puComboBox * combo =
+            new puComboBox(x, y, x + width, y + height, entries,
+                           props->getBoolValue("editable", false));
+        setupObject(combo, props);
+        return combo;
+    } else if (type == "slider") {
+        bool vertical = props->getBoolValue("vertical", false);
+        puSlider * slider = new puSlider(x, y, (vertical ? height : width));
+        slider->setMinValue(props->getFloatValue("min", 0.0));
+        slider->setMaxValue(props->getFloatValue("max", 1.0));
+        setupObject(slider, props);
+        return slider;
+    } else if (type == "dial") {
+        puDial * dial = new puDial(x, y, width);
+        dial->setMinValue(props->getFloatValue("min", 0.0));
+        dial->setMaxValue(props->getFloatValue("max", 1.0));
+        dial->setWrap(props->getBoolValue("wrap", true));
+        setupObject(dial, props);
+        return dial;
     } else {
         return 0;
     }
@@ -280,6 +334,16 @@ FGDialog::setupGroup (puGroup * group, SGPropertyNode * props,
     group->close();
 }
 
+char **
+FGDialog::make_char_array (int size)
+{
+    char ** list = new char*[size+1];
+    for (int i = 0; i <= size; i++)
+        list[i] = 0;
+    _char_arrays.push_back(list);
+    return list;
+}
+
 
 \f
 ////////////////////////////////////////////////////////////////////////