From 8b3b71bce3f2c936e214144888b06db20f478df9 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Fri, 31 May 2013 19:18:36 +0200 Subject: [PATCH] Support for parsing basic CSS color keywords. --- simgear/scene/util/parse_color.cxx | 35 +++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/simgear/scene/util/parse_color.cxx b/simgear/scene/util/parse_color.cxx index f5947122..cb095c3c 100644 --- a/simgear/scene/util/parse_color.cxx +++ b/simgear/scene/util/parse_color.cxx @@ -23,6 +23,8 @@ #include #include +#include + namespace simgear { @@ -81,7 +83,38 @@ namespace simgear } } else - return false; + { + // Basic color keywords + // http://www.w3.org/TR/css3-color/#html4 + typedef std::map ColorMap; + static ColorMap colors; + if( colors.empty() ) + { + colors["red" ] = osg::Vec4(1, 0, 0, 1); + colors["black" ] = osg::Vec4(0, 0, 0, 1); + colors["silver" ] = osg::Vec4(0.75, 0.75, 0.75, 1); + colors["gray" ] = osg::Vec4(0.5, 0.5, 0.5, 1); + colors["white" ] = osg::Vec4(1, 1, 1, 1); + colors["maroon" ] = osg::Vec4(0.5, 0, 0, 1); + colors["red" ] = osg::Vec4(1, 0, 0, 1); + colors["purple" ] = osg::Vec4(0.5, 0, 0.5, 1); + colors["fuchsia"] = osg::Vec4(1, 0, 1, 1); + colors["green" ] = osg::Vec4(0, 0.5, 0, 1); + colors["lime" ] = osg::Vec4(0, 1, 0, 1); + colors["olive" ] = osg::Vec4(0.5, 0.5, 0, 1); + colors["yellow" ] = osg::Vec4(1, 1, 0, 1); + colors["navy" ] = osg::Vec4(0, 0, 0.5, 1); + colors["blue" ] = osg::Vec4(0, 0, 1, 1); + colors["teal" ] = osg::Vec4(0, 0.5, 0.5, 1); + colors["aqua" ] = osg::Vec4(0, 1, 1, 1); + } + ColorMap::const_iterator it = colors.find(str); + if( it == colors.end() ) + return false; + + result = it->second; + return true; + } result = color; return true; -- 2.39.5