#include "Canvas.hxx"
#include <simgear/canvas/MouseEvent.hxx>
-#include <simgear/misc/parse_color.hxx>
+#include <simgear/scene/util/parse_color.hxx>
#include <simgear/scene/util/RenderConstants.hxx>
#include <osg/Camera>
#include <simgear/canvas/Canvas.hxx>
#include <simgear/canvas/CanvasMgr.hxx>
#include <simgear/canvas/CanvasSystemAdapter.hxx>
-#include <simgear/misc/parse_color.hxx>
+#include <simgear/scene/util/parse_color.hxx>
#include <simgear/misc/sg_path.hxx>
#include <osg/Array>
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#include "CanvasPath.hxx"
-#include <simgear/misc/parse_color.hxx>
+#include <simgear/scene/util/parse_color.hxx>
#include <osg/Drawable>
#include <osg/BlendFunc>
#include "CanvasText.hxx"
#include <simgear/canvas/Canvas.hxx>
#include <simgear/canvas/CanvasSystemAdapter.hxx>
-#include <simgear/misc/parse_color.hxx>
+#include <simgear/scene/util/parse_color.hxx>
#include <osgText/Text>
namespace simgear
set(HEADERS
ResourceManager.hxx
interpolator.hxx
- parse_color.hxx
sg_dir.hxx
sg_path.hxx
sgstream.hxx
set(SOURCES
ResourceManager.cxx
interpolator.cxx
- parse_color.cxx
sg_dir.cxx
sg_path.cxx
sgstream.cxx
add_test(test_strings ${EXECUTABLE_OUTPUT_PATH}/test_strings)
target_link_libraries(test_strings SimGearCore)
-add_executable(test_parse_color parse_color_test.cxx )
-add_test(test_parse_color ${EXECUTABLE_OUTPUT_PATH}/test_parse_color)
-target_link_libraries(test_parse_color SimGearCore)
-
add_executable(test_path path_test.cxx )
add_test(test_path ${EXECUTABLE_OUTPUT_PATH}/test_path)
target_link_libraries(test_path SimGearCore)
+++ /dev/null
-// Parse CSS colors
-//
-// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
-
-#include <simgear_config.h>
-#ifndef SIMGEAR_HEADLESS
-# include <osg/Vec4>
-#endif
-#include "parse_color.hxx"
-
-#include <boost/algorithm/string/predicate.hpp>
-#include <boost/algorithm/string/trim.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/tokenizer.hpp>
-
-namespace simgear
-{
-
- //----------------------------------------------------------------------------
- bool parseColor(std::string str, SGVec4f& result)
- {
- boost::trim(str);
- SGVec4f color(0,0,0,1);
-
- if( str.empty() )
- return false;
-
- // #rrggbb
- if( str[0] == '#' )
- {
- const int offsets[] = {2,2,2};
- const boost::offset_separator hex_separator( boost::begin(offsets),
- boost::end(offsets) );
- typedef boost::tokenizer<boost::offset_separator> offset_tokenizer;
- offset_tokenizer tokens(str.begin() + 1, str.end(), hex_separator);
-
- int comp = 0;
- for( offset_tokenizer::const_iterator tok = tokens.begin();
- tok != tokens.end() && comp < 4;
- ++tok, ++comp )
- {
- color[comp] = strtol(std::string(*tok).c_str(), 0, 16) / 255.f;
- }
- }
- // rgb(r,g,b)
- // rgba(r,g,b,a)
- else if( boost::ends_with(str, ")") )
- {
- const std::string RGB = "rgb(",
- RGBA = "rgba(";
- size_t pos;
- if( boost::starts_with(str, RGB) )
- pos = RGB.length();
- else if( boost::starts_with(str, RGBA) )
- pos = RGBA.length();
- else
- return false;
-
- typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
- const boost::char_separator<char> del(", \t\n");
-
- tokenizer tokens(str.begin() + pos, str.end() - 1, del);
- int comp = 0;
- for( tokenizer::const_iterator tok = tokens.begin();
- tok != tokens.end() && comp < 4;
- ++tok, ++comp )
- {
- color[comp] = boost::lexical_cast<float>(*tok)
- // rgb = [0,255], a = [0,1]
- / (comp < 3 ? 255 : 1);
- }
- }
- else
- return false;
-
- result = color;
- 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
+++ /dev/null
-// Parse CSS colors
-//
-// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
-
-#ifndef PARSE_COLOR_HXX_
-#define PARSE_COLOR_HXX_
-
-#include <simgear/math/SGLimits.hxx>
-#include <simgear/math/SGMathFwd.hxx>
-#include <simgear/math/SGVec4.hxx>
-
-#include <string>
-
-namespace simgear
-{
-
- /**
- * Parse a (CSS) color
- *
- * @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, SGVec4f& result);
-
-#ifdef OSG_VEC4
- /**
- * 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
-
-#endif /* PARSE_COLOR_HXX_ */
+++ /dev/null
-#include <simgear/compiler.h>
-
-#include "parse_color.hxx"
-
-#include <iostream>
-
-#define COMPARE(a, b) \
- if( (a) != (b) ) \
- { \
- std::cerr << "failed:" << #a << " != " << #b << std::endl; \
- return 1; \
- }
-
-#define VERIFY(a) \
- if( !(a) ) \
- { \
- std::cerr << "failed:" << #a << std::endl; \
- return 1; \
- }
-
-#define VERIFY_COLOR(str, r, g, b, a) \
- VERIFY(simgear::parseColor(str, color)) \
- COMPARE(color, SGVec4f(r, g, b, a))
-
-int main (int ac, char ** av)
-{
- SGVec4f color;
- VERIFY_COLOR("#ff0000", 1,0,0,1);
- VERIFY_COLOR("#00ff00", 0,1,0,1);
- VERIFY_COLOR("#0000ff", 0,0,1,1);
- VERIFY_COLOR("rgb( 255,\t127.5,0)", 1, 0.5, 0, 1);
- VERIFY_COLOR("rgba(255, 127.5,0, 0.5)", 1, 0.5, 0, 0.5);
- std::cout << "all tests passed successfully!" << std::endl;
- return 0;
-}
OptionsReadFileCallback.hxx
OsgMath.hxx
OsgSingleton.hxx
+ parse_color.hxx
PrimitiveUtils.hxx
QuadTreeBuilder.hxx
RenderConstants.hxx
NodeAndDrawableVisitor.cxx
Noise.cxx
OptionsReadFileCallback.cxx
+ parse_color.cxx
PrimitiveUtils.cxx
QuadTreeBuilder.cxx
SGEnlargeBoundingBox.cxx
)
simgear_scene_component(util scene/util "${SOURCES}" "${HEADERS}")
+
+if(ENABLE_TESTS)
+add_executable(test_parse_color parse_color_test.cxx )
+add_test(test_parse_color ${EXECUTABLE_OUTPUT_PATH}/test_parse_color)
+target_link_libraries(test_parse_color SimGearScene)
+endif(ENABLE_TESTS)
--- /dev/null
+// Parse CSS colors
+//
+// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+
+#include "parse_color.hxx"
+
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/trim.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/tokenizer.hpp>
+
+namespace simgear
+{
+
+ //----------------------------------------------------------------------------
+ bool parseColor(std::string str, osg::Vec4& result)
+ {
+ boost::trim(str);
+ osg::Vec4 color(0,0,0,1);
+
+ if( str.empty() )
+ return false;
+
+ // #rrggbb
+ if( str[0] == '#' )
+ {
+ const int offsets[] = {2,2,2};
+ const boost::offset_separator hex_separator( boost::begin(offsets),
+ boost::end(offsets) );
+ typedef boost::tokenizer<boost::offset_separator> offset_tokenizer;
+ offset_tokenizer tokens(str.begin() + 1, str.end(), hex_separator);
+
+ int comp = 0;
+ for( offset_tokenizer::const_iterator tok = tokens.begin();
+ tok != tokens.end() && comp < 4;
+ ++tok, ++comp )
+ {
+ color[comp] = strtol(std::string(*tok).c_str(), 0, 16) / 255.f;
+ }
+ }
+ // rgb(r,g,b)
+ // rgba(r,g,b,a)
+ else if( boost::ends_with(str, ")") )
+ {
+ const std::string RGB = "rgb(",
+ RGBA = "rgba(";
+ size_t pos;
+ if( boost::starts_with(str, RGB) )
+ pos = RGB.length();
+ else if( boost::starts_with(str, RGBA) )
+ pos = RGBA.length();
+ else
+ return false;
+
+ typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
+ const boost::char_separator<char> del(", \t\n");
+
+ tokenizer tokens(str.begin() + pos, str.end() - 1, del);
+ int comp = 0;
+ for( tokenizer::const_iterator tok = tokens.begin();
+ tok != tokens.end() && comp < 4;
+ ++tok, ++comp )
+ {
+ color[comp] = boost::lexical_cast<float>(*tok)
+ // rgb = [0,255], a = [0,1]
+ / (comp < 3 ? 255 : 1);
+ }
+ }
+ else
+ return false;
+
+ result = color;
+ return true;
+ }
+
+} // namespace simgear
--- /dev/null
+// Parse CSS colors
+//
+// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+
+#ifndef PARSE_COLOR_HXX_
+#define PARSE_COLOR_HXX_
+
+#include <osg/Vec4>
+#include <string>
+
+namespace simgear
+{
+
+ /**
+ * Parse a (CSS) color
+ *
+ * @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);
+
+} // namespace simgear
+
+#endif /* PARSE_COLOR_HXX_ */
--- /dev/null
+#include <simgear/compiler.h>
+
+#include "parse_color.hxx"
+
+#include <iostream>
+
+#define COMPARE(a, b) \
+ if( (a) != (b) ) \
+ { \
+ std::cerr << "failed:" << #a << " != " << #b << std::endl; \
+ return 1; \
+ }
+
+#define VERIFY(a) \
+ if( !(a) ) \
+ { \
+ std::cerr << "failed:" << #a << std::endl; \
+ return 1; \
+ }
+
+#define VERIFY_COLOR(str, r, g, b, a) \
+ VERIFY(simgear::parseColor(str, color)) \
+ COMPARE(color, osg::Vec4(r, g, b, a))
+
+int main (int ac, char ** av)
+{
+ osg::Vec4 color;
+ VERIFY_COLOR("#ff0000", 1,0,0,1);
+ VERIFY_COLOR("#00ff00", 0,1,0,1);
+ VERIFY_COLOR("#0000ff", 0,0,1,1);
+ VERIFY_COLOR("rgb( 255,\t127.5,0)", 1, 0.5, 0, 1);
+ VERIFY_COLOR("rgba(255, 127.5,0, 0.5)", 1, 0.5, 0, 0.5);
+ std::cout << "all tests passed successfully!" << std::endl;
+ return 0;
+}