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>
23 #include <boost/function.hpp>
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, boost::function<void (void)> quitAction);
53 extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function<void (void)> quitAction);
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;
89 #if defined(DEBUG_ENABLED)
91 std::string PropertyValueToString( const Property::Value& value )
95 switch( value.GetType() )
102 case Property::BOOLEAN:
104 ret = value.Get<bool>() ? "True" : "False";
107 case Property::FLOAT:
110 ret = ToString( value.Get<float>() );
113 case Property::INTEGER:
115 ret = ToString( value.Get<int>() );
118 case Property::UNSIGNED_INTEGER:
120 ret = ToString( value.Get<unsigned int>() );
123 case Property::VECTOR2:
125 ret = ToString( value.Get<Vector2>() );
128 case Property::VECTOR3:
130 ret = ToString( value.Get<Vector3>() );
133 case Property::VECTOR4:
135 ret = ToString( value.Get<Vector4>() );
138 case Property::MATRIX3:
140 ret = ToString( value.Get<Matrix3>() );
143 case Property::MATRIX:
145 ret = ToString( value.Get<Matrix>() );
148 case Property::RECTANGLE:
150 ret = ToString( value.Get< Rect<int> >() );
153 case Property::ROTATION:
157 case Property::STRING:
159 ret = value.Get<std::string>();
162 case Property::ARRAY:
164 ret = std::string("Array Size=") + ToString( value.Get<Property::Array>().size() );
169 ret = std::string("Map Size=") + ToString( value.Get<Property::Map>().Count() );
172 case Property::TYPE_COUNT:
181 #endif // DEBUG_ENABLED
184 * Recursively collects all stylesin a node (An array of style names).
186 * stylesCollection The set of styles from the json file (a json object of named styles)
187 * style The style array to begin the collection from
188 * styleList The style list to add nodes to apply
190 void CollectAllStyles( const TreeNode& stylesCollection, const TreeNode& style, TreeNodeList& styleList )
192 // style is an array of style names
193 if( TreeNode::ARRAY == style.GetType() )
195 for(TreeNode::ConstIterator iter = style.CBegin(); iter != style.CEnd(); ++iter)
197 if( OptionalString styleName = IsString( (*iter).second ) )
199 if( OptionalChild node = IsChild( stylesCollection, *styleName) )
201 styleList.push_back( &(*node) );
203 if( OptionalChild subStyle = IsChild( *node, KEYNAME_STYLES ) )
205 CollectAllStyles( stylesCollection, *subStyle, styleList );
216 QuitAction( Builder& builder )
217 : mBuilder( builder )
221 void operator()(void)
223 mBuilder.EmitQuitSignal();
233 * Sets the handle properties found in the tree node
235 void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant )
239 for( TreeNode::ConstIterator iter = node.CBegin(); iter != node.CEnd(); ++iter )
241 const TreeNode::KeyNodePair& keyChild = *iter;
243 std::string key( keyChild.first );
245 // ignore special fields; type,actors,signals,styles
246 if(key == KEYNAME_TYPE || key == KEYNAME_ACTORS || key == KEYNAME_SIGNALS || key == KEYNAME_STYLES)
251 // special field 'image' usually contains an json object description
252 // although sometimes refers to a framebuffer
253 if( 0 == keyChild.second.Size() )
257 ImageActor imageActor = ImageActor::DownCast(handle);
260 if( OptionalString s = constant.IsString( keyChild.second ) )
262 FrameBufferImage fb = GetFrameBufferImage(*s, constant);
265 imageActor.SetImage( fb );
272 // special field 'effect' references the shader effect instances
275 RenderableActor actor = RenderableActor::DownCast(handle);
278 OptionalString str = constant.IsString( keyChild.second );
281 ShaderEffect effect = GetShaderEffect( *str, constant );
282 actor.SetShaderEffect(effect);
287 DALI_SCRIPT_WARNING("Could not find or set shader effect\n");
293 Handle propertyObject( handle );
295 Property::Index index = propertyObject.GetPropertyIndex( key );
297 if( Property::INVALID_INDEX == index )
299 RenderableActor actor = RenderableActor::DownCast(handle);
302 if( ShaderEffect effect = actor.GetShaderEffect() )
304 index = effect.GetPropertyIndex( key );
305 if(index != Property::INVALID_INDEX)
307 propertyObject = effect;
313 if( Property::INVALID_INDEX != index )
315 Property::Type type = propertyObject.GetPropertyType(index);
317 Property::Value value;
318 if( !SetPropertyFromNode( keyChild.second, type, value, constant ) )
320 // verbose as this might not be a problem
321 // eg parent-origin can be a string which is picked up later
322 DALI_SCRIPT_VERBOSE("Could not convert property:%s\n", key.c_str());
326 DALI_SCRIPT_VERBOSE("SetProperty '%s' Index=:%d Value Type=%d Value '%s'\n", key.c_str(), index, value.GetType(), PropertyValueToString(value).c_str() );
328 propertyObject.SetProperty( index, value );
333 DALI_SCRIPT_VERBOSE("SetProperty INVALID '%s' Index=:%d\n", key.c_str(), index);
336 } // for property nodes
340 DALI_SCRIPT_WARNING("Style applied to empty handle\n");
344 // Set properties from node on handle.
345 void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node,
346 Dali::Handle& handle, const Replacement& constant )
348 if( Actor actor = Actor::DownCast(handle) )
350 SetProperties( node, actor, constant );
354 SetupActor( node, actor, constant );
357 QuitAction quitAction( *this );
358 SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor, quitAction );
359 SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor, quitAction );
364 SetProperties( node, handle, constant );
368 // Appling by style helper
369 // use FindChildByName() to apply properties referenced in KEYNAME_ACTORS in the node
370 void Builder::ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
371 Dali::Handle& handle, const Replacement& constant )
373 if( Dali::Actor actor = Dali::Actor::DownCast( handle ) )
375 if( const TreeNode* actors = node.GetChild( KEYNAME_ACTORS ) )
377 // in a style the actor subtree properties referenced by actor name
378 for( TreeConstIter iter = actors->CBegin(); iter != actors->CEnd(); ++iter )
380 Dali::Actor foundActor;
384 foundActor = actor.FindChildByName( (*iter).first );
389 // debug log cannot find searched for actor
390 #if defined(DEBUG_ENABLED)
391 DALI_SCRIPT_VERBOSE("Cannot find actor in style application '%s'\n", (*iter).first);
396 #if defined(DEBUG_ENABLED)
397 DALI_SCRIPT_VERBOSE("Styles applied to actor '%s'\n", (*iter).first);
399 ApplyProperties( root, (*iter).second, foundActor, constant );
407 void Builder::ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
408 Dali::Handle& handle, const Replacement& constant )
410 OptionalChild styles = IsChild(root, KEYNAME_STYLES);
411 OptionalChild style = IsChild(node, KEYNAME_STYLES);
413 if( styles && style )
415 TreeNodeList additionalStyles;
417 CollectAllStyles( *styles, *style, additionalStyles );
419 #if defined(DEBUG_ENABLED)
420 for(TreeNode::ConstIterator iter = (*style).CBegin(); iter != (*style).CEnd(); ++iter)
422 if( OptionalString styleName = IsString( (*iter).second ) )
424 DALI_SCRIPT_VERBOSE("Style Applied '%s'\n", (*styleName).c_str());
429 // a style may have other styles, which has other styles etc so we apply in reverse by convention.
430 for(TreeNodeList::reverse_iterator iter = additionalStyles.rbegin(); iter != additionalStyles.rend(); ++iter)
432 ApplyProperties( root, *(*iter), handle, constant );
434 ApplyStylesByActor( root, *(*iter), handle, constant );
438 // applying given node last
439 ApplyProperties( root, node, handle, constant );
441 ApplyStylesByActor( root, node, handle, constant );
447 * Create a dali type from a node.
448 * If parent given and an actor type was created then add it to the parent and
449 * recursively add nodes children.
451 BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
452 Actor parent, const Replacement& replacements )
454 BaseHandle baseHandle;
456 const TreeNode* templateNode = NULL;
458 if( OptionalString typeName = IsString(node, KEYNAME_TYPE) )
460 typeInfo = TypeRegistry::Get().GetTypeInfo( *typeName );
464 // a template name is also allowed inplace of the type name
465 OptionalChild templates = IsChild( root, KEYNAME_TEMPLATES);
469 if( OptionalChild isTemplate = IsChild( *templates, *typeName ) )
471 templateNode = &(*isTemplate);
473 if( OptionalString templateTypeName = IsString(*templateNode, KEYNAME_TYPE) )
475 typeInfo = TypeRegistry::Get().GetTypeInfo( *templateTypeName );
484 DALI_SCRIPT_WARNING("Cannot create Dali type from node '%s'\n", node.GetName());
488 baseHandle = typeInfo.CreateInstance();
489 Handle handle = Handle::DownCast(baseHandle);
490 Actor actor = Actor::DownCast(handle);
495 DALI_SCRIPT_VERBOSE("Create:%s\n", typeInfo.GetName().c_str());
497 #if defined(DEBUG_ENABLED)
500 DALI_SCRIPT_VERBOSE(" Is Handle Object=%d\n", (long*)handle.GetObjectPtr());
501 DALI_SCRIPT_VERBOSE(" Is Handle Property Count=%d\n", handle.GetPropertyCount());
506 DALI_SCRIPT_VERBOSE(" Is Actor id=%d\n", actor.GetId());
509 Toolkit::Control control = Toolkit::Control::DownCast(handle);
512 DALI_SCRIPT_VERBOSE(" Is Control id=%d\n", actor.GetId());
514 #endif // DEBUG_ENABLED
518 ApplyProperties( root, *templateNode, handle, replacements );
520 if( OptionalChild actors = IsChild( *templateNode, KEYNAME_ACTORS ) )
522 for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
524 DoCreate( root, (*iter).second, actor, replacements );
531 // add children of all the styles
532 if( OptionalChild actors = IsChild( node, KEYNAME_ACTORS ) )
534 for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
536 DoCreate( root, (*iter).second, actor, replacements );
540 // apply style on top as they need the children to exist
541 ApplyAllStyleProperties( root, node, actor, replacements );
543 // then add to parent
551 ApplyProperties( root, node, handle, replacements );
556 DALI_SCRIPT_WARNING("Cannot create handle from type '%s'\n", typeInfo.GetName().c_str());
563 void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replacement& constant )
565 const Stage& stage = Stage::GetCurrent();
566 Layer root = stage.GetRootLayer();
568 if( OptionalString s = constant.IsString( IsChild(node, "source-actor") ) )
570 Actor actor = root.FindChildByName(*s);
573 task.SetSourceActor( actor );
577 DALI_SCRIPT_WARNING("Cannot find source actor on stage for render task called '%s'\n", (*s).c_str() );
581 if( OptionalString s = constant.IsString( IsChild(node, "camera-actor") ) )
583 CameraActor actor = CameraActor::DownCast( root.FindChildByName(*s) );
586 task.SetCameraActor( actor );
590 DALI_SCRIPT_WARNING("Cannot find camera actor on stage for render task called '%s'\n", (*s).c_str() );
594 if( OptionalString s = constant.IsString( IsChild(node, "target-frame-buffer") ) )
596 FrameBufferImage fb = GetFrameBufferImage( *s, constant );
599 task.SetTargetFrameBuffer( fb );
603 DALI_SCRIPT_WARNING("Cannot find target frame buffer '%s'\n", (*s).c_str() );
607 if( OptionalString s = constant.IsString( IsChild(node, "screen-to-frame-buffer-function") ) )
609 if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s)
611 task.SetScreenToFrameBufferFunction( RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION );
613 else if("FULLSCREEN_FRAMEBUFFER_FUNCTION" == *s)
615 task.SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
619 DALI_SCRIPT_WARNING("todo");
623 // other setup is via the property system
624 SetProperties( node, task, constant ); // @ todo, remove 'source-actor', 'camera-actor'?
628 void Builder::CreateRenderTask( const std::string &name )
630 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
632 Replacement constant(mReplacementMap);
634 const Stage& stage = Stage::GetCurrent();
636 OptionalChild tasks = IsChild(*mParser.GetRoot(), "render-tasks");
641 // Create the tasks from the current task as generally we want
642 // to setup task zero and onwards. Although this does overwrite
643 // the properties of the current task.
645 if( OptionalChild renderTask = IsChild(*tasks, name ) )
647 RenderTaskList list = stage.GetRenderTaskList();
648 unsigned int start = list.GetTaskCount();
653 // zero should have already been created by the stage so really
654 // this case should never happen
655 task = list.CreateTask();
659 TreeNode::ConstIterator iter = (*renderTask).CBegin();
660 task = list.GetTask( start - 1 );
662 SetupTask( task, (*iter).second, constant );
666 for(; iter != (*renderTask).CEnd(); ++iter )
668 task = list.CreateTask();
669 SetupTask( task, (*iter).second, constant );
675 ShaderEffect Builder::GetShaderEffect( const std::string &name)
677 Replacement constant( mReplacementMap );
678 return GetShaderEffect( name, constant );
681 ShaderEffect Builder::GetShaderEffect( const std::string &name, const Replacement& constant )
683 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
687 ShaderEffectLut::const_iterator iter( mShaderEffectLut.find( name ) );
688 if( iter != mShaderEffectLut.end() )
694 if( OptionalChild effects = IsChild( *mParser.GetRoot(), "shader-effects") )
696 if( OptionalChild effect = IsChild( *effects, name ) )
698 Dali::Property::Value propertyMap(Property::MAP);
699 if( SetPropertyFromNode( *effect, Property::MAP, propertyMap, constant ) )
701 ret = Dali::Scripting::NewShaderEffect( propertyMap );
702 mShaderEffectLut[ name ] = ret;
711 FrameBufferImage Builder::GetFrameBufferImage( const std::string &name )
713 Replacement constant( mReplacementMap );
714 return GetFrameBufferImage(name, constant);
717 FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Replacement& constant )
719 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
721 FrameBufferImage ret;
723 ImageLut::const_iterator iter( mFrameBufferImageLut.find( name ) );
724 if( iter != mFrameBufferImageLut.end() )
730 if( OptionalChild images = IsChild( *mParser.GetRoot(), "frame-buffer-images") )
732 if( OptionalChild image = IsChild( *images, name ) )
734 Dali::Property::Value propertyMap(Property::MAP);
735 if( SetPropertyFromNode( *image, Property::MAP, propertyMap, constant ) )
737 propertyMap.SetValue(KEYNAME_TYPE, Property::Value(std::string("FrameBufferImage")));
738 ret = FrameBufferImage::DownCast( Dali::Scripting::NewImage( propertyMap ) );
739 mFrameBufferImageLut[ name ] = ret;
748 Toolkit::Builder::Signal& Builder::QuitSignal()
753 void Builder::EmitQuitSignal()
758 void Builder::AddActors( Actor toActor )
760 // 'stage' is the default/by convention section to add from
761 AddActors( "stage", toActor );
764 void Builder::AddActors( const std::string §ionName, Actor toActor )
766 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
768 Property::Map overrideMap;
769 Replacement replacements(overrideMap, mReplacementMap);
771 OptionalChild add = IsChild(*mParser.GetRoot(), sectionName);
775 for( TreeNode::ConstIterator iter = (*add).CBegin(); iter != (*add).CEnd(); ++iter )
777 // empty actor adds directly to the stage
778 BaseHandle baseHandle = DoCreate( *mParser.GetRoot(), (*iter).second, Actor(), replacements );
779 Actor actor = Actor::DownCast(baseHandle);
782 toActor.Add( actor );
786 // if were adding the 'stage' section then also check for a render task called stage
787 // to add automatically
788 if( "stage" == sectionName )
790 if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "render-tasks") )
792 if( OptionalChild tasks = IsChild(*renderTasks, "stage") )
794 CreateRenderTask( "stage" );
801 Animation Builder::CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor )
803 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
807 if( OptionalChild animations = IsChild(*mParser.GetRoot(), "animations") )
809 if( OptionalChild animation = IsChild(*animations, animationName) )
811 anim = Dali::Toolkit::Internal::CreateAnimation( *animation, replacement, sourceActor );
815 DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed\n", animationName.c_str() );
820 DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed (no animation section)\n", animationName.c_str() );
826 Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map, Dali::Actor sourceActor )
828 Replacement replacement(map, mReplacementMap);
829 return CreateAnimation( animationName, replacement, sourceActor);
832 Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map )
834 Replacement replacement(map, mReplacementMap);
835 return CreateAnimation( animationName, replacement, Stage::GetCurrent().GetRootLayer() );
838 Animation Builder::CreateAnimation( const std::string& animationName, Dali::Actor sourceActor )
840 Replacement replacement( mReplacementMap );
842 return CreateAnimation( animationName, replacement, sourceActor );
845 Animation Builder::CreateAnimation( const std::string& animationName )
847 Replacement replacement( mReplacementMap );
849 return CreateAnimation( animationName, replacement, Dali::Stage::GetCurrent().GetRootLayer() );
852 void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::UIFormat format )
854 // parser to get constants and includes only
855 Dali::Toolkit::JsonParser parser = Dali::Toolkit::JsonParser::New();
857 if( !parser.Parse( data ) )
859 DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
860 parser.GetErrorLineNumber(),
861 parser.GetErrorColumn(),
862 parser.GetErrorDescription().c_str() );
864 DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
869 // load constant map (allows the user to override the constants in the json after loading)
870 LoadConstants( *parser.GetRoot(), mReplacementMap );
873 if( OptionalChild includes = IsChild(*parser.GetRoot(), KEYNAME_INCLUDES) )
875 Replacement replacer( mReplacementMap );
877 for(TreeNode::ConstIterator iter = (*includes).CBegin(); iter != (*includes).CEnd(); ++iter)
879 OptionalString filename = replacer.IsString( (*iter).second );
883 #if defined(DEBUG_ENABLED)
884 DALI_SCRIPT_VERBOSE("Loading Include '%s'\n", (*filename).c_str());
886 LoadFromString( GetFileContents(*filename) );
891 if( !mParser.Parse( data ) )
893 DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
894 mParser.GetErrorLineNumber(),
895 mParser.GetErrorColumn(),
896 mParser.GetErrorDescription().c_str() );
898 DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
902 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
906 void Builder::AddConstants( const Property::Map& map )
908 mReplacementMap.Merge( map );
911 void Builder::AddConstant( const std::string& key, const Property::Value& value )
913 mReplacementMap[key] = value;
916 const Property::Map& Builder::GetConstants() const
918 return mReplacementMap;
921 const Property::Value& Builder::GetConstant( const std::string& key ) const
923 Property::Value* match = mReplacementMap.Find( key );
930 static Property::Value invalid;
935 void Builder::LoadConstants( const TreeNode& root, Property::Map& intoMap )
937 Replacement replacer(intoMap);
939 if( OptionalChild constants = IsChild(root, "constants") )
941 for(TreeNode::ConstIterator iter = (*constants).CBegin();
942 iter != (*constants).CEnd(); ++iter)
944 Dali::Property::Value property;
945 if( (*iter).second.GetName() )
947 #if defined(DEBUG_ENABLED)
948 DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName());
950 if( SetPropertyFromNode( (*iter).second, property, replacer ) )
952 intoMap[ (*iter).second.GetName() ] = property;
956 DALI_SCRIPT_WARNING("Cannot convert property for constant %s\n",
957 (*iter).second.GetName() == NULL ? "no name?" : (*iter).second.GetName());
963 #if defined(DEBUG_ENABLED)
964 Property::Value* iter = intoMap.Find( "CONFIG_SCRIPT_LOG_LEVEL" );
965 if( iter && iter->GetType() == Property::STRING )
967 std::string logLevel( iter->Get< std::string >() );
968 if( logLevel == "NoLogging" )
970 gFilterScript->SetLogLevel( Integration::Log::NoLogging );
972 else if( logLevel == "Concise" )
974 gFilterScript->SetLogLevel( Integration::Log::Concise );
976 else if( logLevel == "General" )
978 gFilterScript->SetLogLevel( Integration::Log::General );
980 else if( logLevel == "Verbose" )
982 gFilterScript->SetLogLevel( Integration::Log::Verbose );
989 bool Builder::ApplyStyle( const std::string& styleName, Handle& handle )
991 Replacement replacer( mReplacementMap );
992 return ApplyStyle( styleName, handle, replacer );
995 bool Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement )
997 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
999 OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES );
1000 OptionalChild style = IsChild( *styles, styleName );
1002 if( styles && style )
1004 ApplyAllStyleProperties( *mParser.GetRoot(), *style, handle, replacement );
1013 BaseHandle Builder::Create( const std::string& templateName, const Property::Map& map )
1015 Replacement replacement( map, mReplacementMap );
1016 return Create( templateName, replacement );
1019 BaseHandle Builder::Create( const std::string& templateName, const Replacement& constant )
1021 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
1023 BaseHandle baseHandle;
1025 OptionalChild templates = IsChild(*mParser.GetRoot(), KEYNAME_TEMPLATES);
1029 DALI_SCRIPT_WARNING("No template section found to CreateFromTemplate\n");
1033 OptionalChild childTemplate = IsChild(*templates, templateName);
1036 DALI_SCRIPT_WARNING("Template '%s' does not exist in template section\n", templateName.c_str());
1040 OptionalString type = constant.IsString( IsChild(*childTemplate, KEYNAME_TYPE) );
1044 DALI_SCRIPT_WARNING("Cannot create template '%s' as template section is missing 'type'\n", templateName.c_str());
1048 baseHandle = DoCreate( *mParser.GetRoot(), *childTemplate, Actor(), constant );
1056 BaseHandle Builder::CreateFromJson( const std::string& json )
1060 // merge in new template, hoping no one else has one named '@temp@'
1061 std::string newTemplate =
1062 std::string("{\"templates\":{\"@temp@\":") + \
1066 if( mParser.Parse(newTemplate) )
1068 Replacement replacement( mReplacementMap );
1069 ret = Create( "@temp@", replacement );
1075 bool Builder::ApplyFromJson( Handle& handle, const std::string& json )
1079 // merge new style, hoping no one else has one named '@temp@'
1080 std::string newStyle =
1081 std::string("{\"styles\":{\"@temp@\":") + \
1085 if( mParser.Parse(newStyle) )
1087 Replacement replacement( mReplacementMap );
1088 ret = ApplyStyle( "@temp@", handle, replacement );
1095 BaseHandle Builder::Create( const std::string& templateName )
1097 Replacement replacement( mReplacementMap );
1098 return Create( templateName, replacement );
1102 : mSlotDelegate( this )
1104 mParser = Dali::Toolkit::JsonParser::New();
1111 } // namespace Internal
1113 } // namespace Toolkit