コード例 #1
0
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 UtcDaliPropertyMapInsertP(void)
{
  Property::Map map;
  DALI_TEST_EQUALS( 0, map.Count(), TEST_LOCATION );
  map.Insert( "foo", "bar");
  DALI_TEST_EQUALS( 1, map.Count(), TEST_LOCATION );
  Property::Value* value = map.Find( "foo" );
  DALI_TEST_CHECK( value );
  DALI_TEST_EQUALS( "bar", value->Get<std::string>(), TEST_LOCATION );
  map.Insert( std::string("foo2"), "testing" );
  DALI_TEST_EQUALS( 2, map.Count(), TEST_LOCATION );
  value = map.Find( "foo2" );
  DALI_TEST_CHECK( value );
  DALI_TEST_EQUALS( "testing", value->Get<std::string>(), TEST_LOCATION );

  END_TEST;
}
コード例 #3
0
int UtcDaliPropertyMapCopyAndAssignment(void)
{
  Property::Map map;
  map[ "hello" ] = 1;
  map[ "world" ] = 2;

  Property::Map assignedMap;
  assignedMap[ "foo" ] = 3;
  DALI_TEST_CHECK( assignedMap.Count() == 1 );
  assignedMap = map;
  DALI_TEST_CHECK( assignedMap.Count() == 2 );

  Property::Map copiedMap( map );
  DALI_TEST_CHECK( copiedMap.Count() == 2 );

  // Self assignment
  DALI_TEST_CHECK( map.Count() == 2 );
  map = map;
  DALI_TEST_CHECK( map.Count() == 2 );

  END_TEST;
}
コード例 #4
0
int UtcDaliPropertyMapPopulate(void)
{
  Property::Map map;
  DALI_TEST_CHECK( map.Empty() );

  map[ "hello" ] = 1;
  map[ "world" ] = "world";
  map[ "world" ] = 3; // same item as line above
  DALI_TEST_CHECK( !map.Empty() ); // Should no longer be empty
  DALI_TEST_CHECK( map.Count() == 2 ); // Should only have two items, not three!!
  DALI_TEST_CHECK( map["hello"].Get<int>() == 1 );
  DALI_TEST_CHECK( map["world"].Get<int>() == 3 );

  map.Clear();
  DALI_TEST_CHECK( map.Empty() );
  END_TEST;
}
コード例 #5
0
int UtcDaliPropertyMapConstOperator(void)
{
  Property::Map map;
  map[ "hello" ] = 1;
  map[ "world" ] = 2;
  DALI_TEST_CHECK( map.Count() == 2 );

  const Property::Map& constMap( map );
  DALI_TEST_CHECK( constMap[ "world" ].Get<int>() == 2 );
  DALI_TEST_CHECK( constMap.Count() == 2 ); // Ensure count hasn't gone up

  // Invalid Key
  try
  {
    constMap[ "invalid-key" ];
    tet_result( TET_FAIL );
  }
  catch ( DaliException& e )
  {
    DALI_TEST_ASSERT( e, "! \"Invalid Key\"", TEST_LOCATION );
  }

  END_TEST;
}
コード例 #6
0
bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value,
                          const Replacement& replacer )
{
  bool done = false;

  switch(type)
  {
    case Property::BOOLEAN:
    {
      if( OptionalBoolean v = replacer.IsBoolean(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::FLOAT:
    {
      if( OptionalFloat v = replacer.IsFloat(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::INTEGER:
    {
      if( OptionalInteger v = replacer.IsInteger(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::VECTOR2:
    {
      if( OptionalVector2 v = replacer.IsVector2(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::VECTOR3:
    {
      if( OptionalVector3 v = replacer.IsVector3(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::VECTOR4:
    {
      if( OptionalVector4 v = replacer.IsVector4(node) )
      {
        value = *v;
        done = true;
      }
      else if( OptionalString s = replacer.IsString(node) )
      {
        if( (*s)[0] == '#' && 7 == (*s).size() )
        {
          value = HexStringToVector4( &(*s)[1] );
          done = true;
        }
        else if( Dali::ColorController::Get() )
        {
          Vector4 color;
          done = Dali::ColorController::Get().RetrieveColor( *s, color );
          value = color;
        }
      }
      else if( TreeNode::OBJECT == node.GetType() )
      {
        // check for "r", "g" and "b" child color component nodes
        OptionalInteger r = replacer.IsInteger( IsChild(node, "r") );
        OptionalInteger g = replacer.IsInteger( IsChild(node, "g") );
        OptionalInteger b = replacer.IsInteger( IsChild(node, "b") );
        if( r && g && b )
        {
          float red( (*r) * (1.0f/255.0f) );
          float green( (*g) * (1.0f/255.0f) );
          float blue( (*b) * (1.0f/255.0f) );
          // check for optional "a" (alpha) node, default to fully opaque if it is not found.
          float alpha( 1.0f );
          OptionalInteger a = replacer.IsInteger( IsChild(node, "a") );
          if( a )
          {
            alpha = (*a) * (1.0f/255.0f);
          }
          value = Vector4( red, green, blue, alpha );
          done = true;
        }
      }
      break;
    }
    case Property::MATRIX3:
    {
      if( OptionalMatrix3 v = replacer.IsMatrix3(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::MATRIX:
    {
      if( OptionalMatrix v = replacer.IsMatrix(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::RECTANGLE:
    {
      if( OptionalRect v = replacer.IsRect(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::ROTATION:
    {
      if(4 == node.Size())
      {
        if( OptionalVector4 ov = replacer.IsVector4(node) )
        {
          const Vector4& v = *ov;
          // angle, axis as per spec
          value = Quaternion(Radian(Degree(v[3])),
                             Vector3(v[0],v[1],v[2]));
          done = true;
        }
      }
      else
      {
        // degrees Euler as per spec
        if( OptionalVector3 v = replacer.IsVector3(node) )
        {
          value = Quaternion(Radian(Degree((*v).x)),
                             Radian(Degree((*v).y)),
                             Radian(Degree((*v).z)));
          done = true;
        }
      }
      break;
    }
    case Property::STRING:
    {
      if( OptionalString v = replacer.IsString(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::ARRAY:
    {
      if( replacer.IsArray( node, value ) )
      {
        done = true;
      }
      else if(node.Size())
      {
        value = Property::Value(Property::ARRAY);
        Property::Array* array = value.GetArray();

        unsigned int i = 0;
        TreeNode::ConstIterator iter(node.CBegin());

        if( array )
        {
          for( ; i < node.Size(); ++i, ++iter)
          {
            Property::Value childValue;
            if( SetPropertyFromNode( (*iter).second, childValue, replacer ) )
            {
              array->PushBack( childValue );
            }
          }

          if( array->Count() == node.Size() )
          {
            done = true;
          }
          else
          {
            done = false;
          }
        }
      }
      break;
    }
    case Property::MAP:
    {
      if( replacer.IsMap( node, value ) )
      {
        done = true;
      }
      else if(node.Size())
      {
        value = Property::Value(Property::MAP);
        Property::Map* map = value.GetMap();

        unsigned int i = 0;
        TreeNode::ConstIterator iter(node.CBegin());

        if( map )
        {
          for( ; i < node.Size(); ++i, ++iter)
          {
            Property::Value childValue;
            if( SetPropertyFromNode( (*iter).second, childValue, replacer ) )
            {
              map->Insert( (*iter).first, childValue );
            }
          }

          if( map->Count() == node.Size() )
          {
            done = true;
          }
          else
          {
            done = false;
          }
        }
      }
      break;
    }
    case Property::NONE:
    {
      break;
    }
  } // switch type

  return done;
}
コード例 #7
0
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 );
}
コード例 #8
0
int UtcDaliPropertyMapMerge(void)
{
  Property::Map map;
  map[ "hello" ] = 1;
  map[ "world" ] = 2;

  DALI_TEST_CHECK( map.Count() == 2 );

  // Create another map with the same keys but different values
  Property::Map map2;
  map[ "hello" ] = 3;
  map[ "world" ] = 4;

  // Merge map2 into map1, count should still be 2, map values should be from map2
  map.Merge( map2 );
  DALI_TEST_CHECK( map.Count() == 2 );
  DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
  DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );

  // Create another map with different keys
  Property::Map map3;
  map3[ "foo" ] = 5;
  map3[ "bar" ] = 6;

  // Merge map3 into map1, count should increase, existing values should match previous and new values should match map3
  map.Merge( map3 );
  DALI_TEST_CHECK( map.Count() == 4 );
  DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
  DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
  DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 );
  DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 );

  // Create an empty map and attempt to merge, should be successful, nothing should change
  Property::Map map4;
  DALI_TEST_CHECK( map4.Empty() );
  map.Merge( map4 );
  DALI_TEST_CHECK( map4.Empty() );
  DALI_TEST_CHECK( map.Count() == 4 );
  DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
  DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
  DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 );
  DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 );

  // Merge map into map4, map4 should be the same as map now.
  map4.Merge( map );
  DALI_TEST_CHECK( map4.Count() == 4 );
  DALI_TEST_CHECK( map4[ "hello" ].Get< int >() == 3 );
  DALI_TEST_CHECK( map4[ "world"].Get< int >() == 4 );
  DALI_TEST_CHECK( map4[ "foo"].Get< int >() == 5 );
  DALI_TEST_CHECK( map4[ "bar"].Get< int >() == 6 );

  // Attempt to merge into itself, should be successful, nothing should change
  map.Merge( map );
  DALI_TEST_CHECK( map.Count() == 4 );
  DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
  DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
  DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 );
  DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 );

  END_TEST;
}