2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali/integration-api/debug.h>
21 #include <dali/devel-api/scripting/scripting.h>
24 #include <dali-toolkit/internal/builder/replacement.h>
25 #include <dali-toolkit/internal/builder/builder-impl.h>
36 using namespace Dali::Scripting;
37 extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& constant );
40 * Handles special case actor configuration (anything thats not already a property)
43 Actor SetupActor( const TreeNode& child, Actor& actor, const Replacement& constant )
45 DALI_ASSERT_ALWAYS( actor && "Empty actor handle" );
47 // we allow enums strings for parent-origin and anchor-point but as with the current json
48 // strings always succeed if they exist then check its not vector. If they are Vec3s then
49 // this has already been set as a generic property.
50 if( !IsVector3( child, "parent-origin") )
52 if( OptionalVector3 v = constant.IsVector3( IsChild(child, "parent-origin") ) )
54 actor.SetParentOrigin( *v );
56 else if( OptionalString origin = constant.IsString( IsChild(child, "parent-origin") ) )
58 actor.SetParentOrigin( GetAnchorConstant(*origin) );
62 if( !IsVector3(child, "anchor-point") )
64 if( OptionalVector3 v = constant.IsVector3( IsChild(child, "anchor-point") ) )
66 actor.SetAnchorPoint( *v );
68 else if( OptionalString anchor = constant.IsString( IsChild(child, "anchor-point") ) )
70 actor.SetAnchorPoint( GetAnchorConstant(*anchor) );
74 // Add custom properties
75 if( OptionalChild customPropertiesChild = IsChild(child, "custom-properties") )
77 const TreeNode& customPropertiesNode = *customPropertiesChild;
78 const TreeConstIter endIter = customPropertiesNode.CEnd();
79 for( TreeConstIter iter = customPropertiesNode.CBegin(); endIter != iter; ++iter )
81 const TreeNode::KeyNodePair& keyChild = *iter;
82 std::string key( keyChild.first );
84 Property::Index index = actor.GetPropertyIndex( key );
85 Property::Value value;
86 if( SetPropertyFromNode( keyChild.second, value, constant ))
88 if( Property::INVALID_INDEX == index )
90 actor.RegisterProperty( key, value );
94 actor.SetProperty( index, value );
103 } // namespace Internal
105 } // namespace Toolkit