Actor NewActor( const Property::Map& map )
{
  BaseHandle handle;

  // First find type and create Actor
  Property::Value* typeValue = map.Find( "type" );
  if ( typeValue )
  {
    TypeInfo type = TypeRegistry::Get().GetTypeInfo( typeValue->Get< std::string >() );
    if ( type )
    {
      handle = type.CreateInstance();
    }
  }

  if ( !handle )
  {
    DALI_LOG_ERROR( "Actor type not provided\n" );
    return Actor();
  }

  Actor actor( Actor::DownCast( handle ) );

  if ( actor )
  {
    // Now set the properties, or create children
    for ( unsigned int i = 0, mapCount = map.Count(); i < mapCount; ++i )
    {
      const StringValuePair& pair( map.GetPair( i ) );
      const std::string& key( pair.first );
      if ( key == "type" )
      {
        continue;
      }

      const Property::Value& value( pair.second );

      if ( key == "actors" )
      {
        // Create children
        Property::Array actorArray = value.Get< Property::Array >();
        for ( Property::Array::SizeType i = 0; i < actorArray.Size(); ++i)
        {
          actor.Add( NewActor( actorArray[i].Get< Property::Map >() ) );
        }
      }
      else
      {
        Property::Index index( actor.GetPropertyIndex( key ) );

        if ( index != Property::INVALID_INDEX )
        {
          actor.SetProperty( index, value );
        }
      }
    }
  }

  return actor;
}
예제 #2
0
int UtcDaliPropertyMapGetPair(void)
{
  Property::Map map;
  map[ "hello" ] = 1;
  map[ "world" ] = 2;

  DALI_TEST_CHECK( map.GetPair( 0 ).first == "hello" );
  DALI_TEST_CHECK( map.GetPair( 0 ).second.Get< int >() == 1 );
  DALI_TEST_CHECK( map.GetPair( 1 ).first == "world" );
  DALI_TEST_CHECK( map.GetPair( 1 ).second.Get< int >() == 2 );

  // Out of bounds
  try
  {
    map.GetPair( 2 );
    tet_result( TET_FAIL );
  }
  catch ( DaliException& e )
  {
    DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
  }

  END_TEST;
}
void NewAnimation( const Property::Map& map, Dali::AnimationData& outputAnimationData )
{
  // Note: Builder cannot currently pass generic Property::Maps "{" that are nested, so currently we can only have one AnimateTo per animation.
  Dali::AnimationData::AnimationDataElement* element = new Dali::AnimationData::AnimationDataElement();
  element->alphaFunction = AlphaFunction::LINEAR;
  element->timePeriodDelay = 0.0f;
  element->timePeriodDuration = 1.0f;

  // Now set the properties, or create children
  for( unsigned int i = 0, animationMapCount = map.Count(); i < animationMapCount; ++i )
  {
    const StringValuePair& pair( map.GetPair( i ) );
    const std::string& key( pair.first );
    const Property::Value& value( pair.second );

    if( key == "actor" )
    {
      element->actor = value.Get< std::string >();
    }
    else if( key == "property" )
    {
      element->property = value.Get< std::string >();
    }
    else if( key == "value" )
    {
      element->value = value;
    }
    else if( key == "alphaFunction" )
    {
      std::string alphaFunctionValue = value.Get< std::string >();

      if( alphaFunctionValue == "LINEAR" )
      {
        element->alphaFunction = AlphaFunction::LINEAR;
      }
      else if( alphaFunctionValue == "REVERSE" )
      {
        element->alphaFunction = AlphaFunction::REVERSE;
      }
      else if( alphaFunctionValue == "EASE_IN_SQUARE" )
      {
        element->alphaFunction = AlphaFunction::EASE_IN_SQUARE;
      }
      else if( alphaFunctionValue == "EASE_OUT_SQUARE" )
      {
        element->alphaFunction = AlphaFunction::EASE_OUT_SQUARE;
      }
      else if( alphaFunctionValue == "EASE_IN" )
      {
        element->alphaFunction = AlphaFunction::EASE_IN;
      }
      else if( alphaFunctionValue == "EASE_OUT" )
      {
        element->alphaFunction = AlphaFunction::EASE_OUT;
      }
      else if( alphaFunctionValue == "EASE_IN_OUT" )
      {
        element->alphaFunction = AlphaFunction::EASE_IN_OUT;
      }
      else if( alphaFunctionValue == "EASE_IN_SINE" )
      {
        element->alphaFunction = AlphaFunction::EASE_IN_SINE;
      }
      else if( alphaFunctionValue == "EASE_OUT_SINE" )
      {
        element->alphaFunction = AlphaFunction::EASE_OUT_SINE;
      }
      else if( alphaFunctionValue == "EASE_IN_OUT_SINE" )
      {
        element->alphaFunction = AlphaFunction::EASE_IN_OUT_SINE;
      }
      else if( alphaFunctionValue == "BOUNCE" )
      {
        element->alphaFunction = AlphaFunction::BOUNCE;
      }
      else if( alphaFunctionValue == "SIN" )
      {
        element->alphaFunction = AlphaFunction::SIN;
      }
      else if( alphaFunctionValue == "EASE_OUT_BACK" )
      {
        element->alphaFunction = AlphaFunction::EASE_OUT_BACK;
      }
    }
    else if( key == "timePeriod" )
    {
      Property::Map timeMap = value.Get< Property::Map >();
      for( unsigned int i = 0; i < timeMap.Count(); ++i )
      {
        const StringValuePair& pair( timeMap.GetPair( i ) );
        if( pair.first == "delay" )
        {
          element->timePeriodDelay = pair.second.Get< float >();
        }
        else if( pair.first == "duration" )
        {
          element->timePeriodDuration = pair.second.Get< float >();
        }
      }
    }
  }

  outputAnimationData.Add( element );
}