Example #1
0
float GetHeightForWidth( Actor actor, float width )
{
  Vector3 size = actor.GetCurrentSize();
  float height = 0.f;

  TextActor textActor = TextActor::DownCast( actor );
  if( textActor )
  {
    Font font = textActor.GetFont();
    if( !font )
    {
      font = Font::New();
    }
    size = font.MeasureText( textActor.GetText() );
  }

  ImageActor imageActor = ImageActor::DownCast( actor );
  if( ( imageActor ) && ( imageActor.GetImage() ) )
  {
    Image image = imageActor.GetImage();
    size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), 0.f );
  }

  height = size.height / ( size.width / width );

  return height;
}
static void UtcDaliSwirlDefaultValuesEffect()
{
  ToolkitTestApplication application;

  Toolkit::SwirlEffect effect = Toolkit::SwirlEffect::New(true);
  DALI_TEST_CHECK( effect );

  BitmapImage image = CreateBitmapImage();

  ImageActor actor = ImageActor::New( image );
  actor.SetSize( 100.0f, 100.0f );
  actor.SetShaderEffect( effect );
  Stage::GetCurrent().Add( actor );

  application.SendNotification();
  application.Render();

  // Gets converted to opengl viewport coordinates
  DALI_TEST_CHECK(
      application.GetGlAbstraction().CheckUniformValue(
          effect.GetAnglePropertyName().c_str(),
          0.0f ) );

  DALI_TEST_CHECK(
      application.GetGlAbstraction().CheckUniformValue(
          effect.GetCenterPropertyName().c_str(),
          Vector2(0.5f, 0.5f) ) );

  DALI_TEST_CHECK(
      application.GetGlAbstraction().CheckUniformValue(
          effect.GetRadiusPropertyName().c_str(),
          1.0f ) );
}
static void UtcDaliRippleCustomValuesEffect()
{
  ToolkitTestApplication application;

  Toolkit::RippleEffect effect = Toolkit::RippleEffect::New();
  DALI_TEST_CHECK( effect );

  BitmapImage image = CreateBitmapImage();

  ImageActor actor = ImageActor::New( image );
  actor.SetSize( 100.0f, 100.0f );

  effect.SetAmplitude( 0.5f );
  effect.SetCenter( Vector2( 10.0f, 10.0f ) );
  effect.SetTime( 2.0f );

  actor.SetShaderEffect( effect );
  Stage::GetCurrent().Add( actor );

  application.SendNotification();
  application.Render();

  DALI_TEST_CHECK(
      application.GetGlAbstraction().CheckUniformValue(
          effect.GetAmplitudePropertyName().c_str(),
          0.5f ) );
  DALI_TEST_CHECK(
      application.GetGlAbstraction().CheckUniformValue(
          effect.GetCenterPropertyName().c_str(),
          Vector2( 10.0f, 10.0f ) ) );
  DALI_TEST_CHECK(
      application.GetGlAbstraction().CheckUniformValue(
          effect.GetTimePropertyName().c_str(),
          2.0f ) );
}
int UtcDaliObjectRegistrySignalImageActorCreated(void)
{
  TestApplication application;
  ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();

  static const char* TestImageFilename = "icon_wrt.png";
  Image image = ResourceImage::New(TestImageFilename);

  bool verified = false;
  TestImageActorCallback test(verified);

  Dali::RefObject* objectPointer = NULL;
  TestObjectDestroyedCallback test2(verified, objectPointer);

  registry.ObjectCreatedSignal().Connect(&application, test);
  registry.ObjectDestroyedSignal().Connect(&application, test2);

  {
    ImageActor actor = ImageActor::New(image);
    DALI_TEST_CHECK( test.mSignalVerified );

    verified = false;
    objectPointer = actor.GetObjectPtr();
  }
  DALI_TEST_CHECK( test.mSignalVerified );
  END_TEST;
}
 /**
  * Create an Actor to represent a visible item.
  * @param itemId
  * @return the created actor.
  */
 virtual Actor NewItem(unsigned int itemId)
 {
   // Create an test actor for this item
   ImageActor actor = CreateSolidColorActor(Color::RED);
   actor.SetSize(64.0f, 64.0f);
   return actor;
 }
