]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/FGPUIDialog.cxx
Support for multiple data dirs.
[flightgear.git] / src / GUI / FGPUIDialog.cxx
index 70ba763f4b155753afee914cb3ad58e889b484e9..5620ae0fc6c9d95a6587301da1f469d8348883e5 100644 (file)
@@ -6,6 +6,8 @@
 
 #include <simgear/structure/SGBinding.hxx>
 #include <simgear/props/props_io.hxx>
+#include <simgear/debug/BufferedLogCallback.hxx>
+#include <simgear/scene/tsync/terrasync.hxx>
 
 #include <Scripting/NasalSys.hxx>
 #include <Main/fg_os.hxx>
@@ -23,6 +25,8 @@
 #include "FGFontCache.hxx"
 #include "FGColor.hxx"
 
+using std::string;
+
 enum format_type { f_INVALID, f_INT, f_LONG, f_FLOAT, f_DOUBLE, f_STRING };
 static const int FORMAT_BUFSIZE = 255;
 static const int RESIZE_MARGIN = 7;
@@ -162,6 +166,25 @@ private:
   bool _inHit;
 };
 
+class LogList : public puaList, public FGPUIDialog::ActiveWidget, public GUI_ID {
+public:
+    LogList(int x1, int y1, int x2, int y2, int sw) :
+        puaList(x1, y1, x2, y2, sw),
+        GUI_ID(FGCLASS_LOGLIST)
+    {
+        m_buffer = NULL;
+        m_stamp = 0;
+    }
+    
+    void setBuffer(simgear::BufferedLogCallback* buf);
+    
+    virtual void update();
+private:
+    std::vector<unsigned char*> m_items;
+    simgear::BufferedLogCallback* m_buffer;
+    unsigned int m_stamp;
+};
+
 class fgSelectBox : public fgValueList, public puaSelectBox {
 public:
   fgSelectBox(int x1, int y1, int x2, int y2, SGPropertyNode *p) :
@@ -183,7 +206,7 @@ struct GUIInfo
 
     FGPUIDialog *dialog;
     SGPropertyNode_ptr node;
-    vector <SGBinding *> bindings;
+    std::vector <SGBinding *> bindings;
     int key;
     string label, legend, text, format;
     format_type fmt_type;
@@ -749,6 +772,10 @@ FGPUIDialog::update ()
     _conditionalObjects[j]->update(this);
   }
   
+  for (unsigned int i = 0; i < _activeWidgets.size(); i++) {
+    _activeWidgets[i]->update();
+  }
+  
   if (_needsRelayout) {
     relayout();
   }
@@ -1024,6 +1051,21 @@ FGPUIDialog::makeObject (SGPropertyNode *props, int parentWidth, int parentHeigh
         ScrolledWaypointList* obj = new ScrolledWaypointList(x, y, width, height);
         setupObject(obj, props);
         return obj;
+        
+    } else if (type == "loglist") {
+        LogList* obj = new LogList(x, y, width, height, 20);
+        string logClass = props->getStringValue("logclass");
+        if (logClass == "terrasync") {
+          simgear::SGTerraSync* tsync = (simgear::SGTerraSync*) globals->get_subsystem("terrasync");
+          obj->setBuffer(tsync->log());
+        } else {
+          FGNasalSys* nasal = (FGNasalSys*) globals->get_subsystem("nasal");
+          obj->setBuffer(nasal->log());
+        }
+
+        setupObject(obj, props);
+        _activeWidgets.push_back(obj);
+        return obj;
     } else {
         return 0;
     }
@@ -1113,7 +1155,7 @@ FGPUIDialog::setupObject (puObject *object, SGPropertyNode *props)
     }
 
     SGPropertyNode *dest = fgGetNode("/sim/bindings/gui", true);
-    vector<SGPropertyNode_ptr> bindings = props->getChildren("binding");
+    std::vector<SGPropertyNode_ptr> bindings = props->getChildren("binding");
     if (bindings.size() > 0) {
         info->key = props->getIntValue("keynum", -1);
         if (props->hasValue("key"))
@@ -1445,7 +1487,7 @@ fgValueList::make_list()
     vname = _props->getStringValue("property-name");
   }
   
-  vector<SGPropertyNode_ptr> value_nodes = values->getChildren(vname);
+  std::vector<SGPropertyNode_ptr> value_nodes = values->getChildren(vname);
   _list = new char *[value_nodes.size() + 1];
   unsigned int i;
   for (i = 0; i < value_nodes.size(); i++) {
@@ -1474,6 +1516,34 @@ fgList::update()
     setTopItem(top);
 }
 
+////////////////////////////////////////////////////////////////////////
+// Implementation of fgLogList
+////////////////////////////////////////////////////////////////////////
+
+void LogList::update()
+{
+    if (!m_buffer) return;
+    
+    if (m_stamp != m_buffer->stamp()) {
+        m_stamp = m_buffer->threadsafeCopy(m_items);
+        m_items.push_back(NULL); // terminator value
+        newList((char**) m_items.data());
+        setTopItem(m_items.size() - 1); // scroll to bottom of list
+    }
+}
+
+void LogList::setBuffer(simgear::BufferedLogCallback* buf)
+{
+    m_buffer = buf;
+    m_stamp = m_buffer->stamp() - 1; // force an update
+    update();
+}
+
+////////////////////////////////////////////////////////////////////////
+// Implementation of fgComboBox 
+////////////////////////////////////////////////////////////////////////
+
+
 void fgComboBox::update()
 {
   if (_inHit) {