utc-Dali-VisualModel.cpp
utc-Dali-Text-Layout.cpp
utc-Dali-Text-Controller.cpp
+ utc-Dali-ColorConversion.cpp
)
# Append list of test harness files (Won't get parsed for test cases)
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dali-toolkit-test-suite-utils.h>
+#include <dali-toolkit/internal/helpers/color-conversion.h>
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+void dali_color_conversion_startup(void)
+{
+ test_return_value = TET_UNDEF;
+}
+
+void dali_color_conversion_cleanup(void)
+{
+ test_return_value = TET_PASS;
+}
+
+int UtcDaliPropertyHelperConvertHtmlStringToColor(void)
+{
+ tet_infoline( "Test to check whether An HTML style hex string can be converted" );
+
+ const std::string stringColor( "#FF0000" );
+
+ Vector4 result;
+ DALI_TEST_CHECK( Toolkit::Internal::ConvertStringToColor( stringColor, result ) );
+
+ DALI_TEST_EQUALS( result, Color::RED, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliPropertyHelperConvertStringPropertyToColor(void)
+{
+ tet_infoline( "Test to check whether A Property value containing a string can be converted" );
+
+ const std::string stringColor( "#00FF00" );
+ Property::Value colorProperty( stringColor );
+
+ Vector4 result;
+ DALI_TEST_CHECK( Toolkit::Internal::ConvertPropertyToColor( colorProperty, result ) );
+
+ DALI_TEST_EQUALS( result, Color::GREEN, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliPropertyHelperConvertVector4PropertyToColor(void)
+{
+ tet_infoline( "Test to check whether A Property value containing a string can be converted" );
+
+ const Vector4 color( 0.0, 0.0, 1.0, 1.0 );
+ Property::Value colorProperty( color );
+
+ Vector4 result;
+ DALI_TEST_CHECK( Toolkit::Internal::ConvertPropertyToColor( colorProperty, result ) );
+
+ DALI_TEST_EQUALS( result, Color::BLUE, TEST_LOCATION );
+
+ END_TEST;
+}
#include <sstream>
#include <dali/public-api/object/property-array.h>
#include <dali/public-api/object/property-map.h>
-#include <dali/devel-api/adaptor-framework/color-controller.h>
// INTERNAL INCLUDES
#include <dali-toolkit/internal/builder/builder-impl.h>
#include <dali-toolkit/internal/builder/builder-get-is.inl.h>
#include <dali-toolkit/internal/builder/replacement.h>
#include <dali-toolkit/internal/builder/builder-set-property.h>
+#include <dali-toolkit/internal/helpers/color-conversion.h>
namespace Dali
{
namespace Internal
{
-
-namespace
-{
-
-/**
- * Converts a HTML style 'color' hex string ("#FF0000" for bright red) to a Vector4.
- * The Vector4 alpha component will be set to 1.0f
- * @param hexString The HTML style hex string
- * @return a Vector4 containing the new color value
- */
-Vector4 HexStringToVector4( const char* s )
-{
- unsigned int value(0u);
- std::istringstream( s ) >> std::hex >> value;
- return Vector4( ((value >> 16 ) & 0xff ) / 255.0f,
- ((value >> 8 ) & 0xff ) / 255.0f,
- (value & 0xff ) / 255.0f,
- 1.0f );
-}
-
-} // anon namespace
-
-
/**
* A property value type can be forced when its unknown by a disambiguation convention in the json
* ie "myarray": [1,2,3,4] ; would be a vector but
}
else if( OptionalString s = replacer.IsString(node) )
{
- if( (*s)[0] == '#' && 7 == (*s).size() )
- {
- value = HexStringToVector4( &(*s)[1] );
- done = true;
- }
- else if( Dali::ColorController::Get() )
- {
- Vector4 color;
- done = Dali::ColorController::Get().RetrieveColor( *s, color );
- value = color;
- }
+ Vector4 color;
+ done = ConvertStringToColor( *s, color );
+ value = color;
}
else if( TreeNode::OBJECT == node.GetType() )
{
\
$(toolkit_src_dir)/focus-manager/keyboard-focus-manager-impl.cpp \
$(toolkit_src_dir)/focus-manager/keyinput-focus-manager-impl.cpp \
+ $(toolkit_src_dir)/helpers/color-conversion.cpp \
$(toolkit_src_dir)/filters/blur-two-pass-filter.cpp \
$(toolkit_src_dir)/filters/emboss-filter.cpp \
$(toolkit_src_dir)/filters/image-filter.cpp \
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/internal/helpers/color-conversion.h>
+
+// EXTERNAL INCLUDES
+#include <sstream>
+#include <dali/public-api/math/vector4.h>
+#include <dali/devel-api/adaptor-framework/color-controller.h>
+
+using Dali::Vector4;
+
+namespace
+{
+
+/**
+ * Converts a HTML style 'color' hex string ("#FF0000" for bright red) to a Vector4.
+ * The Vector4 alpha component will be set to 1.0f
+ * @param hexString The HTML style hex string
+ * @return a Vector4 containing the new color value
+ */
+Vector4 HexStringToVector4( const char* s )
+{
+ unsigned int value(0u);
+ std::istringstream( s ) >> std::hex >> value;
+ return Vector4( ((value >> 16 ) & 0xff ) / 255.0f,
+ ((value >> 8 ) & 0xff ) / 255.0f,
+ (value & 0xff ) / 255.0f,
+ 1.0f );
+}
+
+} // unnamed namespace
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Internal
+{
+
+bool ConvertStringToColor( const std::string& colorString, Vector4& outColor )
+{
+ bool success( false );
+
+ if( ( '#' == colorString[0] ) &&
+ ( 7 == colorString.size() ) )
+ {
+ const char* cString = colorString.c_str();
+ outColor = HexStringToVector4( &cString[1] );
+ success = true;
+ }
+ else
+ {
+ Dali::ColorController controller = Dali::ColorController::Get();
+
+ if( controller )
+ {
+ success = controller.RetrieveColor( colorString, outColor );
+ }
+ }
+
+ return success;
+}
+
+bool ConvertPropertyToColor( const Property::Value& colorValue, Vector4& outColor )
+{
+ bool success( false );
+
+ if( Property::VECTOR4 == colorValue.GetType() )
+ {
+ success = colorValue.Get( outColor );
+ }
+ else if( Property::STRING == colorValue.GetType() )
+ {
+ std::string colorString;
+ if( colorValue.Get( colorString ) )
+ {
+ success = ConvertStringToColor( colorString, outColor );
+ }
+ }
+
+ return success;
+}
+
+} // Internal
+} // Toolkit
+} // Dali
--- /dev/null
+#ifndef DALI_TOOLKIT_INTERNAL_COLOR_CONVERSION_H
+#define DALI_TOOLKIT_INTERNAL_COLOR_CONVERSION_H
+
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// EXTERNAL INCLUDES
+#include <string>
+#include <dali/public-api/object/property.h>
+
+namespace Dali
+{
+
+class Vector4;
+
+namespace Toolkit
+{
+namespace Internal
+{
+
+/*
+ * @brief Convert the string representation of a color into a Vector4.
+ *
+ * The supported string formats are:
+ * 1) An HTML style 'color' hex string ("#FF0000" for bright red).
+ * 2) An ID referring to the color palette of the current theme e.g. "B018"
+ *
+ * @param[in] colorString The color in string format.
+ * @param[out] outColor The color if found.
+ * @return True if the conversion was successful.
+ */
+bool ConvertStringToColor( const std::string& colorString, Vector4& outColor );
+
+/*
+ * @brief Convert a variety of different color representations into a Vector4.
+ *
+ * @param[in] colorValue The color in Vector4 or string format.
+ * @param[out] outColor The color if found.
+ * @return True if the conversion was successful.
+ */
+bool ConvertPropertyToColor( const Property::Value& colorValue, Vector4& outColor );
+
+} // Internal
+} // Toolkit
+} // Dali
+
+
+#endif // DALI_TOOLKIT_INTERNAL_COLOR_CONVERSION_H