static void UtcDaliShearEffectCustomValues()
{
  ToolkitTestApplication application;

  Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
  DALI_TEST_CHECK( effect );

  BitmapImage image = CreateBitmapImage();

  ImageActor actor = ImageActor::New( image );
  actor.SetSize( 100.0f, 100.0f );

  const float angleXAxis(10.0f);
  const float angleYAxis(22.5f);
  const Vector2 centerValue(50.0f, 100.0f);

  effect.SetAngleXAxis( angleXAxis );
  effect.SetAngleYAxis( angleYAxis );
  effect.SetCenter( centerValue );

  actor.SetShaderEffect(effect);
  Stage::GetCurrent().Add(actor);

  application.SendNotification();
  application.Render();

  TestGlAbstraction& gl = application.GetGlAbstraction();
  DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleXAxisPropertyName().c_str(), angleXAxis ) );
  DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleYAxisPropertyName().c_str(), angleYAxis ) );
  DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), ToScreenPosition(centerValue) ) );
}
int UtcDaliSpotCustomValuesEffect(void)
{
  ToolkitTestApplication application;

  Toolkit::SpotEffect effect = Toolkit::SpotEffect::New();
  DALI_TEST_CHECK( effect );

  BitmapImage image = CreateBitmapImage();

  ImageActor actor = ImageActor::New( image );
  actor.SetSize( 100.0f, 100.0f );

  effect.SetCenter( Vector2(480.0f, 800.0f) );
  effect.SetRadius( 5.0f );

  actor.SetShaderEffect( effect );
  Stage::GetCurrent().Add( actor );

  application.SendNotification();
  application.Render();

  // Gets converted to opengl viewport coordinates
  DALI_TEST_CHECK(
      application.GetGlAbstraction().CheckUniformValue(
          effect.GetCenterPropertyName().c_str(),
          Vector2(480.0f, 800.0f) ) );

  DALI_TEST_CHECK(
      application.GetGlAbstraction().CheckUniformValue(
          effect.GetRadiusPropertyName().c_str(),
          5.0f ) );
  END_TEST;
}
int UtcDaliImageActorUseImageAlpha04(void)
{
  TestApplication application;

  tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");

  FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
  RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
  RenderTask task = taskList.GetTask( 0u );
  task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
  application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
  application.SendNotification();
  application.Render(0);

  ImageActor actor = ImageActor::New( image );
  application.SendNotification();
  application.Render(0);

  actor.SetBlendMode( BlendingMode::ON );
  actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
  actor.SetSize(100, 50);
  application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
  Stage::GetCurrent().Add(actor);

  application.SendNotification();
  application.Render();

  const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
  DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
  DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
  END_TEST;
}
Example #9
0
Vector3 GetNaturalSize( Actor actor )
{
  Vector3 size = actor.GetCurrentSize();
  const float depth = size.depth;

  // Get natural size for TextActor.
  TextActor textActor = TextActor::DownCast( actor );
  if( textActor )
  {
    Font font = textActor.GetFont();
    if( !font )
    {
      font = Font::New();
    }
    size = font.MeasureText( textActor.GetText() );
    size.depth = depth;
  }

  // Get natural size for ImageActor.
  // TODO: currently it doesn't work as expected.
  ImageActor imageActor = ImageActor::DownCast( actor );
  if( ( imageActor ) && ( imageActor.GetImage() ) )
  {
    Image image = imageActor.GetImage();
    size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), depth );
  }

  return size;
}
static void UtcDaliIrisEffectCustomValues()
{
  ToolkitTestApplication application;

  Toolkit::IrisEffect effect = Toolkit::IrisEffect::New();
  DALI_TEST_CHECK( effect );

  BitmapImage image = CreateBitmapImage();

  ImageActor actor = ImageActor::New( image );
  actor.SetSize( 100.0f, 100.0f );

  const float radiusValue(23.0f);
  const Vector2 centerValue(0.2f, 0.7f);
  const float blendFactorValue(10.0f);

  effect.SetRadius( radiusValue );
  effect.SetCenter( centerValue );
  effect.SetBlendFactor( blendFactorValue );

  actor.SetShaderEffect(effect);
  Stage::GetCurrent().Add(actor);

  application.SendNotification();
  application.Render();

  TestGlAbstraction& gl = application.GetGlAbstraction();
  DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetRadiusPropertyName().c_str(), radiusValue ) );
  DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), centerValue ) );
  DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetBlendFactorPropertyName().c_str(), blendFactorValue ) );
}
static void DoApply( ImageActor actor, const std::string& maskImage, const Vector2& maskSize, Vector4 maskBorder )
{
  const char* ALPHA_MASK_VERTEX_SHADER_SOURCE =
  "uniform vec2 uImageSize;                                                       \n"
  "uniform vec2 uMaskSize;                                                        \n"
  "varying vec2 vMaskTexCoord;                                                    \n"
  "                                                                               \n"
  "void main()                                                                    \n"
  "{                                                                              \n"
  "  gl_Position = uMvpMatrix * vec4(aPosition, 1.0);                             \n"
  "                                                                               \n"
  "  // Ignore mask UVs for image                                                 \n"
  "                                                                               \n"
  "  highp vec2 halfImageSize = uImageSize * 0.5;                                 \n"
  "  vTexCoord = (aPosition.xy + halfImageSize) / uImageSize;                     \n"
  "                                                                               \n"
  "  // UVs were calculated for image size, so convert for mask size              \n"
  "                                                                               \n"
  "  highp vec2 halfMaskSize  = uMaskSize * 0.5;                                  \n"
  "  highp vec2 halfSizeDelta = halfImageSize - halfMaskSize;                     \n"
  "                                                                               \n"
  "  highp vec2 maskPosition = aPosition.xy;                                      \n"
  "  maskPosition.x -= halfSizeDelta.x * sign(aPosition.x);                       \n"
  "  maskPosition.y -= halfSizeDelta.y * sign(aPosition.y);                       \n"
  "                                                                               \n"
  "  vMaskTexCoord = (maskPosition + halfMaskSize) / uMaskSize;                   \n"
  "}                                                                              \n";

  const char* ALPHA_MASK_FRAGMENT_SHADER_SOURCE =
  "varying vec2 vMaskTexCoord;                                                    \n"
  "                                                                               \n"
  "void main()                                                                    \n"
  "{                                                                              \n"
  "  highp vec4 mask = texture2D(sEffect, vMaskTexCoord);                         \n"
  "  gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(1,1,1,mask.a); \n"
  "}                                                                              \n";

  ShaderEffect maskEffect = ShaderEffect::New( ALPHA_MASK_VERTEX_SHADER_SOURCE,
                                               ALPHA_MASK_FRAGMENT_SHADER_SOURCE,
                                               GeometryType( GEOMETRY_TYPE_IMAGE ),
                                               ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) );

  maskEffect.SetEffectImage( Image::New( maskImage ) );

  maskEffect.SetUniform( "uImageSize", Vector2(0,0) /*Constrained to actor size*/ );
  maskEffect.ApplyConstraint( Constraint::New<Vector2>( maskEffect.GetPropertyIndex("uImageSize"),
                                                        Source(actor, Actor::SIZE),
                                                        NinePatchMaskEffectSizeConstraint() ) );

  maskEffect.SetUniform( "uMaskSize", maskSize );

  // Actor must provide nine-patch style geometry for this effect to work
  actor.SetStyle( ImageActor::STYLE_NINE_PATCH );
  actor.SetNinePatchBorder( maskBorder );

  actor.SetShaderEffect( maskEffect );
}
Example #12
0
int UtcDaliImageActorPropertyIndices(void)
{
  TestApplication application;
  Actor basicActor = Actor::New();
  ImageActor imageActor = ImageActor::New();

  Property::IndexContainer indices;
  imageActor.GetPropertyIndices( indices );
  DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
  DALI_TEST_EQUALS( indices.size(), imageActor.GetPropertyCount(), TEST_LOCATION );
  END_TEST;
}
Example #13
0
int UtcDaliImageActorSetImage(void)
{
  TestApplication application;

  ImageActor actor = ImageActor::New(Image());

  DALI_TEST_CHECK(actor);

  actor.SetImage( Image() );

  DALI_TEST_CHECK(!actor.GetImage());
  END_TEST;
}
// Positive test case for a method
int UtcDaliDisplacementEffectTestSetProperty(void)
{
  ToolkitTestApplication application;
  tet_infoline("UtcDaliDisplacementEffectTestSetProperty");

  Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
  DALI_TEST_CHECK( effect );

  ImageActor actor = ImageActor::New( Image::New(TEST_IMAGE_FILE_NAME) );
  actor.SetSize( 100.0f, 100.0f );
  actor.SetShaderEffect( effect );
  Stage::GetCurrent().Add( actor );

  Toolkit::DisplacementEffect effect2 = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::FIXED);
  DALI_TEST_CHECK( effect );

  ImageActor actor2 = ImageActor::New( Image::New(TEST_IMAGE_FILE_NAME) );
  actor2.SetSize( 100.0f, 100.0f );
  actor2.SetShaderEffect( effect2 );
  Stage::GetCurrent().Add( actor2 );

  Vector3 testVector3 = Vector3(45.0f, 55.0f, 65.0f);
  float testFloat = 0.623f;
  effect.SetLightDirection(testVector3);
  effect.SetAmbientLightColorProperty(testVector3);
  effect.SetDiffuseLightColorProperty(testVector3);
  effect.SetStateProperty(testFloat);
  effect.SetLightingMultiplierProperty(testFloat);
  effect.SetHeightScaleProperty(testFloat);

  effect2.SetFixedNormalProperty(testVector3);

  application.SendNotification();
  application.Render(0);
  application.SendNotification();
  application.Render();

  DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetLightDirectionPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
  DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetAmbientLightColorPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
  DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetDiffuseLightColorPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
  DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetStatePropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
  DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetLightingMultiplierPropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
  DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetHeightScalePropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );

  Vector3 normalizedVector3(testVector3);
  normalizedVector3.Normalize();
  DALI_TEST_EQUALS( effect2.GetProperty( effect2.GetPropertyIndex( effect2.GetFixedNormalPropertyName() ) ).Get<Vector3>(), normalizedVector3, TEST_LOCATION );
  END_TEST;
}
Example #15
0
int UtcDaliImageActorImageProperty(void)
{
  TestApplication application;
  Image image = Image::New( "MY_PATH" );
  ImageActor imageActor = ImageActor::New( image );

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

  Property::Value imageMap = imageActor.GetProperty( ImageActor::IMAGE );
  DALI_TEST_CHECK( imageMap.HasKey( "filename" ) );
  DALI_TEST_EQUALS( imageMap.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION );
  END_TEST;
}
Example #16
0
int UtcDaliImageSetNinePatchBorder(void)
{
  TestApplication application;

  Image image = Image::New(TestImageFilename);
  ImageActor actor = ImageActor::New(image);

  actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
  actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));

  DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
  DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
  DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
  DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
  END_TEST;
}
Example #17
0
int UtcDaliImageGetStyle(void)
{
  TestApplication application;

  Image image = Image::New(TestImageFilename);
  ImageActor actor = ImageActor::New(image);

  actor.SetStyle(ImageActor::STYLE_NINE_PATCH);

  // flush the queue and render once
  application.SendNotification();
  application.Render();

  DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
  END_TEST;
}
Example #18
0
// clear the resources created for the off screen rendering
void BubbleEmitter::OnRenderFinished(RenderTask& source)
{
  mRenderTaskRunning = false;
  Actor sourceActor = source.GetSourceActor();
  if( sourceActor )
  {
    ImageActor renderable = ImageActor::DownCast( sourceActor );
    if( renderable )
    {
      renderable.RemoveShaderEffect();
    }
  }

  Stage stage = Stage::GetCurrent();
  stage.Remove(sourceActor);
  stage.GetRenderTaskList().RemoveTask(source);
}
Example #19
0
int UtcDaliImageActorGetCurrentImageSize01(void)
{
  TestApplication application;
  tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize");

  Vector2 initialImageSize(100, 50);
  BitmapImage image = BitmapImage::New( initialImageSize.width, initialImageSize.height );
  ImageActor actor = ImageActor::New( image );
  Stage::GetCurrent().Add(actor);

  application.SendNotification();
  application.Render();

  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );

  Vector2 size(200.0f, 200.0f);
  actor.SetSize(size);

  // flush the queue and render once
  application.SendNotification();
  application.Render();
  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );

  size.x = 200.0f;
  size.y = 200.0f;
  actor.SetSize(size);
  application.Render(8);

  // Test when a pixel area is set
  ImageActor::PixelArea area(0, 0, 10, 10);
  actor.SetPixelArea(area);
  application.Render(9);
  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2( area.width, area.height ), TEST_LOCATION );
  END_TEST;
}
Example #20
0
int UtcDaliImageActor9Patch(void)
{
  TestApplication application;
  tet_infoline("Positive test for Dali::ImageActor:: 9 patch api");

  Image image = Image::New(TestImageFilename);
  ImageActor actor = ImageActor::New(image);

  actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
  Vector4 border(0.1,0.2,0.3,0.4);
  actor.SetNinePatchBorder(border);

  DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION );
  DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION );
  DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION );
  DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION );
  END_TEST;
}
Example #21
0
int UtcDaliImageActorUseImageAlpha02(void)
{
  TestApplication application;

  tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");

  BitmapImage image = BitmapImage::New( 100, 50 );
  ImageActor actor = ImageActor::New( image );
  actor.SetBlendMode( BlendingMode::OFF );
  actor.SetSize(100, 50);
  application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
  Stage::GetCurrent().Add(actor);

  application.SendNotification();
  application.Render();

  const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
  DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
  DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
  END_TEST;
}
Example #22
0
int UtcDaliImageActorPixelArea(void)
{
  TestApplication application;
  tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea");

  BitmapImage img = BitmapImage::New( 10, 10 );
  ImageActor actor = ImageActor::New( img );

  DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );

  ImageActor::PixelArea area( 1, 2, 3, 4 );
  actor.SetPixelArea( area );

  DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );

  DALI_TEST_EQUALS( 1, actor.GetPixelArea().x, TEST_LOCATION );
  DALI_TEST_EQUALS( 2, actor.GetPixelArea().y, TEST_LOCATION );
  DALI_TEST_EQUALS( 3, actor.GetPixelArea().width, TEST_LOCATION );
  DALI_TEST_EQUALS( 4, actor.GetPixelArea().height, TEST_LOCATION );

  ImageActor actor2 = ImageActor::New( img, ImageActor::PixelArea( 5, 6, 7, 8 ) );
  DALI_TEST_CHECK( actor2.IsPixelAreaSet() == true );

  DALI_TEST_EQUALS( 5, actor2.GetPixelArea().x, TEST_LOCATION );
  DALI_TEST_EQUALS( 6, actor2.GetPixelArea().y, TEST_LOCATION );
  DALI_TEST_EQUALS( 7, actor2.GetPixelArea().width, TEST_LOCATION );
  DALI_TEST_EQUALS( 8, actor2.GetPixelArea().height, TEST_LOCATION );
  END_TEST;
}
Example #23
0
void View::SetBackground( ImageActor backgroundImage )
{
  // Create background layer if doesn't exist.

  if( !mBackgroundLayer )
  {
    mBackgroundLayer = Layer::New();

    mBackgroundLayer.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
    mBackgroundLayer.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );

    // Add background layer to custom actor.
    Self().Add( mBackgroundLayer );

    // Drop the background layer

    DALI_ASSERT_ALWAYS( mBackgroundLayer.OnStage() ); // We need to be on-stage to drop the layer
    mBackgroundLayer.LowerToBottom();
  }
  else
  {
    // It removes the old background
    if( 0 < mBackgroundLayer.GetChildCount() )
    {
      mBackgroundLayer.Remove( mBackgroundLayer.GetChildAt(0) );
    }
  }

  backgroundImage.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
  Constraint constraint = Constraint::New<Vector3>(
      Actor::SCALE,
      LocalSource( Actor::SIZE ),
      ParentSource( Actor::SIZE ),
      ScaleToFillXYKeepAspectRatioConstraint() );
  backgroundImage.ApplyConstraint( constraint );
  mBackgroundLayer.Add( backgroundImage );
}
Example #24
0
int UtcDaliImageActorGetCurrentImageSize03(void)
{
  TestApplication application;
  tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - Test that using an image resource with a requested size sets the actor size with it's nearest size immediately rather than on load");

  Vector2 closestImageSize( 80, 45);

  application.GetPlatform().SetClosestImageSize(closestImageSize);

  ImageAttributes attrs;
  attrs.SetSize(40, 30);
  Image image = Image::New("image.jpg", attrs);
  ImageActor actor = ImageActor::New( image );
  Stage::GetCurrent().Add(actor);

  application.SendNotification(); // Flush update messages
  application.Render();           // Process resource request
  application.SendNotification(); // Flush update messages
  application.Render();           // Process resource request

  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );

  // Now complete the image load
  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
  Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );

  Integration::ResourcePointer resourcePtr(bitmap); // reference it
  application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
  application.Render();           // Process LoadComplete
  application.SendNotification(); // Process event messages
  application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
  application.GetPlatform().ClearReadyResources(); //

  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );

  // Test that setting a size on the actor can be 'undone' with SetNaturalSize()
  Vector2 size(200.0f, 200.0f);
  actor.SetSize(size);

  // flush the queue and render once
  application.SendNotification();
  application.Render();
  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );

  actor.SetToNaturalSize();
  application.SendNotification();
  application.Render();
  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
  END_TEST;
}
Example #25
0
int UtcDaliImageSetFadeInDuration(void)
{
  TestApplication application;

  Image image = Image::New(TestImageFilename);
  ImageActor actor = ImageActor::New(image);

  actor.SetFadeInDuration( 1.0f );

  // flush the queue and render once
  application.SendNotification();
  application.Render();

  DALI_TEST_EQUALS( 1.0f, actor.GetFadeInDuration(), TEST_LOCATION );

  actor.SetFadeInDuration( 3.0f );

  // flush the queue and render once
  application.SendNotification();
  application.Render();

  DALI_TEST_EQUALS( 3.0f, actor.GetFadeInDuration(), TEST_LOCATION );
  END_TEST;
}
Example #26
0
void BubbleEmitter::SetBackground( Image bgImage, const Vector3& hsvDelta )
{
  mBackgroundImage = bgImage;
  mHSVDelta = hsvDelta;

  ImageActor sourceActor = ImageActor::New( bgImage );
  sourceActor.SetSize( mMovementArea );
  sourceActor.SetParentOrigin(ParentOrigin::CENTER);
  Stage::GetCurrent().Add( sourceActor );

  ShaderEffect colorAdjuster = CreateColorAdjuster( hsvDelta, true /*ignore alpha to make bubble color always*/ );
  sourceActor.SetShaderEffect( colorAdjuster );

  RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
  RenderTask task = taskList.CreateTask();
  task.SetRefreshRate( RenderTask::REFRESH_ONCE );
  task.SetSourceActor( sourceActor );
  task.SetExclusive(true);
  task.SetCameraActor(mCameraActor);
  task.GetCameraActor().SetInvertYAxis(true);
  task.SetTargetFrameBuffer( mEffectImage );
  task.FinishedSignal().Connect(this, &BubbleEmitter::OnRenderFinished);
  mRenderTaskRunning = true;
}
Example #27
0
void Magnifier::SetFrameVisibility(bool visible)
{
  if(visible && !mFrameLayer)
  {
    Actor self(Self());

    Layer mFrameLayer = Layer::New();
    mFrameLayer.SetParentOrigin( ParentOrigin::CENTER );
    Stage::GetCurrent().Add(mFrameLayer);

    Image image = Image::New( DEFAULT_FRAME_IMAGE_PATH );
    ImageActor frame = ImageActor::New( image );
    frame.SetDrawMode(DrawMode::OVERLAY);
    frame.SetStyle( ImageActor::STYLE_NINE_PATCH );

    frame.SetNinePatchBorder( Vector4::ONE * IMAGE_BORDER_INDENT );
    mFrameLayer.Add(frame);

    // Apply position constraint to the frame
    Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
                                                      Source( self, Actor::WORLD_POSITION ),
                                                      EqualToConstraint() );
    frame.ApplyConstraint(constraint);

    // Apply scale constraint to the frame
    constraint = Constraint::New<Vector3>( Actor::SCALE,
                                           Source( self, Actor::SCALE ),
                                           EqualToConstraint() );
    frame.ApplyConstraint(constraint);

    Source(self, Actor::SCALE),

    // Apply size constraint to the the frame
    constraint = Constraint::New<Vector3>(Actor::SIZE,
                                          Source(self, Actor::SIZE),
                                          ImageBorderSizeConstraint());
    frame.ApplyConstraint(constraint);
  }
  else if(!visible && mFrameLayer)
  {
    Stage::GetCurrent().Remove(mFrameLayer);
    mFrameLayer.Reset();
  }
}
void KeyboardFocusManager::CreateDefaultFocusIndicatorActor()
{
  // Create a focus indicator actor shared by all the keyboard focusable actors
  Image borderImage = ResourceImage::New(FOCUS_BORDER_IMAGE_PATH);

  ImageActor focusIndicator = ImageActor::New(borderImage);
  focusIndicator.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
  focusIndicator.SetStyle( ImageActor::STYLE_NINE_PATCH );
  focusIndicator.SetNinePatchBorder(FOCUS_BORDER_IMAGE_BORDER);
  focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f));

  // Apply size constraint to the focus indicator
  focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );

  SetFocusIndicatorActor(focusIndicator);
}
Example #29
0
int UtcDaliImageActorClearPixelArea(void)
{
  TestApplication application;

  BitmapImage img = BitmapImage::New( 10, 10 );
  ImageActor actor = ImageActor::New( img );

  DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );

  ImageActor::PixelArea area( 1, 2, 3, 4 );
  actor.SetPixelArea( area );

  DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );

  actor.ClearPixelArea();

  DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
  END_TEST;
}
Example #30
0
  // The Init signal is received once (only) during the Application lifetime
  void Create( Application& application )
  {
    //std::cout << "HelloWorldController::Create" << std::endl;

    // Get a handle to the stage
    Stage stage = Stage::GetCurrent();

    //ImageActor bgActor = ImageActor::New(CreateBitmapImage(480, 800));
    Control  bgActor = Control::New();
    bgActor.SetSize(64 * STAGE_COL, 64 * STAGE_ROW);
    //bgActor.SetBackgroundColor(Vector4(.125f, .125f, .125f, 1.f));
    bgActor.SetBackgroundColor(Vector4(1.f, 1.f, 1.f, 1.f));
    bgActor.SetParentOrigin(ParentOrigin::CENTER);
    bgActor.SetAnchorPoint(AnchorPoint::CENTER);
    bgActor.SetZ(0.1f);
    //stage.Add(bgActor);

    ResourceImage spriteImage = ResourceImage::New(PUYO_IMAGE);

    // background
    {
      ResourceImage image = ResourceImage::New(BACKGROUND_IMAGE);
      ImageActor actor = ImageActor::New(image);
      actor.SetParentOrigin(ParentOrigin::BOTTOM_LEFT);
      actor.SetAnchorPoint(AnchorPoint::BOTTOM_LEFT);
      stage.Add(actor);
    }

    // sprites
    {
      ImageActor actor[STAGE_COL * STAGE_ROW];

      for (int i = 0; i < STAGE_ROW; i++)
      {
        for (int j = 0; j < STAGE_COL; j++)
        {
          actor[i * STAGE_COL + j] = ImageActor::New(spriteImage, PUYO_OFFSET[int(Random::Range(0.f, NUM_PUYO))]);
          actor[i * STAGE_COL + j].SetParentOrigin(ParentOrigin::BOTTOM_LEFT);
          actor[i * STAGE_COL + j].SetAnchorPoint(AnchorPoint::BOTTOM_LEFT);
          actor[i * STAGE_COL + j].SetX(i * 60.f);
          actor[i * STAGE_COL + j].SetY(j * -1.f * 60.f);
          actor[i * STAGE_COL + j].SetZ(0.1f);
          stage.Add(actor[i * STAGE_COL + j]);
        }
      }

#if 0
      Animation anim = Animation::New(1.f);

      for (int i = 0; i < STAGE_ROW; i++)
      {
        for (int j = 0; j < STAGE_COL; j++)
        {
          anim.MoveBy(actor[i * STAGE_COL + j], Vector3(0.f, j * _(7), 0.1f), AlphaFunctions::Bounce);
          anim.Resize(actor[i * STAGE_COL + j], _(32), _(25), AlphaFunctions::Bounce);
          anim.SetLooping(true);
        }
      }
      anim.Play();
#endif
    }

    {
      ImageActor actor = ImageActor::New(spriteImage, ImageActor::PixelArea(0, 224, 64, 64));
      actor.SetParentOrigin(ParentOrigin::CENTER);
      actor.SetAnchorPoint(AnchorPoint::CENTER);
      actor.SetSize(_(32), _(32));
      actor.SetZ(0.1f);
      //stage.Add(actor);
    }

    // Respond to a click anywhere on the stage
    stage.GetRootLayer().TouchedSignal().Connect( this, &HelloWorldController::OnTouch );
  }