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=8bcdff1d863f6f273f051f4d9c640573b61c82a6;hp=5a18bef4a46705dfdcc1c3b38f29f720488efd95;hb=078278a2ea58db1f07114513bf21783eb689f63a;hpb=9336a7a410400f6ac2d3c5793e481f7984476517 diff --git a/dali-toolkit/internal/builder/builder-impl.cpp b/dali-toolkit/internal/builder/builder-impl.cpp index 5a18bef..8bcdff1 100644 --- a/dali-toolkit/internal/builder/builder-impl.cpp +++ b/dali-toolkit/internal/builder/builder-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -29,12 +29,14 @@ #include #include #include +#include #include #include #include // INTERNAL INCLUDES #include +#include #include #include @@ -155,10 +157,10 @@ Builder::Builder() 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; + 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 ); } @@ -179,10 +181,10 @@ void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::U } else { - // load configuration map - LoadConfiguration( *parser.GetRoot(), mConfigurationMap ); // 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) ) { @@ -458,48 +460,6 @@ void Builder::CreateRenderTask( const std::string &name ) } } -FrameBufferImage Builder::GetFrameBufferImage( const std::string &name ) -{ - Replacement constant( mReplacementMap ); - return GetFrameBufferImage(name, constant); -} - -FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Replacement& constant ) -{ - DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded"); - - FrameBufferImage ret; - - ImageLut::const_iterator iter( mFrameBufferImageLut.find( name ) ); - if( iter != mFrameBufferImageLut.end() ) - { - ret = iter->second; - } - else - { - if( OptionalChild images = IsChild( *mParser.GetRoot(), "frameBufferImages") ) - { - if( OptionalChild image = IsChild( *images, name ) ) - { - Dali::Property::Value property(Property::MAP); - if( DeterminePropertyFromNode( *image, Property::MAP, property, constant ) ) - { - Property::Map* map = property.GetMap(); - - if( map ) - { - (*map)[ KEYNAME_TYPE ] = Property::Value(std::string("FrameBufferImage") ); - ret = FrameBufferImage::DownCast( Dali::Scripting::NewImage( property ) ); - mFrameBufferImageLut[ name ] = ret; - } - } - } - } - } - - return ret; -} - Path Builder::GetPath( const std::string& name ) { DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded"); @@ -797,6 +757,61 @@ void Builder::LoadConfiguration( const TreeNode& root, Property::Map& intoMap ) if( (*iter).second.GetName() ) { DeterminePropertyFromNode( (*iter).second, property, replacer ); + + // If config is string, find constant and replace it to original value. + if( (*iter).second.GetType() == TreeNode::STRING ) + { + std::string stringConfigValue; + if( property.Get( stringConfigValue ) ) + { + std::size_t pos = 0; + + while( pos < stringConfigValue.size() ) + { + // 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 + { + // If we cannot find constant in const value, will out loop. + pos = stringConfigValue.size(); + } + } + property = Property::Value( stringConfigValue ); + } + } intoMap[ (*iter).second.GetName() ] = property; } } @@ -971,13 +986,13 @@ BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node, if(actor) { - DALI_SCRIPT_VERBOSE(" Is Actor id=%d\n", actor.GetId()); + DALI_SCRIPT_VERBOSE(" Is Actor id=%d\n", actor.GetProperty< int >( Actor::Property::ID )); } Toolkit::Control control = Toolkit::Control::DownCast(handle); if(control) { - DALI_SCRIPT_VERBOSE(" Is Control id=%d\n", actor.GetId()); + DALI_SCRIPT_VERBOSE(" Is Control id=%d\n", actor.GetProperty< int >( Actor::Property::ID )); } #endif // DEBUG_ENABLED @@ -1059,19 +1074,6 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme } } - if( OptionalString s = constant.IsString( IsChild(node, "targetFrameBuffer") ) ) - { - 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, "screenToFrameBufferFunction") ) ) { if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s) @@ -1243,7 +1245,11 @@ void Builder::RecordStyle( StylePtr style, } else { - style->visuals.Add(visual.first, *property.GetMap()); + Property::Map* map = property.GetMap(); + if( map ) + { + style->visuals.Add( visual.first, *map ); + } } } }