2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-toolkit/dali-toolkit.h>
22 class ImageViewAlphaBlendApp : public ConnectionTracker
25 ImageViewAlphaBlendApp( Application& application )
26 : mApplication( application ),
29 // Connect to the Application's Init signal
30 mApplication.InitSignal().Connect( this, &ImageViewAlphaBlendApp::Create );
33 ~ImageViewAlphaBlendApp()
35 // Nothing to do here;
39 // The Init signal is received once (only) during the Application lifetime
40 void Create( Application& application )
42 // Get a handle to the stage
43 Stage stage = Stage::GetCurrent();
44 stage.KeyEventSignal().Connect(this, &ImageViewAlphaBlendApp::OnKeyEvent);
46 Vector4 green0 = Vector4( 0.f, 1.f, 0.f, 0.25f );
47 Vector4 green1 = Vector4( 0.f, 0.25f, 0.f, 0.25f );
48 BufferImage redGreen0 = CreateBufferImage( Color::RED, green0 );
49 BufferImage redGreen1 = CreateBufferImage( Color::RED, green1 );
50 ResourceImage testImage = ResourceImage::New( DEMO_IMAGE_DIR "gallery-large-20.jpg" );
51 float imageSize = 512.f;
53 Toolkit::ImageView imageView0 = Toolkit::ImageView::New( testImage );
54 imageView0.SetSize(imageSize, imageSize);
55 imageView0.SetParentOrigin( ParentOrigin::CENTER );
56 imageView0.SetY( -imageSize*0.5f );
57 stage.Add(imageView0);
58 Toolkit::ImageView imageView1 = Toolkit::ImageView::New( redGreen0 );
59 imageView1.SetParentOrigin( ParentOrigin::CENTER );
60 imageView1.SetSize(imageSize, imageSize);
61 imageView0.Add(imageView1);
63 Toolkit::ImageView imageView2 = Toolkit::ImageView::New( testImage);
64 imageView2.SetSize(imageSize, imageSize);
65 imageView2.SetParentOrigin( ParentOrigin::CENTER );
66 imageView2.SetY( imageSize*0.5f );
67 stage.Add(imageView2);
68 Toolkit::ImageView imageView3 = Toolkit::ImageView::New( redGreen1);
69 imageView3.SetParentOrigin( ParentOrigin::CENTER );
70 imageView3.SetSize(imageSize, imageSize);
71 imageView2.Add(imageView3);
73 imageView2.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
74 imageView3.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
76 Animation animation = Animation::New( 10.f );
77 animation.AnimateTo(Property(imageView0, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 2.f, 8.f ));
78 animation.AnimateTo(Property(imageView2, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 2.f, 8.f ));
79 animation.SetLooping( true );
83 void OnKeyEvent(const KeyEvent& event)
85 if(event.state == KeyEvent::Down)
87 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
94 BufferImage CreateBufferImage( const Vector4& color1, const Vector4& color2 )
96 BufferImage image = BufferImage::New( 2, 1, Pixel::RGBA8888 );
97 PixelBuffer* pixelBuffer = image.GetBuffer();
98 pixelBuffer[0]=0xFF * color1.x;
99 pixelBuffer[1]=0xFF * color1.y;
100 pixelBuffer[2]=0xFF * color1.z;
101 pixelBuffer[3]=0xFF * color1.w;
102 pixelBuffer[4]=0xFF * color2.x;
103 pixelBuffer[5]=0xFF * color2.y;
104 pixelBuffer[6]=0xFF * color2.z;
105 pixelBuffer[7]=0xFF * color2.w;
112 Application& mApplication;
116 void RunTest( Application& application )
118 ImageViewAlphaBlendApp test( application );
120 application.MainLoop();
123 // Entry point for Linux & Tizen applications
125 int main( int argc, char **argv )
127 Application application = Application::New( &argc, &argv );
129 RunTest( application );