]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/dialog.cxx
allow to not only set a general widget <color>, but also specific element
[flightgear.git] / src / GUI / dialog.cxx
index 451cee38da02f4a7a165fe313372586f9db655d4..b248fc9363f926605cfc1cb488fdaa3e0059609e 100644 (file)
@@ -7,6 +7,7 @@
 #include <stdlib.h>            // atof()
 
 #include <Input/input.hxx>
+#include <Scripting/NasalSys.hxx>
 
 #include "dialog.hxx"
 #include "new_gui.hxx"
@@ -303,7 +304,9 @@ copy_from_pui (puObject * object, SGPropertyNode * node)
         // Special case to handle lists, as getStringValue cannot be overridden
         if(object->getType() & PUCLASS_LIST)
         {
-            node->setStringValue(((puList *) object)->getListStringValue());
+            const char *s = ((puList *) object)->getListStringValue();
+            if (s)
+                node->setStringValue(s);
         }
         else
         {
@@ -324,6 +327,17 @@ FGDialog::FGDialog (SGPropertyNode * props)
       _gui((NewGUI *)globals->get_subsystem("gui")),
       _props(props)
 {
+    _module = string("__dlg:") + props->getStringValue("name", "[unnamed]");
+    SGPropertyNode *nasal = props->getNode("nasal");
+    if (nasal) {
+        _nasal_close = nasal->getNode("close");
+        SGPropertyNode *open = nasal->getNode("open");
+        if (open) {
+            const char *s = open->getStringValue();
+            FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
+            nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s));
+        }
+    }
     display(props);
 }
 
@@ -333,6 +347,14 @@ FGDialog::~FGDialog ()
     _object->getAbsolutePosition(&x, &y);
     _props->setIntValue("lastx", x);
     _props->setIntValue("lasty", y);
+
+    FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
+    if (_nasal_close) {
+        const char *s = _nasal_close->getStringValue();
+        nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s));
+    }
+    nas->deleteModule(_module.c_str());
+
     puDeleteObject(_object);
 
     unsigned int i;
@@ -537,13 +559,18 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         for (unsigned int i = 0; i < value_nodes.size(); i++)
             entries[i] = strdup((char *)value_nodes[i]->getStringValue());
 
-        puList * obj = new puList(x, y, x + width, y + height, entries);
+        int slider_width = props->getIntValue("slider", 20);
+        puList * obj = new puList(x, y, x + width, y + height, entries, slider_width);
+        if (presetSize)
+            obj->setSize(width, height);
         setupObject(obj, props);
         setColor(obj, props);
         return obj;
 
     } else if (type == "airport-list") {
         AirportList * obj = new AirportList(x, y, x + width, y + height);
+        if (presetSize)
+            obj->setSize(width, height);
         setupObject(obj, props);
         setColor(obj, props);
         return obj;
@@ -567,8 +594,10 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         }
         // Layed-out objects need their size set, and non-layout ones
         // get a different placement.
-        if(presetSize) obj->setSize(width, height);
-        else obj->setLabelPlace(PUPLACE_LABEL_DEFAULT);
+        if (presetSize)
+            obj->setSize(width, height);
+        else
+            obj->setLabelPlace(PUPLACE_LABEL_DEFAULT);
         setColor(obj, props, LABEL);
         return obj;
 
@@ -593,7 +622,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
             obj = new puOneShot(x, y, legend);
         else
             obj = new puButton(x, y, legend);
-        if(presetSize)
+        if (presetSize)
             obj->setSize(width, height);
         setupObject(obj, props);
         setColor(obj, props);
@@ -621,7 +650,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         obj->setMinValue(props->getFloatValue("min", 0.0));
         obj->setMaxValue(props->getFloatValue("max", 1.0));
         setupObject(obj, props);
-        if(presetSize)
+        if (presetSize)
             obj->setSize(width, height);
         setColor(obj, props, FOREGROUND|LABEL);
         return obj;
@@ -636,9 +665,8 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         return obj;
 
     } else if (type == "textbox") {
-        int slider_width = props->getIntValue("slider", parentHeight);
+        int slider_width = props->getIntValue("slider", 20);
         int wrap = props->getBoolValue("wrap", true);
-        if (slider_width==0) slider_width=20;
         puLargeInput * obj = new puLargeInput(x, y,
                 x+width, x+height, 2, slider_width, wrap);
 
@@ -648,6 +676,8 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
             else
                 obj->enableInput();
         }
+        if (presetSize)
+            obj->setSize(width, height);
         setupObject(obj, props);
         setColor(obj, props, FOREGROUND|LABEL);
         return obj;
@@ -681,6 +711,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
 void
 FGDialog::setupObject (puObject * object, SGPropertyNode * props)
 {
+    string type = props->getName();
     object->setLabelPlace(PUPLACE_CENTERED_RIGHT);
 
     if (props->hasValue("legend"))
@@ -727,11 +758,19 @@ FGDialog::setupObject (puObject * object, SGPropertyNode * props)
             while (dest->getChild("binding", j))
                 j++;
 
+            const char *cmd = bindings[i]->getStringValue("command");
+            if (!strcmp(cmd, "nasal"))
+                bindings[i]->setStringValue("module", _module.c_str());
+
             binding = dest->getChild("binding", j, true);
             copyProperties(bindings[i], binding);
             info->bindings.push_back(new FGBinding(binding));
         }
         object->setCallback(action_callback);
+
+        if (type == "input" && props->getBoolValue("live"))
+            object->setDownCallback(action_callback);
+
         object->setUserData(info);
         _info.push_back(info);
     }
@@ -802,6 +841,8 @@ FGDialog::setColor(puObject * object, SGPropertyNode * props, int which)
         if ((pucol[i].mask == LABEL) && !c->isValid())
             dirty |= c->merge(_gui->getColor("label"));
 
+        dirty |= c->merge(props->getNode(pucol[i].cname));
+
         if (c->isValid() && dirty)
             object->setColor(pucol[i].id, c->red(), c->green(), c->blue(), c->alpha());
     }
@@ -812,6 +853,7 @@ static struct {
     const char *name;
     int key;
 } keymap[] = {
+    {"backspace", 8},
     {"tab", 9},
     {"return", 13},
     {"enter", 13},