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/dali.h>
28 #include <dali/integration-api/debug.h>
30 #include <dali-toolkit/public-api/controls/control.h>
31 #include <dali-toolkit/public-api/builder/json-parser.h>
33 #include <dali-toolkit/internal/builder/builder-get-is.inl.h>
34 #include <dali-toolkit/internal/builder/builder-filesystem.h>
35 #include <dali-toolkit/internal/builder/builder-declarations.h>
36 #include <dali-toolkit/internal/builder/replacement.h>
48 extern Animation CreateAnimation(const TreeNode& child, const Replacement& replacements, const Dali::Actor searchRoot );
49 extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value );
50 extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& replacements );
51 extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value );
52 extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value, const Replacement& replacements );
53 extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function<void (void)> quitAction);
54 extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function<void (void)> quitAction);
55 extern Actor SetupActor( const TreeNode& node, Actor& actor, const Replacement& constant );
57 #if defined(DEBUG_ENABLED)
58 Integration::Log::Filter* gFilterScript = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_SCRIPT");
64 const std::string KEYNAME_STYLES = "styles";
65 const std::string KEYNAME_TYPE = "type";
66 const std::string KEYNAME_ACTORS = "actors";
67 const std::string KEYNAME_SIGNALS = "signals";
68 const std::string KEYNAME_NAME = "name";
69 const std::string KEYNAME_TEMPLATES = "templates";
70 const std::string KEYNAME_INCLUDES = "includes";
72 typedef std::vector<const TreeNode*> TreeNodeList;
75 std::string ToString(const T& value)
83 std::string ToString(const Rect<int>& value)
86 ss << value.x << "," << value.y << "," << value.width << "," << value.height;
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>().size() );
172 case Property::TYPE_COUNT:
183 * Recursively collects all stylesin a node (An array of style names).
185 * stylesCollection The set of styles from the json file (a json object of named styles)
186 * style The style array to begin the collection from
187 * styleList The style list to add nodes to apply
189 void CollectAllStyles( const TreeNode& stylesCollection, const TreeNode& style, TreeNodeList& styleList )
191 // style is an array of style names
192 if( TreeNode::ARRAY == style.GetType() )
194 for(TreeNode::ConstIterator iter = style.CBegin(); iter != style.CEnd(); ++iter)
196 if( OptionalString styleName = IsString( (*iter).second ) )
198 if( OptionalChild node = IsChild( stylesCollection, *styleName) )
200 styleList.push_back( &(*node) );
202 if( OptionalChild subStyle = IsChild( *node, KEYNAME_STYLES ) )
204 CollectAllStyles( stylesCollection, *subStyle, styleList );
215 QuitAction( Builder& builder )
216 : mBuilder( builder )
220 void operator()(void)
222 mBuilder.EmitQuitSignal();
232 * Sets the handle properties found in the tree node
234 void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant )
238 for( TreeNode::ConstIterator iter = node.CBegin(); iter != node.CEnd(); ++iter )
240 const TreeNode::KeyNodePair& keyChild = *iter;
242 std::string key( keyChild.first );
244 // ignore special fields; type,actors,signals,styles
245 if(key == KEYNAME_TYPE || key == KEYNAME_ACTORS || key == KEYNAME_SIGNALS || key == KEYNAME_STYLES)
250 // special field 'image' usually contains an json object description
251 // although sometimes refers to a framebuffer
252 if( 0 == keyChild.second.Size() )
256 ImageActor imageActor = ImageActor::DownCast(handle);
259 if( OptionalString s = constant.IsString( keyChild.second ) )
261 FrameBufferImage fb = GetFrameBufferImage(*s, constant);
264 imageActor.SetImage( fb );
271 // special field 'effect' references the shader effect instances
274 RenderableActor actor = RenderableActor::DownCast(handle);
277 OptionalString str = constant.IsString( keyChild.second );
280 ShaderEffect effect = GetShaderEffect( *str, constant );
281 actor.SetShaderEffect(effect);
286 DALI_SCRIPT_WARNING("Could not find or set shader effect\n");
292 Handle propertyObject( handle );
294 Property::Index index = propertyObject.GetPropertyIndex( key );
296 if( Property::INVALID_INDEX == index )
298 RenderableActor actor = RenderableActor::DownCast(handle);
301 if( ShaderEffect effect = actor.GetShaderEffect() )
303 index = effect.GetPropertyIndex( key );
304 if(index != Property::INVALID_INDEX)
306 propertyObject = effect;
312 if( Property::INVALID_INDEX != index )
314 Property::Type type = propertyObject.GetPropertyType(index);
316 Property::Value value;
317 if( !SetPropertyFromNode( keyChild.second, type, value, constant ) )
319 // verbose as this might not be a problem
320 // eg parent-origin can be a string which is picked up later
321 DALI_SCRIPT_VERBOSE("Could not convert property:%s\n", key.c_str());
325 DALI_SCRIPT_VERBOSE("SetProperty '%s' Index=:%d Value Type=%d Value '%s'\n", key.c_str(), index, value.GetType(), PropertyValueToString(value).c_str() );
327 propertyObject.SetProperty( index, value );
332 DALI_SCRIPT_VERBOSE("SetProperty INVALID '%s' Index=:%d\n", key.c_str(), index);
335 } // for property nodes
339 DALI_SCRIPT_WARNING("Style applied to empty handle\n");
343 // Set properties from node on handle.
344 void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node,
345 Dali::Handle& handle, const Replacement& constant )
347 if( Actor actor = Actor::DownCast(handle) )
349 SetProperties( node, actor, constant );
353 SetupActor( node, actor, constant );
356 QuitAction quitAction( *this );
357 SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor, quitAction );
358 SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor, quitAction );
363 SetProperties( node, handle, constant );
367 // Appling by style helper
368 // use FindChildByName() to apply properties referenced in KEYNAME_ACTORS in the node
369 void Builder::ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
370 Dali::Handle& handle, const Replacement& constant )
372 if( Dali::Actor actor = Dali::Actor::DownCast( handle ) )
374 if( const TreeNode* actors = node.GetChild( KEYNAME_ACTORS ) )
376 // in a style the actor subtree properties referenced by actor name
377 for( TreeConstIter iter = actors->CBegin(); iter != actors->CEnd(); ++iter )
379 Dali::Actor foundActor;
383 foundActor = actor.FindChildByName( (*iter).first );
388 // debug log cannot find searched for actor
389 #if defined(DEBUG_ENABLED)
390 DALI_SCRIPT_VERBOSE("Cannot find actor in style application '%s'\n", (*iter).first);
395 #if defined(DEBUG_ENABLED)
396 DALI_SCRIPT_VERBOSE("Styles applied to actor '%s'\n", (*iter).first);
398 ApplyProperties( root, (*iter).second, foundActor, constant );
406 void Builder::ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
407 Dali::Handle& handle, const Replacement& constant )
409 OptionalChild styles = IsChild(root, KEYNAME_STYLES);
410 OptionalChild style = IsChild(node, KEYNAME_STYLES);
412 if( styles && style )
414 TreeNodeList additionalStyles;
416 CollectAllStyles( *styles, *style, additionalStyles );
418 #if defined(DEBUG_ENABLED)
419 for(TreeNode::ConstIterator iter = (*style).CBegin(); iter != (*style).CEnd(); ++iter)
421 if( OptionalString styleName = IsString( (*iter).second ) )
423 DALI_SCRIPT_VERBOSE("Style Applied '%s'\n", (*styleName).c_str());
428 // a style may have other styles, which has other styles etc so we apply in reverse by convention.
429 for(TreeNodeList::reverse_iterator iter = additionalStyles.rbegin(); iter != additionalStyles.rend(); ++iter)
431 ApplyProperties( root, *(*iter), handle, constant );
433 ApplyStylesByActor( root, *(*iter), handle, constant );
437 // applying given node last
438 ApplyProperties( root, node, handle, constant );
440 ApplyStylesByActor( root, node, handle, constant );
446 * Create a dali type from a node.
447 * If parent given and an actor type was created then add it to the parent and
448 * recursively add nodes children.
450 BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
451 Actor parent, const Replacement& replacements )
453 BaseHandle baseHandle;
455 const TreeNode* templateNode = NULL;
457 if( OptionalString typeName = IsString(node, KEYNAME_TYPE) )
459 typeInfo = TypeRegistry::Get().GetTypeInfo( *typeName );
463 // a template name is also allowed inplace of the type name
464 OptionalChild templates = IsChild( root, KEYNAME_TEMPLATES);
468 if( OptionalChild isTemplate = IsChild( *templates, *typeName ) )
470 templateNode = &(*isTemplate);
472 if( OptionalString templateTypeName = IsString(*templateNode, KEYNAME_TYPE) )
474 typeInfo = TypeRegistry::Get().GetTypeInfo( *templateTypeName );
483 DALI_SCRIPT_WARNING("Cannot create Dali type from node '%s'\n", node.GetName());
487 baseHandle = typeInfo.CreateInstance();
488 Handle handle = Handle::DownCast(baseHandle);
489 Actor actor = Actor::DownCast(handle);
494 DALI_SCRIPT_VERBOSE("Create:%s\n", typeInfo.GetName().c_str());
496 #if defined(DEBUG_ENABLED)
499 DALI_SCRIPT_VERBOSE(" Is Handle Object=%d\n", (long*)handle.GetObjectPtr());
500 DALI_SCRIPT_VERBOSE(" Is Handle Property Count=%d\n", handle.GetPropertyCount());
505 DALI_SCRIPT_VERBOSE(" Is Actor id=%d\n", actor.GetId());
508 Toolkit::Control control = Toolkit::Control::DownCast(handle);
511 DALI_SCRIPT_VERBOSE(" Is Control id=%d\n", actor.GetId());
513 #endif // DEBUG_ENABLED
517 ApplyProperties( root, *templateNode, handle, replacements );
519 if( OptionalChild actors = IsChild( *templateNode, KEYNAME_ACTORS ) )
521 for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
523 DoCreate( root, (*iter).second, actor, replacements );
530 // add children of all the styles
531 if( OptionalChild actors = IsChild( node, KEYNAME_ACTORS ) )
533 for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
535 DoCreate( root, (*iter).second, actor, replacements );
539 // apply style on top as they need the children to exist
540 ApplyAllStyleProperties( root, node, actor, replacements );
542 // then add to parent
550 ApplyProperties( root, node, handle, replacements );
555 DALI_SCRIPT_WARNING("Cannot create handle from type '%s'\n", typeInfo.GetName().c_str());
562 void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replacement& constant )
564 const Stage& stage = Stage::GetCurrent();
565 Layer root = stage.GetRootLayer();
567 if( OptionalString s = constant.IsString( IsChild(node, "source-actor") ) )
569 Actor actor = root.FindChildByName(*s);
572 task.SetSourceActor( actor );
576 DALI_SCRIPT_WARNING("Cannot find source actor on stage for render task called '%s'\n", (*s).c_str() );
580 if( OptionalString s = constant.IsString( IsChild(node, "camera-actor") ) )
582 CameraActor actor = CameraActor::DownCast( root.FindChildByName(*s) );
585 task.SetCameraActor( actor );
589 DALI_SCRIPT_WARNING("Cannot find camera actor on stage for render task called '%s'\n", (*s).c_str() );
593 if( OptionalString s = constant.IsString( IsChild(node, "target-frame-buffer") ) )
595 FrameBufferImage fb = GetFrameBufferImage( *s, constant );
598 task.SetTargetFrameBuffer( fb );
602 DALI_SCRIPT_WARNING("Cannot find target frame buffer '%s'\n", (*s).c_str() );
606 if( OptionalString s = constant.IsString( IsChild(node, "screen-to-frame-buffer-function") ) )
608 if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s)
610 task.SetScreenToFrameBufferFunction( RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION );
612 else if("FULLSCREEN_FRAMEBUFFER_FUNCTION" == *s)
614 task.SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
618 DALI_SCRIPT_WARNING("todo");
622 // other setup is via the property system
623 SetProperties( node, task, constant ); // @ todo, remove 'source-actor', 'camera-actor'?
627 void Builder::CreateRenderTask( const std::string &name )
629 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
631 Replacement constant(mReplacementMap);
633 const Stage& stage = Stage::GetCurrent();
635 OptionalChild tasks = IsChild(*mParser.GetRoot(), "render-tasks");
640 // Create the tasks from the current task as generally we want
641 // to setup task zero and onwards. Although this does overwrite
642 // the properties of the current task.
644 if( OptionalChild renderTask = IsChild(*tasks, name ) )
646 RenderTaskList list = stage.GetRenderTaskList();
647 unsigned int start = list.GetTaskCount();
652 // zero should have already been created by the stage so really
653 // this case should never happen
654 task = list.CreateTask();
658 TreeNode::ConstIterator iter = (*renderTask).CBegin();
659 task = list.GetTask( start - 1 );
661 SetupTask( task, (*iter).second, constant );
665 for(; iter != (*renderTask).CEnd(); ++iter )
667 task = list.CreateTask();
668 SetupTask( task, (*iter).second, constant );
674 ShaderEffect Builder::GetShaderEffect( const std::string &name)
676 Replacement constant( mReplacementMap );
677 return GetShaderEffect( name, constant );
680 ShaderEffect Builder::GetShaderEffect( const std::string &name, const Replacement& constant )
682 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
686 ShaderEffectLut::const_iterator iter( mShaderEffectLut.find( name ) );
687 if( iter != mShaderEffectLut.end() )
693 if( OptionalChild effects = IsChild( *mParser.GetRoot(), "shader-effects") )
695 if( OptionalChild effect = IsChild( *effects, name ) )
697 Dali::Property::Value propertyMap(Property::MAP);
698 if( SetPropertyFromNode( *effect, Property::MAP, propertyMap, constant ) )
700 ret = Dali::Scripting::NewShaderEffect( propertyMap );
701 mShaderEffectLut[ name ] = ret;
710 FrameBufferImage Builder::GetFrameBufferImage( const std::string &name )
712 Replacement constant( mReplacementMap );
713 return GetFrameBufferImage(name, constant);
716 FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Replacement& constant )
718 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
720 FrameBufferImage ret;
722 ImageLut::const_iterator iter( mFrameBufferImageLut.find( name ) );
723 if( iter != mFrameBufferImageLut.end() )
729 if( OptionalChild images = IsChild( *mParser.GetRoot(), "frame-buffer-images") )
731 if( OptionalChild image = IsChild( *images, name ) )
733 Dali::Property::Value propertyMap(Property::MAP);
734 if( SetPropertyFromNode( *image, Property::MAP, propertyMap, constant ) )
736 propertyMap.SetValue(KEYNAME_TYPE, Property::Value(std::string("FrameBufferImage")));
737 ret = FrameBufferImage::DownCast( Dali::Scripting::NewImage( propertyMap ) );
738 mFrameBufferImageLut[ name ] = ret;
747 Toolkit::Builder::Signal& Builder::QuitSignal()
752 void Builder::EmitQuitSignal()
757 void Builder::AddActors( Actor toActor )
759 // 'stage' is the default/by convention section to add from
760 AddActors( "stage", toActor );
763 void Builder::AddActors( const std::string §ionName, Actor toActor )
765 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
767 PropertyValueMap overrideMap;
768 Replacement replacements(overrideMap, mReplacementMap);
770 OptionalChild add = IsChild(*mParser.GetRoot(), sectionName);
774 for( TreeNode::ConstIterator iter = (*add).CBegin(); iter != (*add).CEnd(); ++iter )
776 // empty actor adds directly to the stage
777 BaseHandle baseHandle = DoCreate( *mParser.GetRoot(), (*iter).second, Actor(), replacements );
778 Actor actor = Actor::DownCast(baseHandle);
781 toActor.Add( actor );
785 // if were adding the 'stage' section then also check for a render task called stage
786 // to add automatically
787 if( "stage" == sectionName )
789 if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "render-tasks") )
791 if( OptionalChild tasks = IsChild(*renderTasks, "stage") )
793 CreateRenderTask( "stage" );
800 Animation Builder::CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor )
802 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
806 if( OptionalChild animations = IsChild(*mParser.GetRoot(), "animations") )
808 if( OptionalChild animation = IsChild(*animations, animationName) )
810 anim = Dali::Toolkit::Internal::CreateAnimation( *animation, replacement, sourceActor );
814 DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed\n", animationName.c_str() );
819 DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed (no animation section)\n", animationName.c_str() );
825 Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map, Dali::Actor sourceActor )
827 Replacement replacement(map, mReplacementMap);
828 return CreateAnimation( animationName, replacement, sourceActor);
831 Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map )
833 Replacement replacement(map, mReplacementMap);
834 return CreateAnimation( animationName, replacement, Stage::GetCurrent().GetRootLayer() );
837 Animation Builder::CreateAnimation( const std::string& animationName, Dali::Actor sourceActor )
839 Replacement replacement( mReplacementMap );
841 return CreateAnimation( animationName, replacement, sourceActor );
844 Animation Builder::CreateAnimation( const std::string& animationName )
846 Replacement replacement( mReplacementMap );
848 return CreateAnimation( animationName, replacement, Dali::Stage::GetCurrent().GetRootLayer() );
851 void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::UIFormat format )
853 DALI_ASSERT_ALWAYS( format == Dali::Toolkit::Builder::JSON && "Currently only JSON is supported" );
855 // parser to get constants and includes only
856 Dali::Toolkit::JsonParser parser = Dali::Toolkit::JsonParser::New();
858 if( !parser.Parse( data ) )
860 DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
861 parser.GetErrorLineNumber(),
862 parser.GetErrorColumn(),
863 parser.GetErrorDescription().c_str() );
865 DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
870 // load constant map (allows the user to override the constants in the json after loading)
871 LoadConstants( *parser.GetRoot(), mReplacementMap );
874 if( OptionalChild includes = IsChild(*parser.GetRoot(), KEYNAME_INCLUDES) )
876 Replacement replacer( mReplacementMap );
878 for(TreeNode::ConstIterator iter = (*includes).CBegin(); iter != (*includes).CEnd(); ++iter)
880 OptionalString filename = replacer.IsString( (*iter).second );
884 #if defined(DEBUG_ENABLED)
885 DALI_SCRIPT_VERBOSE("Loading Include '%s'\n", (*filename).c_str());
887 LoadFromString( GetFileContents(*filename) );
892 if( !mParser.Parse( data ) )
894 DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
895 mParser.GetErrorLineNumber(),
896 mParser.GetErrorColumn(),
897 mParser.GetErrorDescription().c_str() );
899 DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
903 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
907 void Builder::AddConstants( const PropertyValueMap& map )
909 for(PropertyValueMap::const_iterator iter = map.begin(); iter != map.end(); ++iter)
911 mReplacementMap[ (*iter).first ] = (*iter).second;
915 void Builder::AddConstant( const std::string& key, const Property::Value& value )
917 mReplacementMap[key] = value;
920 const PropertyValueMap& Builder::GetConstants() const
922 return mReplacementMap;
925 const Property::Value& Builder::GetConstant( const std::string& key ) const
927 PropertyValueMap::const_iterator iter = mReplacementMap.find( key );
928 if( iter != mReplacementMap.end() )
930 return (*iter).second;
934 static Property::Value invalid;
939 void Builder::LoadConstants( const TreeNode& root, PropertyValueMap& intoMap )
941 Replacement replacer(intoMap);
943 if( OptionalChild constants = IsChild(root, "constants") )
945 for(TreeNode::ConstIterator iter = (*constants).CBegin();
946 iter != (*constants).CEnd(); ++iter)
948 Dali::Property::Value property;
949 if( (*iter).second.GetName() )
951 #if defined(DEBUG_ENABLED)
952 DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName());
954 if( SetPropertyFromNode( (*iter).second, property, replacer ) )
956 intoMap[ (*iter).second.GetName() ] = property;
960 DALI_SCRIPT_WARNING("Cannot convert property for constant %s\n",
961 (*iter).second.GetName() == NULL ? "no name?" : (*iter).second.GetName());
967 #if defined(DEBUG_ENABLED)
968 PropertyValueMap::const_iterator iter = intoMap.find( "CONFIG_SCRIPT_LOG_LEVEL" );
969 if( iter != intoMap.end() && (*iter).second.GetType() == Property::STRING )
971 std::string logLevel( (*iter).second.Get< std::string >() );
972 if( logLevel == "NoLogging" )
974 gFilterScript->SetLogLevel( Integration::Log::NoLogging );
976 else if( logLevel == "Concise" )
978 gFilterScript->SetLogLevel( Integration::Log::Concise );
980 else if( logLevel == "General" )
982 gFilterScript->SetLogLevel( Integration::Log::General );
984 else if( logLevel == "Verbose" )
986 gFilterScript->SetLogLevel( Integration::Log::Verbose );
993 bool Builder::ApplyStyle( const std::string& styleName, Handle& handle )
995 Replacement replacer( mReplacementMap );
996 return ApplyStyle( styleName, handle, replacer );
999 bool Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement )
1001 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
1003 OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES );
1004 OptionalChild style = IsChild( *styles, styleName );
1006 if( styles && style )
1008 ApplyAllStyleProperties( *mParser.GetRoot(), *style, handle, replacement );
1017 BaseHandle Builder::Create( const std::string& templateName, const PropertyValueMap& map )
1019 Replacement replacement( map, mReplacementMap );
1020 return Create( templateName, replacement );
1023 BaseHandle Builder::Create( const std::string& templateName, const Replacement& constant )
1025 DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
1027 BaseHandle baseHandle;
1029 OptionalChild templates = IsChild(*mParser.GetRoot(), KEYNAME_TEMPLATES);
1033 DALI_SCRIPT_WARNING("No template section found to CreateFromTemplate\n");
1037 OptionalChild childTemplate = IsChild(*templates, templateName);
1040 DALI_SCRIPT_WARNING("Template '%s' does not exist in template section\n", templateName.c_str());
1044 OptionalString type = constant.IsString( IsChild(*childTemplate, KEYNAME_TYPE) );
1048 DALI_SCRIPT_WARNING("Cannot create template '%s' as template section is missing 'type'\n", templateName.c_str());
1052 baseHandle = DoCreate( *mParser.GetRoot(), *childTemplate, Actor(), constant );
1060 BaseHandle Builder::CreateFromJson( const std::string& json )
1064 // merge in new template, hoping no one else has one named '@temp@'
1065 std::string newTemplate =
1066 std::string("{\"templates\":{\"@temp@\":") + \
1070 if( mParser.Parse(newTemplate) )
1072 Replacement replacement( mReplacementMap );
1073 ret = Create( "@temp@", replacement );
1079 bool Builder::ApplyFromJson( Handle& handle, const std::string& json )
1083 // merge new style, hoping no one else has one named '@temp@'
1084 std::string newStyle =
1085 std::string("{\"styles\":{\"@temp@\":") + \
1089 if( mParser.Parse(newStyle) )
1091 Replacement replacement( mReplacementMap );
1092 ret = ApplyStyle( "@temp@", handle, replacement );
1099 BaseHandle Builder::Create( const std::string& templateName )
1101 Replacement replacement( mReplacementMap );
1102 return Create( templateName, replacement );
1106 : mSlotDelegate( this )
1108 mParser = Dali::Toolkit::JsonParser::New();
1115 } // namespace Internal
1117 } // namespace Toolkit