From: Richard Huang Date: Tue, 10 Oct 2017 14:24:02 +0000 (+0100) Subject: Soft shadow support in text visual X-Git-Tag: dali_1.2.63~5^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=2f09a7825b87ecd29e58f0b2a8d2da5edc4313c3 Soft shadow support in text visual Change-Id: Id6d420e1be92a95edf0b0c6d9b8d91acec78dfde --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 6eefd84..dc30007 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -727,8 +727,9 @@ int UtcDaliTextEditorSetPropertyP(void) Property::Map shadowMapSet; Property::Map shadowMapGet; - shadowMapSet.Insert( "color", "green" ); - shadowMapSet.Insert( "offset", "2 2" ); + shadowMapSet.Insert( "color", Color::GREEN ); + shadowMapSet.Insert( "offset", Vector2(2.0f, 2.0f) ); + shadowMapSet.Insert( "blurRadius", 3.0f ); editor.SetProperty( TextEditor::Property::SHADOW, shadowMapSet ); @@ -2149,11 +2150,11 @@ int utcDaliTextEditorShadowPropertyStringP(void) TextEditor editor = TextEditor::New(); - std::string shadowSettings( "{\"color\":\"green\",\"offset\":\"2 2\"}" ); + std::string shadowSettings( "{\"color\":\"green\",\"offset\":\"2 2\",\"blurRadius\":\"0\"}" ); Stage::GetCurrent().Add( editor ); - editor.SetProperty( TextEditor::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\"}" ); + editor.SetProperty( TextEditor::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\",\"blurRadius\":\"0\"}" ); Property::Value value = editor.GetProperty( TextEditor::Property::SHADOW ); std::string result; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 3e5e7b1..c3da54d 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -805,8 +805,9 @@ int UtcDaliTextFieldSetPropertyP(void) Property::Map shadowMapSet; Property::Map shadowMapGet; - shadowMapSet.Insert( "color", "green" ); - shadowMapSet.Insert( "offset", "2 2" ); + shadowMapSet.Insert( "color", Color::GREEN ); + shadowMapSet.Insert( "offset", Vector2(2.0f, 2.0f) ); + shadowMapSet.Insert( "blurRadius", 3.0f ); field.SetProperty( TextField::Property::SHADOW, shadowMapSet ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 5471c95..7b7bc0d 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -420,8 +420,9 @@ int UtcDaliToolkitTextLabelSetPropertyP(void) Property::Map shadowMapSet; Property::Map shadowMapGet; - shadowMapSet.Insert( "color", "green" ); - shadowMapSet.Insert( "offset", "2 2" ); + shadowMapSet.Insert( "color", Color::GREEN ); + shadowMapSet.Insert( "offset", Vector2(2.0f, 2.0f) ); + shadowMapSet.Insert( "blurRadius", 5.0f ); label.SetProperty( TextLabel::Property::SHADOW, shadowMapSet ); @@ -431,8 +432,9 @@ int UtcDaliToolkitTextLabelSetPropertyP(void) shadowMapSet.Clear(); Property::Map shadowDisabledMapGet; - shadowDisabledMapGet.Insert( "color", "green" ); - shadowDisabledMapGet.Insert( "offset", "0 0" ); + shadowDisabledMapGet.Insert( "color", Color::GREEN ); + shadowDisabledMapGet.Insert( "offset", Vector2(0.0f, 0.0f) ); + shadowDisabledMapGet.Insert( "blurRadius", 5.0f ); label.SetProperty( TextLabel::Property::SHADOW, shadowMapSet ); @@ -1066,6 +1068,7 @@ int UtcDaliToolkitTextlabelTextStyle01(void) Property::Map shadowMapSet; shadowMapSet.Insert( "color", "green" ); shadowMapSet.Insert( "offset", "2 2" ); + shadowMapSet.Insert( "blurRadius", "3" ); label.SetProperty( TextLabel::Property::SHADOW, shadowMapSet ); outlineMapSet["color"] = Color::RED; diff --git a/dali-toolkit/internal/text/rendering/text-typesetter.cpp b/dali-toolkit/internal/text/rendering/text-typesetter.cpp index 9559460..c6e0638 100755 --- a/dali-toolkit/internal/text/rendering/text-typesetter.cpp +++ b/dali-toolkit/internal/text/rendering/text-typesetter.cpp @@ -353,6 +353,14 @@ PixelData Typesetter::Render( const Vector2& size, RenderBehaviour behaviour, bo // Create the image buffer for shadow Devel::PixelBuffer shadowImageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_SHADOW, ignoreHorizontalAlignment, pixelFormat, penY, 0u, numberOfGlyphs - 1 ); + // Check whether it will be a soft shadow + const float& blurRadius = mModel->GetShadowBlurRadius(); + + if ( blurRadius > Math::MACHINE_EPSILON_1 ) + { + shadowImageBuffer.ApplyGaussianBlur( blurRadius ); + } + // Combine the two buffers imageBuffer = CombineImageBuffer( imageBuffer, shadowImageBuffer, bufferWidth, bufferHeight ); } diff --git a/dali-toolkit/internal/text/rendering/view-model.cpp b/dali-toolkit/internal/text/rendering/view-model.cpp index 7c2d156..1721a1c 100755 --- a/dali-toolkit/internal/text/rendering/view-model.cpp +++ b/dali-toolkit/internal/text/rendering/view-model.cpp @@ -163,6 +163,11 @@ const Vector4& ViewModel::GetShadowColor() const return mModel->GetShadowColor(); } +const float& ViewModel::GetShadowBlurRadius() const +{ + return mModel->GetShadowBlurRadius(); +} + const Vector4& ViewModel::GetUnderlineColor() const { return mModel->GetUnderlineColor(); diff --git a/dali-toolkit/internal/text/rendering/view-model.h b/dali-toolkit/internal/text/rendering/view-model.h index c4e1ec0..0c0bb01 100755 --- a/dali-toolkit/internal/text/rendering/view-model.h +++ b/dali-toolkit/internal/text/rendering/view-model.h @@ -148,6 +148,11 @@ public: virtual const Vector4& GetShadowColor() const; /** + * @copydoc ModelInterface::GetShadowBlurRadius() + */ + virtual const float& GetShadowBlurRadius() const; + + /** * @copydoc ModelInterface::GetUnderlineColor() */ virtual const Vector4& GetUnderlineColor() const; diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index ae749e6..0ada75e 100755 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1113,6 +1113,21 @@ const Vector4& Controller::GetShadowColor() const return mImpl->mModel->mVisualModel->GetShadowColor(); } +void Controller::SetShadowBlurRadius( const float& shadowBlurRadius ) +{ + if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 ) + { + mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius ); + + mImpl->RequestRelayout(); + } +} + +const float& Controller::GetShadowBlurRadius() const +{ + return mImpl->mModel->mVisualModel->GetShadowBlurRadius(); +} + void Controller::SetUnderlineColor( const Vector4& color ) { mImpl->mModel->mVisualModel->SetUnderlineColor( color ); diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index e2baa22..86a0e33 100755 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -758,6 +758,20 @@ public: // Default style & Input style const Vector4& GetShadowColor() const; /** + * @brief Set the shadow blur radius. + * + * @param[in] shadowBlurRadius The shadow blur radius, 0,0 indicates no blur. + */ + void SetShadowBlurRadius( const float& shadowBlurRadius ); + + /** + * @brief Retrieve the shadow blur radius. + * + * @return The shadow blur radius. + */ + const float& GetShadowBlurRadius() const; + + /** * @brief Set the underline color. * * @param[in] color color of underline. diff --git a/dali-toolkit/internal/text/text-effects-style.cpp b/dali-toolkit/internal/text/text-effects-style.cpp index ea1b3cf..7c08ebe 100755 --- a/dali-toolkit/internal/text/text-effects-style.cpp +++ b/dali-toolkit/internal/text/text-effects-style.cpp @@ -35,6 +35,7 @@ namespace { const std::string COLOR_KEY( "color" ); const std::string OFFSET_KEY( "offset" ); +const std::string BLUR_RADIUS_KEY( "blurRadius" ); const std::string WIDTH_KEY( "width" ); const std::string HEIGHT_KEY( "height" ); const std::string ENABLE_KEY( "enable" ); @@ -46,7 +47,9 @@ bool ParseShadowProperties( const Property::Map& shadowPropertiesMap, bool& colorDefined, Vector4& color, bool& offsetDefined, - Vector2& offset ) + Vector2& offset, + bool& blurRadiusDefined, + float& blurRadius ) { const unsigned int numberOfItems = shadowPropertiesMap.Count(); @@ -60,18 +63,45 @@ bool ParseShadowProperties( const Property::Map& shadowPropertiesMap, /// Color key. colorDefined = true; - const std::string colorStr = valueGet.second.Get(); - - Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); + if( valueGet.second.GetType() == Dali::Property::STRING ) + { + const std::string colorStr = valueGet.second.Get(); + Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); + } + else + { + color = valueGet.second.Get(); + } } else if( OFFSET_KEY == valueGet.first.stringKey ) { /// Offset key. offsetDefined = true; - const std::string offsetStr = valueGet.second.Get(); + if( valueGet.second.GetType() == Dali::Property::STRING ) + { + const std::string offsetStr = valueGet.second.Get(); + StringToVector2( offsetStr.c_str(), offsetStr.size(), offset ); + } + else + { + offset = valueGet.second.Get(); + } + } + else if( BLUR_RADIUS_KEY == valueGet.first.stringKey ) + { + /// Blur radius key. + blurRadiusDefined = true; - StringToVector2( offsetStr.c_str(), offsetStr.size(), offset ); + if( valueGet.second.GetType() == Dali::Property::STRING ) + { + const std::string blurRadiusStr = valueGet.second.Get(); + blurRadius = StringToFloat( blurRadiusStr.c_str() ); + } + else + { + blurRadius = valueGet.second.Get(); + } } } @@ -321,6 +351,8 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value Vector4 color; bool offsetDefined = false; Vector2 offset; + bool blurRadiusDefined = false; + float blurRadius; bool empty = true; @@ -336,7 +368,9 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value colorDefined, color, offsetDefined, - offset ); + offset, + blurRadiusDefined, + blurRadius ); controller->ShadowSetByString( !empty ); @@ -347,7 +381,9 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value colorDefined, color, offsetDefined, - offset ); + offset, + blurRadiusDefined, + blurRadius ); controller->ShadowSetByString( false ); } @@ -366,6 +402,12 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value controller->SetShadowOffset( offset ); update = true; } + + if( blurRadiusDefined && ( controller->GetShadowBlurRadius() != blurRadius ) ) + { + controller->SetShadowBlurRadius( blurRadius ); + update = true; + } } else { @@ -400,6 +442,7 @@ void GetShadowProperties( ControllerPtr controller, Property::Value& value, Effe { const Vector4& color = controller->GetShadowColor(); const Vector2& offset = controller->GetShadowOffset(); + const float& blurRadius = controller->GetShadowBlurRadius(); if ( controller->IsShadowSetByString() ) { @@ -411,7 +454,11 @@ void GetShadowProperties( ControllerPtr controller, Property::Value& value, Effe std::string offsetStr; Vector2ToString( offset, offsetStr ); - shadowProperties += "\"offset\":\"" + offsetStr + "\"}"; + shadowProperties += "\"offset\":\"" + offsetStr + "\","; + + std::string blurRadiusStr; + FloatToString( blurRadius, blurRadiusStr ); + shadowProperties += "\"blurRadius\":\"" + blurRadiusStr + "\"}"; value = shadowProperties; } @@ -419,13 +466,9 @@ void GetShadowProperties( ControllerPtr controller, Property::Value& value, Effe { Property::Map map; - std::string colorStr; - Vector4ToColorString( color, colorStr ); - map.Insert( COLOR_KEY, colorStr ); - - std::string offsetStr; - Vector2ToString( offset, offsetStr ); - map.Insert( OFFSET_KEY, offsetStr ); + map.Insert( COLOR_KEY, color ); + map.Insert( OFFSET_KEY, offset ); + map.Insert( BLUR_RADIUS_KEY, blurRadius ); value = map; } diff --git a/dali-toolkit/internal/text/text-model-interface.h b/dali-toolkit/internal/text/text-model-interface.h index eca061a..ca575ce 100755 --- a/dali-toolkit/internal/text/text-model-interface.h +++ b/dali-toolkit/internal/text/text-model-interface.h @@ -175,6 +175,13 @@ public: virtual const Vector4& GetShadowColor() const = 0; /** + * @brief Retrieve the shadow blur radius. + * + * @return The shadow blur radius. + */ + virtual const float& GetShadowBlurRadius() const = 0; + + /** * @brief Retrieves the underline color. * * @return The underline color. diff --git a/dali-toolkit/internal/text/text-model.cpp b/dali-toolkit/internal/text/text-model.cpp index e133e81..7b6536d 100755 --- a/dali-toolkit/internal/text/text-model.cpp +++ b/dali-toolkit/internal/text/text-model.cpp @@ -122,6 +122,11 @@ const Vector4& Model::GetShadowColor() const return mVisualModel->mShadowColor; } +const float& Model::GetShadowBlurRadius() const +{ + return mVisualModel->mShadowBlurRadius; +} + const Vector4& Model::GetUnderlineColor() const { return mVisualModel->GetUnderlineColor(); diff --git a/dali-toolkit/internal/text/text-model.h b/dali-toolkit/internal/text/text-model.h index 0812b46..da7fd24 100755 --- a/dali-toolkit/internal/text/text-model.h +++ b/dali-toolkit/internal/text/text-model.h @@ -149,6 +149,11 @@ public: virtual const Vector4& GetShadowColor() const; /** + * @copydoc ModelInterface::GetShadowBlurRadius() + */ + virtual const float& GetShadowBlurRadius() const; + + /** * @copydoc ModelInterface::GetUnderlineColor() */ virtual const Vector4& GetUnderlineColor() const; diff --git a/dali-toolkit/internal/text/visual-model-impl.cpp b/dali-toolkit/internal/text/visual-model-impl.cpp index 3e3f2d6..9caa523 100755 --- a/dali-toolkit/internal/text/visual-model-impl.cpp +++ b/dali-toolkit/internal/text/visual-model-impl.cpp @@ -344,6 +344,11 @@ void VisualModel::SetShadowColor( const Vector4& shadowColor ) mShadowColor = shadowColor; } +void VisualModel::SetShadowBlurRadius( const float& shadowBlurRadius ) +{ + mShadowBlurRadius = shadowBlurRadius; +} + void VisualModel::SetUnderlineColor( const Vector4& color ) { mUnderlineColor = color; @@ -385,6 +390,11 @@ const Vector4& VisualModel::GetShadowColor() const return mShadowColor; } +const float& VisualModel::GetShadowBlurRadius() const +{ + return mShadowBlurRadius; +} + const Vector4& VisualModel::GetUnderlineColor() const { return mUnderlineColor; @@ -440,6 +450,7 @@ VisualModel::VisualModel() mShadowOffset(), mUnderlineHeight( 0.0f ), mOutlineWidth( 0.0f ), + mShadowBlurRadius( 0.0f ), mNaturalSize(), mLayoutSize(), mCachedLineIndex( 0u ), diff --git a/dali-toolkit/internal/text/visual-model-impl.h b/dali-toolkit/internal/text/visual-model-impl.h index ea888cd..28d2269 100755 --- a/dali-toolkit/internal/text/visual-model-impl.h +++ b/dali-toolkit/internal/text/visual-model-impl.h @@ -234,6 +234,20 @@ public: const Vector4& GetShadowColor() const; /** + * @brief Set the shadow blur radius. + * + * @param[in] shadowBlurRadius The shadow blur radius, 0,0 indicates no blur. + */ + void SetShadowBlurRadius( const float& shadowBlurRadius ); + + /** + * @brief Retrieve the shadow blur radius. + * + * @return The shadow blur radius. + */ + const float& GetShadowBlurRadius() const; + + /** * @brief Sets the text's underline color. * * @param[in] color The text's underline color. @@ -356,6 +370,7 @@ public: Vector2 mShadowOffset; ///< Offset for drop shadow, 0 indicates no shadow float mUnderlineHeight; ///< Fixed height for underline to override font metrics. float mOutlineWidth; ///< Width of outline. + float mShadowBlurRadius; ///< Blur radius of shadow, 0 indicates no blur. private: diff --git a/docs/content/shared-javascript-and-cpp-documentation/text-label.md b/docs/content/shared-javascript-and-cpp-documentation/text-label.md index 98734b2..f1c3b77 100644 --- a/docs/content/shared-javascript-and-cpp-documentation/text-label.md +++ b/docs/content/shared-javascript-and-cpp-documentation/text-label.md @@ -207,7 +207,7 @@ label.textColor = dali.COLOR_RED; #### Drop Shadow -To add a drop-shadow to the text, simply set the SHADOW property. Shadow parameters can be set through a json string, see the examples below. +To add a drop-shadow to the text, simply set the SHADOW property. Shadow parameters can be set through a json string or through a property map, see the examples below. ~~~{.cpp} // C++ @@ -222,8 +222,14 @@ label2.SetProperty( TextLabel::Property::SHADOW, "{\"offset\":\"1 1\",\"color\": label3.SetProperty( TextLabel::Property::TEXT, "Text with Bigger Shadow" ); label3.SetProperty( TextLabel::Property::SHADOW, "{\"offset\":\"2 2\",\"color\":\"black\"}" ); -label4.SetProperty( TextLabel::Property::TEXT, "Text with Color Shadow" ); -label4.SetProperty( TextLabel::Property::SHADOW, "{\"offset\":\"1 1\",\"color\":\"red\"}" ); +label4.SetProperty( TextLabel::Property::TEXT, "Text with Color Soft Shadow" ); + +Property::Map shadow; +shadow.Insert( "offset", Vector2(1.0f, 1.0f) ); +shadow.Insert( "color", Color::RED ); +shadow.Insert( "blurRadius", 2.0f ); // A value of 0 indicates no blur. The bigger the radius, the more blurry. +label4.SetProperty( TextLabel::Property::SHADOW, shadow ); + ~~~ ~~~{.js} @@ -240,8 +246,14 @@ label2.shadow = "{\"offset\":\"1 1\",\"color\":\"black\"}"; label3.text = "Text with Bigger Shadow"; label3.shadow = "{\"offset\":\"2 2\",\"color\":\"black\"}"; -label4.SetProperty( TextLabel::Property::TEXT, "Text with Color Shadow" ); -label3.shadow = "{\"offset\":\"1 1\",\"color\":\"red\"}"; +label4.SetProperty( TextLabel::Property::TEXT, "Text with Color Soft Shadow" ); +var shadow = { + "offset" : [ 1.0, 1.0 ], + "color" : dali.COLOR_RED; + "blurRadius" : 2.0 +}; +label4.shadow = shadow; + ~~~