Fix windows and headless build

This commit is contained in:
Thomas Geymayer
2012-11-05 12:59:15 +01:00
parent 509d064286
commit f83c8828f0
9 changed files with 78 additions and 32 deletions
+18 -6
View File
@@ -27,10 +27,10 @@ namespace simgear
{
//----------------------------------------------------------------------------
bool parseColor(std::string str, osg::Vec4& result)
bool parseColor(std::string str, SGVec4f& result)
{
boost::trim(str);
osg::Vec4 color(0,0,0,1);
SGVec4f color(0,0,0,1);
if( str.empty() )
return false;
@@ -49,7 +49,7 @@ namespace simgear
tok != tokens.end() && comp < 4;
++tok, ++comp )
{
color._v[comp] = strtol(std::string(*tok).c_str(), 0, 16) / 255.f;
color[comp] = strtol(std::string(*tok).c_str(), 0, 16) / 255.f;
}
}
// rgb(r,g,b)
@@ -75,9 +75,9 @@ namespace simgear
tok != tokens.end() && comp < 4;
++tok, ++comp )
{
color._v[comp] = boost::lexical_cast<float>(*tok)
// rgb = [0,255], a = [0,1]
/ (comp < 3 ? 255 : 1);
color[comp] = boost::lexical_cast<float>(*tok)
// rgb = [0,255], a = [0,1]
/ (comp < 3 ? 255 : 1);
}
}
else
@@ -87,4 +87,16 @@ namespace simgear
return true;
}
#ifndef SIMGEAR_HEADLESS
bool parseColor(std::string str, osg::Vec4& result)
{
SGVec4f color;
if( !parseColor(str, color) )
return false;
result.set(color[0], color[1], color[2], color[3]);
return true;
}
#endif
} // namespace simgear
+20 -1
View File
@@ -19,7 +19,14 @@
#ifndef PARSE_COLOR_HXX_
#define PARSE_COLOR_HXX_
#include <osg/Vec4>
#include <simgear/math/SGLimits.hxx>
#include <simgear/math/SGMathFwd.hxx>
#include <simgear/math/SGVec4.hxx>
#ifndef SIMGEAR_HEADLESS
# include <osg/Vec4>
#endif
#include <string>
namespace simgear
@@ -33,7 +40,19 @@ namespace simgear
*
* @return Whether str contained a valid color (and result has been modified)
*/
bool parseColor(std::string str, SGVec4f& result);
#ifndef SIMGEAR_HEADLESS
/**
* Parse a (CSS) color into an osg::Vec4
*
* @param str Text to parse
* @param result Output for parse color
*
* @return Whether str contained a valid color (and result has been modified)
*/
bool parseColor(std::string str, osg::Vec4& result);
#endif
} // namespace simgear
+2 -2
View File
@@ -20,11 +20,11 @@
#define VERIFY_COLOR(str, r, g, b, a) \
VERIFY(simgear::parseColor(str, color)) \
COMPARE(color, osg::Vec4(r, g, b, a))
COMPARE(color, SGVec4f(r, g, b, a))
int main (int ac, char ** av)
{
osg::Vec4 color;
SGVec4f color;
VERIFY_COLOR("#ff0000", 1,0,0,1);
VERIFY_COLOR("#00ff00", 0,1,0,1);
VERIFY_COLOR("#0000ff", 0,0,1,1);