]> git.mxchange.org Git - flightgear.git/commitdiff
Started new, XML-configurable GUI subsystem.
authordavid <david>
Thu, 7 Nov 2002 16:27:47 +0000 (16:27 +0000)
committerdavid <david>
Thu, 7 Nov 2002 16:27:47 +0000 (16:27 +0000)
src/GUI/Makefile.am
src/GUI/new_gui.cxx [new file with mode: 0644]
src/GUI/new_gui.hxx [new file with mode: 0644]
src/Main/fg_commands.cxx
src/Main/fg_init.cxx

index ad177f0b296718165879342b157e6d6488450945..e628743858377ef34d74d3de3ee3408c590456a8 100644 (file)
@@ -8,6 +8,7 @@ endif
 
 libGUI_a_SOURCES = \
        apt_dlg.cxx apt_dlg.hxx \
+        new_gui.cxx new_gui.hxx \
        gui.cxx gui.h gui_funcs.cxx \
        gui_local.cxx gui_local.hxx \
        mouse.cxx \
diff --git a/src/GUI/new_gui.cxx b/src/GUI/new_gui.cxx
new file mode 100644 (file)
index 0000000..9301ba9
--- /dev/null
@@ -0,0 +1,170 @@
+// new_gui.cxx: implementation of XML-configurable GUI support.
+
+#include "new_gui.hxx"
+
+#include <plib/pu.h>
+
+#include <vector>
+SG_USING_STD(vector);
+
+#include <simgear/misc/exception.hxx>
+#include <Main/fg_props.hxx>
+
+
+NewGUI::NewGUI ()
+    : _activeObject(0)
+{
+}
+
+NewGUI::~NewGUI ()
+{
+}
+
+void
+NewGUI::init ()
+{
+    SGPropertyNode props;
+
+    try {
+        fgLoadProps("gui.xml", &props);
+    } catch (const sg_exception &ex) {
+        SG_LOG(SG_INPUT, SG_ALERT, "Error parsing gui.xml: "
+               << ex.getMessage());
+        return;
+    }
+
+    int nChildren = props.nChildren();
+    for (int i = 0; i < nChildren; i++) {
+        SGPropertyNode_ptr child = props.getChild(i);
+        if (!child->hasValue("name")) {
+            SG_LOG(SG_INPUT, SG_WARN, "GUI node " << child->getName()
+                   << " has no name; skipping.");
+        } else {
+            string name = child->getStringValue("name");
+            SG_LOG(SG_INPUT, SG_BULK, "Saving GUI node " << name);
+            _objects[name] = child;
+        }
+    }
+}
+
+void
+NewGUI::update (double delta_time_sec)
+{
+    // NO OP
+}
+
+static void
+close_callback (puObject * object)
+{
+    ((NewGUI *)object->getUserData())->closeActiveObject();
+}
+
+void
+NewGUI::closeActiveObject ()
+{
+    delete _activeObject;
+    _activeObject = 0;
+}
+
+void
+NewGUI::display (const string &name)
+{
+    if (_activeObject != 0) {
+        SG_LOG(SG_GENERAL, SG_ALERT, "Another GUI object is still active");
+        return;
+    }
+
+    if (_objects.find(name) == _objects.end()) {
+        SG_LOG(SG_GENERAL, SG_ALERT, "Dialog " << name << " not defined");
+        return;
+    }
+    SGPropertyNode_ptr props = _objects[name];
+    
+    _activeObject = makeObject(props, 1024, 768);
+
+    if (_activeObject != 0) {
+        _activeObject->reveal();
+    } else {
+        SG_LOG(SG_GENERAL, SG_ALERT, "Dialog " << name
+               << " does not contain a proper GUI definition");
+    }
+}
+
+puObject *
+NewGUI::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
+{
+    int width = props->getIntValue("width", parentWidth);
+    int height = props->getIntValue("height", parentHeight);
+
+    int x = props->getIntValue("x", (parentWidth - width) / 2);
+    int y = props->getIntValue("y", (parentHeight - height) / 2);
+
+    string type = props->getName();
+
+    if (type == "dialog") {
+        puPopup * dialog;
+        if (props->getBoolValue("modal", false))
+            dialog = new puDialogBox(x, y);
+        else
+            dialog = new puPopup(x, y);
+        setupGroup(dialog, props, width, height, true);
+        return dialog;
+    } else if (type == "group") {
+        puGroup * group = new puGroup(x, y);
+        setupGroup(group, props, width, height, false);
+        return group;
+    } else if (type == "input") {
+        puInput * input = new puInput(x, y, x + width, y + height);
+        setupObject(input, props);
+        return input;
+    } else if (type == "text") {
+        puText * text = new puText(x, y);
+        setupObject(text, props);
+        return text;
+    } else if (type == "button") {
+        puButton * b;
+        const char * legend = props->getStringValue("legend", "[none]");
+        if (props->getBoolValue("one-shot", true))
+            b = new puOneShot(x, y, legend);
+        else
+            b = new puButton(x, y, legend);
+        setupObject(b, props);
+        b->setCallback(close_callback);
+        b->setUserData(this);
+        return b;
+    } else {
+        return 0;
+    }
+}
+
+void
+NewGUI::setupObject (puObject * object, SGPropertyNode * props)
+{
+    if (props->hasValue("legend"))
+        object->setLegend(props->getStringValue("legend"));
+
+    if (props->hasValue("label"))
+        object->setLabel(props->getStringValue("label"));
+
+    if (props->hasValue("default-value-prop"))
+        object->setValue(fgGetString(props->getStringValue("default-value-prop")));
+
+    object->makeReturnDefault(props->getBoolValue("default"));
+}
+
+void
+NewGUI::setupGroup (puGroup * group, SGPropertyNode * props,
+                    int width, int height, bool makeFrame)
+{
+    setupObject(group, props);
+
+    if (makeFrame)
+        new puFrame(0, 0, width, height);
+
+    int nChildren = props->nChildren();
+    for (int i = 0; i < nChildren; i++)
+        makeObject(props->getChild(i), width, height);
+    group->close();
+}
+
+// end of new_gui.cxx
diff --git a/src/GUI/new_gui.hxx b/src/GUI/new_gui.hxx
new file mode 100644 (file)
index 0000000..3030cae
--- /dev/null
@@ -0,0 +1,46 @@
+#ifndef __NEW_GUI_HXX
+#define __NEW_GUI_HXX 1
+
+#ifndef __cplusplus
+# error This library requires C++
+#endif
+
+#include <plib/pu.h>
+
+#include <simgear/compiler.h>  // for SG_USING_STD
+#include <simgear/misc/props.hxx>
+
+#include <map>
+SG_USING_STD(map);
+
+#include <Main/fgfs.hxx>
+
+
+class NewGUI : public FGSubsystem
+{
+public:
+
+    NewGUI ();
+    virtual ~NewGUI ();
+    virtual void init ();
+    virtual void update (double delta_time_sec);
+
+    virtual void closeActiveObject ();
+    virtual void display (const string &name);
+
+private:
+
+    puObject * makeObject (SGPropertyNode * props,
+                           int parentWidth, int parentHeight);
+
+    void setupObject (puObject * object, SGPropertyNode * props);
+
+    void setupGroup (puGroup * group, SGPropertyNode * props,
+                     int width, int height, bool makeFrame = false);
+
+    map<string,SGPropertyNode_ptr> _objects;
+    puObject * _activeObject;
+
+};
+
+#endif // __NEW_GUI_HXX
index 4f628470990798088f044aa459f9df6b16264d06..5f79c96f5dd1cfa8dc331de5fc404f0e1c401677 100644 (file)
@@ -13,6 +13,7 @@
 #include <simgear/misc/props.hxx>
 
 #include <GUI/gui.h>
