X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=base%2Fdali-toolkit%2Finternal%2Fbuilder%2Fbuilder-animations.cpp;h=c1c8921f1410662ae04114911cd4bcac2916495d;hp=454a686eadb01171dadcde82e1c201f98c0c99a6;hb=bbb84f1c666429f3c1be6519cc903f27cefec96c;hpb=022b76df6f53c2860f2684ef1ffee81af1805e2e diff --git a/base/dali-toolkit/internal/builder/builder-animations.cpp b/base/dali-toolkit/internal/builder/builder-animations.cpp index 454a686..c1c8921 100644 --- a/base/dali-toolkit/internal/builder/builder-animations.cpp +++ b/base/dali-toolkit/internal/builder/builder-animations.cpp @@ -1,18 +1,19 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.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://floralicense.org/license/ -// -// 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. -// +/* + * Copyright (c) 2014 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 @@ -95,7 +96,6 @@ Property::Value GetPropertyValue( const Property::Type& propType, const TreeNode default: { DALI_ASSERT_ALWAYS( !"Property type incorrect" ); - return Property::Value(); } } } @@ -108,20 +108,34 @@ AlphaFunction GetAlphaFunction( const std::string& alphaFunction ) if( 0 == alphaFunctionLut.size() ) { // coding convention is uppercase enums - alphaFunctionLut["DEFAULT"] = Dali::AlphaFunctions::Default; - alphaFunctionLut["LINEAR"] = Dali::AlphaFunctions::Linear; - alphaFunctionLut["REVERSE"] = Dali::AlphaFunctions::Reverse; - alphaFunctionLut["EASE_IN"] = Dali::AlphaFunctions::EaseIn; - alphaFunctionLut["EASE_OUT"] = Dali::AlphaFunctions::EaseOut; - alphaFunctionLut["EASE_IN_OUT"] = Dali::AlphaFunctions::EaseInOut; - alphaFunctionLut["EASE_IN_SINE"] = Dali::AlphaFunctions::EaseInSine; - alphaFunctionLut["EASE_OUT_SINE"] = Dali::AlphaFunctions::EaseOutSine; - alphaFunctionLut["EASE_IN_OUT_SINE"]= Dali::AlphaFunctions::EaseInOutSine; - alphaFunctionLut["BOUNCE"] = Dali::AlphaFunctions::Bounce; - alphaFunctionLut["BOUNCE_BACK"] = Dali::AlphaFunctions::BounceBack; - alphaFunctionLut["EASE_OUT_BACK"] = Dali::AlphaFunctions::EaseOutBack; - alphaFunctionLut["SIN"] = Dali::AlphaFunctions::Sin; - alphaFunctionLut["SIN2X"] = Dali::AlphaFunctions::Sin; + alphaFunctionLut["DEFAULT"] = AlphaFunctions::Default; + alphaFunctionLut["LINEAR"] = AlphaFunctions::Linear; + alphaFunctionLut["SQUARE"] = AlphaFunctions::Square; + alphaFunctionLut["REVERSE"] = AlphaFunctions::Reverse; + alphaFunctionLut["EASE_IN"] = AlphaFunctions::EaseIn; + alphaFunctionLut["EASE_OUT"] = AlphaFunctions::EaseOut; + alphaFunctionLut["EASE_IN_OUT"] = AlphaFunctions::EaseInOut; + alphaFunctionLut["EASE_IN_SINE"] = AlphaFunctions::EaseInSine; + alphaFunctionLut["EASE_OUT_SINE"] = AlphaFunctions::EaseOutSine; + alphaFunctionLut["EASE_IN_OUT_SINE"] = AlphaFunctions::EaseInOutSine; + alphaFunctionLut["EASE_IN_SINE_33"] = AlphaFunctions::EaseInSine33; + alphaFunctionLut["EASE_OUT_SINE_33"] = AlphaFunctions::EaseOutSine33; + alphaFunctionLut["EASE_IN_OUT_SINE_33"] = AlphaFunctions::EaseInOutSine33; + alphaFunctionLut["EASE_IN_OUT_SINE_50"] = AlphaFunctions::EaseInOutSine50; + alphaFunctionLut["EASE_IN_OUT_SINE_60"] = AlphaFunctions::EaseInOutSine60; + alphaFunctionLut["EASE_IN_OUT_SINE_70"] = AlphaFunctions::EaseInOutSine70; + alphaFunctionLut["EASE_IN_OUT_SINE_80"] = AlphaFunctions::EaseInOutSine80; + alphaFunctionLut["EASE_IN_OUT_SINE_90"] = AlphaFunctions::EaseInOutSine90; + alphaFunctionLut["DOUBLE_EASE_IN_OUT_SINE_60"] = AlphaFunctions::DoubleEaseInOutSine60; + alphaFunctionLut["EASE_OUT_QUINT_50"] = AlphaFunctions::EaseOutQuint50; + alphaFunctionLut["EASE_OUT_QUINT_80"] = AlphaFunctions::EaseOutQuint80; + alphaFunctionLut["BOUNCE"] = AlphaFunctions::Bounce; + alphaFunctionLut["BOUNCE_BACK"] = AlphaFunctions::BounceBack; + alphaFunctionLut["EASE_IN_BACK"] = AlphaFunctions::EaseInBack; + alphaFunctionLut["EASE_OUT_BACK"] = AlphaFunctions::EaseOutBack; + alphaFunctionLut["EASE_IN_OUT_BACK"] = AlphaFunctions::EaseInOutBack; + alphaFunctionLut["SIN"] = AlphaFunctions::Sin; + alphaFunctionLut["SIN2X"] = AlphaFunctions::Sin2x; } const AlphaFunctionLut::const_iterator iter( alphaFunctionLut.find( alphaFunction ) ); @@ -149,7 +163,7 @@ namespace Toolkit namespace Internal { -Animation CreateAnimation( const TreeNode& child, const Replacement& constant, Dali::Actor searchRoot ) +Animation CreateAnimation( const TreeNode& child, const Replacement& constant, Dali::Actor searchRoot, Builder* const builder ) { float durationSum = 0.f; @@ -186,19 +200,19 @@ Animation CreateAnimation( const TreeNode& child, const Replacement& constant, D } } - if( OptionalString endAction = constant.IsString( IsChild(child, "destroy-action" ) ) ) + if( OptionalString endAction = constant.IsString( IsChild(child, "disconnect-action" ) ) ) { if("BAKE" == *endAction) { - animation.SetDestroyAction( Animation::Bake ); + animation.SetDisconnectAction( Animation::Bake ); } else if("DISCARD" == *endAction) { - animation.SetDestroyAction( Animation::Discard ); + animation.SetDisconnectAction( Animation::Discard ); } else if("BAKE_FINAL" == *endAction) { - animation.SetDestroyAction( Animation::BakeFinal ); + animation.SetDisconnectAction( Animation::BakeFinal ); } } @@ -213,24 +227,39 @@ Animation CreateAnimation( const TreeNode& child, const Replacement& constant, D OptionalString actorName( constant.IsString( IsChild(pKeyChild.second, "actor" ) ) ); OptionalString property( constant.IsString( IsChild(pKeyChild.second, "property" ) ) ); DALI_ASSERT_ALWAYS( actorName && "Animation must specify actor name" ); - DALI_ASSERT_ALWAYS( property && "Animation must specify a property name" ); - Actor targetActor = searchActor.FindChildByName( *actorName ); - DALI_ASSERT_ALWAYS( targetActor && "Actor must exist for property" ); + Handle targetHandle = searchActor.FindChildByName( *actorName ); + DALI_ASSERT_ALWAYS( targetHandle && "Actor must exist for property" ); - Property::Index idx( targetActor.GetPropertyIndex( *property ) ); - - // A limitation here is that its possible that between binding to the signal and - // the signal call that the ShaderEffect of the targetActor has been changed. - // However this is a unlikely use case especially when using scripts. - if( idx == Property::INVALID_INDEX ) + Property::Value propValue; + Property::Index propIndex = Property::INVALID_INDEX; + if( property ) { - if( ShaderEffect effect = targetActor.GetShaderEffect() ) + propIndex = targetHandle.GetPropertyIndex( *property ); + + // if the property is not found from the (actor) handle, try to downcast it to renderable actor + // to allow animating shader uniforms + if( propIndex == Property::INVALID_INDEX ) { - idx = effect.GetPropertyIndex( *property ); - if(idx != Property::INVALID_INDEX) + RenderableActor renderable = RenderableActor::DownCast( targetHandle ); + if( renderable ) { - targetActor = effect; + // A limitation here is that its possible that between creation of animation + // and running it the ShaderEffect of the actor has been changed. + // However this is a unlikely use case especially when using scripts. + if( ShaderEffect effect = renderable.GetShaderEffect() ) + { + propIndex = effect.GetPropertyIndex( *property ); + if(propIndex != Property::INVALID_INDEX) + { + targetHandle = effect; + } + else + { + DALI_SCRIPT_WARNING( "Cannot find property on object or ShaderEffect\n" ); + continue; + } + } } else { @@ -238,22 +267,14 @@ Animation CreateAnimation( const TreeNode& child, const Replacement& constant, D continue; } } - else + + if( propIndex == Property::INVALID_INDEX) { - DALI_SCRIPT_WARNING( "Cannot find property on object or ShaderEffect\n" ); + DALI_ASSERT_ALWAYS( propIndex != Property::INVALID_INDEX && "Animation must specify a valid property" ); continue; } } - if( idx == Property::INVALID_INDEX) - { - DALI_ASSERT_ALWAYS( idx != Property::INVALID_INDEX && "Animation must specify a valid property" ); - continue; - } - - Property prop( Property( targetActor, idx ) ); - Property::Value propValue; - // these are the defaults AlphaFunction alphaFunction( AlphaFunctions::Default ); TimePeriod timePeriod( 0.f ); @@ -274,6 +295,9 @@ Animation CreateAnimation( const TreeNode& child, const Replacement& constant, D if( OptionalChild keyFrameChild = IsChild(pKeyChild.second, "key-frames") ) { + DALI_ASSERT_ALWAYS( property && "Animation must specify a property name" ); + Property prop = Property( targetHandle, propIndex ); + KeyFrames keyframes = KeyFrames::New(); const TreeNode::ConstIterator endIter = (*keyFrameChild).CEnd(); @@ -318,8 +342,45 @@ Animation CreateAnimation( const TreeNode& child, const Replacement& constant, D animation.AnimateBetween( prop, keyframes, alphaFunction ); } } + else if( OptionalString pathChild = IsString(pKeyChild.second, "path") ) + { + //Get path + Path path = builder->GetPath(*pathChild); + if( path ) + { + //Get forward vector if specified + Vector3 forward( 0.0f, 0.0f, 0.0f ); + OptionalVector3 forwardProperty = constant.IsVector3( IsChild(pKeyChild.second, "forward" ) ); + if( forwardProperty ) + { + forward = *forwardProperty; + } + + Actor actor = Actor::DownCast( targetHandle ); + if( actor ) + { + if( timeChild ) + { + animation.Animate( actor, path, forward, alphaFunction, timePeriod ); + } + else + { + animation.Animate( actor, path, forward, alphaFunction ); + } + + } + } + else + { + //Path not found + DALI_SCRIPT_WARNING( "Cannot find animation path '%s'\n", (*pathChild).c_str() ); + } + } else { + DALI_ASSERT_ALWAYS( property && "Animation must specify a property name" ); + + Property prop = Property( targetHandle, propIndex ); try { propValue = GetPropertyValue( prop.object.GetPropertyType(prop.propertyIndex), *IsChild(pKeyChild.second, "value") ); @@ -366,10 +427,10 @@ Animation CreateAnimation( const TreeNode& child, const Replacement& constant, D return animation; } -Animation CreateAnimation( const TreeNode& child ) +Animation CreateAnimation( const TreeNode& child, Builder* const builder ) { Replacement replacement; - return CreateAnimation( child, replacement, Stage::GetCurrent().GetRootLayer() ); + return CreateAnimation( child, replacement, Stage::GetCurrent().GetRootLayer(), builder ); } } // namespace Internal