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>
24 const char* const IMAGE_PATH ( DEMO_IMAGE_DIR "gallery-large-20.jpg" );
27 class ImageViewAlphaBlendApp : public ConnectionTracker
30 ImageViewAlphaBlendApp( Application& application )
31 : mApplication( application ),
34 // Connect to the Application's Init signal
35 mApplication.InitSignal().Connect( this, &ImageViewAlphaBlendApp::Create );
38 ~ImageViewAlphaBlendApp()
40 // Nothing to do here;
44 // The Init signal is received once (only) during the Application lifetime
45 void Create( Application& application )
47 // Get a handle to the stage
48 Stage stage = Stage::GetCurrent();
49 stage.KeyEventSignal().Connect(this, &ImageViewAlphaBlendApp::OnKeyEvent);
51 Vector4 green0 = Vector4( 0.f, 1.f, 0.f, 0.25f );
52 Vector4 green1 = Vector4( 0.f, 0.25f, 0.f, 0.25f );
53 BufferImage redGreen0 = CreateBufferImage( Color::RED, green0 );
54 BufferImage redGreen1 = CreateBufferImage( Color::RED, green1 );
55 float imageSize = 512.f;
57 Toolkit::ImageView imageView0 = Toolkit::ImageView::New( IMAGE_PATH );
58 imageView0.SetSize(imageSize, imageSize);
59 imageView0.SetParentOrigin( ParentOrigin::CENTER );
60 imageView0.SetY( -imageSize*0.5f );
61 stage.Add(imageView0);
62 Toolkit::ImageView imageView1 = Toolkit::ImageView::New( redGreen0 );
63 imageView1.SetParentOrigin( ParentOrigin::CENTER );
64 imageView1.SetSize(imageSize, imageSize);
65 imageView0.Add(imageView1);
67 Toolkit::ImageView imageView2 = Toolkit::ImageView::New( IMAGE_PATH );
68 imageView2.SetSize(imageSize, imageSize);
69 imageView2.SetParentOrigin( ParentOrigin::CENTER );
70 imageView2.SetY( imageSize*0.5f );
71 stage.Add(imageView2);
72 Toolkit::ImageView imageView3 = Toolkit::ImageView::New( redGreen1);
73 imageView3.SetParentOrigin( ParentOrigin::CENTER );
74 imageView3.SetSize(imageSize, imageSize);
75 imageView2.Add(imageView3);
77 imageView2.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
78 imageView3.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
80 Animation animation = Animation::New( 10.f );
81 animation.AnimateTo(Property(imageView0, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 2.f, 8.f ));
82 animation.AnimateTo(Property(imageView2, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 2.f, 8.f ));
83 animation.SetLooping( true );
87 void OnKeyEvent(const KeyEvent& event)
89 if(event.state == KeyEvent::Down)
91 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
98 BufferImage CreateBufferImage( const Vector4& color1, const Vector4& color2 )
100 BufferImage image = BufferImage::New( 2, 1, Pixel::RGBA8888 );
101 PixelBuffer* pixelBuffer = image.GetBuffer();
102 pixelBuffer[0]=0xFF * color1.x;
103 pixelBuffer[1]=0xFF * color1.y;
104 pixelBuffer[2]=0xFF * color1.z;
105 pixelBuffer[3]=0xFF * color1.w;
106 pixelBuffer[4]=0xFF * color2.x;
107 pixelBuffer[5]=0xFF * color2.y;
108 pixelBuffer[6]=0xFF * color2.z;
109 pixelBuffer[7]=0xFF * color2.w;
116 Application& mApplication;
120 void RunTest( Application& application )
122 ImageViewAlphaBlendApp test( application );
124 application.MainLoop();
127 // Entry point for Linux & Tizen applications
129 int DALI_EXPORT_API main( int argc, char **argv )
131 Application application = Application::New( &argc, &argv );
133 RunTest( application );