+#include <GUI/new_gui.hxx>
 #include <Cockpit/panel.hxx>
 #include <Cockpit/panel_io.hxx>
 #include <Scenery/tilemgr.hxx>
@@ -580,6 +581,14 @@ do_property_scale (const SGPropertyNode * arg)
   return prop->setDoubleValue((setting + offset) * factor);
 }
 
+static bool
+do_gui (const SGPropertyNode * arg)
+{
+    NewGUI * gui = (NewGUI *)globals->get_subsystem_mgr()->get_group(FGSubsystemMgr::INIT)->get_subsystem("gui");
+    gui->display(arg->getStringValue("name"));
+    return true;
+}
+
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -614,6 +623,7 @@ static struct {
     { "property-multiply", do_property_multiply },
     { "property-swap", do_property_swap },
     { "property-scale", do_property_scale },
+    { "gui", do_gui },
     { 0, 0 }                   // zero-terminated
 };
 
index a603ef61f496673e2001ae216209d0ef5704a82d..22f9ee34f93e647cbb32ae849b9d9dd0e5632ce2 100644 (file)
@@ -94,6 +94,7 @@
 #include <FDM/UFO.hxx>
 #include <FDM/NullFDM.hxx>
 #include <FDM/YASim/YASim.hxx>
+#include <GUI/new_gui.hxx>
 #include <Include/general.hxx>
 #include <Input/input.hxx>
 #include <Instrumentation/instrument_mgr.hxx>
@@ -965,7 +966,7 @@ bool fgInitSubsystems( void ) {
 
 
     ////////////////////////////////////////////////////////////////////
-    // Initialize the logger.
+    // Create and register the logger.
     ////////////////////////////////////////////////////////////////////
     
     globals->get_subsystem_mgr()->add(FGSubsystemMgr::GENERAL,
@@ -973,6 +974,15 @@ bool fgInitSubsystems( void ) {
                                       new FGLogger);
 
 
+    ////////////////////////////////////////////////////////////////////
+    // Create and register the XML GUI.
+    ////////////////////////////////////////////////////////////////////
+
+    globals->get_subsystem_mgr()->add(FGSubsystemMgr::INIT,
+                                      "gui",
+                                      new NewGUI);
+
+
     ////////////////////////////////////////////////////////////////////
     // Initialize the local time subsystem.
     ////////////////////////////////////////////////////////////////////