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.
19 #include <dali-toolkit/internal/builder/builder-impl.h>
26 #include <dali/dali.h>
27 #include <dali/integration-api/debug.h>
29 #include <dali-toolkit/public-api/controls/control.h>
30 #include <dali-toolkit/public-api/builder/json-parser.h>
32 #include <dali-toolkit/internal/builder/builder-get-is.inl.h>
33 #include <dali-toolkit/internal/builder/builder-filesystem.h>
34 #include <dali-toolkit/internal/builder/builder-declarations.h>
35 #include <dali-toolkit/internal/builder/replacement.h>
47 extern Animation CreateAnimation(const TreeNode& child, const Replacement& replacements, const Dali::Actor searchRoot );
48 extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value );
49 extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& replacements );
50 extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value );
51 extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value, const Replacement& replacements );
52 extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor);
53 extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor);
54 extern Actor SetupActor( const TreeNode& node, Actor& actor, const Replacement& constant );
56 #if defined(DEBUG_ENABLED)
57 Integration::Log::Filter* gFilterScript = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_SCRIPT");
63 const std::string KEYNAME_STYLES = "styles";
64 const std::string KEYNAME_TYPE = "type";
65 const std::string KEYNAME_ACTORS = "actors";
66 const std::string KEYNAME_SIGNALS = "signals";
67 const std::string KEYNAME_NAME = "name";
68 const std::string KEYNAME_TEMPLATES = "templates";
69 const std::string KEYNAME_INCLUDES = "includes";
71 typedef std::vector<const TreeNode*> TreeNodeList;
74 std::string ToString(const T& value)
82 std::string ToString(const Rect<int>& value)
85 ss << value.x << "," << value.y << "," << value.width << "," << value.height;
90 std::string PropertyValueToString( const Property::Value& value )
94 switch( value.GetType() )
101 case Property::BOOLEAN:
103 ret = value.Get<bool>() ? "True" : "False";
106 case Property::FLOAT:
109 ret = ToString( value.Get<float>() );
112 case Property::INTEGER:
114 ret = ToString( value.Get<int>() );
117 case Property::UNSIGNED_INTEGER:
119 ret = ToString( value.Get<unsigned int>() );
122 case Property::VECTOR2:
124 ret = ToString( value.Get<Vector2>() );
127 case Property::VECTOR3:
129 ret = ToString( value.Get<Vector3>() );
132 case Property::VECTOR4:
134 ret = ToString( value.Get<Vector4>() );
137 case Property::MATRIX3:
139 ret = ToString( value.Get<Matrix3>() );
142 case Property::MATRIX:
144 ret = ToString( value.Get<Matrix>() );
147 case Property::RECTANGLE:
149 ret = ToString( value.Get< Rect<int> >() );
152 case Property::ROTATION:
156 case Property::STRING:
158 ret = value.Get<std::string>();
161 case Property::ARRAY:
163 ret = std::string("Array Size=") + ToString( value.Get<Property::Array>().size() );
168 ret = std::string("Map Size=") + ToString( value.Get<Property::Map>().size() );
171 case Property::TYPE_COUNT:
182 * Recursively collects all stylesin a node (An array of style names).
184 * stylesCollection The set of styles from the json file (a json object of named styles)
185 * style The style array to begin the collection from
186 * styleList The style list to add nodes to apply
188 void CollectAllStyles( const TreeNode& stylesCollection, const TreeNode& style, TreeNodeList& styleList )
190 // style is an array of style names
191 if( TreeNode::ARRAY == style.GetType() )
193 for(TreeNode::ConstIterator iter = style.CBegin(); iter != style.CEnd(); ++iter)
195 if( OptionalString styleName = IsString( (*iter).second ) )
197 if( OptionalChild node = IsChild( stylesCollection, *styleName) )
199 styleList.push_back( &(*node) );
201 if( OptionalChild subStyle = IsChild( *node, KEYNAME_STYLES ) )
203 CollectAllStyles( stylesCollection, *subStyle, styleList );
214 * Sets the handle properties found in the tree node
216 void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant )
220 for( TreeNode::ConstIterator iter = node.CBegin(); iter != node.CEnd(); ++iter )
222 const TreeNode::KeyNodePair& keyChild = *iter;
224 std::string key( keyChild.first );
226 // ignore special fields; type,actors,signals,styles
227 if(key == KEYNAME_TYPE || key == KEYNAME_ACTORS || key == KEYNAME_SIGNALS || key == KEYNAME_STYLES)
232 // special field 'image' usually contains an json object description
233 // although sometimes refers to a framebuffer
234 if( 0 == keyChild.second.Size() )
238 ImageActor imageActor = ImageActor::DownCast(handle);
241 if( OptionalString s = constant.IsString( keyChild.second ) )
243 FrameBufferImage fb = GetFrameBufferImage(*s, constant);
246 imageActor.SetImage( fb );
253 // special field 'effect' references the shader effect instances
256 RenderableActor actor = RenderableActor::DownCast(handle);
259 OptionalString str = constant.IsString( keyChild.second );
262 ShaderEffect effect = GetShaderEffect( *str, constant );
263 actor.SetShaderEffect(effect);
268 DALI_SCRIPT_WARNING("Could not find or set shader effect\n");
274 Handle propertyObject( handle );
276 Property::Index index = propertyObject.GetPropertyIndex( key );
278 if( Property::INVALID_INDEX == index )
280 RenderableActor actor = RenderableActor::DownCast(handle);
283 if( ShaderEffect effect = actor.GetShaderEffect() )
285 index = effect.GetPropertyIndex( key );
286 if(index != Property::INVALID_INDEX)
288 propertyObject = effect;
294 if( Property::INVALID_INDEX != index )
296 Property::Type type = propertyObject.GetPropertyType(index);
298 Property::Value value;
299 if( !SetPropertyFromNode( keyChild.second, type, value, constant ) )
301 // verbose as this might not be a problem
302 // eg parent-origin can be a string which is picked up later
303 DALI_SCRIPT_VERBOSE("Could not convert property:%s\n", key.c_str());
307 DALI_SCRIPT_VERBOSE("SetProperty '%s' Index=:%d Value Type=%d Value '%s'\n", key.c_str(), index, value.GetType(), PropertyValueToString(value).c_str() );
309 propertyObject.SetProperty( index, value );
314 DALI_SCRIPT_VERBOSE("SetProperty INVALID '%s' Index=:%d\n", key.c_str(), index);
317 } // for property nodes
321 DALI_SCRIPT_WARNING("Style applied to empty handle\n");
325 // Set properties from node on handle.
326 void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node,
327 Dali::Handle& handle, const Replacement& constant )
329 if( Actor actor = Actor::DownCast(handle) )
331 SetProperties( node, actor, constant );
335 SetupActor( node, actor, constant );
338 SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor );
340 SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor );
345 SetProperties( node, handle, constant );
349 // Appling by style helper
350 // use FindChildByName() to apply properties referenced in KEYNAME_ACTORS in the node
351 void Builder::ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
352 Dali::Handle& handle, const Replacement& constant )
354 if( Dali::Actor actor = Dali::Actor::DownCast( handle ) )
356 if( const TreeNode* actors = node.GetChild( KEYNAME_ACTORS ) )
358 // in a style the actor subtree properties referenced by actor name
359 for( TreeConstIter iter = actors->CBegin(); iter != actors->CEnd(); ++iter )
361 Dali::Actor foundActor;
365 foundActor = actor.FindChildByName( (*iter).first );
370 // debug log cannot find searched for actor
371 #if defined(DEBUG_ENABLED)
372 DALI_SCRIPT_VERBOSE("Cannot find actor in style application '%s'\n", (*iter).first);
377 #if defined(DEBUG_ENABLED)
378 DALI_SCRIPT_VERBOSE("Styles applied to actor '%s'\n", (*iter).first);
380 ApplyProperties( root, (*iter).second, foundActor, constant );
388 void Builder::ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
389 Dali::Handle& handle, const Replacement& constant )
391 OptionalChild styles = IsChild(root, KEYNAME_STYLES);
392 OptionalChild style = IsChild(node, KEYNAME_STYLES);
394 if( styles && style )
396 TreeNodeList additionalStyles;
398 CollectAllStyles( *styles, *style, additionalStyles );
400 #if defined(DEBUG_ENABLED)
401 for(TreeNode::ConstIterator iter = (*style).CBegin(); iter != (*style).CEnd(); ++iter)
403 if( OptionalString styleName = IsString( (*iter).second ) )
405 DALI_SCRIPT_VERBOSE("Style Applied '%s'\n", (*styleName).c_str());
410 // a style may have other styles, which has other styles etc so we apply in reverse by convention.
411 for(TreeNodeList::reverse_iterator iter = additionalStyles.rbegin(); iter != additionalStyles.rend(); ++iter)
413 ApplyProperties( root, *(*iter), handle, constant );
415 ApplyStylesByActor( root, *(*iter), handle, constant );
419 // applying given node last
420 ApplyProperties( root, node, handle, constant );
422 ApplyStylesByActor( root, node, handle, constant );
428 * Create a dali type from a node.
429 * If parent given and an actor type was created then add it to the parent and
430 * recursively add nodes children.
432 BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
433 Actor parent, const Replacement& replacements )
435 BaseHandle baseHandle;
437 const TreeNode* templateNode = NULL;
439 if( OptionalString typeName = IsString(node, KEYNAME_TYPE) )
441 typeInfo = TypeRegistry::Get().GetTypeInfo( *typeName );
445 // a template name is also allowed inplace of the type name
446 OptionalChild templates = IsChild( root, KEYNAME_TEMPLATES);
450 if( OptionalChild isTemplate = IsChild( *templates, *typeName ) )
452 templateNode = &(*isTemplate);
454 if( OptionalString templateTypeName = IsString(*templateNode, KEYNAME_TYPE) )
456 typeInfo = TypeRegistry::Get().GetTypeInfo( *templateTypeName );
465 DALI_SCRIPT_WARNING("Cannot create Dali type from node '%s'\n", node.GetName());
469 baseHandle = typeInfo.CreateInstance();
470 Handle handle = Handle::DownCast(baseHandle);
471 Actor actor = Actor::DownCast(handle);
476 DALI_SCRIPT_VERBOSE("Create:%s\n", typeInfo.GetName().c_str());
478 #if defined(DEBUG_ENABLED)
481 DALI_SCRIPT_VERBOSE(" Is Handle Object=%d\n", (long*)handle.GetObjectPtr());
482 DALI_SCRIPT_VERBOSE(" Is Handle Property Count=%d\n", handle.GetPropertyCount());
487 DALI_SCRIPT_VERBOSE(" Is Actor id=%d\n", actor.GetId());
490 Toolkit::Control control = Toolkit::Control::DownCast(handle);
493 DALI_SCRIPT_VERBOSE(" Is Control id=%d\n", actor.GetId());
495 #endif // DEBUG_ENABLED
499 ApplyProperties( root, *templateNode, handle, replacements );
501 if( OptionalChild actors = IsChild( *templateNode, KEYNAME_ACTORS ) )
503 for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
505 DoCreate( root, (*iter).second, actor, replacements );
512 // add children of all the styles
513 if( OptionalChild actors = IsChild( node, KEYNAME_ACTORS ) )
515 for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
517 DoCreate( root, (*iter).second, actor, replacements );
521 // apply style on top as they need the children to exist
522 ApplyAllStyleProperties( root, node, actor, replacements );
524 // then add to parent
532 ApplyProperties( root, node, handle, replacements );
537 DALI_SCRIPT_WARNING("Cannot create handle from type '%s'\n", typeInfo.GetName().c_str());
544 void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replacement& constant )
546 const Stage& stage = Stage::GetCurrent();
547 Layer root = stage.GetRootLayer();
549 if( OptionalString s = constant.IsString( IsChild(node, "source-actor") ) )
551 Actor actor = root.FindChildByName(*s);
554 task.SetSourceActor( actor );
558 DALI_SCRIPT_WARNING("Cannot find source actor on stage for render task called '%s'\n", (*s).c_str() );
562 if( OptionalString s = constant.IsString( IsChild(node, "camera-actor") ) )
564 CameraActor actor = CameraActor::DownCast( root.FindChildByName(*s) );
567 task.SetCameraActor( actor );
571 DALI_SCRIPT_WARNING("Cannot find camera actor on stage for render task called '%s'\n", (*s).c_str() );
575 if( OptionalString s = constant.IsString( IsChild(node, "target-frame-buffer") ) )
577 FrameBufferImage fb = GetFrameBufferImage( *s, constant );
580 task.SetTargetFrameBuffer( fb );
584 DALI_SCRIPT_WARNING("Cannot find target frame buffer '%s'\n", (*s).c_str() );
588 if( OptionalString s = constant.IsString( IsChild(node, "screen-to-frame-buffer-function") ) )
590 if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s)
592 task.SetScreenToFrameBufferFunction( RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION );
594 else if("FULLSCREEN_FRAMEBUFFER_FUNCTION" == *s)
596 task.SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
600 DALI_SCRIPT_WARNING("todo");
604 // other setup is via the property system
605 SetProperties( node, task, constant ); // @ todo, remove 'source-actor', 'camera-actor'?
609 void Builder::CreateRenderTask( const std::string &name )
611 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
613 Replacement constant(mReplacementMap);
615 const Stage& stage = Stage::GetCurrent();
617 OptionalChild tasks = IsChild(*mParser.GetRoot(), "render-tasks");
622 // Create the tasks from the current task as generally we want
623 // to setup task zero and onwards. Although this does overwrite
624 // the properties of the current task.
626 if( OptionalChild renderTask = IsChild(*tasks, name ) )
628 RenderTaskList list = stage.GetRenderTaskList();
629 unsigned int start = list.GetTaskCount();
634 // zero should have already been created by the stage so really
635 // this case should never happen
636 task = list.CreateTask();
640 TreeNode::ConstIterator iter = (*renderTask).CBegin();
641 task = list.GetTask( start - 1 );
643 SetupTask( task, (*iter).second, constant );
647 for(; iter != (*renderTask).CEnd(); ++iter )
649 task = list.CreateTask();
650 SetupTask( task, (*iter).second, constant );
656 ShaderEffect Builder::GetShaderEffect( const std::string &name)
658 Replacement constant( mReplacementMap );
659 return GetShaderEffect( name, constant );
662 ShaderEffect Builder::GetShaderEffect( const std::string &name, const Replacement& constant )
664 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
668 ShaderEffectLut::const_iterator iter( mShaderEffectLut.find( name ) );
669 if( iter != mShaderEffectLut.end() )
675 if( OptionalChild effects = IsChild( *mParser.GetRoot(), "shader-effects") )
677 if( OptionalChild effect = IsChild( *effects, name ) )
679 Dali::Property::Value propertyMap(Property::MAP);
680 if( SetPropertyFromNode( *effect, Property::MAP, propertyMap, constant ) )
682 ret = Dali::Scripting::NewShaderEffect( propertyMap );
683 mShaderEffectLut[ name ] = ret;
692 FrameBufferImage Builder::GetFrameBufferImage( const std::string &name )
694 Replacement constant( mReplacementMap );
695 return GetFrameBufferImage(name, constant);
698 FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Replacement& constant )
700 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
702 FrameBufferImage ret;
704 ImageLut::const_iterator iter( mFrameBufferImageLut.find( name ) );
705 if( iter != mFrameBufferImageLut.end() )
711 if( OptionalChild images = IsChild( *mParser.GetRoot(), "frame-buffer-images") )
713 if( OptionalChild image = IsChild( *images, name ) )
715 Dali::Property::Value propertyMap(Property::MAP);
716 if( SetPropertyFromNode( *image, Property::MAP, propertyMap, constant ) )
718 propertyMap.SetValue(KEYNAME_TYPE, Property::Value(std::string("FrameBufferImage")));
719 ret = FrameBufferImage::DownCast( Dali::Scripting::NewImage( propertyMap ) );
720 mFrameBufferImageLut[ name ] = ret;
729 void Builder::AddActors( Actor toActor )
731 // 'stage' is the default/by convention section to add from
732 AddActors( "stage", toActor );
735 void Builder::AddActors( const std::string §ionName, Actor toActor )
737 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
739 PropertyValueMap overrideMap;
740 Replacement replacements(overrideMap, mReplacementMap);
742 OptionalChild add = IsChild(*mParser.GetRoot(), sectionName);
746 for( TreeNode::ConstIterator iter = (*add).CBegin(); iter != (*add).CEnd(); ++iter )
748 // empty actor adds directly to the stage
749 BaseHandle baseHandle = DoCreate( *mParser.GetRoot(), (*iter).second, Actor(), replacements );
750 Actor actor = Actor::DownCast(baseHandle);
753 toActor.Add( actor );
757 // if were adding the 'stage' section then also check for a render task called stage
758 // to add automatically
759 if( "stage" == sectionName )
761 if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "render-tasks") )
763 if( OptionalChild tasks = IsChild(*renderTasks, "stage") )
765 CreateRenderTask( "stage" );
772 Animation Builder::CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor )
774 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
778 if( OptionalChild animations = IsChild(*mParser.GetRoot(), "animations") )
780 if( OptionalChild animation = IsChild(*animations, animationName) )
782 anim = Dali::Toolkit::Internal::CreateAnimation( *animation, replacement, sourceActor );
786 DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed\n", animationName.c_str() );
791 DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed (no animation section)\n", animationName.c_str() );
797 Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map, Dali::Actor sourceActor )
799 Replacement replacement(map, mReplacementMap);
800 return CreateAnimation( animationName, replacement, sourceActor);
803 Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map )
805 Replacement replacement(map, mReplacementMap);
806 return CreateAnimation( animationName, replacement, Stage::GetCurrent().GetRootLayer() );
809 Animation Builder::CreateAnimation( const std::string& animationName, Dali::Actor sourceActor )
811 Replacement replacement( mReplacementMap );
813 return CreateAnimation( animationName, replacement, sourceActor );
816 Animation Builder::CreateAnimation( const std::string& animationName )
818 Replacement replacement( mReplacementMap );
820 return CreateAnimation( animationName, replacement, Dali::Stage::GetCurrent().GetRootLayer() );
823 void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::UIFormat format )
825 DALI_ASSERT_ALWAYS( format == Dali::Toolkit::Builder::JSON && "Currently only JSON is supported" );
827 // parser to get constants and includes only
828 Dali::Toolkit::JsonParser parser = Dali::Toolkit::JsonParser::New();
830 if( !parser.Parse( data ) )
832 DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
833 parser.GetErrorLineNumber(),
834 parser.GetErrorColumn(),
835 parser.GetErrorDescription().c_str() );
837 DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
842 // load constant map (allows the user to override the constants in the json after loading)
843 LoadConstants( *parser.GetRoot(), mReplacementMap );
846 if( OptionalChild includes = IsChild(*parser.GetRoot(), KEYNAME_INCLUDES) )
848 Replacement replacer( mReplacementMap );
850 for(TreeNode::ConstIterator iter = (*includes).CBegin(); iter != (*includes).CEnd(); ++iter)
852 OptionalString filename = replacer.IsString( (*iter).second );
856 #if defined(DEBUG_ENABLED)
857 DALI_SCRIPT_VERBOSE("Loading Include '%s'\n", (*filename).c_str());
859 LoadFromString( GetFileContents(*filename) );
864 if( !mParser.Parse( data ) )
866 DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
867 mParser.GetErrorLineNumber(),
868 mParser.GetErrorColumn(),
869 mParser.GetErrorDescription().c_str() );
871 DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
875 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
879 void Builder::AddConstants( const PropertyValueMap& map )
881 for(PropertyValueMap::const_iterator iter = map.begin(); iter != map.end(); ++iter)
883 mReplacementMap[ (*iter).first ] = (*iter).second;
887 void Builder::AddConstant( const std::string& key, const Property::Value& value )
889 mReplacementMap[key] = value;
892 const PropertyValueMap& Builder::GetConstants() const
894 return mReplacementMap;
897 const Property::Value& Builder::GetConstant( const std::string& key ) const
899 PropertyValueMap::const_iterator iter = mReplacementMap.find( key );
900 if( iter != mReplacementMap.end() )
902 return (*iter).second;
906 static Property::Value invalid;
911 void Builder::LoadConstants( const TreeNode& root, PropertyValueMap& intoMap )
913 Replacement replacer(intoMap);
915 if( OptionalChild constants = IsChild(root, "constants") )
917 for(TreeNode::ConstIterator iter = (*constants).CBegin();
918 iter != (*constants).CEnd(); ++iter)
920 Dali::Property::Value property;
921 if( (*iter).second.GetName() )
923 #if defined(DEBUG_ENABLED)
924 DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName());
926 if( SetPropertyFromNode( (*iter).second, property, replacer ) )
928 intoMap[ (*iter).second.GetName() ] = property;
932 DALI_SCRIPT_WARNING("Cannot convert property for constant %s\n",
933 (*iter).second.GetName() == NULL ? "no name?" : (*iter).second.GetName());
939 #if defined(DEBUG_ENABLED)
940 PropertyValueMap::const_iterator iter = intoMap.find( "CONFIG_SCRIPT_LOG_LEVEL" );
941 if( iter != intoMap.end() && (*iter).second.GetType() == Property::STRING )
943 std::string logLevel( (*iter).second.Get< std::string >() );
944 if( logLevel == "NoLogging" )
946 gFilterScript->SetLogLevel( Integration::Log::NoLogging );
948 else if( logLevel == "Concise" )
950 gFilterScript->SetLogLevel( Integration::Log::Concise );
952 else if( logLevel == "General" )
954 gFilterScript->SetLogLevel( Integration::Log::General );
956 else if( logLevel == "Verbose" )
958 gFilterScript->SetLogLevel( Integration::Log::Verbose );
965 bool Builder::ApplyStyle( const std::string& styleName, Handle& handle )
967 Replacement replacer( mReplacementMap );
968 return ApplyStyle( styleName, handle, replacer );
971 bool Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement )
973 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
975 OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES );
976 OptionalChild style = IsChild( *styles, styleName );
978 if( styles && style )
980 ApplyAllStyleProperties( *mParser.GetRoot(), *style, handle, replacement );
985 DALI_SCRIPT_WARNING("No styles section to create style '%s'\n", styleName.c_str());
990 BaseHandle Builder::Create( const std::string& templateName, const PropertyValueMap& map )
992 Replacement replacement( map, mReplacementMap );
993 return Create( templateName, replacement );
996 BaseHandle Builder::Create( const std::string& templateName, const Replacement& constant )
998 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
1000 BaseHandle baseHandle;
1002 OptionalChild templates = IsChild(*mParser.GetRoot(), KEYNAME_TEMPLATES);
1006 DALI_SCRIPT_WARNING("No template section found to CreateFromTemplate\n");
1010 OptionalChild childTemplate = IsChild(*templates, templateName);
1013 DALI_SCRIPT_WARNING("Template '%s' does not exist in template section\n", templateName.c_str());
1017 OptionalString type = constant.IsString( IsChild(*childTemplate, KEYNAME_TYPE) );
1021 DALI_SCRIPT_WARNING("Cannot create template '%s' as template section is missing 'type'\n", templateName.c_str());
1025 baseHandle = DoCreate( *mParser.GetRoot(), *childTemplate, Actor(), constant );
1034 BaseHandle Builder::Create( const std::string& templateName )
1036 Replacement replacement( mReplacementMap );
1037 return Create( templateName, replacement );
1041 : mSlotDelegate( this )
1043 mParser = Dali::Toolkit::JsonParser::New();
1050 } // namespace Internal
1052 } // namespace Toolkit