From 53dea9b069f2d72902aa8f3be7838f83cc7e5726 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Mon, 5 Nov 2012 17:58:24 +0100 Subject: [PATCH] Move parseColor to scene/util parseColor is used to parse a CSS color string into an osg::Vec4 which is only available in SimGearScene. If someone needs the function also in SimGear headless mode we have to think about where to better place this function. --- simgear/canvas/Canvas.cxx | 2 +- simgear/canvas/elements/CanvasImage.cxx | 2 +- simgear/canvas/elements/CanvasPath.cxx | 2 +- simgear/canvas/elements/CanvasText.cxx | 2 +- simgear/misc/CMakeLists.txt | 6 ------ simgear/scene/util/CMakeLists.txt | 8 ++++++++ simgear/{misc => scene/util}/parse_color.cxx | 20 ++----------------- simgear/{misc => scene/util}/parse_color.hxx | 17 +--------------- .../{misc => scene/util}/parse_color_test.cxx | 4 ++-- 9 files changed, 17 insertions(+), 46 deletions(-) rename simgear/{misc => scene/util}/parse_color.cxx (89%) rename simgear/{misc => scene/util}/parse_color.hxx (74%) rename simgear/{misc => scene/util}/parse_color_test.cxx (92%) diff --git a/simgear/canvas/Canvas.cxx b/simgear/canvas/Canvas.cxx index acb8da88..c998f710 100644 --- a/simgear/canvas/Canvas.cxx +++ b/simgear/canvas/Canvas.cxx @@ -18,7 +18,7 @@ #include "Canvas.hxx" #include -#include +#include #include #include diff --git a/simgear/canvas/elements/CanvasImage.cxx b/simgear/canvas/elements/CanvasImage.cxx index 811c6c17..2d07d8e8 100644 --- a/simgear/canvas/elements/CanvasImage.cxx +++ b/simgear/canvas/elements/CanvasImage.cxx @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include diff --git a/simgear/canvas/elements/CanvasPath.cxx b/simgear/canvas/elements/CanvasPath.cxx index ac9d6a9c..bdbd17c6 100644 --- a/simgear/canvas/elements/CanvasPath.cxx +++ b/simgear/canvas/elements/CanvasPath.cxx @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA #include "CanvasPath.hxx" -#include +#include #include #include diff --git a/simgear/canvas/elements/CanvasText.cxx b/simgear/canvas/elements/CanvasText.cxx index fdaa7895..2ddf39d4 100644 --- a/simgear/canvas/elements/CanvasText.cxx +++ b/simgear/canvas/elements/CanvasText.cxx @@ -19,7 +19,7 @@ #include "CanvasText.hxx" #include #include -#include +#include #include namespace simgear diff --git a/simgear/misc/CMakeLists.txt b/simgear/misc/CMakeLists.txt index 8ef0f2e3..d07b6718 100644 --- a/simgear/misc/CMakeLists.txt +++ b/simgear/misc/CMakeLists.txt @@ -4,7 +4,6 @@ include (SimGearComponent) set(HEADERS ResourceManager.hxx interpolator.hxx - parse_color.hxx sg_dir.hxx sg_path.hxx sgstream.hxx @@ -20,7 +19,6 @@ set(HEADERS set(SOURCES ResourceManager.cxx interpolator.cxx - parse_color.cxx sg_dir.cxx sg_path.cxx sgstream.cxx @@ -41,10 +39,6 @@ add_executable(test_strings strutils_test.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) diff --git a/simgear/scene/util/CMakeLists.txt b/simgear/scene/util/CMakeLists.txt index 124f0ba5..d10a4204 100644 --- a/simgear/scene/util/CMakeLists.txt +++ b/simgear/scene/util/CMakeLists.txt @@ -8,6 +8,7 @@ set(HEADERS OptionsReadFileCallback.hxx OsgMath.hxx OsgSingleton.hxx + parse_color.hxx PrimitiveUtils.hxx QuadTreeBuilder.hxx RenderConstants.hxx @@ -34,6 +35,7 @@ set(SOURCES NodeAndDrawableVisitor.cxx Noise.cxx OptionsReadFileCallback.cxx + parse_color.cxx PrimitiveUtils.cxx QuadTreeBuilder.cxx SGEnlargeBoundingBox.cxx @@ -49,3 +51,9 @@ set(SOURCES ) 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) diff --git a/simgear/misc/parse_color.cxx b/simgear/scene/util/parse_color.cxx similarity index 89% rename from simgear/misc/parse_color.cxx rename to simgear/scene/util/parse_color.cxx index b7395224..f5947122 100644 --- a/simgear/misc/parse_color.cxx +++ b/simgear/scene/util/parse_color.cxx @@ -16,10 +16,6 @@ // 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 -#ifndef SIMGEAR_HEADLESS -# include -#endif #include "parse_color.hxx" #include @@ -31,10 +27,10 @@ namespace simgear { //---------------------------------------------------------------------------- - bool parseColor(std::string str, SGVec4f& result) + bool parseColor(std::string str, osg::Vec4& result) { boost::trim(str); - SGVec4f color(0,0,0,1); + osg::Vec4 color(0,0,0,1); if( str.empty() ) return false; @@ -91,16 +87,4 @@ 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 diff --git a/simgear/misc/parse_color.hxx b/simgear/scene/util/parse_color.hxx similarity index 74% rename from simgear/misc/parse_color.hxx rename to simgear/scene/util/parse_color.hxx index 83d662b7..d4ecad3c 100644 --- a/simgear/misc/parse_color.hxx +++ b/simgear/scene/util/parse_color.hxx @@ -19,10 +19,7 @@ #ifndef PARSE_COLOR_HXX_ #define PARSE_COLOR_HXX_ -#include -#include -#include - +#include #include namespace simgear @@ -36,19 +33,7 @@ namespace simgear * * @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 diff --git a/simgear/misc/parse_color_test.cxx b/simgear/scene/util/parse_color_test.cxx similarity index 92% rename from simgear/misc/parse_color_test.cxx rename to simgear/scene/util/parse_color_test.cxx index c3795e65..c41b2645 100644 --- a/simgear/misc/parse_color_test.cxx +++ b/simgear/scene/util/parse_color_test.cxx @@ -20,11 +20,11 @@ #define VERIFY_COLOR(str, r, g, b, a) \ VERIFY(simgear::parseColor(str, color)) \ - COMPARE(color, SGVec4f(r, g, b, a)) + COMPARE(color, osg::Vec4(r, g, b, a)) int main (int ac, char ** av) { - SGVec4f color; + osg::Vec4 color; VERIFY_COLOR("#ff0000", 1,0,0,1); VERIFY_COLOR("#00ff00", 0,1,0,1); VERIFY_COLOR("#0000ff", 0,0,1,1); -- 2.39.5