X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fbuilder%2Fbuilder-impl.cpp;h=f7b89e1b249356f06233512b7433e8d5e5afc22f;hp=ea0b15a16bf367ab44e4865434be6b91cd29e2fd;hb=912e891b33f2b3b10392094c57b17eefa560b1fa;hpb=577d26decfe241610f22fc92ea0019cd8ac5ceca diff --git a/dali-toolkit/internal/builder/builder-impl.cpp b/dali-toolkit/internal/builder/builder-impl.cpp index ea0b15a..f7b89e1 100644 --- a/dali-toolkit/internal/builder/builder-impl.cpp +++ b/dali-toolkit/internal/builder/builder-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -52,10 +52,10 @@ namespace Internal class Replacement; extern Animation CreateAnimation(const TreeNode& child, const Replacement& replacements, const Dali::Actor searchRoot, Builder* const builder ); -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 void DeterminePropertyFromNode( const TreeNode& node, Property::Value& value ); +extern void DeterminePropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& replacements ); +extern bool DeterminePropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value ); +extern bool DeterminePropertyFromNode( 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, 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); extern Actor SetupActor( const TreeNode& node, Actor& actor, const Replacement& constant ); @@ -67,6 +67,8 @@ Integration::Log::Filter* gFilterScript = Integration::Log::Filter::New(Debug:: namespace { +#define TOKEN_STRING(x) #x + const std::string KEYNAME_STYLES = "styles"; const std::string KEYNAME_TYPE = "type"; const std::string KEYNAME_ACTORS = "actors"; @@ -122,11 +124,6 @@ std::string PropertyValueToString( const Property::Value& value ) ret = ToString( value.Get() ); break; } - case Property::UNSIGNED_INTEGER: - { - ret = ToString( value.Get() ); - break; - } case Property::VECTOR2: { ret = ToString( value.Get() ); @@ -258,7 +255,7 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace // special field 'effect' references the shader effect instances if(key == "effect") { - RenderableActor actor = RenderableActor::DownCast(handle); + ImageActor actor = ImageActor::DownCast(handle); if( actor ) { OptionalString str = constant.IsString( keyChild.second ); @@ -282,7 +279,7 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace if( Property::INVALID_INDEX == index ) { - RenderableActor actor = RenderableActor::DownCast(handle); + ImageActor actor = ImageActor::DownCast(handle); if( actor ) { if( ShaderEffect effect = actor.GetShaderEffect() ) @@ -301,10 +298,10 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace Property::Type type = propertyObject.GetPropertyType(index); Property::Value value; - if( !SetPropertyFromNode( keyChild.second, type, value, constant ) ) + if( !DeterminePropertyFromNode( 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 + // eg parentOrigin can be a string which is picked up later DALI_SCRIPT_VERBOSE("Could not convert property:%s\n", key.c_str()); } else @@ -550,7 +547,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme 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) @@ -563,7 +560,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme } } - 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) @@ -576,7 +573,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme } } - if( OptionalString s = constant.IsString( IsChild(node, "target-frame-buffer") ) ) + if( OptionalString s = constant.IsString( IsChild(node, "targetFrameBuffer") ) ) { FrameBufferImage fb = GetFrameBufferImage( *s, constant ); if(fb) @@ -589,7 +586,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme } } - 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) { @@ -606,8 +603,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme } // other setup is via the property system - SetProperties( node, task, constant ); // @ todo, remove 'source-actor', 'camera-actor'? - + SetProperties( node, task, constant ); } void Builder::CreateRenderTask( const std::string &name ) @@ -618,7 +614,7 @@ void Builder::CreateRenderTask( const std::string &name ) const Stage& stage = Stage::GetCurrent(); - OptionalChild tasks = IsChild(*mParser.GetRoot(), "render-tasks"); + OptionalChild tasks = IsChild(*mParser.GetRoot(), "renderTasks"); if(tasks) { @@ -676,12 +672,12 @@ ShaderEffect Builder::GetShaderEffect( const std::string &name, const Replacemen } else { - if( OptionalChild effects = IsChild( *mParser.GetRoot(), "shader-effects") ) + if( OptionalChild effects = IsChild( *mParser.GetRoot(), "shaderEffects") ) { if( OptionalChild effect = IsChild( *effects, name ) ) { Dali::Property::Value propertyMap(Property::MAP); - if( SetPropertyFromNode( *effect, Property::MAP, propertyMap, constant ) ) + if( DeterminePropertyFromNode( *effect, Property::MAP, propertyMap, constant ) ) { ret = Dali::Scripting::NewShaderEffect( propertyMap ); mShaderEffectLut[ name ] = ret; @@ -712,17 +708,21 @@ FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Re } else { - if( OptionalChild images = IsChild( *mParser.GetRoot(), "frame-buffer-images") ) + if( OptionalChild images = IsChild( *mParser.GetRoot(), "frameBufferImages") ) { if( OptionalChild image = IsChild( *images, name ) ) { Dali::Property::Value property(Property::MAP); - if( SetPropertyFromNode( *image, Property::MAP, property, constant ) ) + if( DeterminePropertyFromNode( *image, Property::MAP, property, constant ) ) { Property::Map* map = property.GetMap(); - (*map)[ KEYNAME_TYPE ] = Property::Value(std::string("FrameBufferImage") ); - ret = FrameBufferImage::DownCast( Dali::Scripting::NewImage( property ) ); - mFrameBufferImageLut[ name ] = ret; + + if( map ) + { + (*map)[ KEYNAME_TYPE ] = Property::Value(std::string("FrameBufferImage") ); + ret = FrameBufferImage::DownCast( Dali::Scripting::NewImage( property ) ); + mFrameBufferImageLut[ name ] = ret; + } } } } @@ -752,16 +752,16 @@ Path Builder::GetPath( const std::string& name ) if( OptionalChild pointsProperty = IsChild( *path, "points") ) { Dali::Property::Value points(Property::ARRAY); - if( SetPropertyFromNode( *pointsProperty, Property::ARRAY, points ) ) + if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) ) { ret = Path::New(); ret.SetProperty( Path::Property::POINTS, points); - //control-points property - if( OptionalChild pointsProperty = IsChild( *path, "control-points") ) + //controlPoints property + if( OptionalChild pointsProperty = IsChild( *path, "controlPoints") ) { Dali::Property::Value points(Property::ARRAY); - if( SetPropertyFromNode( *pointsProperty, Property::ARRAY, points ) ) + if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) ) { ret.SetProperty( Path::Property::CONTROL_POINTS, points); } @@ -826,16 +826,16 @@ PathConstrainer Builder::GetPathConstrainer( const std::string& name ) if( OptionalChild pointsProperty = IsChild( *pathConstrainer, "points") ) { Dali::Property::Value points(Property::ARRAY); - if( SetPropertyFromNode( *pointsProperty, Property::ARRAY, points ) ) + if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) ) { ret = PathConstrainer::New(); ret.SetProperty( PathConstrainer::Property::POINTS, points); - //control-points property - if( OptionalChild pointsProperty = IsChild( *pathConstrainer, "control-points") ) + //controlPoints property + if( OptionalChild pointsProperty = IsChild( *pathConstrainer, "controlPoints") ) { Dali::Property::Value points(Property::ARRAY); - if( SetPropertyFromNode( *pointsProperty, Property::ARRAY, points ) ) + if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) ) { ret.SetProperty( PathConstrainer::Property::CONTROL_POINTS, points); } @@ -935,16 +935,16 @@ Dali::LinearConstrainer Builder::GetLinearConstrainer( const std::string& name ) if( OptionalChild pointsProperty = IsChild( *linearConstrainer, "value") ) { Dali::Property::Value points(Property::ARRAY); - if( SetPropertyFromNode( *pointsProperty, Property::ARRAY, points ) ) + if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) ) { ret = Dali::LinearConstrainer::New(); ret.SetProperty( LinearConstrainer::Property::VALUE, points); - //control-points property + //controlPoints property if( OptionalChild pointsProperty = IsChild( *linearConstrainer, "progress") ) { Dali::Property::Value points(Property::ARRAY); - if( SetPropertyFromNode( *pointsProperty, Property::ARRAY, points ) ) + if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) ) { ret.SetProperty( LinearConstrainer::Property::PROGRESS, points); } @@ -1042,7 +1042,7 @@ void Builder::AddActors( const std::string §ionName, Actor toActor ) // to add automatically if( "stage" == sectionName ) { - if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "render-tasks") ) + if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "renderTasks") ) { if( OptionalChild tasks = IsChild(*renderTasks, "stage") ) { @@ -1117,7 +1117,6 @@ void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::U parser.GetErrorDescription().c_str() ); DALI_ASSERT_ALWAYS(!"Cannot parse JSON"); - } else { @@ -1155,7 +1154,6 @@ void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::U } DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON"); - } void Builder::AddConstants( const Property::Map& map ) @@ -1202,15 +1200,8 @@ void Builder::LoadConstants( const TreeNode& root, Property::Map& intoMap ) #if defined(DEBUG_ENABLED) DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName()); #endif - if( SetPropertyFromNode( (*iter).second, property, replacer ) ) - { - intoMap[ (*iter).second.GetName() ] = property; - } - else - { - DALI_SCRIPT_WARNING("Cannot convert property for constant %s\n", - (*iter).second.GetName() == NULL ? "no name?" : (*iter).second.GetName()); - } + DeterminePropertyFromNode( (*iter).second, property, replacer ); + intoMap[ (*iter).second.GetName() ] = property; } } } @@ -1357,6 +1348,14 @@ Builder::Builder() : mSlotDelegate( this ) { mParser = Dali::Toolkit::JsonParser::New(); + + Property::Map defaultDirs; + defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ] = DALI_IMAGE_DIR; + defaultDirs[ TOKEN_STRING(DALI_SOUND_DIR) ] = DALI_SOUND_DIR; + defaultDirs[ TOKEN_STRING(DALI_STYLE_DIR) ] = DALI_STYLE_DIR; + defaultDirs[ TOKEN_STRING(DALI_STYLE_IMAGE_DIR) ] = DALI_STYLE_IMAGE_DIR; + + AddConstants( defaultDirs ); } Builder::~Builder()