Dali-toolkit: Replace constraints with SizeMode
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / builder / builder-actor.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // EXTERNAL INCLUDES
19 #include <string>
20 #include <dali/integration-api/debug.h>
21 #include <dali/public-api/scripting/scripting.h>
22
23 // INTERNAL INCLUDES
24 #include <dali-toolkit/internal/builder/replacement.h>
25 #include <dali-toolkit/internal/builder/builder-impl.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal
34 {
35
36 using namespace Dali::Scripting;
37 extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& constant );
38
39 /*
40  * Handles special case actor configuration (anything thats not already a property)
41  *
42  */
43 Actor SetupActor( const TreeNode& child, Actor& actor, const Replacement& constant )
44 {
45   DALI_ASSERT_ALWAYS( actor && "Empty actor handle" );
46
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") )
51   {
52     if( OptionalVector3 v = IsVector3(child, "parent-origin") )
53     {
54       actor.SetParentOrigin( *v );
55     }
56     else if( OptionalString origin = IsString(child, "parent-origin") )
57     {
58       actor.SetParentOrigin( GetAnchorConstant(*origin) );
59     }
60   }
61
62   if( !IsVector3(child, "anchor-point") )
63   {
64     if( OptionalVector3 v = IsVector3(child, "anchor-point") )
65     {
66       actor.SetAnchorPoint( *v );
67     }
68     else if( OptionalString anchor = IsString(child, "anchor-point") )
69     {
70       actor.SetAnchorPoint( GetAnchorConstant(*anchor) );
71     }
72   }
73
74   // Add custom properties
75   if( OptionalChild customPropertiesChild = IsChild(child,  "custom-properties") )
76   {
77     const TreeNode& customPropertiesNode = *customPropertiesChild;
78     const TreeConstIter endIter = customPropertiesNode.CEnd();
79     for( TreeConstIter iter = customPropertiesNode.CBegin(); endIter != iter; ++iter )
80     {
81       const TreeNode::KeyNodePair& keyChild = *iter;
82       std::string key( keyChild.first );
83
84       Property::Index index = actor.GetPropertyIndex( key );
85       Property::Value value;
86       if( SetPropertyFromNode( keyChild.second, value, constant ))
87       {
88         if( Property::INVALID_INDEX == index )
89         {
90           actor.RegisterProperty( key, value );
91         }
92         else
93         {
94           actor.SetProperty( index, value );
95         }
96       }
97     }
98   }
99
100   return actor;
101 }
102
103 } // namespace Internal
104
105 } // namespace Toolkit
106
107 } // namespace Dali