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* IMAGE_PATH[] = { DEMO_IMAGE_DIR "gallery-large-7.jpg",
25 DEMO_IMAGE_DIR "gallery-large-12.jpg",
26 DEMO_IMAGE_DIR "gallery-large-18.jpg" };
28 const unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*);
31 class ImageViewPixelAreaApp : public ConnectionTracker
34 ImageViewPixelAreaApp( Application& application )
35 : mApplication( application ),
38 // Connect to the Application's Init signal
39 mApplication.InitSignal().Connect( this, &ImageViewPixelAreaApp::Create );
42 ~ImageViewPixelAreaApp()
44 // Nothing to do here;
48 // The Init signal is received once (only) during the Application lifetime
49 void Create( Application& application )
51 // Get a handle to the stage
52 Stage stage = Stage::GetCurrent();
53 stage.KeyEventSignal().Connect(this, &ImageViewPixelAreaApp::OnKeyEvent);
55 ImageDimensions size( 510, 510 );
56 float subSize = 170.f;
57 float relativeSubSize = 0.33;
58 Animation animation = Animation::New( 10.f );
59 for( int i=0; i<3;i++ )
60 for( int j=0; j<3; j++ )
62 mImageView[i][j] = Toolkit::ImageView::New( IMAGE_PATH[mIndex], size );
63 mImageView[i][j].SetParentOrigin( ParentOrigin::CENTER );
64 mImageView[i][j].SetAnchorPoint(AnchorPoint::CENTER );
65 mImageView[i][j].SetPosition( subSize*(i-1)*1.1f, subSize*(j-1)*1.1f );
66 mImageView[i][j].SetSize( subSize, subSize );
67 stage.Add(mImageView[i][j]);
69 animation.AnimateTo( Property(mImageView[i][j], Toolkit::ImageView::Property::PIXEL_AREA),
70 Vector4( relativeSubSize*i, relativeSubSize*j, relativeSubSize, relativeSubSize ),
71 AlphaFunction::BOUNCE );
73 animation.SetLooping( true );
76 // Respond to a click anywhere on the stage
77 stage.GetRootLayer().TouchSignal().Connect( this, &ImageViewPixelAreaApp::OnTouch );
80 bool OnTouch( Actor actor, const TouchData& touch )
82 if( touch.GetState( 0 ) == PointState::DOWN )
85 for( int i=0; i<3;i++ )
86 for( int j=0; j<3; j++ )
88 mImageView[i][j].SetImage( IMAGE_PATH[mIndex%NUM_IMAGES] );
94 void OnKeyEvent(const KeyEvent& event)
96 if(event.state == KeyEvent::Down)
98 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
106 Application& mApplication;
107 Toolkit::ImageView mImageView[3][3];
111 void RunTest( Application& application )
113 ImageViewPixelAreaApp test( application );
115 application.MainLoop();
118 // Entry point for Linux & Tizen applications
120 int DALI_EXPORT_API main( int argc, char **argv )
122 Application application = Application::New( &argc, &argv );
124 RunTest( application );