]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/dialog.cxx
Oliver Schroeder:
[flightgear.git] / src / GUI / dialog.cxx
index 874a842549e7b7f4a2a60794aca706cd00479c94..7d1475bb9d7cbd11b4e94dd51ddc96d66c54e72a 100644 (file)
@@ -365,12 +365,12 @@ FGDialog::display (SGPropertyNode * props)
     bool userw = props->hasValue("width");
     bool userh = props->hasValue("height");
 
-    // Expand some elements. Has to be done before the layouter sees them.
-//    preprocess(props);
-
     // Let the layout widget work in the same property subtree.
     LayoutWidget wid(props);
 
+    puFont *fnt = _gui->getDefaultFont();
+    wid.setDefaultFont(fnt, int(fnt->getPointSize()));
+
     int pw=0, ph=0;
     if(!userw || !userh)
         wid.calcPrefSize(&pw, &ph);
@@ -406,6 +406,9 @@ FGDialog::display (SGPropertyNode * props)
 puObject *
 FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
 {
+    if (props->getBoolValue("hide"))
+        return 0;
+
     bool presetSize = props->hasValue("width") && props->hasValue("height");
     int width = props->getIntValue("width", parentWidth);
     int height = props->getIntValue("height", parentHeight);
@@ -424,43 +427,43 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         else
             obj = new fgPopup(x, y, draggable);
         setupGroup(obj, props, width, height, true);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props);
         return obj;
 
     } else if (type == "group") {
         puGroup * obj = new puGroup(x, y);
         setupGroup(obj, props, width, height, false);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props);
         return obj;
 
     } else if (type == "frame") {
         puGroup * obj = new puGroup(x, y);
         setupGroup(obj, props, width, height, true);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props);
         return obj;
 
     } else if (type == "hrule" || type == "vrule") {
         puFrame * obj = new puFrame(x, y, x + width, y + height);
         obj->setBorderThickness(0);
-        setColor(obj, props, FOREGROUND);
+        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
         return obj;
 
     } else if (type == "list") {
         puList * obj = new puList(x, y, x + width, y + height);
         setupObject(obj, props);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props);
         return obj;
 
     } else if (type == "airport-list") {
         AirportList * obj = new AirportList(x, y, x + width, y + height);
         setupObject(obj, props);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props);
         return obj;
 
     } else if (type == "input") {
         puInput * obj = new puInput(x, y, x + width, y + height);
         setupObject(obj, props);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props, FOREGROUND|LABEL);
         return obj;
 
     } else if (type == "text") {
@@ -485,14 +488,14 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         puButton * obj;
         obj = new puButton(x, y, x + width, y + height, PUBUTTON_XCHECK);
         setupObject(obj, props);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props, FOREGROUND|LABEL);
         return obj;
 
     } else if (type == "radio") {
         puButton * obj;
         obj = new puButton(x, y, x + width, y + height, PUBUTTON_CIRCLE);
         setupObject(obj, props);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props, FOREGROUND|LABEL);
         return obj;
 
     } else if (type == "button") {
@@ -505,7 +508,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         if(presetSize)
             obj->setSize(width, height);
         setupObject(obj, props);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props);
         return obj;
 
     } else if (type == "combo") {
@@ -518,7 +521,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         puComboBox * obj = new puComboBox(x, y, x + width, y + height, entries,
                            props->getBoolValue("editable", false));
         setupObject(obj, props);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props, FOREGROUND|LABEL);
         return obj;
 
     } else if (type == "slider") {
@@ -529,7 +532,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         setupObject(obj, props);
         if(presetSize)
             obj->setSize(width, height);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props, FOREGROUND|LABEL);
         return obj;
 
     } else if (type == "dial") {
@@ -538,7 +541,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         obj->setMaxValue(props->getFloatValue("max", 1.0));
         obj->setWrap(props->getBoolValue("wrap", true));
         setupObject(obj, props);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props, FOREGROUND|LABEL);
         return obj;
 
     } else if (type == "textbox") {
@@ -548,14 +551,14 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         puLargeInput * obj = new puLargeInput(x, y,
                 x+width, x+height, 2, slider_width, wrap);
 
-        if  (props->hasValue("editable")) {
+        if (props->hasValue("editable")) {
             if (props->getBoolValue("editable")==false)
                 obj->disableInput();
             else
                 obj->enableInput();
         }
         setupObject(obj, props);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props, FOREGROUND|LABEL);
         return obj;
 
     } else if (type == "select") {
@@ -574,7 +577,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
         puSelectBox * obj =
             new puSelectBox(x, y, x + width, y + height, entries);
         setupObject(obj, props);
-        setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(obj, props, FOREGROUND|LABEL);
         return obj;
     } else {
         return 0;
@@ -654,7 +657,7 @@ FGDialog::setupGroup (puGroup * group, SGPropertyNode * props,
 
     if (makeFrame) {
         puFrame* f = new puFrame(0, 0, width, height);
-        setColor(f, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
+        setColor(f, props);
     }
 
     int nChildren = props->nChildren();
@@ -667,58 +670,44 @@ void
 FGDialog::setColor(puObject * object, SGPropertyNode * props, int which)
 {
     string type = props->getName();
-    // first set whole color scheme (see below for a description)
-    FGColor c = _gui->getColor("background");
-    c.merge(_gui->getColor(type));
-    c.merge(props->getNode("color"));
-    object->setColourScheme(c.red(), c.green(), c.blue(), c.alpha());
+    if (type == "")
+        type = "dialog";
+
+    FGColor *c = new FGColor(_gui->getColor("background"));
+    c->merge(_gui->getColor(type));
+    c->merge(props->getNode("color"));
+    if (c->isValid())
+        object->setColourScheme(c->red(), c->green(), c->blue(), c->alpha());
 
-    // now look for the 6 plib color qualities
     const int numcol = 6;
     const struct {
         int mask;
         int id;
         const char *name;
+        const char *cname;
     } pucol[numcol] = {
-        BACKGROUND, PUCOL_BACKGROUND, "background",
-        FOREGROUND, PUCOL_FOREGROUND, "foreground",
-        HIGHLIGHT,  PUCOL_HIGHLIGHT,  "highlight",
-        LABEL,      PUCOL_LABEL,      "label",
-        LEGEND,     PUCOL_LEGEND,     "legend",
-        MISC,       PUCOL_MISC,       "misc",
+        { BACKGROUND, PUCOL_BACKGROUND, "background", "color-background" },
+        { FOREGROUND, PUCOL_FOREGROUND, "foreground", "color-foreground" },
+        { HIGHLIGHT,  PUCOL_HIGHLIGHT,  "highlight",  "color-highlight" },
+        { LABEL,      PUCOL_LABEL,      "label",      "color-label" },
+        { LEGEND,     PUCOL_LEGEND,     "legend",     "color-legend" },
+        { MISC,       PUCOL_MISC,       "misc",       "color-misc" }
     };
 
     for (int i = 0; i < numcol; i++) {
-        // merge in object color quality components (e.g. "button-background")
-        FGColor c(_gui->getColor(type));
-        c.merge(_gui->getColor(type + '-' + pucol[i].name));
-        if (c.isValid()) {
-            // merge in explicit color components from the XML structure (<color>)
-            if (which & pucol[i].mask)
-                c.merge(props->getNode("color"));
-            object->setColor(pucol[i].id, c.red(), c.green(), c.blue(), c.alpha());
-        }
-    }
-}
+        bool dirty = false;
+        c->clear();
+        c->setAlpha(1.0);
 
-void
-FGDialog::preprocess (SGPropertyNode * prop)
-{
-    for (int i = 0; i < prop->nChildren(); i++) {
-        SGPropertyNode *child = prop->getChild(i);
-        const char *name = child->getName();
-
-        if (!strcmp(name, "title")) {
-            prop->removeChild("title", child->getIndex(), false);
-            SGPropertyNode *tit = fgGetNode("/sim/gui/title");
-            if (!tit) {
-                fprintf(stderr, "no tits here!\n");
-                continue;
-            }
-            copyProperties(tit, prop->getChild(child->getIndex()));
-            writeProperties(cerr, prop, true);
-        } else
-            preprocess(prop->getChild(i));
+        dirty |= c->merge(_gui->getColor(type + '-' + pucol[i].name));
+        if (which & pucol[i].mask)
+            dirty |= c->merge(props->getNode("color"));
+
+        if ((pucol[i].mask == LABEL) && !c->isValid())
+            dirty |= c->merge(_gui->getColor("label"));
+
+        if (c->isValid() && dirty)
+            object->setColor(pucol[i].id, c->red(), c->green(), c->blue(), c->alpha());
     }
 }