#include <dali-toolkit/internal/builder/builder-get-is.inl.h>
#include <dali-toolkit/internal/builder/builder-filesystem.h>
#include <dali-toolkit/internal/builder/builder-declarations.h>
+#include <dali-toolkit/internal/builder/replacement.h>
namespace Dali
{
namespace Internal
{
+class Replacement;
-extern Animation CreateAnimation(const TreeNode& child);
+extern Animation CreateAnimation(const TreeNode& child, const Replacement& replacements, const Dali::Actor searchRoot );
+extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value );
+extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& replacements );
extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value );
+extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value, const Replacement& replacements );
extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor);
extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor);
extern Actor SetupActor( const TreeNode& node, Actor& actor );
typedef std::vector<const TreeNode*> TreeNodeList;
+template <typename T>
+std::string ToString(const T& value)
+{
+ std::stringstream ss;
+ ss << value;
+ return ss.str();
+}
+
+template <>
+std::string ToString(const Rect<int>& value)
+{
+ std::stringstream ss;
+ ss << value.x << "," << value.y << "," << value.width << "," << value.height;
+ return ss.str();
+}
+
+
+std::string PropertyValueToString( const Property::Value& value )
+{
+ std::string ret;
+
+ switch( value.GetType() )
+ {
+ case Property::NONE:
+ {
+ ret = "NONE";
+ break;
+ } ///< No type
+ case Property::BOOLEAN:
+ {
+ ret = value.Get<bool>() ? "True" : "False";
+ break;
+ }
+ case Property::FLOAT:
+ {
+
+ ret = ToString( value.Get<float>() );
+ break;
+ }
+ case Property::INTEGER:
+ {
+ ret = ToString( value.Get<int>() );
+ break;
+ }
+ case Property::UNSIGNED_INTEGER:
+ {
+ ret = ToString( value.Get<unsigned int>() );
+ break;
+ }
+ case Property::VECTOR2:
+ {
+ ret = ToString( value.Get<Vector2>() );
+ break;
+ }
+ case Property::VECTOR3:
+ {
+ ret = ToString( value.Get<Vector3>() );
+ break;
+ }
+ case Property::VECTOR4:
+ {
+ ret = ToString( value.Get<Vector4>() );
+ break;
+ }
+ case Property::MATRIX3:
+ {
+ ret = ToString( value.Get<Matrix3>() );
+ break;
+ }
+ case Property::MATRIX:
+ {
+ ret = ToString( value.Get<Matrix>() );
+ break;
+ }
+ case Property::RECTANGLE:
+ {
+ ret = ToString( value.Get< Rect<int> >() );
+ break;
+ }
+ case Property::ROTATION:
+ {
+ break;
+ }
+ case Property::STRING:
+ {
+ ret = value.Get<std::string>();
+ break;
+ }
+ case Property::ARRAY:
+ {
+ ret = std::string("Array Size=") + ToString( value.Get<Property::Array>().size() );
+ break;
+ }
+ case Property::MAP:
+ {
+ ret = std::string("Map Size=") + ToString( value.Get<Property::Map>().size() );
+ break;
+ }
+ case Property::TYPE_COUNT:
+ {
+ ret = "";
+ break;
+ }
+ }
+
+ return ret;
+}
+
/*
* Sets the handle properties found in the tree node
*/
-void SetProperties( const TreeNode& node, Handle& handle, Builder& builder )
+void SetProperties( const TreeNode& node, Handle& handle, Builder& builder, const Replacement& constant )
{
if( handle )
{
ImageActor imageActor = ImageActor::DownCast(handle);
if(imageActor)
{
- if( OptionalString s = IsString( keyChild.second ) )
+ if( OptionalString s = constant.IsString( keyChild.second ) )
{
- FrameBufferImage fb = builder.GetFrameBufferImage(*s);
+ FrameBufferImage fb = builder.GetFrameBufferImage(*s, constant);
if(fb)
{
imageActor.SetImage( fb );
if(key == "effect")
{
Actor actor = Actor::DownCast(handle);
- OptionalString s = IsString( keyChild.second );
+ OptionalString s = constant.IsString( keyChild.second );
if(actor && s)
{
- ShaderEffect e = builder.GetShaderEffect(*s);
+ ShaderEffect e = builder.GetShaderEffect(*s, constant);
actor.SetShaderEffect(e);
}
else
Property::Type type = handle.GetPropertyType(index);
Property::Value value;
- if( !SetPropertyFromNode( keyChild.second, type, value ) )
+ if( !SetPropertyFromNode( keyChild.second, type, value, constant ) )
{
// verbose as this might not be a problem
// eg parent-origin can be a string which is picked up later
}
else
{
- DALI_SCRIPT_VERBOSE("SetProperty '%s' Index=:%d Value Type=%d\n", key.c_str(), index, value.GetType());
+ DALI_SCRIPT_VERBOSE("SetProperty '%s' Index=:%d Value Type=%d Value '%s'\n", key.c_str(), index, value.GetType(), PropertyValueToString(value).c_str() );
handle.SetProperty( index, value );
}
}
}
+} // namespace anon
+
/*
* Create a dali type from a node.
* If parent given and an actor type was created then add it to the parent and
* recursively add nodes children.
*/
-BaseHandle Create( ConnectionTracker* tracker, const OptionalChild& optionalStyles, const TreeNode& node, const TreeNode& root, Actor parent, Builder& builder )
+BaseHandle Builder::Create( const OptionalChild& optionalStyles, const TreeNode& node, const TreeNode& root, Actor parent,
+ const Replacement& replacements )
{
BaseHandle baseHandle;
TreeNodeList allStyles;
if(!typeInfo)
{
- DALI_SCRIPT_WARNING("Unable to create Dali type from node\n");
+ DALI_SCRIPT_WARNING("Cannot create Dali type from node '%s'\n", node.GetName());
}
else
{
for(TreeNodeList::reverse_iterator iter = allStyles.rbegin(); iter != allStyles.rend(); ++iter)
{
- SetProperties( *(*iter), handle, builder );
+ if( (*iter)->GetType() == TreeNode::ARRAY )
+ {
+ // if its an array then its a list of styles to set to objects already in the hiearchy by name
+ if( actor )
+ {
+ const TreeNode& styleList = *(*iter);
+ for( TreeNode::ConstIterator iterSubStyle = styleList.CBegin(); iterSubStyle != styleList.CEnd(); ++iterSubStyle )
+ {
+ const TreeNode* nameNode = (*iterSubStyle).second.Find("name");
+ if( nameNode && nameNode->GetType() == TreeNode::STRING )
+ {
+ Dali::Actor found = actor.FindChildByName( nameNode->GetString() );
+ if( found )
+ {
+ SetProperties( (*iterSubStyle).second, found, *this, replacements );
+ }
+ else
+ {
+ DALI_SCRIPT_VERBOSE("Cannot find object '%s' in tree to style\n", nameNode->GetString());
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_VERBOSE("Style name is not a string '%s' '%d'\n",
+ nameNode->GetString(), (*iterSubStyle).second.GetType());
+ }
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_VERBOSE("Cannot apply style list to non actor\n");
+ }
+ }
+ else
+ {
+ DALI_ASSERT_DEBUG( (*iter)->GetType() == TreeNode::OBJECT );
+ // else it should be a map of properties
+ SetProperties( *(*iter), handle, *this, replacements );
+ }
- if( actor ) // if we created an actor
+ if( actor )
{
SetupActor( *(*iter), actor);
{
for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
{
- Create( tracker, optionalStyles, (*iter).second, root, actor, builder );
+ Create( optionalStyles, (*iter).second, root, actor, replacements );
}
}
}
if( actor )
{
// add signals first
- SetupSignalAction( tracker, root, node, actor );
- SetupPropertyNotification( tracker, root, node, actor );
+ SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor );
+
+ SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor );
// then add to parent
if( parent )
}
-} // namespace anon
-
-
ActorContainer Builder::GetTopLevelActors() const
{
// deprecated function.
return Animation();
}
-void Builder::SetupTask( RenderTask& task, const TreeNode& node )
+void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replacement& constant )
{
const Stage& stage = Stage::GetCurrent();
Layer root = stage.GetRootLayer();
- if( OptionalString s = IsString( IsChild(node, "source-actor") ) )
+ if( OptionalString s = constant.IsString( IsChild(node, "source-actor") ) )
{
Actor actor = root.FindChildByName(*s);
if(actor)
}
}
- if( OptionalString s = IsString( IsChild(node, "camera-actor") ) )
+ if( OptionalString s = constant.IsString( IsChild(node, "camera-actor") ) )
{
CameraActor actor = CameraActor::DownCast( root.FindChildByName(*s) );
if(actor)
}
}
- if( OptionalString s = IsString( IsChild(node, "target-frame-buffer") ) )
+ if( OptionalString s = constant.IsString( IsChild(node, "target-frame-buffer") ) )
{
- FrameBufferImage fb = GetFrameBufferImage( *s );
+ FrameBufferImage fb = GetFrameBufferImage( *s, constant );
if(fb)
{
task.SetTargetFrameBuffer( fb );
}
}
- if( OptionalString s = IsString( IsChild(node, "screen-to-frame-buffer-function") ) )
+ if( OptionalString s = constant.IsString( IsChild(node, "screen-to-frame-buffer-function") ) )
{
if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s)
{
}
// other setup is via the property system
- SetProperties( node, task, *this ); // @ todo, remove 'source-actor', 'camera-actor'?
+ SetProperties( node, task, *this, constant ); // @ todo, remove 'source-actor', 'camera-actor'?
}
void Builder::CreateRenderTask( const std::string &name )
{
+ Replacement constant(mReplacementMap);
+
const Stage& stage = Stage::GetCurrent();
OptionalChild tasks = IsChild(*mParser.GetRoot(), "render-tasks");
TreeNode::ConstIterator iter = (*renderTask).CBegin();
task = list.GetTask( start - 1 );
- SetupTask( task, (*iter).second );
+ SetupTask( task, (*iter).second, constant );
++iter;
for(; iter != (*renderTask).CEnd(); ++iter )
{
task = list.CreateTask();
- SetupTask( task, (*iter).second );
+ SetupTask( task, (*iter).second, constant );
}
}
}
}
-ShaderEffect Builder::GetShaderEffect( const std::string &name )
+ShaderEffect Builder::GetShaderEffect( const std::string &name)
+{
+ Replacement constant;
+ return GetShaderEffect( name, constant );
+}
+
+ShaderEffect Builder::GetShaderEffect( const std::string &name, const Replacement& constant )
{
ShaderEffect ret;
if( OptionalChild effect = IsChild( *effects, name ) )
{
Dali::Property::Value propertyMap(Property::MAP);
- if( SetPropertyFromNode( *effect, Property::MAP, propertyMap ) )
+ if( SetPropertyFromNode( *effect, Property::MAP, propertyMap, constant ) )
{
ret = Dali::Scripting::NewShaderEffect( propertyMap );
mShaderEffectLut[ name ] = ret;
FrameBufferImage Builder::GetFrameBufferImage( const std::string &name )
{
+ Replacement constant;
+ return GetFrameBufferImage(name, constant);
+}
+
+FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Replacement& constant )
+{
FrameBufferImage ret;
ImageLut::const_iterator iter( mFrameBufferImageLut.find( name ) );
if( OptionalChild image = IsChild( *images, name ) )
{
Dali::Property::Value propertyMap(Property::MAP);
- if( SetPropertyFromNode( *image, Property::MAP, propertyMap ) )
+ if( SetPropertyFromNode( *image, Property::MAP, propertyMap, constant ) )
{
propertyMap.SetValue("type", Property::Value(std::string("FrameBufferImage")));
ret = Dali::Scripting::NewImage( propertyMap );
void Builder::AddActors( const std::string §ionName, Actor toActor )
{
+ PropertyValueMap overrideMap;
+ Replacement replacements(overrideMap, mReplacementMap);
+
OptionalChild addToStage = IsChild(*mParser.GetRoot(), sectionName);
if( addToStage )
for( TreeNode::ConstIterator iter = (*addToStage).CBegin(); iter != (*addToStage).CEnd(); ++iter )
{
// empty actor adds directly to the stage
- BaseHandle baseHandle = Create( mSlotDelegate.GetConnectionTracker(), styles, (*iter).second, *mParser.GetRoot(), Actor(), *this);
+ BaseHandle baseHandle = Create( styles, (*iter).second, *mParser.GetRoot(), Actor(), replacements );
Actor actor = Actor::DownCast(baseHandle);
if(actor)
{
}
}
}
-
}
}
-Animation Builder::CreateAnimation( const std::string& animationName )
+Animation Builder::CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor searchRoot )
{
Animation anim;
{
if( OptionalChild animation = IsChild(*animations, animationName) )
{
- anim = Dali::Toolkit::Internal::CreateAnimation( *animation );
+ anim = Dali::Toolkit::Internal::CreateAnimation( *animation, replacement, Stage::GetCurrent().GetRootLayer() );
+ }
+ else
+ {
+ DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed\n", animationName.c_str() );
}
}
else
{
- DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed\n", animationName.c_str() );
+ DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed (no animation section)\n", animationName.c_str() );
}
return anim;
}
+Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map, Dali::Actor searchRoot )
+{
+ Replacement replacement(map, mReplacementMap);
+ return CreateAnimation( animationName, replacement, searchRoot);
+}
+
+Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map )
+{
+ Replacement replacement(map, mReplacementMap);
+ return CreateAnimation( animationName, replacement, Stage::GetCurrent().GetRootLayer() );
+}
+
+Animation Builder::CreateAnimation( const std::string& animationName, Dali::Actor searchRoot )
+{
+ Replacement replacement( mReplacementMap );
+
+ return CreateAnimation( animationName, replacement, searchRoot );
+}
+
+Animation Builder::CreateAnimation( const std::string& animationName )
+{
+ Replacement replacement( mReplacementMap );
+ return CreateAnimation( animationName, replacement, Dali::Stage::GetCurrent().GetRootLayer() );
+}
+
void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::UIFormat format )
{
DALI_ASSERT_ALWAYS( format == Dali::Toolkit::Builder::JSON && "Currently only JSON is supported" );
DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
+ // load constant map (allows the user to override the constants in the json after loading)
+ LoadConstants();
+
+}
+
+void Builder::AddConstants( const PropertyValueMap& map )
+{
+ for(PropertyValueMap::const_iterator iter = map.begin(); iter != map.end(); ++iter)
+ {
+ mReplacementMap[ (*iter).first ] = (*iter).second;
+ }
+}
+
+void Builder::LoadConstants()
+{
+ Replacement replacer(mReplacementMap);
+
+ if( OptionalChild constants = IsChild(*mParser.GetRoot(), "constants") )
+ {
+ for(TreeNode::ConstIterator iter = (*constants).CBegin();
+ iter != (*constants).CEnd(); ++iter)
+ {
+ Dali::Property::Value property;
+ if( (*iter).second.GetName() )
+ {
+#if defined(DEBUG_ENABLED)
+ DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName());
+#endif
+ if( SetPropertyFromNode( (*iter).second, property, replacer ) )
+ {
+ mReplacementMap[ (*iter).second.GetName() ] = property;
+ }
+ else
+ {
+ DALI_SCRIPT_WARNING("Cannot convert property for constant %s\n",
+ (*iter).second.GetName() == NULL ? "no name?" : (*iter).second.GetName());
+ }
+ }
+ }
+ }
+
+#if defined(DEBUG_ENABLED)
+ PropertyValueMap::const_iterator iter = mReplacementMap.find( "CONFIG_SCRIPT_LOG_LEVEL" );
+ if( iter != mReplacementMap.end() && (*iter).second.GetType() == Property::STRING )
+ {
+ std::string logLevel( (*iter).second.Get< std::string >() );
+ if( logLevel == "NoLogging" )
+ {
+ gFilterScript->SetLogLevel( Integration::Log::NoLogging );
+ }
+ else if( logLevel == "Concise" )
+ {
+ gFilterScript->SetLogLevel( Integration::Log::Concise );
+ }
+ else if( logLevel == "General" )
+ {
+ gFilterScript->SetLogLevel( Integration::Log::General );
+ }
+ else if( logLevel == "Verbose" )
+ {
+ gFilterScript->SetLogLevel( Integration::Log::Verbose );
+ }
+ }
+#endif
+
}
void Builder::ApplyStyle( const std::string& styleName, Handle& handle )
{
+ Replacement replacer;
+ ApplyStyle( styleName, handle, replacer );
+}
+
+void Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement )
+{
OptionalChild styles = IsChild(*mParser.GetRoot(), "styles");
if( styles )
for(TreeNodeList::reverse_iterator iter = allStyles.rbegin(); iter != allStyles.rend(); ++iter)
{
- SetProperties( *style, handle, *this );
+ if( (*iter)->GetType() == TreeNode::ARRAY )
+ {
+ // if its an array then its a list of styles to set to objects already in the hiearchy by name
+ if( Dali::Actor actor = Dali::Actor::DownCast( handle ) )
+ {
+ const TreeNode& styleList = *(*iter);
+ for( TreeNode::ConstIterator iterSubStyle = styleList.CBegin(); iterSubStyle != styleList.CEnd(); ++iterSubStyle )
+ {
+ const TreeNode* nameNode = (*iterSubStyle).second.Find("name");
+ if( nameNode && nameNode->GetType() == TreeNode::STRING )
+ {
+ Dali::Actor found = actor.FindChildByName( nameNode->GetString() );
+ if( found )
+ {
+ SetProperties( (*iterSubStyle).second, found, *this, replacement );
+ }
+ else
+ {
+ DALI_SCRIPT_VERBOSE("Cannot find object '%s' in tree to style\n", nameNode->GetString());
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_VERBOSE("Style name is not a string '%s' '%d'\n",
+ nameNode->GetString(), (*iterSubStyle).second.GetType());
+ }
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_VERBOSE("Cannot apply style list to non actor\n");
+ }
+ }
+ else
+ {
+ DALI_ASSERT_DEBUG( (*iter)->GetType() == TreeNode::OBJECT );
+ SetProperties( *style, handle, *this, replacement );
+ }
}
}
else
}
}
-BaseHandle Builder::CreateFromStyle( const std::string& styleName )
+BaseHandle Builder::CreateFromStyle( const std::string& styleName, const PropertyValueMap& map )
+{
+ Replacement replacement( map, mReplacementMap );
+ return CreateFromStyle( styleName, replacement );
+}
+
+BaseHandle Builder::CreateFromStyle( const std::string& styleName, const Replacement& constant )
{
BaseHandle baseHandle;
}
else
{
- OptionalString type = IsString( IsChild(*style, "type") );
+ OptionalString type = constant.IsString( IsChild(*style, "type") );
if(!type)
{
}
else
{
- baseHandle = Create( mSlotDelegate.GetConnectionTracker(), styles, *style, *mParser.GetRoot(), Actor(), *this );
+ baseHandle = Create( styles, *style, *mParser.GetRoot(), Actor(), constant );
}
}
}
return baseHandle;
}
+
+BaseHandle Builder::CreateFromStyle( const std::string& styleName )
+{
+ PropertyValueMap overrideMap;
+ Replacement replacement( overrideMap, mReplacementMap );
+ return CreateFromStyle( styleName, replacement );
+}
+
Builder::Builder()
: mSlotDelegate( this )
{