From 387888862c8e10ee2840c93fbc36f9af7bec87a4 Mon Sep 17 00:00:00 2001 From: mfranz Date: Mon, 11 Jul 2005 08:01:28 +0000 Subject: [PATCH] - let FGColor setters/mergers report if they found something merge-worthy - tune "use--node-for-pucol" masks --- src/GUI/dialog.cxx | 75 ++++++++++++++++++++++++--------------------- src/GUI/new_gui.cxx | 30 +++++++++++------- src/GUI/new_gui.hxx | 11 ++++--- 3 files changed, 65 insertions(+), 51 deletions(-) diff --git a/src/GUI/dialog.cxx b/src/GUI/dialog.cxx index 72fc5823f..f49d990d5 100644 --- a/src/GUI/dialog.cxx +++ b/src/GUI/dialog.cxx @@ -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 () - 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()); - } } } diff --git a/src/GUI/new_gui.cxx b/src/GUI/new_gui.cxx index c9edfd915..5a9f6ee0a 100644 --- a/src/GUI/new_gui.cxx +++ b/src/GUI/new_gui.cxx @@ -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 diff --git a/src/GUI/new_gui.hxx b/src/GUI/new_gui.hxx index a3668f769..6bc5cd7f9 100644 --- a/src/GUI/new_gui.hxx +++ b/src/GUI/new_gui.hxx @@ -210,13 +210,14 @@ public: inline void clear() { _red = _green = _blue = _alpha = -1.0f; } // merges in non-negative components from property with children 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 -- 2.39.5