X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=base%2Fdali-toolkit%2Finternal%2Fbuilder%2Fbuilder-impl.cpp;h=083e80494191ca129af5160a75bebf8e30d2c43c;hb=refs%2Ftags%2Fdali_1.0.14;hp=917eadff22a8182187f74e507119a5a68c970c93;hpb=a481f6f5e535b302f7bf7087cd21641b9d374930;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/base/dali-toolkit/internal/builder/builder-impl.cpp b/base/dali-toolkit/internal/builder/builder-impl.cpp index 917eadf..083e804 100644 --- a/base/dali-toolkit/internal/builder/builder-impl.cpp +++ b/base/dali-toolkit/internal/builder/builder-impl.cpp @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include #include // INTERNAL INCLUDES @@ -49,8 +50,8 @@ 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 SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function quitAction); +extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function quitAction); extern Actor SetupActor( const TreeNode& node, Actor& actor, const Replacement& constant ); #if defined(DEBUG_ENABLED) @@ -86,6 +87,7 @@ std::string ToString(const Rect& value) return ss.str(); } +#if defined(DEBUG_ENABLED) std::string PropertyValueToString( const Property::Value& value ) { @@ -165,7 +167,7 @@ std::string PropertyValueToString( const Property::Value& value ) } case Property::MAP: { - ret = std::string("Map Size=") + ToString( value.Get().size() ); + ret = std::string("Map Size=") + ToString( value.Get().Count() ); break; } case Property::TYPE_COUNT: @@ -177,6 +179,7 @@ std::string PropertyValueToString( const Property::Value& value ) return ret; } +#endif // DEBUG_ENABLED /* * Recursively collects all stylesin a node (An array of style names). @@ -208,6 +211,23 @@ void CollectAllStyles( const TreeNode& stylesCollection, const TreeNode& style, } } +struct QuitAction +{ +public: + QuitAction( Builder& builder ) + : mBuilder( builder ) + { + } + + void operator()(void) + { + mBuilder.EmitQuitSignal(); + } + +private: + Builder& mBuilder; +}; + } // namespace anon /* @@ -253,12 +273,15 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace // 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) + RenderableActor actor = RenderableActor::DownCast(handle); + if( actor ) { - ShaderEffect e = GetShaderEffect(*s, constant); - actor.SetShaderEffect(e); + OptionalString str = constant.IsString( keyChild.second ); + if( str ) + { + ShaderEffect effect = GetShaderEffect( *str, constant ); + actor.SetShaderEffect(effect); + } } else { @@ -274,7 +297,7 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace if( Property::INVALID_INDEX == index ) { - Actor actor = Actor::DownCast(propertyObject); + RenderableActor actor = RenderableActor::DownCast(handle); if( actor ) { if( ShaderEffect effect = actor.GetShaderEffect() ) @@ -332,9 +355,9 @@ void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node, SetupActor( node, actor, constant ); // add signals - SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor ); - - SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor ); + QuitAction quitAction( *this ); + SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor, quitAction ); + SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor, quitAction ); } } else @@ -504,9 +527,7 @@ BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node, } } - ApplyProperties( root, node, handle, replacements ); - - if( actor) + if( actor ) { // add children of all the styles if( OptionalChild actors = IsChild( node, KEYNAME_ACTORS ) ) @@ -526,7 +547,10 @@ BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node, parent.Add( actor ); } } - + else + { + ApplyProperties( root, node, handle, replacements ); + } } else { @@ -722,6 +746,16 @@ FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Re return ret; } +Toolkit::Builder::Signal& Builder::QuitSignal() +{ + return mQuitSignal; +} + +void Builder::EmitQuitSignal() +{ + mQuitSignal.Emit(); +} + void Builder::AddActors( Actor toActor ) { // 'stage' is the default/by convention section to add from @@ -732,7 +766,7 @@ void Builder::AddActors( const std::string §ionName, Actor toActor ) { DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded"); - PropertyValueMap overrideMap; + Property::Map overrideMap; Replacement replacements(overrideMap, mReplacementMap); OptionalChild add = IsChild(*mParser.GetRoot(), sectionName); @@ -790,13 +824,13 @@ Animation Builder::CreateAnimation( const std::string& animationName, const Repl return anim; } -Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map, Dali::Actor sourceActor ) +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 PropertyValueMap& map ) +Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map ) { Replacement replacement(map, mReplacementMap); return CreateAnimation( animationName, replacement, Stage::GetCurrent().GetRootLayer() ); @@ -872,12 +906,9 @@ void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::U } -void Builder::AddConstants( const PropertyValueMap& map ) +void Builder::AddConstants( const Property::Map& map ) { - for(PropertyValueMap::const_iterator iter = map.begin(); iter != map.end(); ++iter) - { - mReplacementMap[ (*iter).first ] = (*iter).second; - } + mReplacementMap.Merge( map ); } void Builder::AddConstant( const std::string& key, const Property::Value& value ) @@ -885,17 +916,17 @@ void Builder::AddConstant( const std::string& key, const Property::Value& value mReplacementMap[key] = value; } -const PropertyValueMap& Builder::GetConstants() const +const Property::Map& Builder::GetConstants() const { return mReplacementMap; } const Property::Value& Builder::GetConstant( const std::string& key ) const { - PropertyValueMap::const_iterator iter = mReplacementMap.find( key ); - if( iter != mReplacementMap.end() ) + Property::Value* match = mReplacementMap.Find( key ); + if( match ) { - return (*iter).second; + return (*match); } else { @@ -904,7 +935,7 @@ const Property::Value& Builder::GetConstant( const std::string& key ) const } } -void Builder::LoadConstants( const TreeNode& root, PropertyValueMap& intoMap ) +void Builder::LoadConstants( const TreeNode& root, Property::Map& intoMap ) { Replacement replacer(intoMap); @@ -933,10 +964,10 @@ void Builder::LoadConstants( const TreeNode& root, PropertyValueMap& intoMap ) } #if defined(DEBUG_ENABLED) - PropertyValueMap::const_iterator iter = intoMap.find( "CONFIG_SCRIPT_LOG_LEVEL" ); - if( iter != intoMap.end() && (*iter).second.GetType() == Property::STRING ) + Property::Value* iter = intoMap.Find( "CONFIG_SCRIPT_LOG_LEVEL" ); + if( iter && iter->GetType() == Property::STRING ) { - std::string logLevel( (*iter).second.Get< std::string >() ); + std::string logLevel( iter->Get< std::string >() ); if( logLevel == "NoLogging" ) { gFilterScript->SetLogLevel( Integration::Log::NoLogging ); @@ -978,12 +1009,11 @@ bool Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Re } else { - DALI_SCRIPT_WARNING("No styles section to create style '%s'\n", styleName.c_str()); return false; } } -BaseHandle Builder::Create( const std::string& templateName, const PropertyValueMap& map ) +BaseHandle Builder::Create( const std::string& templateName, const Property::Map& map ) { Replacement replacement( map, mReplacementMap ); return Create( templateName, replacement ); @@ -1026,6 +1056,44 @@ BaseHandle Builder::Create( const std::string& templateName, const Replacement& return baseHandle; } +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; +} + BaseHandle Builder::Create( const std::string& templateName ) {