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 Property::Index index = handle.GetPropertyIndex(key);
272 if( Property::INVALID_INDEX != index )
274 Property::Type type = handle.GetPropertyType(index);
276 Property::Value value;
277 if( !SetPropertyFromNode( keyChild.second, type, value, constant ) )
279 // verbose as this might not be a problem
280 // eg parent-origin can be a string which is picked up later
281 DALI_SCRIPT_VERBOSE("Could not convert property:%s\n", key.c_str());
285 DALI_SCRIPT_VERBOSE("SetProperty '%s' Index=:%d Value Type=%d Value '%s'\n", key.c_str(), index, value.GetType(), PropertyValueToString(value).c_str() );
287 handle.SetProperty( index, value );
292 DALI_SCRIPT_VERBOSE("SetProperty INVALID '%s' Index=:%d\n", key.c_str(), index);
295 } // for property nodes
299 DALI_SCRIPT_WARNING("Style applied to empty handle\n");
303 // Set properties from node on handle.
304 void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node,
305 Dali::Handle& handle, const Replacement& constant )
307 if( Actor actor = Actor::DownCast(handle) )
309 SetProperties( node, actor, constant );
313 SetupActor( node, actor );
315 Control control = Control::DownCast(actor);
319 SetupControl( node, control );
323 SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor );
325 SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor );
330 SetProperties( node, handle, constant );
334 // Appling by style helper
335 // use FindChildByName() to apply properties referenced in KEYNAME_ACTORS in the node
336 void Builder::ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
337 Dali::Handle& handle, const Replacement& constant )
339 if( Dali::Actor actor = Dali::Actor::DownCast( handle ) )
341 if( const TreeNode* actors = node.GetChild( KEYNAME_ACTORS ) )
343 // in a style the actor subtree properties referenced by actor name
344 for( TreeConstIter iter = actors->CBegin(); iter != actors->CEnd(); ++iter )
346 Dali::Actor foundActor;
350 foundActor = actor.FindChildByName( (*iter).first );
355 // debug log cannot find searched for actor
356 #if defined(DEBUG_ENABLED)
357 DALI_SCRIPT_VERBOSE("Cannot find actor in style application '%s'\n", (*iter).first);
362 #if defined(DEBUG_ENABLED)
363 DALI_SCRIPT_VERBOSE("Styles applied to actor '%s'\n", (*iter).first);
365 ApplyProperties( root, (*iter).second, foundActor, constant );
373 void Builder::ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
374 Dali::Handle& handle, const Replacement& constant )
376 OptionalChild styles = IsChild(root, KEYNAME_STYLES);
377 OptionalChild style = IsChild(node, KEYNAME_STYLES);
379 if( styles && style )
381 TreeNodeList additionalStyles;
383 CollectAllStyles( *styles, *style, additionalStyles );
385 #if defined(DEBUG_ENABLED)
386 for(TreeNode::ConstIterator iter = (*style).CBegin(); iter != (*style).CEnd(); ++iter)
388 if( OptionalString styleName = IsString( (*iter).second ) )
390 DALI_SCRIPT_VERBOSE("Style Applied '%s'\n", (*styleName).c_str());
395 // a style may have other styles, which has other styles etc so we apply in reverse by convention.
396 for(TreeNodeList::reverse_iterator iter = additionalStyles.rbegin(); iter != additionalStyles.rend(); ++iter)
398 ApplyProperties( root, *(*iter), handle, constant );
400 ApplyStylesByActor( root, *(*iter), handle, constant );
404 // applying given node last
405 ApplyProperties( root, node, handle, constant );
407 ApplyStylesByActor( root, node, handle, constant );
413 * Create a dali type from a node.
414 * If parent given and an actor type was created then add it to the parent and
415 * recursively add nodes children.
417 BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
418 Actor parent, const Replacement& replacements )
420 BaseHandle baseHandle;
422 const TreeNode* templateNode = NULL;
424 if( OptionalString typeName = IsString(node, KEYNAME_TYPE) )
426 typeInfo = TypeRegistry::Get().GetTypeInfo( *typeName );
430 // a template name is also allowed inplace of the type name
431 OptionalChild templates = IsChild( root, KEYNAME_TEMPLATES);
435 if( OptionalChild isTemplate = IsChild( *templates, *typeName ) )
437 templateNode = &(*isTemplate);
439 if( OptionalString templateTypeName = IsString(*templateNode, KEYNAME_TYPE) )
441 typeInfo = TypeRegistry::Get().GetTypeInfo( *templateTypeName );
450 DALI_SCRIPT_WARNING("Cannot create Dali type from node '%s'\n", node.GetName());
454 baseHandle = typeInfo.CreateInstance();
455 Handle handle = Handle::DownCast(baseHandle);
456 Actor actor = Actor::DownCast(handle);
457 Control control = Control::DownCast(handle);
462 DALI_SCRIPT_VERBOSE("Create:%s\n", typeInfo.GetName().c_str());
464 #if defined(DEBUG_ENABLED)
467 DALI_SCRIPT_VERBOSE(" Is Handle Object=%d\n", (long*)handle.GetObjectPtr());
468 DALI_SCRIPT_VERBOSE(" Is Handle Property Count=%d\n", handle.GetPropertyCount());
473 DALI_SCRIPT_VERBOSE(" Is Actor id=%d\n", actor.GetId());
478 DALI_SCRIPT_VERBOSE(" Is Control id=%d\n", actor.GetId());
480 #endif // DEBUG_ENABLED
484 ApplyProperties( root, *templateNode, handle, replacements );
486 if( OptionalChild actors = IsChild( *templateNode, KEYNAME_ACTORS ) )
488 for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
490 DoCreate( root, (*iter).second, actor, replacements );
495 ApplyProperties( root, node, handle, replacements );
499 // add children of all the styles
500 if( OptionalChild actors = IsChild( node, KEYNAME_ACTORS ) )
502 for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
504 DoCreate( root, (*iter).second, actor, replacements );
508 // apply style on top as they need the children to exist
509 ApplyAllStyleProperties( root, node, actor, replacements );
511 // then add to parent
521 DALI_SCRIPT_WARNING("Cannot create handle from type '%s'\n", typeInfo.GetName().c_str());
529 ActorContainer Builder::GetTopLevelActors() const
531 // deprecated function.
532 return ActorContainer();
535 Animation Builder::GetAnimation( const std::string &name ) const
541 void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replacement& constant )
543 const Stage& stage = Stage::GetCurrent();
544 Layer root = stage.GetRootLayer();
546 if( OptionalString s = constant.IsString( IsChild(node, "source-actor") ) )
548 Actor actor = root.FindChildByName(*s);
551 task.SetSourceActor( actor );
555 DALI_SCRIPT_WARNING("Cannot find source actor on stage for render task called '%s'\n", (*s).c_str() );
559 if( OptionalString s = constant.IsString( IsChild(node, "camera-actor") ) )
561 CameraActor actor = CameraActor::DownCast( root.FindChildByName(*s) );
564 task.SetCameraActor( actor );
568 DALI_SCRIPT_WARNING("Cannot find camera actor on stage for render task called '%s'\n", (*s).c_str() );
572 if( OptionalString s = constant.IsString( IsChild(node, "target-frame-buffer") ) )
574 FrameBufferImage fb = GetFrameBufferImage( *s, constant );
577 task.SetTargetFrameBuffer( fb );
581 DALI_SCRIPT_WARNING("Cannot find target frame buffer '%s'\n", (*s).c_str() );
585 if( OptionalString s = constant.IsString( IsChild(node, "screen-to-frame-buffer-function") ) )
587 if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s)
589 task.SetScreenToFrameBufferFunction( RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION );
591 else if("FULLSCREEN_FRAMEBUFFER_FUNCTION" == *s)
593 task.SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
597 DALI_SCRIPT_WARNING("todo");
601 // other setup is via the property system
602 SetProperties( node, task, constant ); // @ todo, remove 'source-actor', 'camera-actor'?
606 void Builder::CreateRenderTask( const std::string &name )
608 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
610 Replacement constant(mReplacementMap);
612 const Stage& stage = Stage::GetCurrent();
614 OptionalChild tasks = IsChild(*mParser.GetRoot(), "render-tasks");
619 // Create the tasks from the current task as generally we want
620 // to setup task zero and onwards. Although this does overwrite
621 // the properties of the current task.
623 if( OptionalChild renderTask = IsChild(*tasks, name ) )
625 RenderTaskList list = stage.GetRenderTaskList();
626 unsigned int start = list.GetTaskCount();
631 // zero should have already been created by the stage so really
632 // this case should never happen
633 task = list.CreateTask();
637 TreeNode::ConstIterator iter = (*renderTask).CBegin();
638 task = list.GetTask( start - 1 );
640 SetupTask( task, (*iter).second, constant );
644 for(; iter != (*renderTask).CEnd(); ++iter )
646 task = list.CreateTask();
647 SetupTask( task, (*iter).second, constant );
653 ShaderEffect Builder::GetShaderEffect( const std::string &name)
655 Replacement constant( mReplacementMap );
656 return GetShaderEffect( name, constant );
659 ShaderEffect Builder::GetShaderEffect( const std::string &name, const Replacement& constant )
661 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
665 ShaderEffectLut::const_iterator iter( mShaderEffectLut.find( name ) );
666 if( iter != mShaderEffectLut.end() )
672 if( OptionalChild effects = IsChild( *mParser.GetRoot(), "shader-effects") )
674 if( OptionalChild effect = IsChild( *effects, name ) )
676 Dali::Property::Value propertyMap(Property::MAP);
677 if( SetPropertyFromNode( *effect, Property::MAP, propertyMap, constant ) )
679 ret = Dali::Scripting::NewShaderEffect( propertyMap );
680 mShaderEffectLut[ name ] = ret;
689 FrameBufferImage Builder::GetFrameBufferImage( const std::string &name )
691 Replacement constant( mReplacementMap );
692 return GetFrameBufferImage(name, constant);
695 FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Replacement& constant )
697 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
699 FrameBufferImage ret;
701 ImageLut::const_iterator iter( mFrameBufferImageLut.find( name ) );
702 if( iter != mFrameBufferImageLut.end() )
708 if( OptionalChild images = IsChild( *mParser.GetRoot(), "frame-buffer-images") )
710 if( OptionalChild image = IsChild( *images, name ) )
712 Dali::Property::Value propertyMap(Property::MAP);
713 if( SetPropertyFromNode( *image, Property::MAP, propertyMap, constant ) )
715 propertyMap.SetValue(KEYNAME_TYPE, Property::Value(std::string("FrameBufferImage")));
716 ret = Dali::Scripting::NewImage( propertyMap );
717 mFrameBufferImageLut[ name ] = ret;
726 Font Builder::GetFont( const std::string& name ) const
728 // deprecated function.
733 TextStyle Builder::GetTextStyle( const std::string& name ) const
739 Image Builder::GetImage( const std::string& name) const
741 // deprecated function.
745 Actor Builder::GetActor( const std::string &name ) const
747 // deprecated function.
751 void Builder::AddActors( Actor toActor )
753 // 'stage' is the default/by convention section to add from
754 AddActors( "stage", toActor );
757 void Builder::AddActors( const std::string §ionName, Actor toActor )
759 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
761 PropertyValueMap overrideMap;
762 Replacement replacements(overrideMap, mReplacementMap);
764 OptionalChild add = IsChild(*mParser.GetRoot(), sectionName);
768 for( TreeNode::ConstIterator iter = (*add).CBegin(); iter != (*add).CEnd(); ++iter )
770 // empty actor adds directly to the stage
771 BaseHandle baseHandle = DoCreate( *mParser.GetRoot(), (*iter).second, Actor(), replacements );
772 Actor actor = Actor::DownCast(baseHandle);
775 toActor.Add( actor );
779 // if were adding the 'stage' section then also check for a render task called stage
780 // to add automatically
781 if( "stage" == sectionName )
783 if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "render-tasks") )
785 if( OptionalChild tasks = IsChild(*renderTasks, "stage") )
787 CreateRenderTask( "stage" );
794 Animation Builder::CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor )
796 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
800 if( OptionalChild animations = IsChild(*mParser.GetRoot(), "animations") )
802 if( OptionalChild animation = IsChild(*animations, animationName) )
804 anim = Dali::Toolkit::Internal::CreateAnimation( *animation, replacement, sourceActor );
808 DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed\n", animationName.c_str() );
813 DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed (no animation section)\n", animationName.c_str() );
819 Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map, Dali::Actor sourceActor )
821 Replacement replacement(map, mReplacementMap);
822 return CreateAnimation( animationName, replacement, sourceActor);
825 Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map )
827 Replacement replacement(map, mReplacementMap);
828 return CreateAnimation( animationName, replacement, Stage::GetCurrent().GetRootLayer() );
831 Animation Builder::CreateAnimation( const std::string& animationName, Dali::Actor sourceActor )
833 Replacement replacement( mReplacementMap );
835 return CreateAnimation( animationName, replacement, sourceActor );
838 Animation Builder::CreateAnimation( const std::string& animationName )
840 Replacement replacement( mReplacementMap );
842 return CreateAnimation( animationName, replacement, Dali::Stage::GetCurrent().GetRootLayer() );
845 void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::UIFormat format )
847 DALI_ASSERT_ALWAYS( format == Dali::Toolkit::Builder::JSON && "Currently only JSON is supported" );
849 // parser to get constants and includes only
850 Dali::Toolkit::JsonParser parser = Dali::Toolkit::JsonParser::New();
852 if( !parser.Parse( data ) )
854 DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
855 parser.GetErrorLineNumber(),
856 parser.GetErrorColumn(),
857 parser.GetErrorDescription().c_str() );
859 DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
864 // load constant map (allows the user to override the constants in the json after loading)
865 LoadConstants( *parser.GetRoot(), mReplacementMap );
868 if( OptionalChild includes = IsChild(*parser.GetRoot(), KEYNAME_INCLUDES) )
870 Replacement replacer( mReplacementMap );
872 for(TreeNode::ConstIterator iter = (*includes).CBegin(); iter != (*includes).CEnd(); ++iter)
874 OptionalString filename = replacer.IsString( (*iter).second );
878 #if defined(DEBUG_ENABLED)
879 DALI_SCRIPT_VERBOSE("Loading Include '%s'\n", (*filename).c_str());
881 LoadFromString( GetFileContents(*filename) );
886 if( !mParser.Parse( data ) )
888 DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
889 mParser.GetErrorLineNumber(),
890 mParser.GetErrorColumn(),
891 mParser.GetErrorDescription().c_str() );
893 DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
897 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
901 void Builder::AddConstants( const PropertyValueMap& map )
903 for(PropertyValueMap::const_iterator iter = map.begin(); iter != map.end(); ++iter)
905 mReplacementMap[ (*iter).first ] = (*iter).second;
909 void Builder::AddConstant( const std::string& key, const Property::Value& value )
911 mReplacementMap[key] = value;
914 const PropertyValueMap& Builder::GetConstants() const
916 return mReplacementMap;
919 const Property::Value& Builder::GetConstant( const std::string& key ) const
921 PropertyValueMap::const_iterator iter = mReplacementMap.find( key );
922 if( iter != mReplacementMap.end() )
924 return (*iter).second;
928 static Property::Value invalid;
933 void Builder::LoadConstants( const TreeNode& root, PropertyValueMap& intoMap )
935 Replacement replacer(intoMap);
937 if( OptionalChild constants = IsChild(root, "constants") )
939 for(TreeNode::ConstIterator iter = (*constants).CBegin();
940 iter != (*constants).CEnd(); ++iter)
942 Dali::Property::Value property;
943 if( (*iter).second.GetName() )
945 #if defined(DEBUG_ENABLED)
946 DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName());
948 if( SetPropertyFromNode( (*iter).second, property, replacer ) )
950 intoMap[ (*iter).second.GetName() ] = property;
954 DALI_SCRIPT_WARNING("Cannot convert property for constant %s\n",
955 (*iter).second.GetName() == NULL ? "no name?" : (*iter).second.GetName());
961 #if defined(DEBUG_ENABLED)
962 PropertyValueMap::const_iterator iter = intoMap.find( "CONFIG_SCRIPT_LOG_LEVEL" );
963 if( iter != intoMap.end() && (*iter).second.GetType() == Property::STRING )
965 std::string logLevel( (*iter).second.Get< std::string >() );
966 if( logLevel == "NoLogging" )
968 gFilterScript->SetLogLevel( Integration::Log::NoLogging );
970 else if( logLevel == "Concise" )
972 gFilterScript->SetLogLevel( Integration::Log::Concise );
974 else if( logLevel == "General" )
976 gFilterScript->SetLogLevel( Integration::Log::General );
978 else if( logLevel == "Verbose" )
980 gFilterScript->SetLogLevel( Integration::Log::Verbose );
987 void Builder::ApplyStyle( const std::string& styleName, Handle& handle )
989 Replacement replacer( mReplacementMap );
990 ApplyStyle( styleName, handle, replacer );
993 void Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement )
995 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
997 OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES );
998 OptionalChild style = IsChild( *styles, styleName );
1000 if( styles && style )
1002 ApplyAllStyleProperties( *mParser.GetRoot(), *style, handle, replacement );
1006 DALI_SCRIPT_WARNING("No styles section to create style '%s'\n", styleName.c_str());
1011 BaseHandle Builder::Create( const std::string& templateName, const PropertyValueMap& map )
1013 Replacement replacement( map, mReplacementMap );
1014 return Create( templateName, replacement );
1017 BaseHandle Builder::Create( const std::string& templateName, const Replacement& constant )
1019 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
1021 BaseHandle baseHandle;
1023 OptionalChild templates = IsChild(*mParser.GetRoot(), KEYNAME_TEMPLATES);
1027 DALI_SCRIPT_WARNING("No template section found to CreateFromTemplate\n");
1031 OptionalChild childTemplate = IsChild(*templates, templateName);
1034 DALI_SCRIPT_WARNING("Template '%s' does not exist in template section\n", templateName.c_str());
1038 OptionalString type = constant.IsString( IsChild(*childTemplate, KEYNAME_TYPE) );
1042 DALI_SCRIPT_WARNING("Cannot create template '%s' as template section is missing 'type'\n", templateName.c_str());
1046 baseHandle = DoCreate( *mParser.GetRoot(), *childTemplate, Actor(), constant );
1055 BaseHandle Builder::Create( const std::string& templateName )
1057 Replacement replacement( mReplacementMap );
1058 return Create( templateName, replacement );
1062 : mSlotDelegate( this )
1064 mParser = Dali::Toolkit::JsonParser::New();
1071 } // namespace Internal
1073 } // namespace Toolkit