/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/image-loader/texture-manager.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
using namespace Dali;
+namespace
+{
+const char* const IMAGE_PATH ( DEMO_IMAGE_DIR "gallery-large-20.jpg" );
+}
+
class ImageViewAlphaBlendApp : public ConnectionTracker
{
public:
Stage stage = Stage::GetCurrent();
stage.KeyEventSignal().Connect(this, &ImageViewAlphaBlendApp::OnKeyEvent);
- Vector4 green0 = Vector4( 0.f, 1.f, 0.f, 0.25f );
- Vector4 green1 = Vector4( 0.f, 0.25f, 0.f, 0.25f );
- BufferImage redGreen0 = CreateBufferImage( Color::RED, green0 );
- BufferImage redGreen1 = CreateBufferImage( Color::RED, green1 );
- ResourceImage testImage = ResourceImage::New( DEMO_IMAGE_DIR "gallery-large-20.jpg" );
+ auto green0 = Vector4( 0.f, 1.f, 0.f, 0.25f );
+ auto green1 = Vector4( 0.f, 0.25f, 0.f, 0.25f );
+ auto redGreen0 = CreateTexture( Color::RED, green0 );
+ auto redGreen1 = CreateTexture( Color::RED, green1 );
float imageSize = 512.f;
- Toolkit::ImageView imageView0 = Toolkit::ImageView::New( testImage );
+ Toolkit::ImageView imageView0 = CreateImageView( IMAGE_PATH );
imageView0.SetSize(imageSize, imageSize);
imageView0.SetParentOrigin( ParentOrigin::CENTER );
imageView0.SetY( -imageSize*0.5f );
stage.Add(imageView0);
- Toolkit::ImageView imageView1 = Toolkit::ImageView::New( redGreen0 );
+ Toolkit::ImageView imageView1 = CreateImageView( redGreen0 );
imageView1.SetParentOrigin( ParentOrigin::CENTER );
imageView1.SetSize(imageSize, imageSize);
imageView0.Add(imageView1);
- Toolkit::ImageView imageView2 = Toolkit::ImageView::New( testImage);
+ Toolkit::ImageView imageView2 = CreateImageView( IMAGE_PATH );
imageView2.SetSize(imageSize, imageSize);
imageView2.SetParentOrigin( ParentOrigin::CENTER );
imageView2.SetY( imageSize*0.5f );
stage.Add(imageView2);
- Toolkit::ImageView imageView3 = Toolkit::ImageView::New( redGreen1);
+ Toolkit::ImageView imageView3 = CreateImageView( redGreen1);
imageView3.SetParentOrigin( ParentOrigin::CENTER );
imageView3.SetSize(imageSize, imageSize);
imageView2.Add(imageView3);
}
}
- BufferImage CreateBufferImage( const Vector4& color1, const Vector4& color2 )
+ std::string CreateTexture( const Vector4& color1, const Vector4& color2 )
{
- BufferImage image = BufferImage::New( 2, 1, Pixel::RGBA8888 );
- PixelBuffer* pixelBuffer = image.GetBuffer();
- pixelBuffer[0]=0xFF * color1.x;
- pixelBuffer[1]=0xFF * color1.y;
- pixelBuffer[2]=0xFF * color1.z;
- pixelBuffer[3]=0xFF * color1.w;
- pixelBuffer[4]=0xFF * color2.x;
- pixelBuffer[5]=0xFF * color2.y;
- pixelBuffer[6]=0xFF * color2.z;
- pixelBuffer[7]=0xFF * color2.w;
- image.Update();
- return image;
+ const auto width = 2u;
+ const auto height = 1u;
+ auto size = width * height * 4;
+ auto pixelBuffer = new unsigned char[size];
+ pixelBuffer[0] = 0xFF * color1.x;
+ pixelBuffer[1] = 0xFF * color1.y;
+ pixelBuffer[2] = 0xFF * color1.z;
+ pixelBuffer[3] = 0xFF * color1.w;
+ pixelBuffer[4] = 0xFF * color2.x;
+ pixelBuffer[5] = 0xFF * color2.y;
+ pixelBuffer[6] = 0xFF * color2.z;
+ pixelBuffer[7] = 0xFF * color2.w;
+
+ auto pixelData = PixelData::New(pixelBuffer, size, width, height, Pixel::RGBA8888, PixelData::ReleaseFunction::DELETE_ARRAY);
+ auto texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+ texture.Upload(pixelData);
+
+ return Toolkit::TextureManager::AddTexture(texture);
}
+ template<typename TextT>
+ Toolkit::ImageView CreateImageView(TextT&& filename)
+ {
+ auto imageView = Toolkit::ImageView::New();
+
+ Property::Map propertyMap;
+ propertyMap.Insert(Toolkit::ImageVisual::Property::URL, std::forward<TextT>(filename));
+ propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
+ propertyMap.Insert(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL);
+ imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap );
+
+ return imageView;
+ }
private:
Application& mApplication;
unsigned int mIndex;
};
-void RunTest( Application& application )
+int DALI_EXPORT_API main( int argc, char **argv )
{
+ Application application = Application::New( &argc, &argv );
ImageViewAlphaBlendApp test( application );
-
application.MainLoop();
-}
-
-// Entry point for Linux & Tizen applications
-//
-int main( int argc, char **argv )
-{
- Application application = Application::New( &argc, &argv );
-
- RunTest( application );
-
return 0;
}