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=edf961f5cc34a64968dd605cd4bd0f3164ece5cb;hb=b398ab61279f2fe1e96f7567cecb123c25e2edb1;hpb=72992c098f444c003165389b36bde5a130101e09 diff --git a/dali-toolkit/internal/builder/builder-signals.cpp b/dali-toolkit/internal/builder/builder-signals.cpp index edf961f..804deb3 100644 --- a/dali-toolkit/internal/builder/builder-signals.cpp +++ b/dali-toolkit/internal/builder/builder-signals.cpp @@ -1,21 +1,28 @@ -// -// 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 +#include +#include +#include +#include #include +#include // INTERNAL INCLUDES #include @@ -27,7 +34,7 @@ namespace Toolkit { namespace Internal { -extern Animation CreateAnimation( const TreeNode& child ); +extern Animation CreateAnimation( const TreeNode& child, Dali::Toolkit::Internal::Builder* const builder ); extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value ); } } @@ -41,24 +48,13 @@ using namespace Dali; // Signal Actions // -// Action quit; connected to signals -// TODO: MOVE TO BUILDER TEMPLATE -struct ActionQuit -{ - ActionQuit(void) {}; - - void operator()(void) { - // Dali::Application::Get().Quit(); - }; -}; - -// 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::vector parameters; + std::string childName; + PropertyValueContainer parameters; void operator()(void) { @@ -66,7 +62,7 @@ struct ChildActorAction if(actor) { - Actor child_actor = actor.FindChildByAlias(childAlias); + Actor child_actor = actor.FindChildByName(childName); if(child_actor) { @@ -74,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()); } } }; @@ -119,7 +115,7 @@ struct GenericAction { std::string actorName; std::string actionName; - std::vector parameters; + PropertyValueContainer parameters; void operator()(void) { @@ -135,11 +131,12 @@ struct GenericAction // Delay an animation play; ie wait as its not on stage yet struct DelayedAnimationPlay { - Toolkit::JsonParser memento; + OptionalChild animNode; + Dali::IntrusivePtr builder; void operator()(void) { - Animation anim = Toolkit::Internal::CreateAnimation(*memento.GetRoot()); + Animation anim = Toolkit::Internal::CreateAnimation(*animNode, builder.Get() ); if(anim) { anim.Play(); @@ -147,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 ¶ms) +void GetParameters(const TreeNode& child, PropertyValueContainer& params) { if( OptionalChild c = IsChild(child, "parameters") ) { @@ -231,7 +404,7 @@ void DoNothing(void) {}; /** * Get an action as boost function callback */ -boost::function GetAction(const TreeNode &root, const TreeNode &child, Actor actor) +boost::function GetAction(const TreeNode &root, const TreeNode &child, Actor actor, boost::function quitAction, Dali::Toolkit::Internal::Builder* const builder) { OptionalString childActorName(IsString( IsChild(&child, "child-actor")) ); OptionalString actorName(IsString( IsChild(&child, "actor")) ); @@ -247,7 +420,7 @@ boost::function 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; @@ -277,7 +450,7 @@ boost::function GetAction(const TreeNode &root, const TreeNode &chi } else if("quit" == *actionName) { - callback = ActionQuit(); + callback = quitAction; } else if("play" == *actionName) { @@ -288,7 +461,9 @@ boost::function GetAction(const TreeNode &root, const TreeNode &chi if( OptionalChild animNode = IsChild(*animations, *animationName) ) { DelayedAnimationPlay action; - action.memento = Toolkit::JsonParser::New(*animNode); + action.animNode = animNode; + action.builder = builder; + // @todo; put constants into the map callback = action; } else @@ -301,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 @@ -330,15 +614,10 @@ float GetConditionArg0(const TreeNode &child) { f = IsFloat( IsChild(child, "min") ); } + DALI_ASSERT_ALWAYS(f && "Notification condition for arg0 not specified"); - if(f) - { - return *f; - } - else - { - return 0.f; - } + + return *f; } /** @@ -352,15 +631,10 @@ float GetConditionArg1(const TreeNode &child) { f = IsFloat( IsChild(child, "max") ); } + DALI_ASSERT_ALWAYS(f && "Notification condition for arg1 not specified"); - if(f) - { - return *f; - } - else - { - return 0.f; - } + + return *f; } @@ -374,13 +648,13 @@ namespace Toolkit namespace Internal { -Actor SetupSignalAction(const TreeNode &child, Actor actor); -Actor SetupPropertyNotification(const TreeNode &child, Actor actor); +Actor SetupSignalAction(const TreeNode &child, Actor actor, Dali::Toolkit::Internal::Builder* const builder ); +Actor SetupPropertyNotification(const TreeNode &child, Actor actor, Dali::Toolkit::Internal::Builder* const builder ); /** * Setup signals and actions on an actor */ -Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor) +Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function quitAction, Dali::Toolkit::Internal::Builder* const builder ) { DALI_ASSERT_ALWAYS(actor); @@ -397,7 +671,7 @@ Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const OptionalString name( IsString( IsChild( key_child.second, "name")) ); DALI_ASSERT_ALWAYS(name && "Signal must have a name"); - boost::function callback = GetAction(root, key_child.second, actor); + boost::function callback = GetAction(root, key_child.second, actor, quitAction, builder ); actor.ConnectSignal(tracker, *name, callback); } @@ -409,7 +683,7 @@ Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const /** * Setup Property notifications for an actor */ -Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor) +Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function quitAction, Dali::Toolkit::Internal::Builder* const builder ) { DALI_ASSERT_ALWAYS(actor); @@ -423,7 +697,7 @@ Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root // Actor actions reference by pointer because of circular reference actor->signal // So this callback should only go onto the actor maintained list. - boost::function callback = GetAction(root, key_child.second, actor); + boost::function callback = GetAction(root, key_child.second, actor, quitAction, builder ); OptionalString prop(IsString( IsChild(key_child.second, "property")) ); DALI_ASSERT_ALWAYS(prop && "Notification signal must specify a property");