2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
19 #include <dali/integration-api/debug.h>
20 #include <dali/public-api/scripting/scripting.h>
23 #include <dali-toolkit/internal/builder/builder-get-is.inl.h>
25 namespace // unnamed namespace
29 using namespace Dali::Scripting;
31 ColorMode GetColorMode( const std::string& value )
33 ColorMode v( USE_OWN_COLOR );
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);
42 DALI_ASSERT_ALWAYS( !"Unknown Color mode" );
48 PositionInheritanceMode GetPositionInheritanceMode( const std::string& value )
50 PositionInheritanceMode v(INHERIT_PARENT_POSITION);
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);
60 DALI_ASSERT_ALWAYS( !"Unknown position inheritance mode" );
66 DrawMode::Type GetDrawMode( const std::string& value )
68 DrawMode::Type e(DrawMode::NORMAL);
71 SetIfEqual(value, "NORMAL", e, DrawMode::NORMAL ) || \
72 SetIfEqual(value, "OVERLAY",e, DrawMode::OVERLAY ) || \
73 SetIfEqual(value, "STENCIL",e, DrawMode::STENCIL);
77 DALI_ASSERT_ALWAYS( !"Unknown DrawMode type" );
84 Vector3 GetAnchorConstant( const std::string& value )
86 Vector3 v = ParentOrigin::CENTER; // a Vector3x
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 );
119 DALI_ASSERT_ALWAYS(!"Unknown Parent origin Constant" );
126 }; // unnamed namespace
139 * Handles special case actor configuration (anything thats not already a property)
142 Actor SetupActor( const TreeNode& child, Actor& actor )
144 DALI_ASSERT_ALWAYS( actor && "Empty actor handle" );
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") )
151 if( OptionalVector3 v = IsVector3(child, "parent-origin") )
153 actor.SetParentOrigin( *v );
155 else if( OptionalString origin = IsString(child, "parent-origin") )
157 actor.SetParentOrigin( GetAnchorConstant(*origin) );
161 if( !IsVector3(child, "anchor-point") )
163 if( OptionalVector3 v = IsVector3(child, "anchor-point") )
165 actor.SetParentOrigin( *v );
167 else if( OptionalString anchor = IsString(child, "anchor-point") )
169 actor.SetAnchorPoint( GetAnchorConstant(*anchor) );
173 if( OptionalFloat opacity = IsFloat(child, "opacity") )
175 actor.SetOpacity( *opacity );
178 if( OptionalFloat opacity = IsFloat(child, "opacity-by") )
180 actor.OpacityBy( *opacity );
183 if( OptionalString colorMode = IsString(child, "color-mode") )
185 actor.SetColorMode( GetColorMode(*colorMode) );
188 if( OptionalBoolean inherit = IsBoolean(child, "inherit-shader-effect") )
190 actor.SetInheritShaderEffect( *inherit );
193 if( OptionalBoolean sensitive = IsBoolean(child, "sensitive") )
195 actor.SetSensitive( *sensitive );
198 if( OptionalBoolean leaveRequired = IsBoolean(child, "leave-required") )
200 actor.SetLeaveRequired( *leaveRequired );
203 if( OptionalString v = IsString(child, "position-inheritance") )
205 actor.SetPositionInheritanceMode( GetPositionInheritanceMode(*v) );
208 if( OptionalString v = IsString(child, "draw-mode") )
210 actor.SetDrawMode( GetDrawMode(*v) );
213 if( OptionalBoolean v = IsBoolean(child, "inherit-rotation") )
215 actor.SetInheritRotation( *v );
218 if( OptionalBoolean v = IsBoolean(child, "inherit-scale") )
220 actor.SetInheritScale( *v );
226 } // namespace Internal
228 } // namespace Toolkit