From: suhyung Eom Date: Mon, 27 Feb 2017 10:49:31 +0000 (-0800) Subject: Merge "[3.0] Fixed to show textSelectionPop up normally on second long press" into... X-Git-Tag: submit/tizen_3.0/20170227.105302 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Ftags%2Fsubmit%2Ftizen_3.0%2F20170227.105302;hp=8a4dcac0834bdd4dffba0482f21014846196c170;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git Merge "[3.0] Fixed to show textSelectionPop up normally on second long press" into tizen_3.0 --- diff --git a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt index bb55422..0feca8b 100644 --- a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt @@ -18,6 +18,7 @@ SET(TC_SOURCES 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) diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-ColorConversion.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-ColorConversion.cpp new file mode 100644 index 0000000..14cef1c --- /dev/null +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-ColorConversion.cpp @@ -0,0 +1,76 @@ +/* + * 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 +#include + +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; +} diff --git a/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h b/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h index 5201c08..31cf939 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h @@ -75,23 +75,114 @@ public: { enum { - POPUP_MAX_SIZE = PROPERTY_START_INDEX, ///< name "popupMaxSize", maximum size the Popup can be, type VECTOR2 - POPUP_MIN_SIZE, ///< name "popupMinSize", minimum size the Popup can be, type VECTOR2 - OPTION_MAX_SIZE, ///< name "optionMaxSize", maximum size an option can be, type VECTOR2 - OPTION_MIN_SIZE, ///< name "optionMinSize", minimum size an option can be, type VECTOR2 - OPTION_DIVIDER_SIZE, ///< name "optionDividerSize", size of the divider between options type VECTOR2 - POPUP_CLIPBOARD_BUTTON_ICON_IMAGE, ///< name "popupClipboardButtonImage", The image to use as the popup clipboard icon, type STRING - POPUP_CUT_BUTTON_ICON_IMAGE, ///< name "popupCutButtonImage", The image to use as the popup cut icon, type STRING - POPUP_COPY_BUTTON_ICON_IMAGE, ///< name "popupCopyButtonImage", The image to use as the popup copy icon, type STRING - POPUP_PASTE_BUTTON_ICON_IMAGE, ///< name "popupPasteButtonImage", The image to use as the popup paste icon, type STRING - POPUP_SELECT_BUTTON_ICON_IMAGE, ///< name "popupSelectButtonImage", The image to use as the popup select icon, type STRING - POPUP_SELECT_ALL_BUTTON_ICON_IMAGE, ///< name "popupSelectAllButtonImage", The image to use as the popup select all icon, type STRING - POPUP_DIVIDER_COLOR, ///< name "popupDividerColor", The color of the divider between options, type VECTOR4 - POPUP_ICON_COLOR, ///< name "popupIconColor", The color of the icons (if supplied), type VECTOR4 - POPUP_PRESSED_COLOR, ///< name "popupPressedColor", The color of the option when pressed, type VECTOR4 - POPUP_PRESSED_IMAGE, ///< name "popupPressedImage", The image to use for the option when pressed, type STRING - POPUP_FADE_IN_DURATION, ///< name "popupFadeInDuration", The duration of the fade-in animation, type FLOAT - POPUP_FADE_OUT_DURATION, ///< name "popupFadeOutDuration", The duration of the fade-out animation, type FLOAT + /** + * @brief The maximum size the Popup can be. + * @details Name "popupMaxSize", type Vector2. + */ + POPUP_MAX_SIZE = PROPERTY_START_INDEX, + + /** + * @brief The minimum size the Popup can be. + * @details Name "popupMinSize", type Vector2. + */ + POPUP_MIN_SIZE, + + /** + * @brief The maximum size an option can be. + * @details Name "optionMaxSize", type Vector2. + */ + OPTION_MAX_SIZE, + + /** + * @brief The minimum size an option can be. + * @details Name "optionMinSize", type Vector2. + */ + OPTION_MIN_SIZE, + + /** + * @brief The size of the divider between options. + * @details Name "optionDividerSize", type Vector2. + */ + OPTION_DIVIDER_SIZE, + + /** + * @brief The image to use as the popup clipboard icon. + * @details Name "popupClipboardButtonImage", type string. + */ + POPUP_CLIPBOARD_BUTTON_ICON_IMAGE, + + /** + * @brief The image to use as the popup cut icon. + * @details Name "popupCutButtonImage", type string. + */ + POPUP_CUT_BUTTON_ICON_IMAGE, + + /** + * @brief The image to use as the popup copy icon. + * @details Name "popupCopyButtonImage", type string. + */ + POPUP_COPY_BUTTON_ICON_IMAGE, + + /** + * @brief The image to use as the popup paste icon. + * @details Name "popupPasteButtonImage", type string. + */ + POPUP_PASTE_BUTTON_ICON_IMAGE, + + /** + * @brief The image to use as the popup select icon. + * @details Name "popupSelectButtonImage", type string. + */ + POPUP_SELECT_BUTTON_ICON_IMAGE, + + /** + * @brief The image to use as the popup select all icon. + * @details Name "popupSelectAllButtonImage", type string. + */ + POPUP_SELECT_ALL_BUTTON_ICON_IMAGE, + + /** + * @brief The color of the divider between options. + * @details Name "popupDividerColor", type Vector4. + */ + POPUP_DIVIDER_COLOR, + + /** + * @brief The color of the icons (if supplied). + * @details Name "popupIconColor", type Vector4. + */ + POPUP_ICON_COLOR, + + /** + * @brief The color of the option when pressed. + * @details Name "popupPressedColor", type Vector4. + */ + POPUP_PRESSED_COLOR, + + /** + * @brief The image to use for the option when pressed. + * @details Name "popupPressedImage", type string. + */ + POPUP_PRESSED_IMAGE, + + /** + * @brief The duration of the fade-in animation. + * @details Name "popupFadeInDuration", type float. + */ + POPUP_FADE_IN_DURATION, + + /** + * @brief The duration of the fade-out animation. + * @details Name "popupFadeOutDuration", type float. + */ + POPUP_FADE_OUT_DURATION, + + /** + * @brief The popup background can have a separate border with a different color. + * @details Name "backgroundBorder", type Property::Map. + * @note Optional. + */ + BACKGROUND_BORDER }; }; diff --git a/dali-toolkit/internal/builder/builder-set-property.cpp b/dali-toolkit/internal/builder/builder-set-property.cpp index d64a04c..93a1fbe 100644 --- a/dali-toolkit/internal/builder/builder-set-property.cpp +++ b/dali-toolkit/internal/builder/builder-set-property.cpp @@ -19,13 +19,13 @@ #include #include #include -#include // INTERNAL INCLUDES #include #include #include #include +#include namespace Dali { @@ -36,29 +36,6 @@ namespace Toolkit 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 @@ -194,17 +171,9 @@ bool DeterminePropertyFromNode( const TreeNode& node, Property::Type type, Prope } 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() ) { diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp index 4e07ba8..6876ff2 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp @@ -35,6 +35,7 @@ #include #include #include +#include namespace Dali { @@ -47,7 +48,7 @@ namespace Internal namespace { -// todo Move this to adaptor?? + #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string) const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "TextSelectionPopupButton" ); @@ -113,6 +114,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedColor", VE DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE ) DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION ) DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "backgroundBorder", MAP, BACKGROUND_BORDER ) DALI_TYPE_REGISTRATION_END() @@ -232,6 +234,12 @@ void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, impl.mFadeOutDuration = value.Get < float >(); break; } + case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER: + { + Property::Map map = value.Get(); + impl.CreateBackgroundBorder( map ); + break; + } } // switch } // TextSelectionPopup } @@ -337,6 +345,11 @@ Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::I value = impl.mFadeOutDuration; break; } + case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER: + { + value = impl.mBackgroundBorderProperties; + break; + } } // switch } return value; @@ -825,6 +838,34 @@ std::string TextSelectionPopup::GetPressedImage() const } } +void TextSelectionPopup::CreateBackgroundBorder( Property::Map& propertyMap ) +{ + // Removes previous image if necessary + UnparentAndReset( mBackgroundBorder ); + + mBackgroundBorderProperties = propertyMap; + + if( ! propertyMap.Empty() ) + { + mBackgroundBorder = Dali::Toolkit::ImageView::New(); + mBackgroundBorder.SetProperty( Dali::Toolkit::ImageView::Property::IMAGE, propertyMap ); + mBackgroundBorder.SetParentOrigin( ParentOrigin::CENTER ); + mBackgroundBorder.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + + Property::Value* colorValue = propertyMap.Find( "borderColor" ); + if( colorValue ) + { + Vector4 color; + if( ConvertPropertyToColor( *colorValue, color ) ) + { + mBackgroundBorder.SetColor( color ); + } + } + + Self().Add( mBackgroundBorder ); + } +} + TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface ) : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), mToolbar(), diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h index e2a9497..734d105 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h @@ -2,7 +2,7 @@ #define __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * 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. @@ -21,12 +21,14 @@ // INTERNAL INCLUDES #include #include +#include #include #include #include // EXTERNAL INCLUDES #include +#include namespace Dali { @@ -247,6 +249,13 @@ private: // Implementation void AddPopupOptionsToToolbar( bool showIcons, bool showCaptions ); /** + * Creates the background-border image + * + * @param[in] propertyMap The properties describing the background-border + */ + void CreateBackgroundBorder( Property::Map& propertyMap ); + + /** * Construct a new TextField. */ TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface ); @@ -277,6 +286,9 @@ private: // Data Image mSelectIconImage; Image mSelectAllIconImage; + Dali::Toolkit::ImageView mBackgroundBorder; ///< The popup background can have a separate border with a different color + Property::Map mBackgroundBorderProperties; ///< The properties used to create mBackgroundBorder + Size mPopupMaxSize; // Maximum size of the Popup Size mOptionMaxSize; // Maximum size of an Option button Size mOptionMinSize; // Minimum size of an Option button diff --git a/dali-toolkit/internal/file.list b/dali-toolkit/internal/file.list index 847d9b1..3488b4c 100644 --- a/dali-toolkit/internal/file.list +++ b/dali-toolkit/internal/file.list @@ -79,6 +79,7 @@ toolkit_src_files = \ \ $(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 \ diff --git a/dali-toolkit/internal/helpers/color-conversion.cpp b/dali-toolkit/internal/helpers/color-conversion.cpp new file mode 100644 index 0000000..6789cee --- /dev/null +++ b/dali-toolkit/internal/helpers/color-conversion.cpp @@ -0,0 +1,101 @@ +/* + * 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 + +// EXTERNAL INCLUDES +#include +#include +#include + +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 diff --git a/dali-toolkit/internal/helpers/color-conversion.h b/dali-toolkit/internal/helpers/color-conversion.h new file mode 100644 index 0000000..dcd51bd --- /dev/null +++ b/dali-toolkit/internal/helpers/color-conversion.h @@ -0,0 +1,61 @@ +#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 +#include + +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 diff --git a/dali-toolkit/internal/text/multi-language-support-impl.cpp b/dali-toolkit/internal/text/multi-language-support-impl.cpp index c803c1d..ab4b388 100644 --- a/dali-toolkit/internal/text/multi-language-support-impl.cpp +++ b/dali-toolkit/internal/text/multi-language-support-impl.cpp @@ -594,10 +594,8 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, if( isValidFont && isEmojiScript ) { - const PixelData bitmap = fontClient.CreateBitmap( fontId, glyphIndex ); - - // For color emojis, the font is valid if the bitmap is RGBA. - isValidFont = bitmap && ( Pixel::BGRA8888 == bitmap.GetPixelFormat() ); + // For color emojis, the font is valid if the glyph is a color glyph (the bitmap is RGBA). + isValidFont = fontClient.IsColorGlyph( fontId, glyphIndex ); } // If there is a valid font, cache it. diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp index 12d39a5..7e672bd 100644 --- a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp @@ -27,50 +27,6 @@ namespace Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_RENDERING"); #endif -#define MAKE_SHADER(A)#A - -const char* VERTEX_SHADER = MAKE_SHADER( -attribute mediump vec2 aPosition; -attribute mediump vec2 aTexCoord; -attribute mediump vec4 aColor; -uniform mediump vec2 uOffset; -uniform mediump mat4 uMvpMatrix; -varying mediump vec2 vTexCoord; -varying mediump vec4 vColor; - -void main() -{ - mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 ); - gl_Position = uMvpMatrix * position; - vTexCoord = aTexCoord; - vColor = aColor; -} -); - -const char* FRAGMENT_SHADER_L8 = MAKE_SHADER( -uniform lowp vec4 uColor; -uniform sampler2D sTexture; -varying mediump vec2 vTexCoord; -varying mediump vec4 vColor; - -void main() -{ - mediump vec4 color = texture2D( sTexture, vTexCoord ); - gl_FragColor = vec4( vColor.rgb * uColor.rgb, vColor.a * uColor.a * color.r ); -} -); - -const char* FRAGMENT_SHADER_RGBA = MAKE_SHADER( -uniform lowp vec4 uColor; -uniform sampler2D sTexture; -varying mediump vec2 vTexCoord; - -void main() -{ - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor; -} -); - } // unnamed namespace namespace Dali @@ -84,8 +40,6 @@ namespace Internal AtlasGlyphManager::AtlasGlyphManager() { - mShaderL8 = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_L8 ); - mShaderRgba = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_RGBA ); mAtlasManager = Dali::Toolkit::AtlasManager::New(); } @@ -257,12 +211,6 @@ TextureSet AtlasGlyphManager::GetTextures( uint32_t atlasId ) const return mAtlasManager.GetTextures( atlasId ); } -Shader AtlasGlyphManager::GetShader( uint32_t atlasId ) const -{ - Pixel::Format pixelFormat = mAtlasManager.GetPixelFormat( atlasId ); - return pixelFormat == Pixel::L8 ? mShaderL8 : mShaderRgba; -} - AtlasGlyphManager::~AtlasGlyphManager() { // mAtlasManager handle is automatically released here diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.h b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.h index b72b649..a2232f9 100644 --- a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.h +++ b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.h @@ -113,11 +113,6 @@ public: TextureSet GetTextures( uint32_t atlasId ) const; /** - * @copydoc Toolkit::AtlasGlyphManager::GetShader - */ - Shader GetShader( uint32_t atlasId ) const; - - /** * @copydoc Toolkit::AtlasGlyphManager::GetMetrics */ const Toolkit::AtlasGlyphManager::Metrics& GetMetrics(); @@ -134,9 +129,6 @@ private: Dali::Toolkit::AtlasManager mAtlasManager; ///> Atlas Manager created by GlyphManager std::vector< FontGlyphRecord > mFontGlyphRecords; Toolkit::AtlasGlyphManager::Metrics mMetrics; ///> Metrics to pass back on GlyphManager status - - Shader mShaderL8; - Shader mShaderRgba; }; } // namespace Internal diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.cpp b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.cpp index 6858f26..743bc6c 100644 --- a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.cpp @@ -111,11 +111,6 @@ TextureSet AtlasGlyphManager::GetTextures( uint32_t atlasId ) const return GetImplementation(*this).GetTextures( atlasId ); } -Shader AtlasGlyphManager::GetShader( uint32_t atlasId ) const -{ - return GetImplementation(*this).GetShader( atlasId ); -} - const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics() { return GetImplementation(*this).GetMetrics(); diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h index 3ba54de..1bc058b 100644 --- a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h +++ b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h @@ -149,15 +149,6 @@ public: TextureSet GetTextures( uint32_t atlasId ) const; /** - * @brief Get the shader used by an atlas - * - * @param[in] atlasId Id of an atlas - * - * @return The shader used by the atlas - */ - Shader GetShader( uint32_t atlasId ) const; - - /** * @brief Get Glyph Manager metrics * * @return const reference to glyph manager metrics diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-manager-impl.cpp b/dali-toolkit/internal/text/rendering/atlas/atlas-manager-impl.cpp index bc3a70a..958749e 100644 --- a/dali-toolkit/internal/text/rendering/atlas/atlas-manager-impl.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/atlas-manager-impl.cpp @@ -79,6 +79,14 @@ Toolkit::AtlasManager::AtlasId AtlasManager::CreateAtlas( const Toolkit::AtlasMa } Dali::Texture atlas = Dali::Texture::New( TextureType::TEXTURE_2D, pixelformat, width, height ); + + // Clear the background + unsigned int bufferSize( width * height * Dali::Pixel::GetBytesPerPixel( pixelformat ) ); + unsigned char* background = new unsigned char[bufferSize]; + memset( background, 0, bufferSize ); + PixelData backgroundPixels = PixelData::New( background, bufferSize, width, height, pixelformat, PixelData::DELETE_ARRAY ); + atlas.Upload( backgroundPixels, 0u, 0u, 0u, 0u, width, height ); + AtlasDescriptor atlasDescriptor; atlasDescriptor.mAtlas = atlas; atlasDescriptor.mSize = size; @@ -86,7 +94,7 @@ Toolkit::AtlasManager::AtlasId AtlasManager::CreateAtlas( const Toolkit::AtlasMa atlasDescriptor.mTotalBlocks = ( ( width - 1u ) / blockWidth ) * ( ( height - 1u ) / blockHeight ); atlasDescriptor.mAvailableBlocks = atlasDescriptor.mTotalBlocks; - unsigned int bufferSize( blockWidth * SINGLE_PIXEL_PADDING * Dali::Pixel::GetBytesPerPixel(pixelformat) ); + bufferSize = blockWidth * SINGLE_PIXEL_PADDING * Dali::Pixel::GetBytesPerPixel(pixelformat); unsigned char* bufferHorizontalStrip = new unsigned char[bufferSize]; memset( bufferHorizontalStrip, 0, bufferSize ); atlasDescriptor.mHorizontalStrip = PixelData::New( bufferHorizontalStrip, bufferSize, blockWidth, SINGLE_PIXEL_PADDING, pixelformat, PixelData::DELETE_ARRAY ); diff --git a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp index de437fb..0136a05 100644 --- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp @@ -41,6 +41,50 @@ namespace Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_RENDERING"); #endif +#define MAKE_SHADER(A)#A + +const char* VERTEX_SHADER = MAKE_SHADER( +attribute mediump vec2 aPosition; +attribute mediump vec2 aTexCoord; +attribute mediump vec4 aColor; +uniform mediump vec2 uOffset; +uniform mediump mat4 uMvpMatrix; +varying mediump vec2 vTexCoord; +varying mediump vec4 vColor; + +void main() +{ + mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 ); + gl_Position = uMvpMatrix * position; + vTexCoord = aTexCoord; + vColor = aColor; +} +); + +const char* FRAGMENT_SHADER_L8 = MAKE_SHADER( +uniform lowp vec4 uColor; +uniform sampler2D sTexture; +varying mediump vec2 vTexCoord; +varying mediump vec4 vColor; + +void main() +{ + mediump vec4 color = texture2D( sTexture, vTexCoord ); + gl_FragColor = vec4( vColor.rgb * uColor.rgb, vColor.a * uColor.a * color.r ); +} +); + +const char* FRAGMENT_SHADER_RGBA = MAKE_SHADER( +uniform lowp vec4 uColor; +uniform sampler2D sTexture; +varying mediump vec2 vTexCoord; + +void main() +{ + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor; +} +); + const float ZERO( 0.0f ); const float HALF( 0.5f ); const float ONE( 1.0f ); @@ -289,7 +333,28 @@ struct AtlasRenderer::Impl } // Create a new image for the glyph - PixelData bitmap = mFontClient.CreateBitmap( glyph.fontId, glyph.index ); + PixelData bitmap; + + // Whether the current glyph is a color one. + const bool isColorGlyph = mFontClient.IsColorGlyph( glyph.fontId, glyph.index ); + + // Retrieve the emoji's bitmap. + TextAbstraction::FontClient::GlyphBufferData glyphBufferData; + glyphBufferData.width = isColorGlyph ? glyph.width : 0; // Desired width and height. + glyphBufferData.height = isColorGlyph ? glyph.height : 0; + + mFontClient.CreateBitmap( glyph.fontId, + glyph.index, + glyphBufferData ); + + // Create the pixel data. + bitmap = PixelData::New( glyphBufferData.buffer, + glyph.width * glyph.height * GetBytesPerPixel( glyphBufferData.format ), + glyph.width, + glyph.height, + glyphBufferData.format, + PixelData::DELETE_ARRAY ); + if( bitmap ) { MaxBlockSize& blockSize = mBlockSizes[currentBlockSize]; @@ -338,21 +403,6 @@ struct AtlasRenderer::Impl AtlasManager::Vertex2D* verticesBuffer = newMesh.mVertices.Begin(); - // Adjust the vertices if the fixed-size font should be down-scaled - if( glyph.scaleFactor > 0 ) - { - for( unsigned int index = 0u, size = newMesh.mVertices.Count(); - index < size; - ++index ) - { - AtlasManager::Vertex2D& vertex = *( verticesBuffer + index ); - - // Set the position of the vertex. - vertex.mPosition.x = position.x + ( ( vertex.mPosition.x - position.x ) * glyph.scaleFactor ); - vertex.mPosition.y = position.y + ( ( vertex.mPosition.y - position.y ) * glyph.scaleFactor ); - } - } - // Get the color of the character. const ColorIndex colorIndex = useDefaultColor ? 0u : *( colorIndicesBuffer + i ); const Vector4& color = ( useDefaultColor || ( 0u == colorIndex ) ) ? defaultColor : *( colorsBuffer + colorIndex - 1u ); @@ -408,7 +458,7 @@ struct AtlasRenderer::Impl { MeshRecord& meshRecord = *it; - Actor actor = CreateMeshActor( meshRecord, textSize ); + Actor actor = CreateMeshActor( meshRecord, textSize, STYLE_NORMAL ); // Whether the actor has renderers. const bool hasRenderer = actor.GetRendererCount() > 0u; @@ -428,7 +478,7 @@ struct AtlasRenderer::Impl vertex.mColor = shadowColor; } - Actor shadowActor = CreateMeshActor( meshRecord, textSize ); + Actor shadowActor = CreateMeshActor( meshRecord, textSize, STYLE_DROP_SHADOW ); #if defined(DEBUG_ENABLED) shadowActor.SetName( "Text Shadow renderable actor" ); #endif @@ -479,7 +529,7 @@ struct AtlasRenderer::Impl mTextCache.Resize( 0 ); } - Actor CreateMeshActor( const MeshRecord& meshRecord, const Vector2& actorSize ) + Actor CreateMeshActor( const MeshRecord& meshRecord, const Vector2& actorSize, Style style ) { PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat ); quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ), meshRecord.mMesh.mVertices.Size() ); @@ -489,7 +539,29 @@ struct AtlasRenderer::Impl quadGeometry.SetIndexBuffer( &meshRecord.mMesh.mIndices[0], meshRecord.mMesh.mIndices.Size() ); TextureSet textureSet( mGlyphManager.GetTextures( meshRecord.mAtlasId ) ); - Shader shader( mGlyphManager.GetShader( meshRecord.mAtlasId ) ); + + // Choose the shader to use. + const bool isColorShader = ( STYLE_DROP_SHADOW != style ) && ( Pixel::BGRA8888 == mGlyphManager.GetPixelFormat( meshRecord.mAtlasId ) ); + Shader shader; + if( isColorShader ) + { + // The glyph is an emoji and is not a shadow. + if( !mShaderRgba ) + { + mShaderRgba = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_RGBA ); + } + shader = mShaderRgba; + } + else + { + // The glyph is text or a shadow. + if( !mShaderL8 ) + { + mShaderL8 = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_L8 ); + } + shader = mShaderL8; + } + Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, shader ); renderer.SetTextures( textureSet ); renderer.SetProperty( Dali::Renderer::Property::BLEND_MODE, BlendMode::ON ); @@ -722,11 +794,13 @@ struct AtlasRenderer::Impl Actor mActor; ///< The actor parent which renders the text AtlasGlyphManager mGlyphManager; ///< Glyph Manager to handle upload and caching - TextAbstraction::FontClient mFontClient; ///> The font client used to supply glyph information - std::vector< MaxBlockSize > mBlockSizes; ///> Maximum size needed to contain a glyph in a block within a new atlas - Vector< TextCacheEntry > mTextCache; ///> Caches data from previous render - Property::Map mQuadVertexFormat; ///> Describes the vertex format for text - int mDepth; ///> DepthIndex passed by control when connect to stage + TextAbstraction::FontClient mFontClient; ///< The font client used to supply glyph information + Shader mShaderL8; ///< The shader for glyphs and emoji's shadows. + Shader mShaderRgba; ///< The shader for emojis. + std::vector< MaxBlockSize > mBlockSizes; ///< Maximum size needed to contain a glyph in a block within a new atlas + Vector< TextCacheEntry > mTextCache; ///< Caches data from previous render + Property::Map mQuadVertexFormat; ///< Describes the vertex format for text + int mDepth; ///< DepthIndex passed by control when connect to stage }; Text::RendererPtr AtlasRenderer::New() diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index 4bc0d02..f3d4feb 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -296,13 +296,6 @@ void ImageVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) } } - NativeImage nativeImage = NativeImage::DownCast( mImage ); - - if( nativeImage ) - { - SetNativeFragmentShaderCode( nativeImage ); - } - // if actor is on stage, create new renderer and apply to actor if( actor && actor.OnStage() ) { @@ -562,6 +555,13 @@ void ImageVisual::InitializeRenderer( const Image& image ) { mImpl->mFlags &= ~Impl::IS_FROM_CACHE; + NativeImage nativeImage = NativeImage::DownCast( image ); + + if( nativeImage ) + { + SetNativeFragmentShaderCode( nativeImage ); + } + mImpl->mRenderer = CreateRenderer(); if( image ) diff --git a/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json b/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json index 616b913..1274cf0 100644 --- a/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json @@ -99,7 +99,12 @@ "popupPressedColor":[0.24,0.72,0.8,0.11], "background": { "rendererType": "image", - "url": "{DALI_IMAGE_DIR}selection-popup-bg.9.png" + "url": "{DALI_IMAGE_DIR}selection-popup-background.9.png" + }, + "backgroundBorder": { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}selection-popup-border.9.png", + "borderColor":[0.24,0.72,0.8,1.0] }, "popupFadeInDuration":0.25, "popupFadeOutDuration":0.25 @@ -122,6 +127,20 @@ "overshootSize":[1920.0,130.0] } }, + "TextSelectionScrollBar": + { + "indicatorShowDuration":0.25, + "indicatorHideDuration":0.25 + }, + "TextSelectionScrollIndicator": + { + "image": + { + "visualType":"IMAGE", + "url":"{DALI_IMAGE_DIR}text_selection_scroll_indicator.9.png" + }, + "color":[0.0,0.72,0.9,0.7] + }, "ScrollView": { "overshootEffectColor":"B018", diff --git a/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json b/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json index bff0d6e..2548843 100644 --- a/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json @@ -86,7 +86,12 @@ "popupPressedColor":[0.24,0.72,0.8,0.11], "background": { "visualType": "IMAGE", - "url": "{DALI_IMAGE_DIR}selection-popup-bg.9.png" + "url": "{DALI_IMAGE_DIR}selection-popup-background.9.png" + }, + "backgroundBorder": { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}selection-popup-border.9.png", + "borderColor":[0.24,0.72,0.8,1.0] }, "popupFadeInDuration":0.25, "popupFadeOutDuration":0.25 @@ -119,9 +124,10 @@ "image": { "visualType":"IMAGE", - "url":"{DALI_IMAGE_DIR}text_selection_scroll_indicator.9.png" + "url":"{DALI_IMAGE_DIR}text_selection_scroll_indicator.9.png" // designed for HD resolution }, - "color":[0.0,0.72,0.9,0.7] + "color":[0.0,0.72,0.9,0.7], + "scale":[0.625,1.0,1.0] // Note: This reduces height for WVGA resolution }, "ScrollView": { diff --git a/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json b/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json index 5484f17..0958f29 100644 --- a/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json @@ -106,7 +106,12 @@ "popupPressedColor":[0.24,0.72,0.8,0.11], "background": { "visualType": "IMAGE", - "url": "{DALI_IMAGE_DIR}selection-popup-bg.9.png" + "url": "{DALI_IMAGE_DIR}selection-popup-background.9.png" + }, + "backgroundBorder": { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}selection-popup-border.9.png", + "borderColor":[0.24,0.72,0.8,1.0] }, "popupFadeInDuration":0.25, "popupFadeOutDuration":0.25 @@ -129,6 +134,20 @@ "overshootSize":[720.0,130.0] } }, + "TextSelectionScrollBar": + { + "indicatorShowDuration":0.25, + "indicatorHideDuration":0.25 + }, + "TextSelectionScrollIndicator": + { + "image": + { + "visualType":"IMAGE", + "url":"{DALI_IMAGE_DIR}text_selection_scroll_indicator.9.png" + }, + "color":[0.0,0.72,0.9,0.7] + }, "ScrollView": { "overshootEffectColor":"B018", diff --git a/dali-toolkit/styles/images-common/selection-popup-background.9.png b/dali-toolkit/styles/images-common/selection-popup-background.9.png new file mode 100644 index 0000000..0b59668 Binary files /dev/null and b/dali-toolkit/styles/images-common/selection-popup-background.9.png differ diff --git a/dali-toolkit/styles/images-common/selection-popup-border.9.png b/dali-toolkit/styles/images-common/selection-popup-border.9.png new file mode 100644 index 0000000..d7454f5 Binary files /dev/null and b/dali-toolkit/styles/images-common/selection-popup-border.9.png differ