]> 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 28f60ad6129f74030fb050199b307263666d02ec..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,16 +429,30 @@ 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;
     if(!userw || !userh)
         wid.calcPrefSize(&pw, &ph);
     pw = props->getIntValue("width", pw);
     ph = props->getIntValue("height", ph);
-    int px = props->getIntValue("x", (screenw - pw) / 2);
-    int py = props->getIntValue("y", (screenh - ph) / 2);
+    px = savex = props->getIntValue("x", (screenw - pw) / 2);
+    py = savey = props->getIntValue("y", (screenh - ph) / 2);
+
+    // Negative x/y coordinates are interpreted as distance from the top/right
+    // corner rather than bottom/left.
+    if (userx && px < 0)
+        px = screenw - pw + px;
+    if (usery && py < 0)
+        py = screenh - ph + py;
 
     // Define "x", "y", "width" and/or "height" in the property tree if they
     // are not specified in the configuration file.
@@ -448,9 +463,17 @@ FGDialog::display (SGPropertyNode * props)
     _object = makeObject(props, screenw, screenh);
 
     // Remove automatically generated properties, so the layout looks
-    // the same next time around.
-    if(!userx) props->removeChild("x");
-    if(!usery) props->removeChild("y");
+    // the same next time around, or restore x and y to preserve negative coords.
+    if(userx)
+        props->setIntValue("x", savex);
+    else
+        props->removeChild("x");
+
+    if(usery)
+        props->setIntValue("y", savey);
+    else
+        props->removeChild("y");
+
     if(!userw) props->removeChild("width");
     if(!userh) props->removeChild("height");
 
@@ -509,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;
@@ -574,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());
-        puaComboBox * obj = new puaComboBox(x, y, x + width, y + height, entries,
+
+        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") {
@@ -608,7 +639,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         int slider_width = props->getIntValue("slider", parentHeight);
         int wrap = props->getBoolValue("wrap", true);
         if (slider_width==0) slider_width=20;
-        puaLargeInput * obj = new puaLargeInput(x, y,
+        puLargeInput * obj = new puLargeInput(x, y,
                 x+width, x+height, 2, slider_width, wrap);
 
         if (props->hasValue("editable")) {
@@ -630,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());
-        puaSelectBox * obj =
-            new puaSelectBox(x, y, x + width, y + height, entries);
+
+        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;
@@ -659,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")) {
@@ -735,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));
@@ -753,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]);