Make ItemView::ActivateLayout do what it says on the tin
[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 Flora License, Version 1.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://floralicense.org/license/
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 // EXTERNAL INCLUDES
18 #include <string>
19 #include <dali/integration-api/debug.h>
20 #include <dali/public-api/scripting/scripting.h>
21
22 // INTERNAL INCLUDES
23 #include <dali-toolkit/internal/builder/builder-get-is.inl.h>
24
25 namespace // unnamed namespace
26 {
27
28 using namespace Dali;
29 using namespace Dali::Scripting;
30
31 ColorMode GetColorMode( const std::string& value )
32 {
33   ColorMode v( USE_OWN_COLOR );
34
35   bool set = \
36     SetIfEqual(value, "USE_OWN_COLOR"                , v, USE_OWN_COLOR                 ) || \
37     SetIfEqual(value, "USE_PARENT_COLOR"             , v, USE_PARENT_COLOR              ) || \
38     SetIfEqual(value, "USE_OWN_MULTIPLY_PARENT_COLOR", v, USE_OWN_MULTIPLY_PARENT_COLOR);
39
40   if( !set )
41   {
42     DALI_ASSERT_ALWAYS( !"Unknown Color mode" );
43   }
44
45   return v;
46 }
47
48 PositionInheritanceMode GetPositionInheritanceMode( const std::string& value )
49 {
50   PositionInheritanceMode v(INHERIT_PARENT_POSITION);
51
52   bool set = \
53     SetIfEqual(value, "INHERIT_PARENT_POSITION", v, INHERIT_PARENT_POSITION                                    ) || \
54     SetIfEqual(value, "USE_PARENT_POSITION"    , v, USE_PARENT_POSITION                                        ) || \
55     SetIfEqual(value, "USE_PARENT_POSITION_PLUS_LOCAL_POSITION", v, USE_PARENT_POSITION_PLUS_LOCAL_POSITION    ) || \
56     SetIfEqual(value, "DONT_INHERIT_POSITION"  , v, DONT_INHERIT_POSITION);
57
58   if( !set )
59   {
60     DALI_ASSERT_ALWAYS( !"Unknown position inheritance mode" );
61   }
62
63   return v;
64 }
65
66 DrawMode::Type GetDrawMode( const std::string& value )
67 {
68   DrawMode::Type e(DrawMode::NORMAL);
69
70   bool set = \
71     SetIfEqual(value, "NORMAL", e, DrawMode::NORMAL  ) || \
72     SetIfEqual(value, "OVERLAY",e, DrawMode::OVERLAY ) || \
73     SetIfEqual(value, "STENCIL",e, DrawMode::STENCIL);
74
75   if(!set)
76   {
77     DALI_ASSERT_ALWAYS( !"Unknown DrawMode type" );
78   }
79
80   return e;
81 }
82
83
84 Vector3 GetAnchorConstant( const std::string& value )
85 {
86   Vector3 v = ParentOrigin::CENTER; // a Vector3x
87
88   bool set =
89     SetIfEqual( value, "BACK_TOP_LEFT",        v, ParentOrigin::BACK_TOP_LEFT      ) ||
90     SetIfEqual( value, "BACK_TOP_CENTER",      v, ParentOrigin::BACK_TOP_CENTER    ) ||
91     SetIfEqual( value, "BACK_TOP_RIGHT",       v, ParentOrigin::BACK_TOP_RIGHT     ) ||
92     SetIfEqual( value, "BACK_CENTER_LEFT",     v, ParentOrigin::BACK_CENTER_LEFT   ) ||
93     SetIfEqual( value, "BACK_CENTER",          v, ParentOrigin::BACK_CENTER        ) ||
94     SetIfEqual( value, "BACK_CENTER_RIGHT",    v, ParentOrigin::BACK_CENTER_RIGHT  ) ||
95     SetIfEqual( value, "BACK_BOTTOM_LEFT",     v, ParentOrigin::BACK_BOTTOM_LEFT   ) ||
96     SetIfEqual( value, "BACK_BOTTOM_CENTER",   v, ParentOrigin::BACK_BOTTOM_CENTER ) ||
97     SetIfEqual( value, "BACK_BOTTOM_RIGHT",    v, ParentOrigin::BACK_BOTTOM_RIGHT  ) ||
98     SetIfEqual( value, "TOP_LEFT",             v, ParentOrigin::TOP_LEFT           ) ||
99     SetIfEqual( value, "TOP_CENTER",           v, ParentOrigin::TOP_CENTER         ) ||
100     SetIfEqual( value, "TOP_RIGHT",            v, ParentOrigin::TOP_RIGHT          ) ||
101     SetIfEqual( value, "CENTER_LEFT",          v, ParentOrigin::CENTER_LEFT        ) ||
102     SetIfEqual( value, "CENTER",               v, ParentOrigin::CENTER             ) ||
103     SetIfEqual( value, "CENTER_RIGHT",         v, ParentOrigin::CENTER_RIGHT       ) ||
104     SetIfEqual( value, "BOTTOM_LEFT",          v, ParentOrigin::BOTTOM_LEFT        ) ||
105     SetIfEqual( value, "BOTTOM_CENTER",        v, ParentOrigin::BOTTOM_CENTER      ) ||
106     SetIfEqual( value, "BOTTOM_RIGHT",         v, ParentOrigin::BOTTOM_RIGHT       ) ||
107     SetIfEqual( value, "FRONT_TOP_LEFT",       v, ParentOrigin::FRONT_TOP_LEFT     ) ||
108     SetIfEqual( value, "FRONT_TOP_CENTER",     v, ParentOrigin::FRONT_TOP_CENTER   ) ||
109     SetIfEqual( value, "FRONT_TOP_RIGHT",      v, ParentOrigin::FRONT_TOP_RIGHT    ) ||
110     SetIfEqual( value, "FRONT_CENTER_LEFT",    v, ParentOrigin::FRONT_CENTER_LEFT  ) ||
111     SetIfEqual( value, "FRONT_CENTER",         v, ParentOrigin::FRONT_CENTER       ) ||
112     SetIfEqual( value, "FRONT_CENTER_RIGHT",   v, ParentOrigin::FRONT_CENTER_RIGHT ) ||
113     SetIfEqual( value, "FRONT_BOTTOM_LEFT",    v, ParentOrigin::FRONT_BOTTOM_LEFT  ) ||
114     SetIfEqual( value, "FRONT_BOTTOM_CENTER",  v, ParentOrigin::FRONT_BOTTOM_CENTER) ||
115     SetIfEqual( value, "FRONT_BOTTOM_RIGHT",   v, ParentOrigin::FRONT_BOTTOM_RIGHT );
116
117   if(!set)
118   {
119     DALI_ASSERT_ALWAYS(!"Unknown Parent origin Constant" );
120   }
121
122   return v;
123 }
124
125
126 }; // unnamed namespace
127
128
129 namespace Dali
130 {
131
132 namespace Toolkit
133 {
134
135 namespace Internal
136 {
137
138 /*
139  * Handles special case actor configuration (anything thats not already a property)
140  *
141  */
142 Actor SetupActor( const TreeNode& child, Actor& actor )
143 {
144   DALI_ASSERT_ALWAYS( actor && "Empty actor handle" );
145
146   // we allow enums strings for parent-origin and anchor-point but as with the current json
147   // strings always succeed if they exist then check its not vector. If they are Vec3s then
148   // this has already been set as a generic property.
149   if( !IsVector3( child, "parent-origin") )
150   {
151     if( OptionalVector3 v = IsVector3(child, "parent-origin") )
152     {
153       actor.SetParentOrigin( *v );
154     }
155     else if( OptionalString origin = IsString(child, "parent-origin") )
156     {
157       actor.SetParentOrigin( GetAnchorConstant(*origin) );
158     }
159   }
160
161   if( !IsVector3(child, "anchor-point") )
162   {
163     if( OptionalVector3 v = IsVector3(child, "anchor-point") )
164     {
165       actor.SetParentOrigin( *v );
166     }
167     else if( OptionalString anchor = IsString(child, "anchor-point") )
168     {
169       actor.SetAnchorPoint( GetAnchorConstant(*anchor) );
170     }
171   }
172
173   if( OptionalFloat opacity = IsFloat(child, "opacity") )
174   {
175     actor.SetOpacity( *opacity );
176   }
177
178   if( OptionalFloat opacity = IsFloat(child, "opacity-by") )
179   {
180     actor.OpacityBy( *opacity );
181   }
182
183   if( OptionalString colorMode = IsString(child, "color-mode") )
184   {
185     actor.SetColorMode( GetColorMode(*colorMode) );
186   }
187
188   if( OptionalBoolean inherit = IsBoolean(child, "inherit-shader-effect") )
189   {
190     actor.SetInheritShaderEffect( *inherit );
191   }
192
193   if( OptionalBoolean sensitive = IsBoolean(child, "sensitive") )
194   {
195     actor.SetSensitive( *sensitive );
196   }
197
198   if( OptionalBoolean leaveRequired = IsBoolean(child, "leave-required") )
199   {
200     actor.SetLeaveRequired( *leaveRequired );
201   }
202
203   if( OptionalString v = IsString(child, "position-inheritance") )
204   {
205     actor.SetPositionInheritanceMode( GetPositionInheritanceMode(*v) );
206   }
207
208   if( OptionalString v = IsString(child, "draw-mode") )
209   {
210     actor.SetDrawMode( GetDrawMode(*v) );
211   }
212
213   if( OptionalBoolean v = IsBoolean(child, "inherit-rotation") )
214   {
215     actor.SetInheritRotation( *v );
216   }
217
218   if( OptionalBoolean v = IsBoolean(child, "inherit-scale") )
219   {
220     actor.SetInheritScale( *v );
221   }
222
223   return actor;
224 }
225
226 } // namespace Internal
227
228 } // namespace Toolkit
229
230 } // namespace Dali