-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
// CLASS HEADER
#include <dali-toolkit/internal/builder/builder-impl.h>
// EXTERNAL INCLUDES
#include <sys/stat.h>
-
-// INTERNAL INCLUDES
-#include <dali/dali.h>
+#include <sstream>
+
+#include <dali/public-api/actors/camera-actor.h>
+#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/object/property-array.h>
+#include <dali/public-api/object/type-info.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/render-tasks/render-task-list.h>
+#include <dali/public-api/signals/functor-delegate.h>
+#include <dali/devel-api/scripting/scripting.h>
#include <dali/integration-api/debug.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/control.h>
+#include <dali-toolkit/devel-api/asset-manager/asset-manager.h>
+#include <dali-toolkit/devel-api/builder/json-parser.h>
-#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/builder-filesystem.h>
+#include <dali-toolkit/internal/builder/builder-get-is.inl.h>
+#include <dali-toolkit/internal/builder/builder-impl-debug.h>
+#include <dali-toolkit/internal/builder/builder-set-property.h>
#include <dali-toolkit/internal/builder/replacement.h>
+#include <dali-toolkit/internal/builder/tree-node-manipulator.h>
namespace Dali
{
{
class Replacement;
-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 );
-extern Control SetupControl( const TreeNode& node, Control& actor );
+extern Animation CreateAnimation(const TreeNode& child, const Replacement& replacements, const Dali::Actor searchRoot, Builder* const builder );
+
+extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, Dali::Toolkit::Internal::Builder* const builder);
+
+extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, Dali::Toolkit::Internal::Builder* const builder);
+
#if defined(DEBUG_ENABLED)
Integration::Log::Filter* gFilterScript = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_SCRIPT");
namespace
{
+#define TOKEN_STRING(x) #x
+
+const std::string KEYNAME_ACTORS = "actors";
+const std::string KEYNAME_ENTRY_TRANSITION = "entryTransition";
+const std::string KEYNAME_EXIT_TRANSITION = "exitTransition";
+const std::string KEYNAME_INCLUDES = "includes";
+const std::string KEYNAME_INHERIT = "inherit";
+const std::string KEYNAME_MAPPINGS = "mappings";
+const std::string KEYNAME_NAME = "name";
+const std::string KEYNAME_SIGNALS = "signals";
+const std::string KEYNAME_STATES = "states";
+const std::string KEYNAME_STYLES = "styles";
+const std::string KEYNAME_TEMPLATES = "templates";
+const std::string KEYNAME_TRANSITIONS = "transitions";
+const std::string KEYNAME_TYPE = "type";
+const std::string KEYNAME_VISUALS = "visuals";
+
+const std::string PROPERTIES = "properties";
+const std::string ANIMATABLE_PROPERTIES = "animatableProperties";
+
typedef std::vector<const TreeNode*> TreeNodeList;
-template <typename T>
-std::string ToString(const T& value)
+
+bool GetMappingKey( const std::string& str, std::string& key )
{
- std::stringstream ss;
- ss << value;
- return ss.str();
+ bool result = false;
+ std::string test( str );
+ if( ! test.empty() )
+ {
+ if( test.at(0) == '<' )
+ {
+ if( test.at(test.length()-1) == '>' )
+ {
+ key = test.substr( 1, test.length()-2 );
+ result = true;
+ }
+ }
+ }
+ return result;
}
-template <>
-std::string ToString(const Rect<int>& value)
+/*
+ * Recursively collects all styles in a node (An array of style names).
+ *
+ * stylesCollection The set of styles from the json file (a json object of named styles)
+ * style The style array to begin the collection from
+ * styleList The style list to add nodes to apply
+ */
+void CollectAllStyles( const TreeNode& stylesCollection, const TreeNode& style, TreeNodeList& styleList )
{
- std::stringstream ss;
- ss << value.x << "," << value.y << "," << value.width << "," << value.height;
- return ss.str();
+ // style is an array of style names
+ if( TreeNode::ARRAY == style.GetType() )
+ {
+ for(TreeNode::ConstIterator iter = style.CBegin(); iter != style.CEnd(); ++iter)
+ {
+ if( OptionalString styleName = IsString( (*iter).second ) )
+ {
+ if( OptionalChild node = IsChildIgnoreCase( stylesCollection, *styleName) )
+ {
+ styleList.push_back( &(*node) );
+
+ OptionalChild subStyle = IsChild( *node, KEYNAME_INHERIT );
+ if( ! subStyle )
+ {
+ subStyle = IsChild( *node, KEYNAME_STYLES );
+ }
+ if( subStyle )
+ {
+ CollectAllStyles( stylesCollection, *subStyle, styleList );
+ }
+ }
+ }
+ }
+ }
}
-std::string PropertyValueToString( const Property::Value& value )
+} // namespace anon
+
+
+Builder::Builder()
+: mSlotDelegate( this )
{
- std::string ret;
+ mParser = Dali::Toolkit::JsonParser::New();
- switch( value.GetType() )
+ Property::Map defaultDirs;
+ defaultDirs[TOKEN_STRING(DALI_IMAGE_DIR)] = AssetManager::GetDaliImagePath();
+ defaultDirs[TOKEN_STRING(DALI_SOUND_DIR)] = AssetManager::GetDaliSoundPath();
+ defaultDirs[TOKEN_STRING(DALI_STYLE_DIR)] = AssetManager::GetDaliStylePath();
+ defaultDirs[TOKEN_STRING(DALI_STYLE_IMAGE_DIR)] = AssetManager::GetDaliStyleImagePath();
+
+ AddConstants( defaultDirs );
+}
+
+void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::UIFormat format )
+{
+ // parser to get constants and includes only
+ Dali::Toolkit::JsonParser parser = Dali::Toolkit::JsonParser::New();
+
+ if( !parser.Parse( data ) )
{
- case Property::NONE:
- {
- ret = "NONE";
- break;
- } ///< No type
- case Property::BOOLEAN:
- {
- ret = value.Get<bool>() ? "True" : "False";
- break;
- }
- case Property::FLOAT:
- {
+ DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
+ parser.GetErrorLineNumber(),
+ parser.GetErrorColumn(),
+ parser.GetErrorDescription().c_str() );
- ret = ToString( value.Get<float>() );
- break;
- }
- case Property::INTEGER:
+ DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
+ }
+ else
+ {
+ // load constant map (allows the user to override the constants in the json after loading)
+ LoadConstants( *parser.GetRoot(), mReplacementMap );
+ // load configuration map
+ LoadConfiguration( *parser.GetRoot(), mConfigurationMap );
+ // merge includes
+ if( OptionalChild includes = IsChild(*parser.GetRoot(), KEYNAME_INCLUDES) )
{
- ret = ToString( value.Get<int>() );
- break;
+ Replacement replacer( mReplacementMap );
+
+ for(TreeNode::ConstIterator iter = (*includes).CBegin(); iter != (*includes).CEnd(); ++iter)
+ {
+ OptionalString filename = replacer.IsString( (*iter).second );
+
+ if( filename )
+ {
+#if defined(DEBUG_ENABLED)
+ DALI_SCRIPT_VERBOSE("Loading Include '%s'\n", (*filename).c_str());
+#endif
+ LoadFromString( GetFileContents(*filename) );
+ }
+ }
}
- case Property::UNSIGNED_INTEGER:
+
+ if( mParser.Parse( data ) )
{
- ret = ToString( value.Get<unsigned int>() );
- break;
+ // Drop the styles and get them to be rebuilt against the new parse tree as required.
+ mStyles.Clear();
}
- case Property::VECTOR2:
+ else
{
- ret = ToString( value.Get<Vector2>() );
- break;
+ DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
+ mParser.GetErrorLineNumber(),
+ mParser.GetErrorColumn(),
+ mParser.GetErrorDescription().c_str() );
+
+ DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
}
- case Property::VECTOR3:
+ }
+
+ DUMP_PARSE_TREE(mParser); // This macro only writes out if DEBUG is enabled and the "DUMP_TREE" constant is defined in the stylesheet.
+ DUMP_TEST_MAPPINGS(mParser);
+
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
+}
+
+void Builder::AddConstants( const Property::Map& map )
+{
+ mReplacementMap.Merge( map );
+}
+
+void Builder::AddConstant( const std::string& key, const Property::Value& value )
+{
+ mReplacementMap[key] = value;
+}
+
+const Property::Map& Builder::GetConfigurations() const
+{
+ return mConfigurationMap;
+}
+
+const Property::Map& Builder::GetConstants() const
+{
+ return mReplacementMap;
+}
+
+const Property::Value& Builder::GetConstant( const std::string& key ) const
+{
+ Property::Value* match = mReplacementMap.Find( key );
+ if( match )
+ {
+ return (*match);
+ }
+ else
+ {
+ static Property::Value invalid;
+ return invalid;
+ }
+}
+
+Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map, Dali::Actor sourceActor )
+{
+ Replacement replacement(map, mReplacementMap);
+ return CreateAnimation( animationName, replacement, sourceActor);
+}
+
+Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map )
+{
+ Replacement replacement(map, mReplacementMap);
+ return CreateAnimation( animationName, replacement, Stage::GetCurrent().GetRootLayer() );
+}
+
+Animation Builder::CreateAnimation( const std::string& animationName, Dali::Actor sourceActor )
+{
+ Replacement replacement( mReplacementMap );
+
+ return CreateAnimation( animationName, replacement, sourceActor );
+}
+
+Animation Builder::CreateAnimation( const std::string& animationName )
+{
+ Replacement replacement( mReplacementMap );
+
+ return CreateAnimation( animationName, replacement, Dali::Stage::GetCurrent().GetRootLayer() );
+}
+
+BaseHandle Builder::Create( const std::string& templateName )
+{
+ Replacement replacement( mReplacementMap );
+ return Create( templateName, replacement );
+}
+
+BaseHandle Builder::Create( const std::string& templateName, const Property::Map& map )
+{
+ Replacement replacement( map, mReplacementMap );
+ return Create( templateName, replacement );
+}
+
+BaseHandle Builder::CreateFromJson( const std::string& json )
+{
+ BaseHandle ret;
+
+ // merge in new template, hoping no one else has one named '@temp@'
+ std::string newTemplate =
+ std::string("{\"templates\":{\"@temp@\":") + \
+ json + \
+ std::string("}}");
+
+ if( mParser.Parse(newTemplate) )
+ {
+ Replacement replacement( mReplacementMap );
+ ret = Create( "@temp@", replacement );
+ }
+
+ return ret;
+}
+
+bool Builder::ApplyFromJson( Handle& handle, const std::string& json )
+{
+ bool ret = false;
+
+ // merge new style, hoping no one else has one named '@temp@'
+ std::string newStyle =
+ std::string("{\"styles\":{\"@temp@\":") + \
+ json + \
+ std::string("}}");
+
+ if( mParser.Parse(newStyle) )
+ {
+ Replacement replacement( mReplacementMap );
+ ret = ApplyStyle( "@temp@", handle, replacement );
+ }
+
+ return ret;
+}
+
+bool Builder::ApplyStyle( const std::string& styleName, Handle& handle )
+{
+ Replacement replacer( mReplacementMap );
+ return ApplyStyle( styleName, handle, replacer );
+}
+
+bool Builder::LookupStyleName( const std::string& styleName )
+{
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+ OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES );
+ OptionalChild style = IsChildIgnoreCase( *styles, styleName );
+
+ if( styles && style )
+ {
+ return true;
+ }
+ return false;
+}
+
+const StylePtr Builder::GetStyle( const std::string& styleName )
+{
+ const StylePtr* style = mStyles.FindConst( styleName );
+
+ if( style==NULL )
+ {
+ return StylePtr(NULL);
+ }
+ else
+ {
+ return *style;
+ }
+}
+
+void Builder::AddActors( Actor toActor )
+{
+ // 'stage' is the default/by convention section to add from
+ AddActors( "stage", toActor );
+}
+
+void Builder::AddActors( const std::string §ionName, Actor toActor )
+{
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+ Property::Map overrideMap;
+ Replacement replacements(overrideMap, mReplacementMap);
+
+ OptionalChild add = IsChild(*mParser.GetRoot(), sectionName);
+
+ if( add )
+ {
+ for( TreeNode::ConstIterator iter = (*add).CBegin(); iter != (*add).CEnd(); ++iter )
{
- ret = ToString( value.Get<Vector3>() );
- break;
+ // empty actor adds directly to the stage
+ BaseHandle baseHandle = DoCreate( *mParser.GetRoot(), (*iter).second, Actor(), replacements );
+ Actor actor = Actor::DownCast(baseHandle);
+ if(actor)
+ {
+ toActor.Add( actor );
+ }
}
- case Property::VECTOR4:
+
+ // if were adding the 'stage' section then also check for a render task called stage
+ // to add automatically
+ if( "stage" == sectionName )
{
- ret = ToString( value.Get<Vector4>() );
- break;
+ if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "renderTasks") )
+ {
+ if( OptionalChild tasks = IsChild(*renderTasks, "stage") )
+ {
+ CreateRenderTask( "stage" );
+ }
+ }
}
- case Property::MATRIX3:
+ }
+}
+
+void Builder::CreateRenderTask( const std::string &name )
+{
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+ Replacement constant(mReplacementMap);
+
+ const Stage& stage = Stage::GetCurrent();
+
+ OptionalChild tasks = IsChild(*mParser.GetRoot(), "renderTasks");
+
+ if(tasks)
+ {
+ //
+ // Create the tasks from the current task as generally we want
+ // to setup task zero and onwards. Although this does overwrite
+ // the properties of the current task.
+ //
+ if( OptionalChild renderTask = IsChild(*tasks, name ) )
{
- ret = ToString( value.Get<Matrix3>() );
- break;
+ RenderTaskList list = stage.GetRenderTaskList();
+ unsigned int start = list.GetTaskCount();
+
+ RenderTask task;
+ if(0 == start)
+ {
+ // zero should have already been created by the stage so really
+ // this case should never happen
+ task = list.CreateTask();
+ start++;
+ }
+
+ TreeNode::ConstIterator iter = (*renderTask).CBegin();
+ task = list.GetTask( start - 1 );
+
+ SetupTask( task, (*iter).second, constant );
+
+ ++iter;
+
+ for(; iter != (*renderTask).CEnd(); ++iter )
+ {
+ task = list.CreateTask();
+ SetupTask( task, (*iter).second, constant );
+ }
}
- case Property::MATRIX:
+ }
+}
+
+Path Builder::GetPath( const std::string& name )
+{
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+ Path ret;
+
+ PathLut::const_iterator iter( mPathLut.find( name ) );
+ if( iter != mPathLut.end() )
+ {
+ ret = iter->second;
+ }
+ else
+ {
+ if( OptionalChild paths = IsChild( *mParser.GetRoot(), "paths") )
{
- ret = ToString( value.Get<Matrix>() );
- break;
+ if( OptionalChild path = IsChild( *paths, name ) )
+ {
+ //points property
+ if( OptionalChild pointsProperty = IsChild( *path, "points") )
+ {
+ Dali::Property::Value points(Property::ARRAY);
+ if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+ {
+ ret = Path::New();
+ ret.SetProperty( Path::Property::POINTS, points);
+
+ //controlPoints property
+ if( OptionalChild pointsProperty = IsChild( *path, "controlPoints") )
+ {
+ Dali::Property::Value points(Property::ARRAY);
+ if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+ {
+ ret.SetProperty( Path::Property::CONTROL_POINTS, points);
+ }
+ }
+ else
+ {
+ //Curvature
+ float curvature(0.25f);
+ if( OptionalFloat pointsProperty = IsFloat( *path, "curvature") )
+ {
+ curvature = *pointsProperty;
+ }
+ ret.GenerateControlPoints(curvature);
+ }
+
+ //Add the new path to the hash table for paths
+ mPathLut[ name ] = ret;
+ }
+ }
+ else
+ {
+ //Interpolation points not specified
+ DALI_SCRIPT_WARNING("Interpolation points not specified for path '%s'\n", name.c_str() );
+ }
+ }
+
}
- case Property::RECTANGLE:
+ }
+
+ return ret;
+}
+
+PathConstrainer Builder::GetPathConstrainer( const std::string& name )
+{
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+ //Search the pathConstrainer in the LUT
+ size_t count( mPathConstrainerLut.size() );
+ for( size_t i(0); i!=count; ++i )
+ {
+ if( mPathConstrainerLut[i].name == name )
{
- ret = ToString( value.Get< Rect<int> >() );
- break;
+ //PathConstrainer has already been created
+ return mPathConstrainerLut[i].pathConstrainer;
}
- case Property::ROTATION:
+ }
+
+ //Create a new PathConstrainer
+ PathConstrainer ret;
+ if( OptionalChild constrainers = IsChild( *mParser.GetRoot(), "constrainers") )
+ {
+ if( OptionalChild pathConstrainer = IsChild( *constrainers, name ) )
{
- break;
+ OptionalString constrainerType(IsString(IsChild(*pathConstrainer, "type")));
+ if(!constrainerType)
+ {
+ DALI_SCRIPT_WARNING("Constrainer type not specified for constrainer '%s'\n", name.c_str() );
+ }
+ else if( *constrainerType == "PathConstrainer")
+ {
+ //points property
+ if( OptionalChild pointsProperty = IsChild( *pathConstrainer, "points") )
+ {
+ Dali::Property::Value points(Property::ARRAY);
+ if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+ {
+ ret = PathConstrainer::New();
+ ret.SetProperty( PathConstrainer::Property::POINTS, points);
+
+ //controlPoints property
+ if( OptionalChild pointsProperty = IsChild( *pathConstrainer, "controlPoints") )
+ {
+ Dali::Property::Value points(Property::ARRAY);
+ if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+ {
+ ret.SetProperty( PathConstrainer::Property::CONTROL_POINTS, points);
+ }
+
+ //Forward vector
+ OptionalVector3 forward( IsVector3( IsChild(*pathConstrainer, "forward" ) ) );
+ if( forward )
+ {
+ ret.SetProperty( PathConstrainer::Property::FORWARD, *forward);
+ }
+
+ //Add the new constrainer to the vector of PathConstrainer
+ PathConstrainerEntry entry = {name,ret};
+ mPathConstrainerLut.push_back( entry );
+ }
+ else
+ {
+ //Control points not specified
+ DALI_SCRIPT_WARNING("Control points not specified for pathConstrainer '%s'\n", name.c_str() );
+ }
+ }
+ }
+ else
+ {
+ //Interpolation points not specified
+ DALI_SCRIPT_WARNING("Interpolation points not specified for pathConstrainer '%s'\n", name.c_str() );
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_WARNING("Constrainer '%s' is not a PathConstrainer\n", name.c_str() );
+ }
}
- case Property::STRING:
+ }
+
+ return ret;
+}
+
+
+bool Builder::IsPathConstrainer( const std::string& name )
+{
+ size_t count( mPathConstrainerLut.size() );
+ for( size_t i(0); i!=count; ++i )
+ {
+ if( mPathConstrainerLut[i].name == name )
{
- ret = value.Get<std::string>();
- break;
+ return true;
}
- case Property::ARRAY:
+ }
+
+ if( OptionalChild constrainers = IsChild( *mParser.GetRoot(), "constrainers") )
+ {
+ if( OptionalChild constrainer = IsChild( *constrainers, name ) )
{
- ret = std::string("Array Size=") + ToString( value.Get<Property::Array>().size() );
- break;
+ OptionalString constrainerType(IsString(IsChild(*constrainer, "type")));
+ if(!constrainerType)
+ {
+ return false;
+ }
+ else
+ {
+ return *constrainerType == "PathConstrainer";
+ }
}
- case Property::MAP:
+ }
+ return false;
+}
+
+Dali::LinearConstrainer Builder::GetLinearConstrainer( const std::string& name )
+{
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+ //Search the LinearConstrainer in the LUT
+ size_t count( mLinearConstrainerLut.size() );
+ for( size_t i(0); i!=count; ++i )
+ {
+ if( mLinearConstrainerLut[i].name == name )
{
- ret = std::string("Map Size=") + ToString( value.Get<Property::Map>().size() );
- break;
+ //LinearConstrainer has already been created
+ return mLinearConstrainerLut[i].linearConstrainer;
}
- case Property::TYPE_COUNT:
+ }
+
+ //Create a new LinearConstrainer
+ LinearConstrainer ret;
+ if( OptionalChild constrainers = IsChild( *mParser.GetRoot(), "constrainers") )
+ {
+ if( OptionalChild linearConstrainer = IsChild( *constrainers, name ) )
{
- ret = "";
- break;
+ OptionalString constrainerType(IsString(IsChild(*linearConstrainer, "type")));
+ if(!constrainerType)
+ {
+ DALI_SCRIPT_WARNING("Constrainer type not specified for constrainer '%s'\n", name.c_str() );
+ }
+ else if( *constrainerType == "LinearConstrainer")
+ {
+ //points property
+ if( OptionalChild pointsProperty = IsChild( *linearConstrainer, "value") )
+ {
+ Dali::Property::Value points(Property::ARRAY);
+ if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+ {
+ ret = Dali::LinearConstrainer::New();
+ ret.SetProperty( LinearConstrainer::Property::VALUE, points);
+
+ //controlPoints property
+ if( OptionalChild pointsProperty = IsChild( *linearConstrainer, "progress") )
+ {
+ Dali::Property::Value points(Property::ARRAY);
+ if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+ {
+ ret.SetProperty( LinearConstrainer::Property::PROGRESS, points);
+ }
+ }
+ //Add the new constrainer to vector of LinearConstrainer
+ LinearConstrainerEntry entry = {name,ret};
+ mLinearConstrainerLut.push_back( entry );
+ }
+ }
+ else
+ {
+ //Interpolation points not specified
+ DALI_SCRIPT_WARNING("Values not specified for LinearConstrainer '%s'\n", name.c_str() );
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_WARNING("Constrainer '%s' is not a LinearConstrainer\n", name.c_str() );
+ }
}
}
return ret;
}
-/*
- * Sets the handle properties found in the tree node
- */
-void SetProperties( const TreeNode& node, Handle& handle, Builder& builder, const Replacement& constant )
+bool Builder::IsLinearConstrainer( const std::string& name )
{
- if( handle )
+ // Search the LinearConstrainer in the LUT
+ size_t count( mLinearConstrainerLut.size() );
+ for( size_t i(0); i!=count; ++i )
{
- for( TreeNode::ConstIterator iter = node.CBegin(); iter != node.CEnd(); ++iter )
+ if( mLinearConstrainerLut[i].name == name )
{
- const TreeNode::KeyNodePair& keyChild = *iter;
-
- std::string key( keyChild.first );
+ return true;
+ }
+ }
- // ignore special fields; type,actors,signals
- if(key == "type" || key == "actors" || key == "signals")
+ if( OptionalChild constrainers = IsChild( *mParser.GetRoot(), "constrainers") )
+ {
+ if( OptionalChild constrainer = IsChild( *constrainers, name ) )
+ {
+ OptionalString constrainerType(IsString(IsChild(*constrainer, "type")));
+ if(!constrainerType)
{
- continue;
+ return false;
+ }
+ else
+ {
+ return *constrainerType == "LinearConstrainer";
}
+ }
+ }
+ return false;
+}
- // special field 'image' usually contains an json object description
- // although sometimes refers to a framebuffer
- if( 0 == keyChild.second.Size() )
+Toolkit::Builder::BuilderSignalType& Builder::QuitSignal()
+{
+ return mQuitSignal;
+}
+
+void Builder::EmitQuitSignal()
+{
+ mQuitSignal.Emit();
+}
+
+Builder::~Builder()
+{
+}
+
+void Builder::LoadConfiguration( const TreeNode& root, Property::Map& intoMap )
+{
+ Replacement replacer(intoMap);
+
+ if( OptionalChild constants = IsChild(root, "config") )
+ {
+ for(TreeNode::ConstIterator iter = (*constants).CBegin();
+ iter != (*constants).CEnd(); ++iter)
+ {
+ Dali::Property::Value property;
+ if( (*iter).second.GetName() )
{
- if(key == "image")
+ DeterminePropertyFromNode( (*iter).second, property, replacer );
+
+ // If config is string, find constant and replace it to original value.
+ if( (*iter).second.GetType() == TreeNode::STRING )
{
- ImageActor imageActor = ImageActor::DownCast(handle);
- if(imageActor)
+ std::string stringConfigValue;
+ if( property.Get( stringConfigValue ) )
{
- if( OptionalString s = constant.IsString( keyChild.second ) )
+ std::size_t pos = 0;
+
+ while( pos < stringConfigValue.size() )
{
- FrameBufferImage fb = builder.GetFrameBufferImage(*s, constant);
- if(fb)
+ // If we can't find "{","}" pair in stringConfigValue, will out loop.
+ std::size_t leftPos = stringConfigValue.find( "{", pos );
+ if( leftPos != std::string::npos )
+ {
+ std::size_t rightPos = stringConfigValue.find( "}", pos+1 );
+
+ if( rightPos != std::string::npos )
+ {
+ // If we find "{","}" pair but can't find matched constant
+ // try to find other "{","}" pair after current left position.
+ pos = leftPos+1;
+
+ for( uint32_t i = 0; i < mReplacementMap.Count() ; i++ )
+ {
+ Property::Key constant = mReplacementMap.GetKeyAt(i);
+
+ // Compare string which is between "{" and "}" with constant string
+ // If they are same, change string in stringConfigValue to mapped constant value.
+ if ( 0 == stringConfigValue.compare( leftPos+1, rightPos-leftPos-1, constant.stringKey ) )
+ {
+ std::string replaceString;
+ mReplacementMap.GetValue(i).Get( replaceString );
+
+ stringConfigValue.replace( leftPos, rightPos-leftPos+1, replaceString );
+ pos = leftPos + replaceString.size();
+ break;
+ }
+ }
+ }
+ else
+ {
+ // If we cannot find constant in const value, will out loop.
+ pos = stringConfigValue.size();
+ }
+ }
+ else
{
- imageActor.SetImage( fb );
+ // If we cannot find constant in const value, will out loop.
+ pos = stringConfigValue.size();
}
}
+ property = Property::Value( stringConfigValue );
}
}
+ intoMap[ (*iter).second.GetName() ] = property;
}
+ }
+ }
+}
- // special field 'effect' references the shader effect instances
- if(key == "effect")
- {
- Actor actor = Actor::DownCast(handle);
- OptionalString s = constant.IsString( keyChild.second );
- if(actor && s)
- {
- ShaderEffect e = builder.GetShaderEffect(*s, constant);
- actor.SetShaderEffect(e);
- }
- else
- {
- DALI_SCRIPT_WARNING("Could not find or set shader effect\n");
- }
-
- continue;
- }
-
- Property::Index index = handle.GetPropertyIndex(key);
-
- if( Property::INVALID_INDEX != index )
- {
- Property::Type type = handle.GetPropertyType(index);
-
- Property::Value 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
- DALI_SCRIPT_VERBOSE("Could not convert property:%s\n", key.c_str());
- }
- else
- {
- DALI_SCRIPT_VERBOSE("SetProperty '%s' Index=:%d Value Type=%d Value '%s'\n", key.c_str(), index, value.GetType(), PropertyValueToString(value).c_str() );
+void Builder::LoadConstants( const TreeNode& root, Property::Map& intoMap )
+{
+ Replacement replacer(intoMap);
- handle.SetProperty( index, value );
- }
- }
- else
+ if( OptionalChild constants = IsChild(root, "constants") )
+ {
+ for(TreeNode::ConstIterator iter = (*constants).CBegin();
+ iter != (*constants).CEnd(); ++iter)
+ {
+ Dali::Property::Value property;
+ if( (*iter).second.GetName() )
{
- DALI_SCRIPT_VERBOSE("SetProperty INVALID '%s' Index=:%d\n", key.c_str(), index);
+#if defined(DEBUG_ENABLED)
+ DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName());
+#endif
+ DeterminePropertyFromNode( (*iter).second, property, replacer );
+ intoMap[ (*iter).second.GetName() ] = property;
}
-
- } // for property nodes
- }
- else
- {
- DALI_SCRIPT_WARNING("Style applied to empty handle\n");
+ }
}
-}
-/*
- * Split a string by delimiter
- */
-std::vector<std::string> SplitString(const std::string &s, char delim, std::vector<std::string> &elems)
-{
- std::stringstream ss(s);
- std::string item;
- while(std::getline(ss, item, delim))
+#if defined(DEBUG_ENABLED)
+ Property::Value* iter = intoMap.Find( "CONFIG_SCRIPT_LOG_LEVEL" );
+ if( iter && iter->GetType() == Property::STRING )
{
- elems.push_back(item);
+ std::string logLevel( iter->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 );
+ }
}
- return elems;
+#endif
}
-/*
- * Recursively collects all styles listed in a json node 'type' field. (Could be a comma separated list).
- * It also returns the first found base typeInfo from the TypeRegistry. This is the concrete object to instance.
- * i.e. the type field can name a json style section or a TypeRegistry base type.
- */
-void CollectAllStyles( const TreeNode& styles, const std::string& typeStyleString, TreeNodeList& additionalStyles, TypeInfo& typeInfo )
+Animation Builder::CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor )
{
- typedef std::vector<std::string> StyleNames;
- StyleNames styleNames;
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
- SplitString(typeStyleString, ',', styleNames);
+ Animation anim;
- for(StyleNames::iterator iter = styleNames.begin(); iter != styleNames.end(); ++iter)
+ if( OptionalChild animations = IsChild(*mParser.GetRoot(), "animations") )
{
- const std::string typeName(*iter);
-
- OptionalChild style = IsChild(styles, typeName);
- if(style)
+ if( OptionalChild animation = IsChild(*animations, animationName) )
{
- additionalStyles.push_back(&(*style));
-
- OptionalString styleType = IsString( IsChild(*style, "type") );
- if( styleType )
- {
- CollectAllStyles(styles, *styleType, additionalStyles, typeInfo);
- }
- else
- {
- if(!typeInfo)
- {
- // if its not a style then check for a type but only the first found
- typeInfo = TypeRegistry::Get().GetTypeInfo( typeName );
- }
- }
+ anim = Dali::Toolkit::Internal::CreateAnimation( *animation, replacement, sourceActor, this );
}
else
{
- DALI_ASSERT_DEBUG(!typeInfo);
- typeInfo = TypeRegistry::Get().GetTypeInfo( typeName );
+ DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed\n", animationName.c_str() );
}
}
+ else
+ {
+ DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed (no animation section)\n", animationName.c_str() );
+ }
+
+ return anim;
}
-/*
- * Recursively collects all styles listed in a json node 'type' field. (Could be a comma separated list).
- * Adds the given node to the end of the additional styles list.
- * It also returns the first found base typeInfo from the TypeRegistry. This is the concrete object to instance.
- * i.e. the type field can name a json style section or a TypeRegistry base type.
- */
-void CollectAllStyles( const OptionalChild& optionalStyles, const TreeNode& node, TreeNodeList& additionalStyles, TypeInfo& typeInfo )
+BaseHandle Builder::Create( const std::string& templateName, const Replacement& constant )
{
- OptionalString type = IsString( IsChild(node, "type") );
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+ BaseHandle baseHandle;
+
+ OptionalChild templates = IsChild(*mParser.GetRoot(), KEYNAME_TEMPLATES);
- if(!type)
+ if( !templates )
{
- DALI_SCRIPT_WARNING("Cannot create style as type section is missing\n");
+ DALI_SCRIPT_WARNING("No template section found to CreateFromTemplate\n");
}
else
{
- additionalStyles.push_back(&node);
-
- if( optionalStyles )
+ OptionalChild childTemplate = IsChild(*templates, templateName);
+ if(!childTemplate)
{
- CollectAllStyles( *optionalStyles, *type, additionalStyles, typeInfo );
+ DALI_SCRIPT_WARNING("Template '%s' does not exist in template section\n", templateName.c_str());
}
else
{
- typeInfo = TypeRegistry::Get().GetTypeInfo( *type );
- }
+ OptionalString type = constant.IsString( IsChild(*childTemplate, KEYNAME_TYPE) );
+ if(!type)
+ {
+ DALI_SCRIPT_WARNING("Cannot create template '%s' as template section is missing 'type'\n", templateName.c_str());
+ }
+ else
+ {
+ baseHandle = DoCreate( *mParser.GetRoot(), *childTemplate, Actor(), constant );
+ }
+ }
}
-}
-} // namespace anon
+ return baseHandle;
+}
/*
* 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 Builder::Create( const OptionalChild& optionalStyles, const TreeNode& node, const TreeNode& root, Actor parent,
- const Replacement& replacements )
+BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
+ Actor parent, const Replacement& replacements )
{
BaseHandle baseHandle;
- TreeNodeList allStyles;
TypeInfo typeInfo;
+ const TreeNode* templateNode = NULL;
+
+ if( OptionalString typeName = IsString(node, KEYNAME_TYPE) )
+ {
+ typeInfo = TypeRegistry::Get().GetTypeInfo( *typeName );
+
+ if( !typeInfo )
+ {
+ // a template name is also allowed inplace of the type name
+ OptionalChild templates = IsChild( root, KEYNAME_TEMPLATES);
+
+ if( templates )
+ {
+ if( OptionalChild isTemplate = IsChild( *templates, *typeName ) )
+ {
+ templateNode = &(*isTemplate);
- CollectAllStyles( optionalStyles, node, allStyles, typeInfo );
+ if( OptionalString templateTypeName = IsString(*templateNode, KEYNAME_TYPE) )
+ {
+ typeInfo = TypeRegistry::Get().GetTypeInfo( *templateTypeName );
+ }
+ }
+ }
+ }
+ }
if(!typeInfo)
{
baseHandle = typeInfo.CreateInstance();
Handle handle = Handle::DownCast(baseHandle);
Actor actor = Actor::DownCast(handle);
- Control control = Control::DownCast(handle);
if(handle)
{
DALI_SCRIPT_VERBOSE("Create:%s\n", typeInfo.GetName().c_str());
- DALI_SCRIPT_VERBOSE(" %d style sections\n", allStyles.size());
#if defined(DEBUG_ENABLED)
if(handle)
DALI_SCRIPT_VERBOSE(" Is Actor id=%d\n", actor.GetId());
}
+ Toolkit::Control control = Toolkit::Control::DownCast(handle);
if(control)
{
DALI_SCRIPT_VERBOSE(" Is Control id=%d\n", actor.GetId());
}
#endif // DEBUG_ENABLED
- for(TreeNodeList::reverse_iterator iter = allStyles.rbegin(); iter != allStyles.rend(); ++iter)
+ if( templateNode )
{
- 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 );
- }
+ ApplyProperties( root, *templateNode, handle, replacements );
- if( actor )
+ if( OptionalChild actors = IsChild( *templateNode, KEYNAME_ACTORS ) )
{
- SetupActor( *(*iter), actor);
-
- if( control )
- {
- SetupControl( *(*iter), control);
- }
-
- // add children of all the styles
- if( OptionalChild actors = IsChild( *(*iter), "actors" ) )
+ for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
{
- for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
- {
- Create( optionalStyles, (*iter).second, root, actor, replacements );
- }
+ DoCreate( root, (*iter).second, actor, replacements );
}
}
}
if( actor )
{
- // add signals first
- SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor );
+ // add children of all the styles
+ if( OptionalChild actors = IsChild( node, KEYNAME_ACTORS ) )
+ {
+ for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
+ {
+ DoCreate( root, (*iter).second, actor, replacements );
+ }
+ }
- SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor );
+ // apply style on top as they need the children to exist
+ ApplyAllStyleProperties( root, node, actor, replacements );
// then add to parent
if( parent )
{
parent.Add( actor );
}
-
+ }
+ else
+ {
+ ApplyProperties( root, node, handle, replacements );
}
}
else
return baseHandle;
}
-
-ActorContainer Builder::GetTopLevelActors() const
-{
- // deprecated function.
- return ActorContainer();
-}
-
-Animation Builder::GetAnimation( const std::string &name ) const
-{
- // deprecated
- return Animation();
-}
-
void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replacement& constant )
{
const Stage& stage = Stage::GetCurrent();
Layer root = stage.GetRootLayer();
- if( OptionalString s = constant.IsString( IsChild(node, "source-actor") ) )
+ if( OptionalString s = constant.IsString( IsChild(node, "sourceActor") ) )
{
Actor actor = root.FindChildByName(*s);
if(actor)
}
}
- if( OptionalString s = constant.IsString( IsChild(node, "camera-actor") ) )
+ if( OptionalString s = constant.IsString( IsChild(node, "cameraActor") ) )
{
CameraActor actor = CameraActor::DownCast( root.FindChildByName(*s) );
if(actor)
}
}
- if( OptionalString s = constant.IsString( IsChild(node, "target-frame-buffer") ) )
- {
- FrameBufferImage fb = GetFrameBufferImage( *s, constant );
- if(fb)
- {
- task.SetTargetFrameBuffer( fb );
- }
- else
- {
- DALI_SCRIPT_WARNING("Cannot find target frame buffer '%s'\n", (*s).c_str() );
- }
- }
-
- if( OptionalString s = constant.IsString( IsChild(node, "screen-to-frame-buffer-function") ) )
+ if( OptionalString s = constant.IsString( IsChild(node, "screenToFrameBufferFunction") ) )
{
if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s)
{
}
// other setup is via the property system
- SetProperties( node, task, *this, constant ); // @ todo, remove 'source-actor', 'camera-actor'?
-
+ SetProperties( node, task, constant );
}
-void Builder::CreateRenderTask( const std::string &name )
+bool Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement )
{
- Replacement constant(mReplacementMap);
-
- const Stage& stage = Stage::GetCurrent();
-
- OptionalChild tasks = IsChild(*mParser.GetRoot(), "render-tasks");
-
- if(tasks)
- {
- //
- // Create the tasks from the current task as generally we want
- // to setup task zero and onwards. Although this does overwrite
- // the properties of the current task.
- //
- if( OptionalChild renderTask = IsChild(*tasks, name ) )
- {
- RenderTaskList list = stage.GetRenderTaskList();
- unsigned int start = list.GetTaskCount();
-
- RenderTask task;
- if(0 == start)
- {
- // zero should have already been created by the stage so really
- // this case should never happen
- task = list.CreateTask();
- start++;
- }
-
- TreeNode::ConstIterator iter = (*renderTask).CBegin();
- task = list.GetTask( start - 1 );
-
- SetupTask( task, (*iter).second, constant );
-
- ++iter;
-
- for(; iter != (*renderTask).CEnd(); ++iter )
- {
- task = list.CreateTask();
- SetupTask( task, (*iter).second, constant );
- }
- }
- }
-}
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
-ShaderEffect Builder::GetShaderEffect( const std::string &name)
-{
- Replacement constant;
- return GetShaderEffect( name, constant );
-}
+ OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES );
-ShaderEffect Builder::GetShaderEffect( const std::string &name, const Replacement& constant )
-{
- ShaderEffect ret;
+ std::string styleNameLower(styleName);
+ OptionalChild style = IsChildIgnoreCase( *styles, styleNameLower );
- ShaderEffectLut::const_iterator iter( mShaderEffectLut.find( name ) );
- if( iter != mShaderEffectLut.end() )
+ if( styles && style )
{
- ret = iter->second;
+ ApplyAllStyleProperties( *mParser.GetRoot(), *style, handle, replacement );
+ return true;
}
else
{
- if( OptionalChild effects = IsChild( *mParser.GetRoot(), "shader-effects") )
- {
- if( OptionalChild effect = IsChild( *effects, name ) )
- {
- Dali::Property::Value propertyMap(Property::MAP);
- if( SetPropertyFromNode( *effect, Property::MAP, propertyMap, constant ) )
- {
- ret = Dali::Scripting::NewShaderEffect( propertyMap );
- mShaderEffectLut[ name ] = ret;
- }
- }
- }
+ return false;
}
-
- return ret;
}
-FrameBufferImage Builder::GetFrameBufferImage( const std::string &name )
+void Builder::ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
+ Dali::Handle& handle, const Replacement& constant )
{
- Replacement constant;
- return GetFrameBufferImage(name, constant);
-}
+ const char* styleName = node.GetName();
-FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Replacement& constant )
-{
- FrameBufferImage ret;
+ StylePtr style = Style::New();
- ImageLut::const_iterator iter( mFrameBufferImageLut.find( name ) );
- if( iter != mFrameBufferImageLut.end() )
- {
- ret = iter->second;
- }
- else
+ StylePtr* matchedStyle = NULL;
+ if( styleName )
{
- if( OptionalChild images = IsChild( *mParser.GetRoot(), "frame-buffer-images") )
+ matchedStyle = mStyles.Find( styleName );
+ if( ! matchedStyle )
{
- if( OptionalChild image = IsChild( *images, name ) )
+ OptionalChild styleNodes = IsChild(root, KEYNAME_STYLES);
+ OptionalChild inheritFromNode = IsChild(node, KEYNAME_INHERIT);
+ if( !inheritFromNode )
{
- Dali::Property::Value propertyMap(Property::MAP);
- if( SetPropertyFromNode( *image, Property::MAP, propertyMap, constant ) )
- {
- propertyMap.SetValue("type", Property::Value(std::string("FrameBufferImage")));
- ret = Dali::Scripting::NewImage( propertyMap );
- mFrameBufferImageLut[ name ] = ret;
- }
+ inheritFromNode = IsChild( node, KEYNAME_STYLES );
}
- }
- }
- return ret;
-}
+ if( styleNodes )
+ {
+ if( inheritFromNode )
+ {
+ TreeNodeList additionalStyleNodes;
-Font Builder::GetFont( const std::string& name ) const
-{
- // deprecated function.
- Font font;
- return font;
-}
+ CollectAllStyles( *styleNodes, *inheritFromNode, additionalStyleNodes );
-TextStyle Builder::GetTextStyle( const std::string& name ) const
-{
- // deprecated
- return TextStyle();
-}
+#if defined(DEBUG_ENABLED)
+ for(TreeNode::ConstIterator iter = (*inheritFromNode).CBegin(); iter != (*inheritFromNode).CEnd(); ++iter)
+ {
+ if( OptionalString styleName = IsString( (*iter).second ) )
+ {
+ DALI_SCRIPT_VERBOSE("Style Applied '%s'\n", (*styleName).c_str());
+ }
+ }
+#endif
-Image Builder::GetImage( const std::string& name) const
-{
- // deprecated function.
- return Image();
-}
+ // a style may have other styles, which has other styles etc so we apply in reverse by convention.
+ for(TreeNodeList::reverse_iterator iter = additionalStyleNodes.rbegin(); iter != additionalStyleNodes.rend(); ++iter)
+ {
+ RecordStyle( style, *(*iter), handle, constant );
+ ApplySignals( root, *(*iter), handle );
+ ApplyStylesByActor( root, *(*iter), handle, constant );
+ }
+ }
-Actor Builder::GetActor( const std::string &name ) const
-{
- // deprecated function.
- return Actor();
-}
+ RecordStyle( style, node, handle, constant );
+ mStyles.Add( styleName, style ); // shallow copy
+ matchedStyle = &style;
+ }
+ }
+ }
-void Builder::AddActors( Actor toActor )
-{
- // 'stage' is the default/by convention section to add from
- AddActors( "stage", toActor );
+ if( matchedStyle )
+ {
+ StylePtr style( *matchedStyle );
+ Dictionary<Property::Map> instancedProperties;
+ style->ApplyVisualsAndPropertiesRecursively( handle, instancedProperties );
+ }
+ else // If there were no styles, instead set properties
+ {
+ SetProperties( node, handle, constant );
+ }
+ ApplySignals( root, node, handle );
+ ApplyStylesByActor( root, node, handle, constant );
}
-void Builder::AddActors( const std::string §ionName, Actor toActor )
-{
- PropertyValueMap overrideMap;
- Replacement replacements(overrideMap, mReplacementMap);
-
- OptionalChild addToStage = IsChild(*mParser.GetRoot(), sectionName);
+void Builder::RecordStyle( StylePtr style,
+ const TreeNode& node,
+ Dali::Handle& handle,
+ const Replacement& replacements )
+{
+ // With repeated calls, accumulate inherited states, visuals and properties
+ // but override any with same name
- if( addToStage )
+ for( TreeNode::ConstIterator iter = node.CBegin(); iter != node.CEnd(); ++iter )
{
- OptionalChild styles = IsChild(*mParser.GetRoot(), "styles");
+ const TreeNode::KeyNodePair& keyValue = *iter;
+ std::string key( keyValue.first );
+ if( key == KEYNAME_STATES )
+ {
+ const TreeNode& states = keyValue.second;
+ if( states.GetType() != TreeNode::OBJECT )
+ {
+ DALI_LOG_WARNING( "RecordStyle() Node \"%s\" is not a JSON object\n", key.c_str() );
+ continue;
+ }
+
+ for( TreeNode::ConstIterator iter = states.CBegin(); iter != states.CEnd(); ++iter )
+ {
+ const TreeNode& stateNode = (*iter).second;
+ const char* stateName = stateNode.GetName();
+ if( stateNode.GetType() != TreeNode::OBJECT )
+ {
+ DALI_LOG_WARNING( "RecordStyle() Node \"%s\" is not a JSON object\n", stateName );
+ continue;
+ }
- for( TreeNode::ConstIterator iter = (*addToStage).CBegin(); iter != (*addToStage).CEnd(); ++iter )
+ StylePtr* stylePtr = style->subStates.Find( stateName );
+ if( stylePtr )
+ {
+ StylePtr style(*stylePtr);
+ RecordStyle( style, stateNode, handle, replacements );
+ }
+ else
+ {
+ StylePtr subState = Style::New();
+ RecordStyle( subState, stateNode, handle, replacements );
+ style->subStates.Add( stateName, subState );
+ }
+ }
+ }
+ else if( key == KEYNAME_VISUALS )
{
- // empty actor adds directly to the stage
- BaseHandle baseHandle = Create( styles, (*iter).second, *mParser.GetRoot(), Actor(), replacements );
- Actor actor = Actor::DownCast(baseHandle);
- if(actor)
+ for( TreeNode::ConstIterator iter = keyValue.second.CBegin(); iter != keyValue.second.CEnd(); ++iter )
{
- toActor.Add( actor );
+ // Each key in this table should be a property name matching a visual.
+ const TreeNode::KeyNodePair& visual = *iter;
+ Dali::Property::Value property(Property::MAP);
+ if( DeterminePropertyFromNode( visual.second, Property::MAP, property, replacements ) )
+ {
+ Property::Map* mapPtr = style->visuals.Find( visual.first );
+ if( mapPtr )
+ {
+ // Override existing visuals
+ mapPtr->Clear();
+ mapPtr->Merge( *property.GetMap() );
+ }
+ else
+ {
+ Property::Map* map = property.GetMap();
+ if( map )
+ {
+ style->visuals.Add( visual.first, *map );
+ }
+ }
+ }
}
}
-
- // if were adding the 'stage' section then also check for a render task called stage
- // to add automatically
- if( "stage" == sectionName )
+ else if( key == KEYNAME_ENTRY_TRANSITION )
+ {
+ RecordTransitionData( keyValue, style->entryTransition, replacements );
+ }
+ else if( key == KEYNAME_EXIT_TRANSITION )
+ {
+ RecordTransitionData( keyValue, style->exitTransition, replacements );
+ }
+ else if( key == KEYNAME_TRANSITIONS )
+ {
+ RecordTransitions( keyValue, style->transitions, replacements );
+ }
+ else if( key == KEYNAME_TYPE ||
+ key == KEYNAME_ACTORS ||
+ key == KEYNAME_SIGNALS ||
+ key == KEYNAME_STYLES ||
+ key == KEYNAME_MAPPINGS ||
+ key == KEYNAME_INHERIT )
+ {
+ continue;
+ }
+ else // It's a property
{
- if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "render-tasks") )
+ Property::Index index;
+ Property::Value value;
+ if( MapToTargetProperty( handle, key, keyValue.second, replacements, index, value ) )
{
- if( OptionalChild tasks = IsChild(*renderTasks, "stage") )
+ Property::Value* existingValuePtr = style->properties.Find( index );
+ if( existingValuePtr != NULL )
{
- CreateRenderTask( "stage" );
+ *existingValuePtr = value; // Overwrite existing property.
+ }
+ else
+ {
+ style->properties.Add( index, value );
}
}
}
}
}
-Animation Builder::CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor searchRoot )
+void Builder::RecordTransitions(
+ const TreeNode::KeyNodePair& keyValue,
+ Property::Array& value,
+ const Replacement& replacements )
{
- Animation anim;
-
- if( OptionalChild animations = IsChild(*mParser.GetRoot(), "animations") )
+ //@todo add new transitions to style.transitions
+ // override existing transitions. A transition matches on target & property name
+ const TreeNode& node = keyValue.second;
+ if( node.GetType() == TreeNode::ARRAY )
{
- if( OptionalChild animation = IsChild(*animations, animationName) )
+ Dali::Property::Value property(Property::ARRAY);
+ if( DeterminePropertyFromNode( node, Property::ARRAY, property, replacements ) )
{
- anim = Dali::Toolkit::Internal::CreateAnimation( *animation, replacement, Stage::GetCurrent().GetRootLayer() );
+ value = *property.GetArray();
}
- else
+ }
+ else if( node.GetType() == TreeNode::OBJECT )
+ {
+ Dali::Property::Value property(Property::MAP);
+ if( DeterminePropertyFromNode( node, Property::MAP, property, replacements ) )
{
- DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed\n", animationName.c_str() );
+ Property::Array propertyArray;
+ propertyArray.Add( property );
+ value = propertyArray;
}
}
else
{
- DALI_SCRIPT_WARNING( "Request for Animation called '%s' failed (no animation section)\n", animationName.c_str() );
+ DALI_LOG_WARNING( "RecordStyle() Node \"%s\" is not a JSON array or object\n", keyValue.first );
}
-
- 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 )
+void Builder::RecordTransitionData(
+ const TreeNode::KeyNodePair& keyValue,
+ Toolkit::TransitionData& transitionData,
+ const Replacement& replacements )
{
- DALI_ASSERT_ALWAYS( format == Dali::Toolkit::Builder::JSON && "Currently only JSON is supported" );
-
- if( !mParser.Parse(data) )
+ const TreeNode& node = keyValue.second;
+ if( node.GetType() == TreeNode::ARRAY )
{
- DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
- mParser.GetErrorLineNumber(),
- mParser.GetErrorColumn(),
- mParser.GetErrorDescription().c_str() );
-
- DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
+ Dali::Property::Value property(Property::ARRAY);
+ if( DeterminePropertyFromNode( keyValue.second, Property::ARRAY, property, replacements ) )
+ {
+ transitionData = Toolkit::TransitionData::New( *property.GetArray() );
+ }
}
-
- 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)
+ else if( node.GetType() == TreeNode::OBJECT )
{
- mReplacementMap[ (*iter).first ] = (*iter).second;
+ Dali::Property::Value property(Property::MAP);
+ if( DeterminePropertyFromNode( keyValue.second, Property::MAP, property, replacements ) )
+ {
+ transitionData = Toolkit::TransitionData::New( *property.GetMap() );
+ }
}
}
-void Builder::AddConstant( const std::string& key, const Property::Value& value )
-{
- mReplacementMap[key] = value;
-}
-const PropertyValueMap& Builder::GetConstants() const
+// Set properties from node on handle.
+void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node,
+ Dali::Handle& handle, const Replacement& constant )
{
- return mReplacementMap;
+ SetProperties( node, handle, constant );
+ ApplySignals( root, node, handle );
}
-const Property::Value& Builder::GetConstant( const std::string& key ) const
+void Builder::ApplySignals(const TreeNode& root, const TreeNode& node, Dali::Handle& handle )
{
- PropertyValueMap::const_iterator iter = mReplacementMap.find( key );
- if( iter != mReplacementMap.end() )
- {
- return (*iter).second;
- }
- else
+ Actor actor = Actor::DownCast(handle);
+ if( actor )
{
- static Property::Value invalid;
- return invalid;
+ // add signals
+ SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor, this );
+ SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor, this );
}
}
-void Builder::LoadConstants()
-{
- Replacement replacer(mReplacementMap);
- if( OptionalChild constants = IsChild(*mParser.GetRoot(), "constants") )
+// Appling by style helper
+// use FindChildByName() to apply properties referenced in KEYNAME_ACTORS in the node
+void Builder::ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
+ Dali::Handle& handle, const Replacement& constant )
+{
+ if( Dali::Actor actor = Dali::Actor::DownCast( handle ) )
{
- for(TreeNode::ConstIterator iter = (*constants).CBegin();
- iter != (*constants).CEnd(); ++iter)
+ if( const TreeNode* actors = node.GetChild( KEYNAME_ACTORS ) )
{
- Dali::Property::Value property;
- if( (*iter).second.GetName() )
+ // in a style the actor subtree properties referenced by actor name
+ for( TreeConstIter iter = actors->CBegin(); iter != actors->CEnd(); ++iter )
{
-#if defined(DEBUG_ENABLED)
- DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName());
-#endif
- if( SetPropertyFromNode( (*iter).second, property, replacer ) )
+ Dali::Actor foundActor;
+
+ if( (*iter).first )
+ {
+ foundActor = actor.FindChildByName( (*iter).first );
+ }
+
+ if( !foundActor )
{
- mReplacementMap[ (*iter).second.GetName() ] = property;
+ DALI_SCRIPT_VERBOSE("Cannot find actor in style application '%s'\n", (*iter).first);
}
else
{
- DALI_SCRIPT_WARNING("Cannot convert property for constant %s\n",
- (*iter).second.GetName() == NULL ? "no name?" : (*iter).second.GetName());
+ DALI_SCRIPT_VERBOSE("Styles applied to actor '%s'\n", (*iter).first);
+ ApplyProperties( root, (*iter).second, foundActor, constant );
}
}
}
}
+}
-#if defined(DEBUG_ENABLED)
- PropertyValueMap::const_iterator iter = mReplacementMap.find( "CONFIG_SCRIPT_LOG_LEVEL" );
- if( iter != mReplacementMap.end() && (*iter).second.GetType() == Property::STRING )
+/*
+ * Sets the handle properties found in the tree node
+ */
+void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant )
+{
+ if( handle )
{
- 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" )
+ for( TreeNode::ConstIterator iter = node.CBegin(); iter != node.CEnd(); ++iter )
{
- gFilterScript->SetLogLevel( Integration::Log::Verbose );
- }
- }
-#endif
+ const TreeNode::KeyNodePair& keyChild = *iter;
-}
+ std::string key( keyChild.first );
-void Builder::ApplyStyle( const std::string& styleName, Handle& handle )
-{
- Replacement replacer;
- ApplyStyle( styleName, handle, replacer );
+ // ignore special fields;
+ if( key == KEYNAME_TYPE ||
+ key == KEYNAME_ACTORS ||
+ key == KEYNAME_SIGNALS ||
+ key == KEYNAME_STYLES ||
+ key == KEYNAME_MAPPINGS ||
+ key == KEYNAME_INHERIT ||
+ key == KEYNAME_STATES ||
+ key == KEYNAME_VISUALS ||
+ key == KEYNAME_ENTRY_TRANSITION ||
+ key == KEYNAME_EXIT_TRANSITION ||
+ key == KEYNAME_TRANSITIONS )
+ {
+ continue;
+ }
+
+ Property::Index index;
+ Property::Value value;
+
+ bool mapped = MapToTargetProperty( handle, key, keyChild.second, constant, index, value );
+ if( mapped )
+ {
+ 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 );
+ }
+
+ // Add custom properties
+ SetCustomProperties(node, handle, constant, PROPERTIES, Property::READ_WRITE);
+ SetCustomProperties(node, handle, constant, ANIMATABLE_PROPERTIES, Property::ANIMATABLE);
+
+ } // for property nodes
+ }
+ else
+ {
+ DALI_SCRIPT_WARNING("Style applied to empty handle\n");
+ }
}
-void Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement )
+bool Builder::MapToTargetProperty(
+ Handle& propertyObject,
+ const std::string& key,
+ const TreeNode& node,
+ const Replacement& constant,
+ Property::Index& index,
+ Property::Value& value )
{
- OptionalChild styles = IsChild(*mParser.GetRoot(), "styles");
+ bool mapped = false;
- if( styles )
+ index = propertyObject.GetPropertyIndex( key );
+ if( Property::INVALID_INDEX != index )
{
- if( OptionalChild style = IsChild(*styles, styleName) )
- {
- TreeNodeList allStyles;
- TypeInfo typeInfo;
-
- CollectAllStyles( styles, *style, allStyles, typeInfo );
+ Property::Type type = propertyObject.GetPropertyType(index);
- for(TreeNodeList::reverse_iterator iter = allStyles.rbegin(); iter != allStyles.rend(); ++iter)
+ // if node.value is a mapping, get the property value from the "mappings" table
+ if( node.GetType() == TreeNode::STRING )
+ {
+ std::string mappingKey;
+ if( GetMappingKey( node.GetString(), mappingKey) )
{
- 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 );
- }
+ OptionalChild mappingRoot = IsChild( mParser.GetRoot(), KEYNAME_MAPPINGS );
+ mapped = GetPropertyMap( *mappingRoot, mappingKey.c_str(), type, value );
}
}
- else
+ if( ! mapped )
{
- DALI_SCRIPT_WARNING("Could not find style:%s\n", styleName.c_str());
+ mapped = DeterminePropertyFromNode( node, type, value, constant );
+ if( ! mapped )
+ {
+ // Just determine the property from the node and if it's valid, let the property object handle it
+ DeterminePropertyFromNode( node, value, constant );
+ mapped = ( value.GetType() != Property::NONE );
+ }
}
}
else
{
- DALI_SCRIPT_WARNING("No style section available for style:%s\n", styleName.c_str());
+ DALI_LOG_ERROR("Key '%s' not found.\n", key.c_str());
}
+ return mapped;
}
-BaseHandle Builder::CreateFromStyle( const std::string& styleName, const PropertyValueMap& map )
+bool Builder::GetPropertyMap( const TreeNode& mappingRoot, const char* theKey, Property::Type propertyType, Property::Value& value )
{
- Replacement replacement( map, mReplacementMap );
- return CreateFromStyle( styleName, replacement );
+ KeyStack keyStack;
+ return RecursePropertyMap( mappingRoot, keyStack, theKey, propertyType, value );
}
-BaseHandle Builder::CreateFromStyle( const std::string& styleName, const Replacement& constant )
+bool Builder::RecursePropertyMap( const TreeNode& mappingRoot, KeyStack& keyStack, const char* theKey, Property::Type propertyType, Property::Value& value )
{
- BaseHandle baseHandle;
+ Replacement replacer( mReplacementMap );
+ bool result = false;
- OptionalChild styles = IsChild(*mParser.GetRoot(), "styles");
+ keyStack.push_back( theKey );
- if( !styles )
+ for( TreeNode::ConstIterator iter = mappingRoot.CBegin(); iter != mappingRoot.CEnd(); ++iter )
{
- DALI_SCRIPT_WARNING("No style section found to CreateFromStyle\n");
+ std::string aKey( (*iter).first );
+ if( aKey.compare( theKey ) == 0 )
+ {
+ if( propertyType == Property::NONE )
+ {
+ DeterminePropertyFromNode( (*iter).second, value, replacer );
+ result = true;
+ }
+ else
+ {
+ result = DeterminePropertyFromNode( (*iter).second, propertyType, value, replacer );
+ }
+
+ if( result )
+ {
+ ConvertChildValue(mappingRoot, keyStack, value);
+ }
+ break;
+ }
}
- else
+ keyStack.pop_back();
+
+ return result;
+}
+
+bool Builder::ConvertChildValue( const TreeNode& mappingRoot, KeyStack& keyStack, Property::Value& child )
+{
+ bool result = false;
+
+ switch( child.GetType() )
{
- OptionalChild style = IsChild(*styles, styleName);
- if(!style)
+ case Property::STRING:
{
- DALI_SCRIPT_WARNING("Style '%s' does not exist in style section\n", styleName.c_str());
+ std::string value;
+ if( child.Get( value ) )
+ {
+ std::string key;
+ if( GetMappingKey( value, key ) )
+ {
+ // Check key for cycles:
+ result=true;
+ for( KeyStack::iterator iter = keyStack.begin() ; iter != keyStack.end(); ++iter )
+ {
+ if( key.compare(*iter) == 0 )
+ {
+ // key is already in stack; stop.
+ DALI_LOG_WARNING("Detected cycle in stylesheet mapping table:%s\n", key.c_str());
+ child = Property::Value("");
+ result=false;
+ break;
+ }
+ }
+
+ if( result )
+ {
+ // The following call will overwrite the child with the value
+ // from the mapping.
+ RecursePropertyMap( mappingRoot, keyStack, key.c_str(), Property::NONE, child );
+ result = true;
+ }
+ }
+ }
+ break;
}
- else
- {
- OptionalString type = constant.IsString( IsChild(*style, "type") );
- if(!type)
+ case Property::MAP:
+ {
+ Property::Map* map = child.GetMap();
+ if( map )
{
- DALI_SCRIPT_WARNING("Cannot create style '%s' as style section is missing 'type'\n", styleName.c_str());
+ for( Property::Map::SizeType i=0; i < map->Count(); ++i )
+ {
+ Property::Value& child = map->GetValue(i);
+ ConvertChildValue(mappingRoot, keyStack, child);
+ }
}
- else
+ break;
+ }
+
+ case Property::ARRAY:
+ {
+ Property::Array* array = child.GetArray();
+ if( array )
{
- baseHandle = Create( styles, *style, *mParser.GetRoot(), Actor(), constant );
+ for( Property::Array::SizeType i=0; i < array->Count(); ++i )
+ {
+ Property::Value& child = array->GetElementAt(i);
+ ConvertChildValue(mappingRoot, keyStack, child);
+ }
}
+ break;
}
+
+ default:
+ // Ignore other types.
+ break;
}
- return baseHandle;
+ return result;
}
-
-BaseHandle Builder::CreateFromStyle( const std::string& styleName )
+void Builder::SetCustomProperties( const TreeNode& node, Handle& handle, const Replacement& constant,
+ const std::string& childName, Property::AccessMode accessMode )
{
- PropertyValueMap overrideMap;
- Replacement replacement( overrideMap, mReplacementMap );
- return CreateFromStyle( styleName, replacement );
-}
+ // Add custom properties
+ if( OptionalChild customPropertiesChild = IsChild(node, childName) )
+ {
+ const TreeNode& customPropertiesNode = *customPropertiesChild;
+ const TreeConstIter endIter = customPropertiesNode.CEnd();
+ for( TreeConstIter iter = customPropertiesNode.CBegin(); endIter != iter; ++iter )
+ {
+ const TreeNode::KeyNodePair& keyChild = *iter;
+ std::string key( keyChild.first );
+ Property::Value value;
+ DeterminePropertyFromNode( keyChild.second, value, constant );
-Builder::Builder()
-: mSlotDelegate( this )
-{
- mParser = Dali::Toolkit::JsonParser::New();
+ // Register/Set property.
+ handle.RegisterProperty( key, value, accessMode );
+ }
+ }
}
-Builder::~Builder()
-{
-}
} // namespace Internal