Пример #1
0
Property::Value& Property::Value::GetValue(const std::string& key) const
{
  DALI_ASSERT_DEBUG(Property::MAP == GetType() && "Property type invalid");

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

  DALI_ASSERT_DEBUG(container);

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

  DALI_LOG_WARNING("Cannot find property map key %s", key.c_str());
  DALI_ASSERT_ALWAYS(!"Cannot find property map key");

  // should never return this
  static Property::Value null;
  return null;
}
Пример #2
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;
    }
  }
}
Пример #3
0
const std::string& Property::Value::GetKey(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)
      {
        if(0 <= index && index < static_cast<int>(container->size()))
        {
          for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter)
          {
            if(i++ == index)
            {
              return iter->first;
            }
          }
        }
      }
    }
    break;
    case Property::NONE:
    case Property::ARRAY:
    case Property::BOOLEAN:
    case Property::FLOAT:
    case Property::UNSIGNED_INTEGER:
    case Property::INTEGER:
    case Property::VECTOR2:
    case Property::VECTOR3:
    case Property::VECTOR4:
    case Property::MATRIX:
    case Property::MATRIX3:
    case Property::RECTANGLE:
    case Property::ROTATION:
    case Property::STRING:
    case Property::TYPE_COUNT:
    {
      break;
    }
  }


  // should never return this
  static std::string null;
  return null;
}
Пример #4
0
void Property::Value::SetValue(const std::string& key, const Property::Value &value)
{
  DALI_ASSERT_DEBUG(Property::MAP == GetType() && "Property type invalid");

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

  if(container)
  {
    for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter)
    {
      if(iter->first == key)
      {
        iter->second = value;
        return;
      }
    }

    // if we get here its a new key
    container->push_back(Property::StringValuePair(key, value));

  }
}
Пример #5
0
bool Property::Value::HasKey(const std::string& key) const
{
  bool has = false;

  if( Property::MAP == GetType() )
  {
    Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue));

    DALI_ASSERT_DEBUG(container && "Property::Map has no container?");

    if(container)
    {
      for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter)
      {
        if(iter->first == key)
        {
          has = true;
        }
      }
    }
  }

  return has;
}
Пример #6
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;
}
Пример #7
0
int UtcDaliScriptingNewActorProperties(void)
{
  TestApplication application;

  Property::Map map;
  map.push_back( Property::StringValuePair( "type", "Actor" ) );
  map.push_back( Property::StringValuePair( "size", Vector3::ONE ) );
  map.push_back( Property::StringValuePair( "position", Vector3::XAXIS ) );
  map.push_back( Property::StringValuePair( "scale", Vector3::ONE ) );
  map.push_back( Property::StringValuePair( "visible", false ) );
  map.push_back( Property::StringValuePair( "color", Color::MAGENTA ) );
  map.push_back( Property::StringValuePair( "name", "MyActor" ) );
  map.push_back( Property::StringValuePair( "color-mode", "USE_PARENT_COLOR" ) );
  map.push_back( Property::StringValuePair( "inherit-shader-effect", false ) );
  map.push_back( Property::StringValuePair( "sensitive", false ) );
  map.push_back( Property::StringValuePair( "leave-required", true ) );
  map.push_back( Property::StringValuePair( "position-inheritance", "DONT_INHERIT_POSITION" ) );
  map.push_back( Property::StringValuePair( "draw-mode", "STENCIL" ) );
  map.push_back( Property::StringValuePair( "inherit-rotation", false ) );
  map.push_back( Property::StringValuePair( "inherit-scale", false ) );

  // Default properties
  {
    Actor handle = NewActor( map );
    DALI_TEST_CHECK( handle );

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

    DALI_TEST_EQUALS( handle.GetCurrentSize(), Vector3::ONE, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.IsVisible(), false, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.GetName(), "MyActor", TEST_LOCATION );
    DALI_TEST_EQUALS( handle.GetColorMode(), USE_PARENT_COLOR, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.GetInheritShaderEffect(), false, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.IsSensitive(), false, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.GetLeaveRequired(), true, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.GetDrawMode(), DrawMode::STENCIL, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.IsRotationInherited(), false, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.IsScaleInherited(), false, TEST_LOCATION );

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

  // Check Anchor point and parent origin vector3s
  map.push_back( Property::StringValuePair( "parent-origin", ParentOrigin::TOP_CENTER ) );
  map.push_back( Property::StringValuePair( "anchor-point", AnchorPoint::TOP_LEFT ) );
  {
    Actor handle = NewActor( map );
    DALI_TEST_CHECK( handle );

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

    DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_CENTER, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::TOP_LEFT, TEST_LOCATION );

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

  // Check Anchor point and parent origin STRINGS
  map.erase( map.end() - 2, map.end() ); // delete previously added parent origin and anchor point
  map.push_back( Property::StringValuePair( "parent-origin", "BACK_TOP_LEFT" ) );
  map.push_back( Property::StringValuePair( "anchor-point", "FRONT_CENTER_LEFT" ) );
  {
    Actor handle = NewActor( map );
    DALI_TEST_CHECK( handle );

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

    DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::BACK_TOP_LEFT, TEST_LOCATION );
    DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::FRONT_CENTER_LEFT, TEST_LOCATION );

    Stage::GetCurrent().Remove( handle );
  }
  END_TEST;
}
Пример #8
0
int UtcDaliScriptingNewImage(void)
{
  TestApplication application;

  Property::Map map;
  map.push_back( Property::StringValuePair( "filename", "TEST_FILE" ) );

  // Filename only
  {
    Image image = NewImage( map );
    DALI_TEST_EQUALS( "TEST_FILE", image.GetFilename(), TEST_LOCATION );
  }

  // load-policy
  map.push_back( Property::StringValuePair( "load-policy", "" ) );
  {
    const StringEnum values[] =
    {
        { "IMMEDIATE", Image::Immediate },
        { "ON_DEMAND", Image::OnDemand }
    };
    TestEnumStrings< Image::LoadPolicy, Image >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &Image::GetLoadPolicy, &NewImage );
  }

  // release-policy
  map.push_back( Property::StringValuePair( "release-policy", "" ) );
  {
    const StringEnum values[] =
    {
        { "UNUSED", Image::Unused },
        { "NEVER", Image::Never }
    };
    TestEnumStrings< Image::ReleasePolicy, Image >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &Image::GetReleasePolicy, &NewImage );
  }

  // float width and height
  map.push_back( Property::StringValuePair( "width", (float) 10.0f ) );
  map.push_back( Property::StringValuePair( "height", (float) 20.0f ) );
  {
    Image image = NewImage( map );
    DALI_TEST_EQUALS( image.GetWidth(), 10.0f, TEST_LOCATION );
    DALI_TEST_EQUALS( image.GetHeight(), 20.0f, TEST_LOCATION );
  }

  // int width and height
  map.erase( map.end() - 2, map.end() );
  map.push_back( Property::StringValuePair( "width", 50 ) );
  map.push_back( Property::StringValuePair( "height", 70 ) );
  {
    Image image = NewImage( map );
    DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION );
    DALI_TEST_EQUALS( image.GetHeight(), 70u, TEST_LOCATION );
  }

  //map.erase( map.end() - 2, map.end() );

  // pixel-format
  map.push_back( Property::StringValuePair( "pixel-format", "" ) );
  {
    const StringEnum values[] =
    {
        { "A8", Pixel::A8 },
        { "L8", Pixel::L8 },
        { "LA88", Pixel::LA88 },
        { "RGB565", Pixel::RGB565 },
        { "BGR565", Pixel::BGR565 },
        { "RGBA4444", Pixel::RGBA4444 },
        { "BGRA4444", Pixel::BGRA4444 },
        { "RGBA5551", Pixel::RGBA5551 },
        { "BGRA5551", Pixel::BGRA5551 },
        { "RGB888", Pixel::RGB888 },
        { "RGB8888", Pixel::RGB8888 },
        { "BGR8888", Pixel::BGR8888 },
        { "RGBA8888", Pixel::RGBA8888 },
        { "BGRA8888", Pixel::BGRA8888 },
        { "COMPRESSED_R11_EAC", Pixel::COMPRESSED_R11_EAC },
        { "COMPRESSED_SIGNED_R11_EAC", Pixel::COMPRESSED_SIGNED_R11_EAC },
        { "COMPRESSED_RG11_EAC", Pixel::COMPRESSED_RG11_EAC },
        { "COMPRESSED_SIGNED_RG11_EAC", Pixel::COMPRESSED_SIGNED_RG11_EAC },
        { "COMPRESSED_RGB8_ETC2", Pixel::COMPRESSED_RGB8_ETC2 },
        { "COMPRESSED_SRGB8_ETC2", Pixel::COMPRESSED_SRGB8_ETC2 },
        { "COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 },
        { "COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 },
        { "COMPRESSED_RGBA8_ETC2_EAC", Pixel::COMPRESSED_RGBA8_ETC2_EAC },
        { "COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC },
        { "COMPRESSED_RGB8_ETC1", Pixel::COMPRESSED_RGB8_ETC1 },
        { "COMPRESSED_RGB_PVRTC_4BPPV1", Pixel::COMPRESSED_RGB_PVRTC_4BPPV1 },
        { "A8", Pixel::A8 }, // Checked already but reset so that BitmapImage works
    };
    TestEnumStrings< Pixel::Format, ImageAttributes >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &ImageAttributes::GetPixelFormat, &NewImageAttributes );
  }

  // scaling-mode
  map.push_back( Property::StringValuePair( "scaling-mode", "" ) );
  {
    const StringEnum values[] =
    {
        { "SHRINK_TO_FIT", ImageAttributes::ShrinkToFit },
        { "SCALE_TO_FILL", ImageAttributes::ScaleToFill },
        { "FIT_WIDTH", ImageAttributes::FitWidth },
        { "FIT_HEIGHT", ImageAttributes::FitHeight },
    };
    TestEnumStrings< ImageAttributes::ScalingMode, ImageAttributes >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &ImageAttributes::GetScalingMode, &NewImageAttributes );
  }

  // crop
  map.push_back( Property::StringValuePair( "crop", Vector4( 50, 60, 70, 80 ) ) );
  {
    Image image = NewImage( map );
    ImageAttributes attributes = image.GetAttributes();
    Rect<float> crop = attributes.GetCrop();
    DALI_TEST_EQUALS( crop.x, 50, TEST_LOCATION );
    DALI_TEST_EQUALS( crop.y, 60, TEST_LOCATION );
    DALI_TEST_EQUALS( crop.width, 70, TEST_LOCATION );
    DALI_TEST_EQUALS( crop.height, 80, TEST_LOCATION );
  }

  // type FrameBufferImage
  map.push_back( Property::StringValuePair( "type", "FrameBufferImage" ) );
  {
    Image image = NewImage( map );
    DALI_TEST_CHECK( FrameBufferImage::DownCast( image ) );
  }
  // type BitMapImage
  (map.end() - 1)->second = "BitmapImage";
  {
    Image image = NewImage( map );
    DALI_TEST_CHECK( BitmapImage::DownCast( image ) );
  }
  // type Image
  (map.end() - 1)->second = "Image";
  {
    Image image = NewImage( map );
    DALI_TEST_CHECK( Image::DownCast( image ) );
    DALI_TEST_CHECK( !FrameBufferImage::DownCast( image ) );
    DALI_TEST_CHECK( !BitmapImage::DownCast( image ) );
  }
  END_TEST;
}