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.
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
#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>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#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>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// 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>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 <simgear_config.h>
|
||||
#ifndef SIMGEAR_HEADLESS
|
||||
# include <osg/Vec4>
|
||||
#endif
|
||||
#include "parse_color.hxx"
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
@@ -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
|
||||
@@ -19,10 +19,7 @@
|
||||
#ifndef PARSE_COLOR_HXX_
|
||||
#define PARSE_COLOR_HXX_
|
||||
|
||||
#include <simgear/math/SGLimits.hxx>
|
||||
#include <simgear/math/SGMathFwd.hxx>
|
||||
#include <simgear/math/SGVec4.hxx>
|
||||
|
||||
#include <osg/Vec4>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
Reference in New Issue
Block a user