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=de40d44e3caeb219fc004fb708ff26774cbab635;hp=be1993cf03c6bc35308f20ee9eab865724a4103a;hb=4ff601968ee16e6d401977900d2aed328bdc6707;hpb=22e89375677d1fe737d5472e21ab681f2f3e4ca7 diff --git a/dali-toolkit/internal/builder/builder-impl.cpp b/dali-toolkit/internal/builder/builder-impl.cpp index be1993c..de40d44 100644 --- a/dali-toolkit/internal/builder/builder-impl.cpp +++ b/dali-toolkit/internal/builder/builder-impl.cpp @@ -20,20 +20,21 @@ // EXTERNAL INCLUDES #include -#include #include #include #include #include +#include #include #include #include -#include +#include +#include #include // INTERNAL INCLUDES #include -#include +#include #include #include @@ -55,8 +56,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, boost::function quitAction, Dali::Toolkit::Internal::Builder* const builder); -extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function quitAction, Dali::Toolkit::Internal::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); extern Actor SetupActor( const TreeNode& node, Actor& actor, const Replacement& constant ); #if defined(DEBUG_ENABLED) @@ -66,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"; @@ -121,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() ); @@ -167,7 +165,7 @@ std::string PropertyValueToString( const Property::Value& value ) } case Property::ARRAY: { - ret = std::string("Array Size=") + ToString( value.Get().size() ); + ret = std::string("Array Size=") + ToString( value.Get().Size() ); break; } case Property::MAP: @@ -175,11 +173,6 @@ std::string PropertyValueToString( const Property::Value& value ) ret = std::string("Map Size=") + ToString( value.Get().Count() ); break; } - case Property::TYPE_COUNT: - { - ret = ""; - break; - } } return ret; @@ -216,22 +209,6 @@ 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 @@ -278,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 ); @@ -302,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() ) @@ -324,7 +301,7 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace 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 + // eg parentOrigin can be a string which is picked up later DALI_SCRIPT_VERBOSE("Could not convert property:%s\n", key.c_str()); } else @@ -360,9 +337,8 @@ void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node, SetupActor( node, actor, constant ); // add signals - QuitAction quitAction( *this ); - SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor, quitAction, this ); - SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor, quitAction, this ); + SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor, this ); + SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor, this ); } } else @@ -571,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) @@ -584,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) @@ -597,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) @@ -610,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) { @@ -627,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 ) @@ -639,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) { @@ -697,7 +672,7 @@ 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 ) ) { @@ -733,16 +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 propertyMap(Property::MAP); - if( SetPropertyFromNode( *image, Property::MAP, propertyMap, constant ) ) + Dali::Property::Value property(Property::MAP); + if( SetPropertyFromNode( *image, Property::MAP, property, constant ) ) { - propertyMap.SetValue(KEYNAME_TYPE, Property::Value(std::string("FrameBufferImage"))); - ret = FrameBufferImage::DownCast( Dali::Scripting::NewImage( propertyMap ) ); - mFrameBufferImageLut[ name ] = ret; + 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; + } } } } @@ -777,8 +757,8 @@ Path Builder::GetPath( const std::string& name ) 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 ) ) @@ -814,6 +794,212 @@ Path Builder::GetPath( const std::string& name ) 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 ) + { + //PathConstrainer has already been created + return mPathConstrainerLut[i].pathConstrainer; + } + } + + //Create a new PathConstrainer + PathConstrainer ret; + if( OptionalChild constrainers = IsChild( *mParser.GetRoot(), "constrainers") ) + { + if( OptionalChild pathConstrainer = IsChild( *constrainers, name ) ) + { + 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( SetPropertyFromNode( *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( SetPropertyFromNode( *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() ); + } + } + } + + 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 ) + { + return true; + } + } + + if( OptionalChild constrainers = IsChild( *mParser.GetRoot(), "constrainers") ) + { + if( OptionalChild constrainer = IsChild( *constrainers, name ) ) + { + OptionalString constrainerType(IsString(IsChild(*constrainer, "type"))); + if(!constrainerType) + { + return false; + } + else + { + return *constrainerType == "PathConstrainer"; + } + } + } + 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 ) + { + //LinearConstrainer has already been created + return mLinearConstrainerLut[i].linearConstrainer; + } + } + + //Create a new LinearConstrainer + LinearConstrainer ret; + if( OptionalChild constrainers = IsChild( *mParser.GetRoot(), "constrainers") ) + { + if( OptionalChild linearConstrainer = IsChild( *constrainers, name ) ) + { + 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( SetPropertyFromNode( *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( SetPropertyFromNode( *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; +} + +bool Builder::IsLinearConstrainer( const std::string& name ) +{ + //Search the LinearConstrainer in the LUT + size_t count( mLinearConstrainerLut.size() ); + for( size_t i(0); i!=count; ++i ) + { + if( mLinearConstrainerLut[i].name == name ) + { + return true; + } + } + + if( OptionalChild constrainers = IsChild( *mParser.GetRoot(), "constrainers") ) + { + if( OptionalChild constrainer = IsChild( *constrainers, name ) ) + { + OptionalString constrainerType(IsString(IsChild(*constrainer, "type"))); + if(!constrainerType) + { + return false; + } + else + { + return *constrainerType == "LinearConstrainer"; + } + } + } + return false; +} + Toolkit::Builder::BuilderSignalType& Builder::QuitSignal() { return mQuitSignal; @@ -856,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") ) { @@ -931,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 { @@ -969,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 ) @@ -1171,6 +1355,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()