void CreatePropertyMap( Actor actor, Property::Map& map )
{
  map.Clear();

  if ( actor )
  {
    map[ "type" ] = actor.GetTypeName();

    // Default properties
    Property::IndexContainer indices;
    actor.GetPropertyIndices( indices );
    const Property::IndexContainer::ConstIterator endIter = indices.End();

    for ( Property::IndexContainer::Iterator iter = indices.Begin(); iter != endIter; ++iter )
    {
      map[ actor.GetPropertyName( *iter ) ] = actor.GetProperty( *iter );
    }

    // Children
    unsigned int childCount( actor.GetChildCount() );
    if ( childCount )
    {
      Property::Array childArray;
      for ( unsigned int child = 0; child < childCount; ++child )
      {
        Property::Map childMap;
        CreatePropertyMap( actor.GetChildAt( child ), childMap );
        childArray.PushBack( childMap );
      }
      map[ "actors" ] = childArray;
    }
  }
}
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;
}
示例#3
0
int UtcDaliPropertyArrayCapacityP(void)
{
  Property::Array array;
  DALI_TEST_CHECK( array.Empty() );

  array.Reserve(3);

  DALI_TEST_CHECK( 3 == array.Capacity() );
  END_TEST;
}
示例#4
0
int UtcDaliPropertyArrayResize(void)
{
  Property::Array array;

  array.Resize(3);
  DALI_TEST_CHECK( array.Count() == 3 );

  array.Resize(5);
  DALI_TEST_CHECK( array.Count() == 5 );

  END_TEST;
}
示例#5
0
void Property::Value::SetItem(const int index, const Property::Value &value)
{
  switch( GetType() )
  {
    case Property::MAP:
    {
      Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue));
      if( container && index < static_cast<int>(container->size()) )
      {
        int i = 0;
        for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter)
        {
          if(i++ == index)
          {
            iter->second = value;
            break;
          }
        }
      }
    }
    break;

    case Property::ARRAY:
    {
      Property::Array *container = AnyCast<Property::Array>(&(mImpl->mValue));
      if( container && index < static_cast<int>(container->size()) )
      {
        (*container)[index] = value;
      }
    }
    break;

    case Property::NONE:
    case Property::BOOLEAN:
    case Property::FLOAT:
    case Property::INTEGER:
    case Property::UNSIGNED_INTEGER:
    case Property::VECTOR2:
    case Property::VECTOR3:
    case Property::VECTOR4:
    case Property::MATRIX3:
    case Property::MATRIX:
    case Property::RECTANGLE:
    case Property::ROTATION:
    case Property::STRING:
    case Property::TYPE_COUNT:
    {
      DALI_ASSERT_ALWAYS(!"Cannot SetItem on property Type; not a container");
      break;
    }
  }
}
示例#6
0
int UtcDaliPropertyArrayPushBackP(void)
{
  Property::Array array;

  DALI_TEST_CHECK( 0 == array.Size() );

  array.PushBack( 1 );

  DALI_TEST_CHECK( 1 == array.Size() );

  DALI_TEST_CHECK( array[0].Get<int>() == 1 );

  END_TEST;
}
示例#7
0
int UtcDaliPropertyArrayIndexOperatorP(void)
{
  Property::Array array;

  array.Reserve(3);
  array.PushBack( 1 );
  array.PushBack( "world" );
  array.PushBack( 3 );

  DALI_TEST_CHECK( array[0].Get<int>() == 1 );
  DALI_TEST_CHECK( array[1].Get<std::string>() == "world" );
  DALI_TEST_CHECK( array[2].Get<int>() == 3 );

  END_TEST;
}
示例#8
0
int Property::Value::GetSize() const
{
  int ret = 0;

  switch(GetType())
  {
    case Property::MAP:
    {
      Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue));
      if(container)
      {
        ret = container->size();
      }
    }
    break;

    case Property::ARRAY:
    {
      Property::Array *container = AnyCast<Property::Array>(&(mImpl->mValue));
      if(container)
      {
        ret = container->size();
      }
    }
    break;

    case Property::NONE:
    case Property::BOOLEAN:
    case Property::FLOAT:
    case Property::INTEGER:
    case Property::UNSIGNED_INTEGER:
    case Property::VECTOR2:
    case Property::VECTOR3:
    case Property::VECTOR4:
    case Property::MATRIX3:
    case Property::MATRIX:
    case Property::RECTANGLE:
    case Property::ROTATION:
    case Property::STRING:
    case Property::TYPE_COUNT:
    {
      break;
    }

  }

  return ret;
}
示例#9
0
int Property::Value::AppendItem(const Property::Value &value)
{
  DALI_ASSERT_DEBUG(Property::ARRAY == GetType() && "Property type invalid");

  Property::Array *container = AnyCast<Property::Array>(&(mImpl->mValue));

  if(container)
  {
    container->push_back(value);
    return container->size() - 1;
  }
  else
  {
    return -1;
  }

}
示例#10
0
int UtcDaliPropertyArrayCountP(void)
{
  Property::Array array;
  DALI_TEST_CHECK( 0 == array.Capacity() );
  DALI_TEST_CHECK( 0 == array.Count() );

  array.Reserve(3);

  DALI_TEST_CHECK( 3 == array.Capacity() );
  DALI_TEST_CHECK( 0 == array.Count() );

  array.PushBack( 1 );
  array.PushBack( "world" );
  array.PushBack( 3 );

  DALI_TEST_CHECK( 3 == array.Count() );

  END_TEST;
}
示例#11
0
int UtcDaliPropertyArrayClearP(void)
{
  Property::Array array;
  DALI_TEST_CHECK( array.Empty() );

  array.Reserve(3);

  DALI_TEST_CHECK( array.Empty() );

  array.PushBack( 1 );
  array.PushBack( "world" );
  array.PushBack( 3 );

  DALI_TEST_CHECK( !array.Empty() );

  array.Clear();

  DALI_TEST_CHECK( array.Empty() );

  END_TEST;
}
示例#12
0
int UtcDaliScriptingNewActorChildren(void)
{
  TestApplication application;

  Property::Map map;
  map[ "type" ] = "Actor";
  map[ "position" ] = Vector3::XAXIS;

  Property::Map child1Map;
  child1Map[ "type" ] = "ImageActor";
  child1Map[ "position" ] = Vector3::YAXIS;

  Property::Array childArray;
  childArray.PushBack( child1Map );
  map[ "actors" ] = childArray;

  // Create
  Actor handle = NewActor( map );
  DALI_TEST_CHECK( handle );

  Stage::GetCurrent().Add( handle );
  application.SendNotification();
  application.Render();

  DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
  DALI_TEST_EQUALS( handle.GetChildCount(), 1u, TEST_LOCATION );

  Actor child1 = handle.GetChildAt(0);
  DALI_TEST_CHECK( child1 );
  DALI_TEST_CHECK( ImageActor::DownCast( child1 ) );
  DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION );
  DALI_TEST_EQUALS( child1.GetChildCount(), 0u, TEST_LOCATION );

  Stage::GetCurrent().Remove( handle );
  END_TEST;
}
示例#13
0
Property::Value PathConstrainer::GetDefaultProperty( Property::Index index ) const
{
  if( index == Dali::PathConstrainer::Property::FORWARD )
  {
    return Property::Value( mForward );
  }
  else
  {
    if( index == Dali::PathConstrainer::Property::POINTS )
    {
      Property::Value value( Property::ARRAY );
      Property::Array* array = value.GetArray();
      const Dali::Vector<Vector3>& point = mPath->GetPoints();
      Property::Array::SizeType pointCount = point.Size();

      if( array )
      {
        array->Reserve( pointCount );
        for( Property::Array::SizeType i = 0; i < pointCount; ++i )
        {
          array->PushBack( point[i] );
        }
      }
      return value;
    }
    else if( index == Dali::PathConstrainer::Property::CONTROL_POINTS )
    {
      Property::Value value( Property::ARRAY );
      Property::Array* array = value.GetArray();
      const Dali::Vector<Vector3>& point = mPath->GetControlPoints();
      Property::Array::SizeType pointCount = point.Size();

      if( array )
      {
        array->Reserve( pointCount );
        for( Property::Array::SizeType i = 0; i < pointCount; ++i )
        {
          array->PushBack( point[i] );
        }
      }
      return value;
    }
  }

  return Property::Value();
}
示例#14
0
Property::Value LinearConstrainer::GetDefaultProperty( Property::Index index ) const
{
  if( index == Dali::LinearConstrainer::Property::VALUE )
  {
    Property::Value value( Property::ARRAY );
    Property::Array* array = value.GetArray();
    size_t count( mValue.Size() );

    if( array )
    {
      array->Reserve( count );
      for( size_t i( 0 ); i != count; ++i )
      {
        array->PushBack( mValue[i] );
      }
    }
    return value;
  }
  else if( index == Dali::LinearConstrainer::Property::PROGRESS )
  {
    Property::Value value( Property::ARRAY );
    Property::Array* array = value.GetArray();
    size_t count( mValue.Size() );

    if( array )
    {
      array->Reserve( count );
      for( size_t i( 0 ); i != count; ++i )
      {
        array->PushBack( mProgress[i] );
      }
    }
    return value;
  }

  return Property::Value();
}
示例#15
0
int UtcDaliControlRendererSize(void)
{
  ToolkitTestApplication application;
  tet_infoline( "UtcDaliControlRendererGetNaturalSize" );

  RendererFactory factory = RendererFactory::Get();
  Vector2 rendererSize( 20.f, 30.f );
  Vector2 naturalSize;

  // color renderer
  ControlRenderer colorRenderer = factory.GetControlRenderer( Color::MAGENTA );
  colorRenderer.SetSize( rendererSize );
  DALI_TEST_EQUALS( colorRenderer.GetSize(), rendererSize, TEST_LOCATION );
  colorRenderer.GetNaturalSize(naturalSize);
  DALI_TEST_EQUALS( naturalSize, Vector2::ZERO, TEST_LOCATION );

  // image renderer
  Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME, ImageDimensions(100, 200));
  ControlRenderer imageRenderer = factory.GetControlRenderer( image );
  imageRenderer.SetSize( rendererSize );
  DALI_TEST_EQUALS( imageRenderer.GetSize(), rendererSize, TEST_LOCATION );
  imageRenderer.GetNaturalSize(naturalSize);
  DALI_TEST_EQUALS( naturalSize, Vector2(100.f, 200.f), TEST_LOCATION );

  // n patch renderer
  TestPlatformAbstraction& platform = application.GetPlatform();
  Vector2 testSize(80.f, 160.f);
  platform.SetClosestImageSize(testSize);
  image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
  ControlRenderer nPatchRenderer = factory.GetControlRenderer( image );
  nPatchRenderer.SetSize( rendererSize );
  DALI_TEST_EQUALS( nPatchRenderer.GetSize(), rendererSize, TEST_LOCATION );
  nPatchRenderer.GetNaturalSize(naturalSize);
  DALI_TEST_EQUALS( naturalSize, testSize, TEST_LOCATION );

  // border renderer
  float borderSize = 5.f;
  ControlRenderer borderRenderer = factory.GetControlRenderer( borderSize, Color::RED );
  borderRenderer.SetSize( rendererSize );
  DALI_TEST_EQUALS( borderRenderer.GetSize(), rendererSize, TEST_LOCATION );
  borderRenderer.GetNaturalSize(naturalSize);
  DALI_TEST_EQUALS( naturalSize, Vector2::ZERO, TEST_LOCATION );

  // gradient renderer
  Property::Map propertyMap;
  propertyMap.Insert("renderer-type", "gradient-renderer");
  Vector2 start(-1.f, -1.f);
  Vector2 end(1.f, 1.f);
  propertyMap.Insert("gradient-start-position", start);
  propertyMap.Insert("gradient-end-position", end);
  propertyMap.Insert("gradient-stop-offset", Vector2(0.f, 1.f));
  Property::Array stopColors;
  stopColors.PushBack( Color::RED );
  stopColors.PushBack( Color::GREEN );
  propertyMap.Insert("gradient-stop-color", stopColors);
  ControlRenderer gradientRenderer = factory.GetControlRenderer(propertyMap);
  gradientRenderer.SetSize( rendererSize );
  DALI_TEST_EQUALS( gradientRenderer.GetSize(), rendererSize, TEST_LOCATION );
  gradientRenderer.GetNaturalSize(naturalSize);
  DALI_TEST_EQUALS( naturalSize, Vector2::ZERO,TEST_LOCATION );

  END_TEST;
}
示例#16
0
Property::Value& Property::Value::GetItem(const int index) const
{
  switch( GetType() )
  {
    case Property::MAP:
    {
      int i = 0;
      Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue));

      DALI_ASSERT_DEBUG(container && "Property::Map has no container?");
      if(container)
      {
        DALI_ASSERT_ALWAYS(index < static_cast<int>(container->size()) && "Property array index invalid");
        DALI_ASSERT_ALWAYS(index >= 0 && "Property array index invalid");

        for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter)
        {
          if(i++ == index)
          {
            return iter->second;
          }
        }
      }
    }
    break;

    case Property::ARRAY:
    {
      int i = 0;
      Property::Array *container = AnyCast<Property::Array>(&(mImpl->mValue));

      DALI_ASSERT_DEBUG(container && "Property::Map has no container?");
      if(container)
      {
        DALI_ASSERT_ALWAYS(index < static_cast<int>(container->size()) && "Property array index invalid");
        DALI_ASSERT_ALWAYS(index >= 0 && "Property array index invalid");

        for(Property::Array::iterator iter = container->begin(); iter != container->end(); ++iter)
        {
          if(i++ == index)
          {
            return *iter;
          }
        }
      }
    }
    break;

    case Property::NONE:
    case Property::BOOLEAN:
    case Property::FLOAT:
    case Property::INTEGER:
    case Property::UNSIGNED_INTEGER:
    case Property::VECTOR2:
    case Property::VECTOR3:
    case Property::VECTOR4:
    case Property::MATRIX3:
    case Property::MATRIX:
    case Property::RECTANGLE:
    case Property::ROTATION:
    case Property::STRING:
    case Property::TYPE_COUNT:
    {
      DALI_ASSERT_ALWAYS(!"Cannot GetItem on property Type; not a container");
      break;
    }

  } // switch GetType()


  DALI_ASSERT_ALWAYS(!"Property value index not valid");

  // should never return this
  static Property::Value null;
  return null;
}
示例#17
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;
}
示例#18
0
int UtcDaliControlRendererGetPropertyMap3(void)
{
  ToolkitTestApplication application;
  tet_infoline( "UtcDaliControlRendererGetPropertyMap3: linear GradientRenderer" );

  RendererFactory factory = RendererFactory::Get();
  DALI_TEST_CHECK( factory );

  Property::Map propertyMap;
  propertyMap.Insert("renderer-type", "gradient-renderer");

  Vector2 start(-1.f, -1.f);
  Vector2 end(1.f, 1.f);
  propertyMap.Insert("gradient-start-position", start);
  propertyMap.Insert("gradient-end-position", end);
  propertyMap.Insert("gradient-spread-method", "repeat");

  propertyMap.Insert("gradient-stop-offset", Vector2(0.2f, 0.8f));

  Property::Array stopColors;
  stopColors.PushBack( Color::RED );
  stopColors.PushBack( Color::GREEN );
  propertyMap.Insert("gradient-stop-color", stopColors);

  ControlRenderer gradientRenderer = factory.GetControlRenderer(propertyMap);

  Property::Map resultMap;
  gradientRenderer.CreatePropertyMap( resultMap );

  // check the property values from the returned map from control renderer
  Property::Value* value = resultMap.Find( "renderer-type", Property::STRING );
  DALI_TEST_CHECK( value );
  DALI_TEST_CHECK( value->Get<std::string>() == "gradient-renderer" );

  value = resultMap.Find( "gradient-units", Property::STRING );
  DALI_TEST_CHECK( value );
  DALI_TEST_CHECK( value->Get<std::string>() == "object-bounding-box" );

  value = resultMap.Find( "gradient-spread-method", Property::STRING );
  DALI_TEST_CHECK( value );
  DALI_TEST_CHECK( value->Get<std::string>() == "repeat" );

  value = resultMap.Find( "gradient-start-position", Property::VECTOR2 );
  DALI_TEST_CHECK( value );
  DALI_TEST_EQUALS( value->Get<Vector2>(), start , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  value = resultMap.Find( "gradient-end-position", Property::VECTOR2 );
  DALI_TEST_CHECK( value );
  DALI_TEST_EQUALS( value->Get<Vector2>(), end , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  value = resultMap.Find( "gradient-stop-offset", Property::ARRAY );
  DALI_TEST_CHECK( value );
  Property::Array* offsetArray = value->GetArray();
  DALI_TEST_CHECK( offsetArray->Count() == 2 );
  DALI_TEST_EQUALS( offsetArray->GetElementAt(0).Get<float>(), 0.2f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
  DALI_TEST_EQUALS( offsetArray->GetElementAt(1).Get<float>(), 0.8f , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  value = resultMap.Find( "gradient-stop-color", Property::ARRAY );
  DALI_TEST_CHECK( value );
  Property::Array* colorArray = value->GetArray();
  DALI_TEST_CHECK( colorArray->Count() == 2 );
  DALI_TEST_EQUALS( colorArray->GetElementAt(0).Get<Vector4>(), Color::RED , Math::MACHINE_EPSILON_100, TEST_LOCATION );
  DALI_TEST_EQUALS( colorArray->GetElementAt(1).Get<Vector4>(), Color::GREEN , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  END_TEST;
}
示例#19
0
bool SetPropertyFromNode( const TreeNode& node, Property::Value& value,
                          const Replacement& replacer )
{
  bool done = false;

  // some values are ambiguous as we have no Property::Type but can be disambiguated in the json

  // Currently Rotations and Rectangle must always be disambiguated when a type isnt available
  if( Disambiguated( node, value, replacer ) )
  {
    done = true;
  }
  else
  {
    if( node.Size() )
    {
      // our current heuristic for deciding an array is actually a vector and not say a map
      // is to check if the values are all floats
      bool allNumbers = true;
      for(TreeConstIter iter = node.CBegin(); iter != node.CEnd(); ++iter)
      {
        OptionalFloat f = IsFloat((*iter).second);
        if(!f)
        {
          allNumbers = false;
          break;
        }
      }

      if( allNumbers )
      {
        // prefer finding vectors over presuming composite Property::Array...
        if( OptionalMatrix v = IsMatrix(node) )
        {
          value = *v;
          done = true;
        }
        else if( OptionalMatrix3 v = IsMatrix3(node) )
        {
          value = *v;
          done = true;
        }
        else if( OptionalVector4 v = IsVector4(node) )
        {
          value = *v;
          done = true;
        }
        else if( OptionalVector3 v = IsVector3(node) )
        {
          value = *v;
          done = true;
        }
        else if( OptionalVector2 v = IsVector2(node) )
        {
          value = *v;
          done = true;
        }
        else if( 4 == node.Size() )
        {
          if( OptionalVector4 v = IsVector4(node) )
          {
            value = *v;
            done = true;
          }
        }
        else
        {
          value = Property::Value(Property::ARRAY);
          Property::Array* array = value.GetArray();

          if( array )
          {
            for(TreeConstIter iter = node.CBegin(); iter != node.CEnd(); ++iter)
            {
              Property::Value childValue;
              if( SetPropertyFromNode( (*iter).second, childValue, replacer ) )
              {
                array->PushBack( childValue );
                done = true;
              }
            }
          }
        }
      }

      if(!done)
      {
        // presume an array or map
        // container of size 1
        TreeNode::ConstIterator iter = node.CBegin();

        // its seems legal with current json parser for a map to have an empty key
        // but here we take that to mean the structure is a list
        if( ((*iter).first) == 0 )
        {
          value = Property::Value(Property::ARRAY);
          Property::Array* array = value.GetArray();

          if( array )
          {
            for(unsigned int i = 0; i < node.Size(); ++i, ++iter)
            {
              Property::Value childValue;
              if( SetPropertyFromNode( (*iter).second, childValue, replacer ) )
              {
                array->PushBack( childValue );
                done = true;
              }
            }
          }
        }
        else
        {
          value = Property::Value(Property::MAP);
          Property::Map* map = value.GetMap();

          if( map )
          {
            for(unsigned int i = 0; i < node.Size(); ++i, ++iter)
            {
              Property::Value childValue;
              if( SetPropertyFromNode( (*iter).second, childValue, replacer ) )
              {
                map->Insert( (*iter).first, childValue );
                done = true;
              }
            }
          }
        }
      } // if!done
    } // if node.size()
    else // if( 0 == node.size() )
    {
      // no children so either one of bool, float, integer, string
      OptionalBoolean aBool    = replacer.IsBoolean(node);
      OptionalInteger anInt    = replacer.IsInteger(node);
      OptionalFloat   aFloat   = replacer.IsFloat(node);
      OptionalString  aString  = replacer.IsString(node);

      if(aBool)
      {
        // a bool is also an int but here we presume int
        if(anInt)
        {
          value = *anInt;
          done = true;
        }
        else
        {
          value = *aBool;
          done = true;
        }
      }
      else
      {
        // Note: These are both floats and strings
        // {"value":"123"}
        // {"value":123}
        // This means we can't have a string with purely numeric content without disambiguation.
        if(aFloat)
        {
          value = *aFloat;
          done = true;
        }
        else if(anInt)
        {
          value = *anInt;
          done = true;
        }
        else
        {
          // string always succeeds with the current json parser so its last
          value = *aString;
          done = true;
        }

      } // if aBool

    } // if( node.size() )

  } // if Disambiguated()

  return done;
} // bool SetPropertyFromNode( const TreeNode& node, Property::Value& value )
示例#20
0
int UtcDaliControlRendererGetPropertyMap4(void)
{
  ToolkitTestApplication application;
  tet_infoline( "UtcDaliControlRendererGetPropertyMap4: radial GradientRenderer" );

  RendererFactory factory = RendererFactory::Get();
  DALI_TEST_CHECK( factory );

  Property::Map propertyMap;
  propertyMap.Insert("renderer-type", "gradient-renderer");

  Vector2 center(100.f, 100.f);
  float radius = 100.f;
  propertyMap.Insert("gradient-units", "user-space");
  propertyMap.Insert("gradient-center", center);
  propertyMap.Insert("gradient-radius", radius);
  propertyMap.Insert("gradient-stop-offset", Vector3(0.1f, 0.3f, 1.1f));

  Property::Array stopColors;
  stopColors.PushBack( Color::RED );
  stopColors.PushBack( Color::BLACK );
  stopColors.PushBack( Color::GREEN );
  propertyMap.Insert("gradient-stop-color", stopColors);

  ControlRenderer gradientRenderer = factory.GetControlRenderer(propertyMap);
  DALI_TEST_CHECK( gradientRenderer );

  Property::Map resultMap;
  gradientRenderer.CreatePropertyMap( resultMap );

  // check the property values from the returned map from control renderer
  Property::Value* value = resultMap.Find( "renderer-type", Property::STRING );
  DALI_TEST_CHECK( value );
  DALI_TEST_CHECK( value->Get<std::string>() == "gradient-renderer" );

  value = resultMap.Find( "gradient-units", Property::STRING );
  DALI_TEST_CHECK( value );
  DALI_TEST_CHECK( value->Get<std::string>() == "user-space" );

  value = resultMap.Find( "gradient-spread-method", Property::STRING );
  DALI_TEST_CHECK( value );
  DALI_TEST_CHECK( value->Get<std::string>() == "pad" );

  value = resultMap.Find( "gradient-center", Property::VECTOR2 );
  DALI_TEST_CHECK( value );
  DALI_TEST_EQUALS( value->Get<Vector2>(), center , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  value = resultMap.Find( "gradient-radius", Property::FLOAT );
  DALI_TEST_CHECK( value );
  DALI_TEST_EQUALS( value->Get<float>(), radius , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  value = resultMap.Find( "gradient-stop-offset", Property::ARRAY );
  DALI_TEST_CHECK( value );
  Property::Array* offsetArray = value->GetArray();
  DALI_TEST_CHECK( offsetArray->Count() == 3 );
  DALI_TEST_EQUALS( offsetArray->GetElementAt(0).Get<float>(), 0.1f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
  DALI_TEST_EQUALS( offsetArray->GetElementAt(1).Get<float>(), 0.3f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
  // any stop value will be clamped to [0.0, 1.0];
  DALI_TEST_EQUALS( offsetArray->GetElementAt(2).Get<float>(), 1.0f , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  value = resultMap.Find( "gradient-stop-color", Property::ARRAY );
  DALI_TEST_CHECK( value );
  Property::Array* colorArray = value->GetArray();
  DALI_TEST_CHECK( colorArray->Count() == 3 );
  DALI_TEST_EQUALS( colorArray->GetElementAt(0).Get<Vector4>(), Color::RED , Math::MACHINE_EPSILON_100, TEST_LOCATION );
  DALI_TEST_EQUALS( colorArray->GetElementAt(1).Get<Vector4>(), Color::BLACK , Math::MACHINE_EPSILON_100, TEST_LOCATION );
  DALI_TEST_EQUALS( colorArray->GetElementAt(2).Get<Vector4>(), Color::GREEN , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  END_TEST;
}
示例#21
0
int UtcDaliScriptingNewActorChildren(void)
{
  TestApplication application;

  Property::Map map;
  map.push_back( Property::StringValuePair( "type", "Actor" ) );
  map.push_back( Property::StringValuePair( "position", Vector3::XAXIS ) );

  Property::Map child1Map;
  child1Map.push_back( Property::StringValuePair( "type", "ImageActor" ) );
  child1Map.push_back( Property::StringValuePair( "position", Vector3::YAXIS ) );

  Property::Map child2Map;
  child2Map.push_back( Property::StringValuePair( "type", "TextActor" ) );
  child2Map.push_back( Property::StringValuePair( "position", Vector3::ZAXIS ) );

  Property::Map grandChildMap;
  grandChildMap.push_back( Property::StringValuePair( "type", "LightActor" ) );
  grandChildMap.push_back( Property::StringValuePair( "position", Vector3::ONE ) );

  // Add arrays to appropriate maps
  Property::Array grandChildArray;
  grandChildArray.push_back( grandChildMap );
  Property::Array childArray;
  child1Map.push_back( Property::StringValuePair( "actors", grandChildArray ) );
  childArray.push_back( child1Map );
  childArray.push_back( child2Map );
  map.push_back( Property::StringValuePair( "actors", childArray ) );

  // Create
  Actor handle = NewActor( map );
  DALI_TEST_CHECK( handle );

  Stage::GetCurrent().Add( handle );
  application.SendNotification();
  application.Render();

  DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
  DALI_TEST_EQUALS( handle.GetChildCount(), 2u, TEST_LOCATION );

  Actor child1 = handle.GetChildAt(0);
  DALI_TEST_CHECK( child1 );
  DALI_TEST_CHECK( ImageActor::DownCast( child1 ) );
  DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION );
  DALI_TEST_EQUALS( child1.GetChildCount(), 1u, TEST_LOCATION );

  Actor child2 = handle.GetChildAt(1);
  DALI_TEST_CHECK( child2 );
  DALI_TEST_CHECK( TextActor::DownCast( child2 ) );
  DALI_TEST_EQUALS( child2.GetCurrentPosition(), Vector3::ZAXIS, TEST_LOCATION );
  DALI_TEST_EQUALS( child2.GetChildCount(), 0u, TEST_LOCATION );

  Actor grandChild = child1.GetChildAt( 0 );
  DALI_TEST_CHECK( grandChild );
  DALI_TEST_CHECK( LightActor::DownCast( grandChild ) );
  DALI_TEST_EQUALS( grandChild.GetCurrentPosition(), Vector3::ONE, TEST_LOCATION );
  DALI_TEST_EQUALS( grandChild.GetChildCount(), 0u, TEST_LOCATION );

  Stage::GetCurrent().Remove( handle );
  END_TEST;
}