]> git.mxchange.org Git - flightgear.git/commitdiff
- let FGColor setters/mergers report if they found something merge-worthy
authormfranz <mfranz>
Mon, 11 Jul 2005 08:01:28 +0000 (08:01 +0000)
committermfranz <mfranz>
Mon, 11 Jul 2005 08:01:28 +0000 (08:01 +0000)
- tune "use-<color>-node-for-pucol" masks

src/GUI/dialog.cxx
src/GUI/new_gui.cxx
src/GUI/new_gui.hxx

index 72fc5823f2dbdb7f2e930297daf97c7e0da22841..f49d990d560bd9a9e151871ea406965b0f28c348 100644 (file)
@@ -424,43 +424,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 +485,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 +505,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 +518,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 +529,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 +538,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 +548,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 +574,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 +654,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();
@@ -666,38 +666,43 @@ FGDialog::setupGroup (puGroup * group, SGPropertyNode * props,
 void
 FGDialog::setColor(puObject * object, SGPropertyNode * props, int which)
 {
+    string label = props->getStringValue("label", "--");
     string type = props->getName();
-    // first set whole color scheme (see below for a description)
-    FGColor c = _gui->getColor("background");
+    string watch = "button";
+    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 (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"));
+        bool dirty = false;
+        c.clear();
+        c.setAlpha(1.0);
+        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());
-        }
     }
 }
 
index c9edfd915d73f847aa8eace4e689e518a749d0ea..5a9f6ee0a6f0aaf76965ee840b71b67e13872daf 100644 (file)
@@ -356,34 +356,42 @@ NewGUI::setupFont ()
 // FGColor class.
 ////////////////////////////////////////////////////////////////////////
 
-void
+bool
 FGColor::merge(const SGPropertyNode *node)
 {
     if (!node)
-        return;
+        return false;
 
+    bool dirty = false;
     const SGPropertyNode * n;
     if ((n = node->getNode("red")))
-        _red = n->getFloatValue();
+        _red = n->getFloatValue(), dirty = true;
     if ((n = node->getNode("green")))
-        _green = n->getFloatValue();
+        _green = n->getFloatValue(), dirty = true;
     if ((n = node->getNode("blue")))
-        _blue = n->getFloatValue();
+        _blue = n->getFloatValue(), dirty = true;
     if ((n = node->getNode("alpha")))
-        _alpha = n->getFloatValue();
+        _alpha = n->getFloatValue(), dirty = true;
+    else
+        _alpha = 1.0;
+    return dirty;
 }
 
-void
+bool
 FGColor::merge(const FGColor& color)
 {
+    bool dirty = false;
     if (color._red >= 0.0)
-        _red = color._red;
+        _red = color._red, dirty = true;
     if (color._green >= 0.0)
-        _green = color._green;
+        _green = color._green, dirty = true;
     if (color._blue >= 0.0)
-        _blue = color._blue;
+        _blue = color._blue, dirty = true;
     if (color._alpha >= 0.0)
-        _alpha = color._alpha;
+        _alpha = color._alpha, dirty = true;
+    else
+        _alpha = 1.0;
+    return dirty;
 }
 
 // end of new_gui.cxx
index a3668f769b4804cbcd885d5ead36dc1381f10f8c..6bc5cd7f9d1d1137e2a9acaac86b9c7d29432ca7 100644 (file)
@@ -210,13 +210,14 @@ public:
 
     inline void clear() { _red = _green = _blue = _alpha = -1.0f; }
     // merges in non-negative components from property with children <red> etc.
-    void merge(const SGPropertyNode *prop);
-    void merge(const FGColor& color);
+    bool merge(const SGPropertyNode *prop);
+    bool merge(const FGColor& color);
 
-    void set(const SGPropertyNode *prop) { clear(); merge(prop); };
-    void set(const FGColor& color) { clear(); merge(color); }
-    void set(float r, float g, float b, float a = 1.0f) {
+    bool set(const SGPropertyNode *prop) { clear(); return merge(prop); };
+    bool set(const FGColor& color) { clear(); return merge(color); }
+    bool set(float r, float g, float b, float a = 1.0f) {
         _red = clamp(r), _green = clamp(g), _blue = clamp(b), _alpha = clamp(a);
+        return true;
     }
     bool isValid() const {
         return _red >= 0.0 && _green >= 0.0 && _blue >= 0.0