]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/dialog.cxx
Add missing include files needed by the new math code under windows
[flightgear.git] / src / GUI / dialog.cxx
index ca8e19753f53224aa22df321ec4bcb5d24d1024a..451cee38da02f4a7a165fe313372586f9db655d4 100644 (file)
@@ -1,5 +1,9 @@
 // dialog.cxx: implementation of an XML-configurable dialog box.
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <stdlib.h>            // atof()
 
 #include <Input/input.hxx>
@@ -317,21 +321,18 @@ copy_from_pui (puObject * object, SGPropertyNode * node)
 
 FGDialog::FGDialog (SGPropertyNode * props)
     : _object(0),
-      _gui((NewGUI *)globals->get_subsystem("gui"))
+      _gui((NewGUI *)globals->get_subsystem("gui")),
+      _props(props)
 {
-    char* envp = ::getenv( "FG_FONTS" );
-    if ( envp != NULL ) {
-        _font_path.set( envp );
-    } else {
-        _font_path.set( globals->get_fg_root() );
-        _font_path.append( "Fonts" );
-    }
-
     display(props);
 }
 
 FGDialog::~FGDialog ()
 {
+    int x, y;
+    _object->getAbsolutePosition(&x, &y);
+    _props->setIntValue("lastx", x);
+    _props->setIntValue("lasty", y);
     puDeleteObject(_object);
 
     unsigned int i;
@@ -428,8 +429,14 @@ FGDialog::display (SGPropertyNode * props)
     // Let the layout widget work in the same property subtree.
     LayoutWidget wid(props);
 
-    puFont *fnt = _gui->getDefaultFont();
-    wid.setDefaultFont(fnt, int(fnt->getPointSize()));
+    SGPropertyNode *fontnode = props->getNode("font");
+    if (fontnode) {
+        FGFontCache *fc = _gui->get_fontcache();
+        _font = fc->get(fontnode);
+    } else {
+        _font = _gui->getDefaultFont();
+    }
+    wid.setDefaultFont(_font, int(_font->getPointSize()));
 
     int pw=0, ph=0;
     int px, py, savex, savey;
@@ -442,9 +449,9 @@ FGDialog::display (SGPropertyNode * props)
 
     // Negative x/y coordinates are interpreted as distance from the top/right
     // corner rather than bottom/left.
-    if (px < 0)
+    if (userx && px < 0)
         px = screenw - pw + px;
-    if (py < 0)
+    if (usery && py < 0)
         py = screenh - ph + py;
 
     // Define "x", "y", "width" and/or "height" in the property tree if they
@@ -525,7 +532,12 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         return obj;
 
     } else if (type == "list") {
-        puList * obj = new puList(x, y, x + width, y + height);
+        vector<SGPropertyNode_ptr> value_nodes = props->getChildren("value");
+        char ** entries = make_char_array(value_nodes.size());
+        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);
         setupObject(obj, props);
         setColor(obj, props);
         return obj;
@@ -590,14 +602,17 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
     } else if (type == "combo") {
         vector<SGPropertyNode_ptr> value_nodes = props->getChildren("value");
         char ** entries = make_char_array(value_nodes.size());
-        for (unsigned int i = 0, j = value_nodes.size() - 1;
-             i < value_nodes.size();
-             i++, j--)
+        for (unsigned int i = 0; i < value_nodes.size(); i++)
             entries[i] = strdup((char *)value_nodes[i]->getStringValue());
+
         puComboBox * obj = new puComboBox(x, y, x + width, y + height, entries,
                            props->getBoolValue("editable", false));
         setupObject(obj, props);
+#ifdef PUCOL_EDITFIELD  // plib > 0.8.4
+        setColor(obj, props, EDITFIELD);
+#else
         setColor(obj, props, FOREGROUND|LABEL);
+#endif
         return obj;
 
     } else if (type == "slider") {
@@ -646,14 +661,17 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
             value_nodes.push_back(selection_node->getChild(q));
 
         char ** entries = make_char_array(value_nodes.size());
-        for (unsigned int i = 0, j = value_nodes.size() - 1;
-             i < value_nodes.size();
-             i++, j--)
+        for (unsigned int i = 0; i < value_nodes.size(); i++)
             entries[i] = strdup((char *)value_nodes[i]->getName());
+
         puSelectBox * obj =
             new puSelectBox(x, y, x + width, y + height, entries);
         setupObject(obj, props);
+#ifdef PUCOL_EDITFIELD  // plib > 0.8.4
+        setColor(obj, props, EDITFIELD);
+#else
         setColor(obj, props, FOREGROUND|LABEL);
+#endif
         return obj;
     } else {
         return 0;
@@ -675,18 +693,11 @@ FGDialog::setupObject (puObject * object, SGPropertyNode * props)
         object->setBorderThickness( props->getIntValue("border", 2) );
 
     if ( SGPropertyNode *nft = props->getNode("font", false) ) {
-       SGPath path( _font_path );
-       const char *name = nft->getStringValue("name", "default");
-       float size = nft->getFloatValue("size", 13.0);
-       float slant = nft->getFloatValue("slant", 0.0);
-       path.append( name );
-       path.concat( ".txf" );
-
-       fntFont *font = new fntTexFont;
-       font->load( (char *)path.c_str() );
-
-       puFont lfnt(font, size, slant);
-       object->setLabelFont( lfnt );
+       FGFontCache *fc = _gui->get_fontcache();
+       puFont *lfnt = fc->get(nft);
+       object->setLabelFont(*lfnt);
+    } else {
+       object->setLabelFont(*_font);
     }
 
     if (props->hasValue("property")) {
@@ -751,6 +762,8 @@ FGDialog::setColor(puObject * object, SGPropertyNode * props, int which)
     string type = props->getName();
     if (type == "")
         type = "dialog";
+    if (type == "textbox" && props->getBoolValue("editable"))
+        type += "-editable";
 
     FGColor *c = new FGColor(_gui->getColor("background"));
     c->merge(_gui->getColor(type));
@@ -769,7 +782,10 @@ FGDialog::setColor(puObject * object, SGPropertyNode * props, int which)
         { HIGHLIGHT,  PUCOL_HIGHLIGHT,  "highlight",  "color-highlight" },
         { LABEL,      PUCOL_LABEL,      "label",      "color-label" },
         { LEGEND,     PUCOL_LEGEND,     "legend",     "color-legend" },
-        { MISC,       PUCOL_MISC,       "misc",       "color-misc" }
+        { MISC,       PUCOL_MISC,       "misc",       "color-misc" },
+#ifdef PUCOL_EDITFIELD  // plib > 0.8.4
+        { EDITFIELD,  PUCOL_EDITFIELD,  "editfield",  "color-editfield" },
+#endif
     };
 
     const int numcol = sizeof(pucol) / sizeof(pucol[0]);