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.
18 #include <dali-toolkit/internal/builder/builder-impl.h>
24 #include <dali/dali.h>
25 #include <dali/integration-api/debug.h>
27 #include <dali-toolkit/public-api/controls/control.h>
28 #include <dali-toolkit/public-api/builder/json-parser.h>
30 #include <dali-toolkit/internal/builder/builder-get-is.inl.h>
31 #include <dali-toolkit/internal/builder/builder-filesystem.h>
32 #include <dali-toolkit/internal/builder/builder-declarations.h>
33 #include <dali-toolkit/internal/builder/replacement.h>
45 extern Animation CreateAnimation(const TreeNode& child, const Replacement& replacements, const Dali::Actor searchRoot );
46 extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value );
47 extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& replacements );
48 extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value );
49 extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value, const Replacement& replacements );
50 extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor);
51 extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor);
52 extern Actor SetupActor( const TreeNode& node, Actor& actor );
53 extern Control SetupControl( const TreeNode& node, Control& actor );
55 #if defined(DEBUG_ENABLED)
56 Integration::Log::Filter* gFilterScript = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_SCRIPT");
62 const std::string KEYNAME_STYLES = "styles";
63 const std::string KEYNAME_TYPE = "type";
64 const std::string KEYNAME_ACTORS = "actors";
65 const std::string KEYNAME_SIGNALS = "signals";
66 const std::string KEYNAME_NAME = "name";
67 const std::string KEYNAME_TEMPLATES = "templates";
68 const std::string KEYNAME_INCLUDES = "includes";
70 typedef std::vector<const TreeNode*> TreeNodeList;
73 std::string ToString(const T& value)
81 std::string ToString(const Rect<int>& value)
84 ss << value.x << "," << value.y << "," << value.width << "," << value.height;
89 std::string PropertyValueToString( const Property::Value& value )
93 switch( value.GetType() )
100 case Property::BOOLEAN:
102 ret = value.Get<bool>() ? "True" : "False";
105 case Property::FLOAT:
108 ret = ToString( value.Get<float>() );
111 case Property::INTEGER:
113 ret = ToString( value.Get<int>() );
116 case Property::UNSIGNED_INTEGER:
118 ret = ToString( value.Get<unsigned int>() );
121 case Property::VECTOR2:
123 ret = ToString( value.Get<Vector2>() );
126 case Property::VECTOR3:
128 ret = ToString( value.Get<Vector3>() );
131 case Property::VECTOR4:
133 ret = ToString( value.Get<Vector4>() );
136 case Property::MATRIX3:
138 ret = ToString( value.Get<Matrix3>() );
141 case Property::MATRIX:
143 ret = ToString( value.Get<Matrix>() );
146 case Property::RECTANGLE:
148 ret = ToString( value.Get< Rect<int> >() );
151 case Property::ROTATION:
155 case Property::STRING:
157 ret = value.Get<std::string>();
160 case Property::ARRAY:
162 ret = std::string("Array Size=") + ToString( value.Get<Property::Array>().size() );
167 ret = std::string("Map Size=") + ToString( value.Get<Property::Map>().size() );
170 case Property::TYPE_COUNT:
181 * Recursively collects all stylesin a node (An array of style names).
183 * stylesCollection The set of styles from the json file (a json object of named styles)
184 * style The style array to begin the collection from
185 * styleList The style list to add nodes to apply
187 void CollectAllStyles( const TreeNode& stylesCollection, const TreeNode& style, TreeNodeList& styleList )
189 // style is an array of style names
190 if( TreeNode::ARRAY == style.GetType() )
192 for(TreeNode::ConstIterator iter = style.CBegin(); iter != style.CEnd(); ++iter)
194 if( OptionalString styleName = IsString( (*iter).second ) )
196 if( OptionalChild node = IsChild( stylesCollection, *styleName) )
198 styleList.push_back( &(*node) );
200 if( OptionalChild subStyle = IsChild( *node, KEYNAME_STYLES ) )
202 CollectAllStyles( stylesCollection, *subStyle, styleList );
213 * Sets the handle properties found in the tree node
215 void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant )
219 for( TreeNode::ConstIterator iter = node.CBegin(); iter != node.CEnd(); ++iter )
221 const TreeNode::KeyNodePair& keyChild = *iter;
223 std::string key( keyChild.first );
225 // ignore special fields; type,actors,signals
226 if(key == KEYNAME_TYPE || key == KEYNAME_ACTORS || key == KEYNAME_SIGNALS || key == KEYNAME_STYLES)
231 // special field 'image' usually contains an json object description
232 // although sometimes refers to a framebuffer
233 if( 0 == keyChild.second.Size() )
237 ImageActor imageActor = ImageActor::DownCast(handle);
240 if( OptionalString s = constant.IsString( keyChild.second ) )
242 FrameBufferImage fb = GetFrameBufferImage(*s, constant);
245 imageActor.SetImage( fb );
252 // special field 'effect' references the shader effect instances
255 Actor actor = Actor::DownCast(handle);
256 OptionalString s = constant.IsString( keyChild.second );
259 ShaderEffect e = GetShaderEffect(*s, constant);
260 actor.SetShaderEffect(e);
264 DALI_SCRIPT_WARNING("Could not find or set shader effect\n");
270 Handle propertyObject( handle );
272 Property::Index index = propertyObject.GetPropertyIndex( key );
274 if( Property::INVALID_INDEX == index )
276 Actor actor = Actor::DownCast(propertyObject);
279 if( ShaderEffect effect = actor.GetShaderEffect() )
281 index = effect.GetPropertyIndex( key );
282 if(index != Property::INVALID_INDEX)
284 propertyObject = effect;
290 if( Property::INVALID_INDEX != index )
292 Property::Type type = propertyObject.GetPropertyType(index);
294 Property::Value value;
295 if( !SetPropertyFromNode( keyChild.second, type, value, constant ) )
297 // verbose as this might not be a problem
298 // eg parent-origin can be a string which is picked up later
299 DALI_SCRIPT_VERBOSE("Could not convert property:%s\n", key.c_str());
303 DALI_SCRIPT_VERBOSE("SetProperty '%s' Index=:%d Value Type=%d Value '%s'\n", key.c_str(), index, value.GetType(), PropertyValueToString(value).c_str() );
305 propertyObject.SetProperty( index, value );
310 DALI_SCRIPT_VERBOSE("SetProperty INVALID '%s' Index=:%d\n", key.c_str(), index);
313 } // for property nodes
317 DALI_SCRIPT_WARNING("Style applied to empty handle\n");
321 // Set properties from node on handle.
322 void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node,
323 Dali::Handle& handle, const Replacement& constant )
325 if( Actor actor = Actor::DownCast(handle) )
327 SetProperties( node, actor, constant );
331 SetupActor( node, actor );
333 Control control = Control::DownCast(actor);
337 SetupControl( node, control );
341 SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor );
343 SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor );
348 SetProperties( node, handle, constant );
352 // Appling by style helper
353 // use FindChildByName() to apply properties referenced in KEYNAME_ACTORS in the node
354 void Builder::ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
355 Dali::Handle& handle, const Replacement& constant )
357 if( Dali::Actor actor = Dali::Actor::DownCast( handle ) )
359 if( const TreeNode* actors = node.GetChild( KEYNAME_ACTORS ) )
361 // in a style the actor subtree properties referenced by actor name
362 for( TreeConstIter iter = actors->CBegin(); iter != actors->CEnd(); ++iter )
364 Dali::Actor foundActor;
368 foundActor = actor.FindChildByName( (*iter).first );
373 // debug log cannot find searched for actor
374 #if defined(DEBUG_ENABLED)
375 DALI_SCRIPT_VERBOSE("Cannot find actor in style application '%s'\n", (*iter).first);
380 #if defined(DEBUG_ENABLED)
381 DALI_SCRIPT_VERBOSE("Styles applied to actor '%s'\n", (*iter).first);
383 ApplyProperties( root, (*iter).second, foundActor, constant );
391 void Builder::ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
392 Dali::Handle& handle, const Replacement& constant )
394 OptionalChild styles = IsChild(root, KEYNAME_STYLES);
395 OptionalChild style = IsChild(node, KEYNAME_STYLES);
397 if( styles && style )
399 TreeNodeList additionalStyles;
401 CollectAllStyles( *styles, *style, additionalStyles );
403 #if defined(DEBUG_ENABLED)
404 for(TreeNode::ConstIterator iter = (*style).CBegin(); iter != (*style).CEnd(); ++iter)
406 if( OptionalString styleName = IsString( (*iter).second ) )
408 DALI_SCRIPT_VERBOSE("Style Applied '%s'\n", (*styleName).c_str());
413 // a style may have other styles, which has other styles etc so we apply in reverse by convention.
414 for(TreeNodeList::reverse_iterator iter = additionalStyles.rbegin(); iter != additionalStyles.rend(); ++iter)
416 ApplyProperties( root, *(*iter), handle, constant );
418 ApplyStylesByActor( root, *(*iter), handle, constant );
422 // applying given node last
423 ApplyProperties( root, node, handle, constant );
425 ApplyStylesByActor( root, node, handle, constant );
431 * Create a dali type from a node.
432 * If parent given and an actor type was created then add it to the parent and
433 * recursively add nodes children.
435 BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
436 Actor parent, const Replacement& replacements )
438 BaseHandle baseHandle;
440 const TreeNode* templateNode = NULL;
442 if( OptionalString typeName = IsString(node, KEYNAME_TYPE) )
444 typeInfo = TypeRegistry::Get().GetTypeInfo( *typeName );
448 // a template name is also allowed inplace of the type name
449 OptionalChild templates = IsChild( root, KEYNAME_TEMPLATES);
453 if( OptionalChild isTemplate = IsChild( *templates, *typeName ) )
455 templateNode = &(*isTemplate);
457 if( OptionalString templateTypeName = IsString(*templateNode, KEYNAME_TYPE) )
459 typeInfo = TypeRegistry::Get().GetTypeInfo( *templateTypeName );
468 DALI_SCRIPT_WARNING("Cannot create Dali type from node '%s'\n", node.GetName());
472 baseHandle = typeInfo.CreateInstance();
473 Handle handle = Handle::DownCast(baseHandle);
474 Actor actor = Actor::DownCast(handle);
475 Control control = Control::DownCast(handle);
480 DALI_SCRIPT_VERBOSE("Create:%s\n", typeInfo.GetName().c_str());
482 #if defined(DEBUG_ENABLED)
485 DALI_SCRIPT_VERBOSE(" Is Handle Object=%d\n", (long*)handle.GetObjectPtr());
486 DALI_SCRIPT_VERBOSE(" Is Handle Property Count=%d\n", handle.GetPropertyCount());
491 DALI_SCRIPT_VERBOSE(" Is Actor id=%d\n", actor.GetId());
496 DALI_SCRIPT_VERBOSE(" Is Control id=%d\n", actor.GetId());
498 #endif // DEBUG_ENABLED
502 ApplyProperties( root, *templateNode, handle, replacements );
504 if( OptionalChild actors = IsChild( *templateNode, KEYNAME_ACTORS ) )
506 for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
508 DoCreate( root, (*iter).second, actor, replacements );
513 ApplyProperties( root, node, handle, replacements );
517 // add children of all the styles
518 if( OptionalChild actors = IsChild( node, KEYNAME_ACTORS ) )
520 for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
522 DoCreate( root, (*iter).second, actor, replacements );
526 // apply style on top as they need the children to exist
527 ApplyAllStyleProperties( root, node, actor, replacements );
529 // then add to parent
539 DALI_SCRIPT_WARNING("Cannot create handle from type '%s'\n", typeInfo.GetName().c_str());
547 ActorContainer Builder::GetTopLevelActors() const
549 // deprecated function.
550 return ActorContainer();
553 Animation Builder::GetAnimation( const std::string &name ) const
559 void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replacement& constant )
561 const Stage& stage = Stage::GetCurrent();
562 Layer root = stage.GetRootLayer();
564 if( OptionalString s = constant.IsString( IsChild(node, "source-actor") ) )
566 Actor actor = root.FindChildByName(*s);
569 task.SetSourceActor( actor );
573 DALI_SCRIPT_WARNING("Cannot find source actor on stage for render task called '%s'\n", (*s).c_str() );
577 if( OptionalString s = constant.IsString( IsChild(node, "camera-actor") ) )
579 CameraActor actor = CameraActor::DownCast( root.FindChildByName(*s) );
582 task.SetCameraActor( actor );
586 DALI_SCRIPT_WARNING("Cannot find camera actor on stage for render task called '%s'\n", (*s).c_str() );
590 if( OptionalString s = constant.IsString( IsChild(node, "target-frame-buffer") ) )
592 FrameBufferImage fb = GetFrameBufferImage( *s, constant );
595 task.SetTargetFrameBuffer( fb );
599 DALI_SCRIPT_WARNING("Cannot find target frame buffer '%s'\n", (*s).c_str() );
603 if( OptionalString s = constant.IsString( IsChild(node, "screen-to-frame-buffer-function") ) )
605 if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s)
607 task.SetScreenToFrameBufferFunction( RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION );
609 else if("FULLSCREEN_FRAMEBUFFER_FUNCTION" == *s)
611 task.SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
615 DALI_SCRIPT_WARNING("todo");
619 // other setup is via the property system
620 SetProperties( node, task, constant ); // @ todo, remove 'source-actor', 'camera-actor'?
624 void Builder::CreateRenderTask( const std::string &name )
626 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
628 Replacement constant(mReplacementMap);
630 const Stage& stage = Stage::GetCurrent();
632 OptionalChild tasks = IsChild(*mParser.GetRoot(), "render-tasks");
637 // Create the tasks from the current task as generally we want
638 // to setup task zero and onwards. Although this does overwrite
639 // the properties of the current task.
641 if( OptionalChild renderTask = IsChild(*tasks, name ) )
643 RenderTaskList list = stage.GetRenderTaskList();
644 unsigned int start = list.GetTaskCount();
649 // zero should have already been created by the stage so really
650 // this case should never happen
651 task = list.CreateTask();
655 TreeNode::ConstIterator iter = (*renderTask).CBegin();
656 task = list.GetTask( start - 1 );
658 SetupTask( task, (*iter).second, constant );
662 for(; iter != (*renderTask).CEnd(); ++iter )
664 task = list.CreateTask();
665 SetupTask( task, (*iter).second, constant );
671 ShaderEffect Builder::GetShaderEffect( const std::string &name)
673 Replacement constant( mReplacementMap );
674 return GetShaderEffect( name, constant );
677 ShaderEffect Builder::GetShaderEffect( const std::string &name, const Replacement& constant )
679 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
683 ShaderEffectLut::const_iterator iter( mShaderEffectLut.find( name ) );
684 if( iter != mShaderEffectLut.end() )
690 if( OptionalChild effects = IsChild( *mParser.GetRoot(), "shader-effects") )
692 if( OptionalChild effect = IsChild( *effects, name ) )
694 Dali::Property::Value propertyMap(Property::MAP);
695 if( SetPropertyFromNode( *effect, Property::MAP, propertyMap, constant ) )
697 ret = Dali::Scripting::NewShaderEffect( propertyMap );
698 mShaderEffectLut[ name ] = ret;
707 FrameBufferImage Builder::GetFrameBufferImage( const std::string &name )
709 Replacement constant( mReplacementMap );
710 return GetFrameBufferImage(name, constant);
713 FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Replacement& constant )
715 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
717 FrameBufferImage ret;
719 ImageLut::const_iterator iter( mFrameBufferImageLut.find( name ) );
720 if( iter != mFrameBufferImageLut.end() )
726 if( OptionalChild images = IsChild( *mParser.GetRoot(), "frame-buffer-images") )
728 if( OptionalChild image = IsChild( *images, name ) )
730 Dali::Property::Value propertyMap(Property::MAP);
731 if( SetPropertyFromNode( *image, Property::MAP, propertyMap, constant ) )
733 propertyMap.SetValue(KEYNAME_TYPE, Property::Value(std::string("FrameBufferImage")));
734 ret = Dali::Scripting::NewImage( propertyMap );
735 mFrameBufferImageLut[ name ] = ret;
744 Font Builder::GetFont( const std::string& name ) const
746 // deprecated function.
751 TextStyle Builder::GetTextStyle( const std::string& name ) const
757 Image Builder::GetImage( const std::string& name) const
759 // deprecated function.
763 Actor Builder::GetActor( const std::string &name ) const
765 // deprecated function.
769 void Builder::AddActors( Actor toActor )
771 // 'stage' is the default/by convention section to add from
772 AddActors( "stage", toActor );
775 void Builder::AddActors( const std::string §ionName, Actor toActor )
777 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
779 PropertyValueMap overrideMap;
780 Replacement replacements(overrideMap, mReplacementMap);
782 OptionalChild add = IsChild(*mParser.GetRoot(), sectionName);
786 for( TreeNode::ConstIterator iter = (*add).CBegin(); iter != (*add).CEnd(); ++iter )
788 // empty actor adds directly to the stage
789 BaseHandle baseHandle = DoCreate( *mParser.GetRoot(), (*iter).second, Actor(), replacements );
790 Actor actor = Actor::DownCast(baseHandle);
793 toActor.Add( actor );
797 // if were adding the 'stage' section then also check for a render task called stage
798 // to add automatically
799 if( "stage" == sectionName )
801 if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "render-tasks") )
803 if( OptionalChild tasks = IsChild(*renderTasks, "stage") )
805 CreateRenderTask( "stage" );
812 Animation Builder::CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor )
814 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
818 if( OptionalChild animations = IsChild(*mParser.GetRoot(), "animations") )
820 if( OptionalChild animation = IsChild(*animations, animationName) )
822 anim = Dali::Toolkit::Internal::CreateAnimation( *animation, replacement, sourceActor );
826 DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed\n", animationName.c_str() );
831 DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed (no animation section)\n", animationName.c_str() );
837 Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map, Dali::Actor sourceActor )
839 Replacement replacement(map, mReplacementMap);
840 return CreateAnimation( animationName, replacement, sourceActor);
843 Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map )
845 Replacement replacement(map, mReplacementMap);
846 return CreateAnimation( animationName, replacement, Stage::GetCurrent().GetRootLayer() );
849 Animation Builder::CreateAnimation( const std::string& animationName, Dali::Actor sourceActor )
851 Replacement replacement( mReplacementMap );
853 return CreateAnimation( animationName, replacement, sourceActor );
856 Animation Builder::CreateAnimation( const std::string& animationName )
858 Replacement replacement( mReplacementMap );
860 return CreateAnimation( animationName, replacement, Dali::Stage::GetCurrent().GetRootLayer() );
863 void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::UIFormat format )
865 DALI_ASSERT_ALWAYS( format == Dali::Toolkit::Builder::JSON && "Currently only JSON is supported" );
867 // parser to get constants and includes only
868 Dali::Toolkit::JsonParser parser = Dali::Toolkit::JsonParser::New();
870 if( !parser.Parse( data ) )
872 DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
873 parser.GetErrorLineNumber(),
874 parser.GetErrorColumn(),
875 parser.GetErrorDescription().c_str() );
877 DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
882 // load constant map (allows the user to override the constants in the json after loading)
883 LoadConstants( *parser.GetRoot(), mReplacementMap );
886 if( OptionalChild includes = IsChild(*parser.GetRoot(), KEYNAME_INCLUDES) )
888 Replacement replacer( mReplacementMap );
890 for(TreeNode::ConstIterator iter = (*includes).CBegin(); iter != (*includes).CEnd(); ++iter)
892 OptionalString filename = replacer.IsString( (*iter).second );
896 #if defined(DEBUG_ENABLED)
897 DALI_SCRIPT_VERBOSE("Loading Include '%s'\n", (*filename).c_str());
899 LoadFromString( GetFileContents(*filename) );
904 if( !mParser.Parse( data ) )
906 DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
907 mParser.GetErrorLineNumber(),
908 mParser.GetErrorColumn(),
909 mParser.GetErrorDescription().c_str() );
911 DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
915 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
919 void Builder::AddConstants( const PropertyValueMap& map )
921 for(PropertyValueMap::const_iterator iter = map.begin(); iter != map.end(); ++iter)
923 mReplacementMap[ (*iter).first ] = (*iter).second;
927 void Builder::AddConstant( const std::string& key, const Property::Value& value )
929 mReplacementMap[key] = value;
932 const PropertyValueMap& Builder::GetConstants() const
934 return mReplacementMap;
937 const Property::Value& Builder::GetConstant( const std::string& key ) const
939 PropertyValueMap::const_iterator iter = mReplacementMap.find( key );
940 if( iter != mReplacementMap.end() )
942 return (*iter).second;
946 static Property::Value invalid;
951 void Builder::LoadConstants( const TreeNode& root, PropertyValueMap& intoMap )
953 Replacement replacer(intoMap);
955 if( OptionalChild constants = IsChild(root, "constants") )
957 for(TreeNode::ConstIterator iter = (*constants).CBegin();
958 iter != (*constants).CEnd(); ++iter)
960 Dali::Property::Value property;
961 if( (*iter).second.GetName() )
963 #if defined(DEBUG_ENABLED)
964 DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName());
966 if( SetPropertyFromNode( (*iter).second, property, replacer ) )
968 intoMap[ (*iter).second.GetName() ] = property;
972 DALI_SCRIPT_WARNING("Cannot convert property for constant %s\n",
973 (*iter).second.GetName() == NULL ? "no name?" : (*iter).second.GetName());
979 #if defined(DEBUG_ENABLED)
980 PropertyValueMap::const_iterator iter = intoMap.find( "CONFIG_SCRIPT_LOG_LEVEL" );
981 if( iter != intoMap.end() && (*iter).second.GetType() == Property::STRING )
983 std::string logLevel( (*iter).second.Get< std::string >() );
984 if( logLevel == "NoLogging" )
986 gFilterScript->SetLogLevel( Integration::Log::NoLogging );
988 else if( logLevel == "Concise" )
990 gFilterScript->SetLogLevel( Integration::Log::Concise );
992 else if( logLevel == "General" )
994 gFilterScript->SetLogLevel( Integration::Log::General );
996 else if( logLevel == "Verbose" )
998 gFilterScript->SetLogLevel( Integration::Log::Verbose );
1005 void Builder::ApplyStyle( const std::string& styleName, Handle& handle )
1007 Replacement replacer( mReplacementMap );
1008 ApplyStyle( styleName, handle, replacer );
1011 void Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement )
1013 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
1015 OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES );
1016 OptionalChild style = IsChild( *styles, styleName );
1018 if( styles && style )
1020 ApplyAllStyleProperties( *mParser.GetRoot(), *style, handle, replacement );
1024 DALI_SCRIPT_WARNING("No styles section to create style '%s'\n", styleName.c_str());
1029 BaseHandle Builder::Create( const std::string& templateName, const PropertyValueMap& map )
1031 Replacement replacement( map, mReplacementMap );
1032 return Create( templateName, replacement );
1035 BaseHandle Builder::Create( const std::string& templateName, const Replacement& constant )
1037 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
1039 BaseHandle baseHandle;
1041 OptionalChild templates = IsChild(*mParser.GetRoot(), KEYNAME_TEMPLATES);
1045 DALI_SCRIPT_WARNING("No template section found to CreateFromTemplate\n");
1049 OptionalChild childTemplate = IsChild(*templates, templateName);
1052 DALI_SCRIPT_WARNING("Template '%s' does not exist in template section\n", templateName.c_str());
1056 OptionalString type = constant.IsString( IsChild(*childTemplate, KEYNAME_TYPE) );
1060 DALI_SCRIPT_WARNING("Cannot create template '%s' as template section is missing 'type'\n", templateName.c_str());
1064 baseHandle = DoCreate( *mParser.GetRoot(), *childTemplate, Actor(), constant );
1073 BaseHandle Builder::Create( const std::string& templateName )
1075 Replacement replacement( mReplacementMap );
1076 return Create( templateName, replacement );
1080 : mSlotDelegate( this )
1082 mParser = Dali::Toolkit::JsonParser::New();
1089 } // namespace Internal
1091 } // namespace Toolkit