X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fbuilder%2Fbuilder-signals.cpp;h=804deb359e3e5d4e0c4ee187d7714745784a2135;hp=40428e34aaf0dab8c585f0f3608c76147a840ae9;hb=ff26956b1702af9d1ffff11d93cc118f6db5c4ba;hpb=57869973578f6a0b0f836d396c7232ddb8302c6b diff --git a/dali-toolkit/internal/builder/builder-signals.cpp b/dali-toolkit/internal/builder/builder-signals.cpp index 40428e3..804deb3 100644 --- a/dali-toolkit/internal/builder/builder-signals.cpp +++ b/dali-toolkit/internal/builder/builder-signals.cpp @@ -16,8 +16,13 @@ */ // EXTERNAL INCLUDES -#include #include +#include +#include +#include +#include +#include +#include // INTERNAL INCLUDES #include @@ -43,12 +48,12 @@ using namespace Dali; // Signal Actions // -// Action on child actor. The child is found by alias so can be 'previous' etc. +// Action on child actor. The child is found by name struct ChildActorAction { std::string actorName; std::string actionName; - std::string childAlias; + std::string childName; PropertyValueContainer parameters; void operator()(void) @@ -57,7 +62,7 @@ struct ChildActorAction if(actor) { - Actor child_actor = actor.FindChildByAlias(childAlias); + Actor child_actor = actor.FindChildByName(childName); if(child_actor) { @@ -65,7 +70,7 @@ struct ChildActorAction } else { - DALI_SCRIPT_WARNING("Could not find child by alias '%s'\n", childAlias.c_str()); + DALI_SCRIPT_WARNING("Could not find child by name '%s'\n", childName.c_str()); } } }; @@ -139,6 +144,182 @@ struct DelayedAnimationPlay }; }; +// Delay a pathConstrainer apply +struct DelayedConstrainerApply +{ + std::string constrainerName; + + std::vector targetActorNames; + std::vector sourceActorNames; + std::vector targetPropertyNames; + std::vector sourcePropertyNames; + std::vector ranges; + std::vector wrapRanges; + + Dali::IntrusivePtr builder; + + /* + * Helper function to get the parameters to apply each constraint + * @param[in] i i-essim element + * @param[out] tagetActor Target actor for the constraint + * @param[out] tagetPropertyIndex Target property index for the constraint + * @param[out] sourceActor Source actor for the constraint + * @param[out] sourcePropertyIndex Source property index for the constraint + */ + bool GetApplyParameters( size_t i, + Actor& targetActor, Property::Index& targetPropertyIndex, + Actor& sourceActor, Property::Index& sourcePropertyIndex) + { + + targetActor = Stage::GetCurrent().GetRootLayer().FindChildByName(targetActorNames[i]); + targetPropertyIndex = Property::INVALID_INDEX; + if(targetActor) + { + targetPropertyIndex = targetActor.GetPropertyIndex(targetPropertyNames[i]); + if( targetPropertyIndex == Property::INVALID_INDEX ) + { + DALI_SCRIPT_WARNING("Property '%s' not founded in actor '%s'\n", targetPropertyNames[i].c_str(), targetActorNames[i].c_str() ); + return false; + } + } + else + { + DALI_SCRIPT_WARNING("Actor '%s' not founded\n", targetActorNames[i].c_str() ); + return false; + } + + + sourceActor = Stage::GetCurrent().GetRootLayer().FindChildByName(sourceActorNames[i]); + sourcePropertyIndex = Property::INVALID_INDEX; + if(sourceActor) + { + sourcePropertyIndex = sourceActor.GetPropertyIndex(sourcePropertyNames[i]); + if( sourcePropertyIndex == Property::INVALID_INDEX ) + { + DALI_SCRIPT_WARNING("Property '%s' not founded in actor '%s'\n", sourcePropertyNames[i].c_str(), sourceActorNames[i].c_str() ); + return false; + } + } + else + { + DALI_SCRIPT_WARNING("Actor '%s' not founded\n", targetActorNames[i].c_str() ); + return false; + } + return true; + } + + void operator()(void) + { + Actor sourceActor, targetActor; + Property::Index targetPropertyIndex(Property::INVALID_INDEX); + Property::Index sourcePropertyIndex(Property::INVALID_INDEX); + size_t actorCount( targetActorNames.size() ); + if( builder.Get()->IsPathConstrainer( constrainerName )) + { + PathConstrainer constrainer = builder.Get()->GetPathConstrainer(constrainerName); + if( constrainer ) + { + for(size_t i(0); iIsLinearConstrainer( constrainerName ) ) + { + Dali::LinearConstrainer constrainer( builder.Get()->GetLinearConstrainer(constrainerName)); + if( constrainer ) + { + for(size_t i(0); i targetActorNames; + Dali::IntrusivePtr builder; + + void operator()(void) + { + size_t actorCount( targetActorNames.size() ); + if( builder.Get()->IsPathConstrainer( constrainerName )) + { + PathConstrainer constrainer = builder.Get()->GetPathConstrainer(constrainerName); + if( constrainer ) + { + for(size_t i(0); iIsLinearConstrainer( constrainerName )) + { + LinearConstrainer constrainer = builder.Get()->GetLinearConstrainer(constrainerName); + if( constrainer ) + { + for(size_t i(0); i GetAction(const TreeNode &root, const TreeNode &chi { ChildActorAction action; action.actorName = *actorName; - action.childAlias = *childActorName; + action.childName = *childActorName; action.actionName = *actionName; GetParameters(child, action.parameters); callback = action; @@ -295,6 +476,115 @@ boost::function GetAction(const TreeNode &root, const TreeNode &chi DALI_SCRIPT_WARNING("Cannot find animations section\n"); } } + else if("applyConstraint" == *actionName ) + { + OptionalString constrainerName = IsString( IsChild(child, "constrainer") ); + if( !constrainerName ) + { + DALI_SCRIPT_WARNING("Need to specify a constrainer\n"); + } + else + { + DelayedConstrainerApply action; + action.constrainerName = *constrainerName; + action.builder = builder; + OptionalChild propertiesNode = IsChild(child, "properties"); + if(propertiesNode) + { + const TreeNode::ConstIterator endIter = (*propertiesNode).CEnd(); + for( TreeNode::ConstIterator iter = (*propertiesNode).CBegin(); endIter != iter; ++iter ) + { + const TreeNode::KeyNodePair& pKeyChild = *iter; + OptionalString sourceActorName(IsString(IsChild(pKeyChild.second, "source"))); + if(!sourceActorName) + { + DALI_SCRIPT_WARNING("Need to specify source actor to apply the constraint\n"); + continue; + } + OptionalString sourcePropertyName( IsString( IsChild(pKeyChild.second, "sourceProperty" ) ) ); + if(!sourcePropertyName) + { + DALI_SCRIPT_WARNING("Need to specify source property to apply the constraint\n"); + continue; + } + + OptionalString targetActorName(IsString(IsChild(pKeyChild.second, "target"))); + if(!targetActorName) + { + DALI_SCRIPT_WARNING("Need to specify target actor to apply the constraint\n"); + continue; + } + + OptionalString targetPropertyName( IsString( IsChild(pKeyChild.second, "targetProperty" ) ) ); + if(!targetPropertyName) + { + DALI_SCRIPT_WARNING("Need to specify target property name to apply the constraint\n"); + continue; + } + + OptionalVector2 range(IsVector2(IsChild(pKeyChild.second, "range"))); + if(!range) + { + DALI_SCRIPT_WARNING("Constrainer range not specified\n"); + continue; + } + + Vector2 wrap(-std::numeric_limits::max(), std::numeric_limits::max()); + OptionalVector2 wrapRange(IsVector2(IsChild(pKeyChild.second, "wrap"))); + if(wrapRange) + { + wrap = *wrapRange; + } + + action.sourceActorNames.push_back(*sourceActorName); + action.sourcePropertyNames.push_back(*sourcePropertyName); + action.targetActorNames.push_back(*targetActorName); + action.targetPropertyNames.push_back(*targetPropertyName); + action.ranges.push_back(*range); + action.wrapRanges.push_back(wrap); + } + + callback = action; + } + } + + + } + else if("removeConstraints" == *actionName ) + { + OptionalString constrainerName = IsString( IsChild(child, "constrainer") ); + if( !constrainerName ) + { + DALI_SCRIPT_WARNING("Need to specify a constrainer\n"); + } + else + { + + DelayedConstrainerRemove action; + action.constrainerName = *constrainerName; + action.builder = builder; + OptionalChild propertiesNode = IsChild(child, "properties"); + if(propertiesNode) + { + const TreeNode::ConstIterator endIter = (*propertiesNode).CEnd(); + for( TreeNode::ConstIterator iter = (*propertiesNode).CBegin(); endIter != iter; ++iter ) + { + const TreeNode::KeyNodePair& pKeyChild = *iter; + OptionalString targetActorName(IsString(IsChild(pKeyChild.second, "target"))); + if(targetActorName) + { + action.targetActorNames.push_back(*targetActorName); + } + else + { + DALI_SCRIPT_WARNING("Need to specify target actor to remove the constraint\n"); + continue; + } + } + } + callback = action; + } + } else { // no named actor; presume self