From cac0a9b32619e5182cf1db84faf0e64544d10fe9 Mon Sep 17 00:00:00 2001 From: mfranz Date: Mon, 4 Jul 2005 07:27:17 +0000 Subject: [PATCH] - abstract out reading colors from the property tree into a routine. This could also be used to read the default foreground/background color from a definition in preferences.xml or gui/color.xml. --- src/GUI/dialog.cxx | 47 +++++++++++++++++++++++++++------------------- src/GUI/dialog.hxx | 5 +++++ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/GUI/dialog.cxx b/src/GUI/dialog.cxx index d067dbfd2..173b9254d 100644 --- a/src/GUI/dialog.cxx +++ b/src/GUI/dialog.cxx @@ -266,6 +266,10 @@ FGDialog::FGDialog (SGPropertyNode * props) _font_path.append( "Fonts" ); } + const sgVec4 background = {0.8, 0.8, 0.9, 0.85}; + const sgVec4 foreground = {0, 0, 0, 1}; + sgCopyVec4(_bgcolor, background); + sgCopyVec4(_fgcolor, foreground); display(props); } @@ -409,22 +413,14 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight) int y = props->getIntValue("y", (parentHeight - height) / 2); string type = props->getName(); - const sgVec4 background = {0.8, 0.8, 0.9, 0.85}; - const sgVec4 foreground = {0, 0, 0, 1}; sgVec4 color; if (type == "hrule" || type == "vrule") - sgCopyVec4(color, foreground); + sgCopyVec4(color, _fgcolor); else - sgCopyVec4(color, background); + sgCopyVec4(color, _bgcolor); - SGPropertyNode *ncs = props->getNode("color", false); - if ( ncs ) { - color[0] = ncs->getFloatValue("red", color[0]); - color[1] = ncs->getFloatValue("green", color[1]); - color[2] = ncs->getFloatValue("blue", color[2]); - color[3] = ncs->getFloatValue("alpha", color[3]); - } + getColor(props->getNode("color"), color); if (type == "") type = "dialog"; @@ -596,14 +592,10 @@ FGDialog::setupObject (puObject * object, SGPropertyNode * props) object->setLabelFont( lfnt ); } - if ( SGPropertyNode *ncs = props->getNode("color", false) ) { - sgVec4 color; - color[0] = ncs->getFloatValue("red", 0.0); - color[1] = ncs->getFloatValue("green", 0.0); - color[2] = ncs->getFloatValue("blue", 0.0); - color[3] = ncs->getFloatValue("alpha", 1.0); - object->setColor(PUCOL_LABEL, color[0], color[1], color[2], color[3]); - } + sgVec4 color; + sgCopyVec4(color, _fgcolor); + getColor(props->getNode("color"), color); + object->setColor(PUCOL_LABEL, color[0], color[1], color[2], color[3]); if (props->hasValue("property")) { const char * name = props->getStringValue("name"); @@ -658,6 +650,23 @@ FGDialog::setupGroup (puGroup * group, SGPropertyNode * props, group->close(); } +void +FGDialog::getColor (const SGPropertyNode * prop, sgVec4 color) +{ + if (!prop) + return; + + const SGPropertyNode *p; + if ((p = prop->getChild("red"))) + color[0] = p->getFloatValue(); + if ((p = prop->getChild("green"))) + color[1] = p->getFloatValue(); + if ((p = prop->getChild("blue"))) + color[2] = p->getFloatValue(); + if ((p = prop->getChild("alpha"))) + color[3] = p->getFloatValue(); +} + char ** FGDialog::make_char_array (int size) { diff --git a/src/GUI/dialog.hxx b/src/GUI/dialog.hxx index 55b0f9061..d0c6d70b9 100644 --- a/src/GUI/dialog.hxx +++ b/src/GUI/dialog.hxx @@ -118,6 +118,9 @@ private: int width, int height, sgVec4 color, bool makeFrame = false); + // Read color properties and merge them into color vector. + void getColor(const SGPropertyNode * prop, sgVec4 color); + // The top-level PUI object. puObject * _object; @@ -144,6 +147,8 @@ private: vector _char_arrays; SGPath _font_path; + sgVec4 _fgcolor; + sgVec4 _bgcolor; }; //