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 "shared/view.h"
19 #include <dali/dali.h>
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <dali-toolkit/devel-api/controls/slider/slider.h>
28 const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" );
29 const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
30 const char* APPLICATION_TITLE( "Image view" );
32 const char* IMAGE_PATH[] = {
33 DALI_IMAGE_DIR "blocks-ball.png",
34 DALI_IMAGE_DIR "gallery-small-23.jpg",
35 DALI_IMAGE_DIR "selection-popup-bg.2.9.png",
36 DALI_IMAGE_DIR "heartsframe.9.png",
39 const char* RESOURCE_IMAGE_PATH[] = {
40 DALI_IMAGE_DIR "contacts-image.png",
41 DALI_IMAGE_DIR "gallery-small-27.jpg",
42 DALI_IMAGE_DIR "selection-popup-bg.8.9.png",
43 DALI_IMAGE_DIR "heartsframe.9.png",
46 const unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*);
47 const unsigned int NUM_RESOURCE_IMAGES = sizeof(RESOURCE_IMAGE_PATH) / sizeof(char*);
49 const unsigned int COLUMNS = 3;
50 const unsigned int ROWS = 4;
54 class ImageViewController: public ConnectionTracker
58 ImageViewController( Application& application )
59 : mApplication( application ),
60 mCurrentPositionToggle( 0, 0 ),
61 mCurrentPositionImage( 0, 0 ),
63 mUseResource( false ),
66 // Connect to the Application's Init signal
67 mApplication.InitSignal().Connect( this, &ImageViewController::Create );
70 ~ImageViewController()
75 void Create( Application& application )
77 // The Init signal is received once (only) during the Application lifetime
79 // Creates a default view with a default tool bar.
80 // The view is added to the stage.
81 mContentLayer = DemoHelper::CreateView( application,
89 mTable = Toolkit::TableView::New( ROWS, COLUMNS );
90 mTable.SetAnchorPoint( AnchorPoint::CENTER );
91 mTable.SetParentOrigin( ParentOrigin::CENTER );
92 mTable.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
93 Vector3 offset( -50.0f, -350.0f, 0.0f );
94 mTable.SetSizeModeFactor( offset );
96 mContentLayer.Add( mTable );
98 for( unsigned int y = 0; y < ROWS; ++y )
100 for( unsigned int x = 0; x < COLUMNS; ++x )
102 mImageViews[x][y] = Toolkit::ImageView::New( IMAGE_PATH[ 0 ] );
103 mImageViews[x][y].SetParentOrigin( ParentOrigin::CENTER );
104 mImageViews[x][y].SetAnchorPoint( AnchorPoint::CENTER );
105 mImageViews[x][y].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
107 mTable.AddChild( mImageViews[x][y], Toolkit::TableView::CellPosition( y, x ) );
111 Toolkit::TableView buttonsTable = Toolkit::TableView::New( 3, 1 );
112 buttonsTable.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
113 buttonsTable.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
114 buttonsTable.SetFitHeight( 0 );
115 buttonsTable.SetFitHeight( 1 );
116 buttonsTable.SetFitHeight( 2 );
117 buttonsTable.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
119 Toolkit::PushButton button = Toolkit::PushButton::New();
120 button.SetLabelText( "Toggle on/off stage" );
121 button.SetParentOrigin( ParentOrigin::CENTER );
122 button.SetAnchorPoint( AnchorPoint::CENTER );
123 button.ClickedSignal().Connect( this, &ImageViewController::ToggleImageOnStage );
124 button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
125 buttonsTable.AddChild( button, Toolkit::TableView::CellPosition( 0, 0 ) );
127 Toolkit::PushButton button2 = Toolkit::PushButton::New();
128 button2.SetLabelText( "Change Image" );
129 button2.SetParentOrigin( ParentOrigin::CENTER );
130 button2.SetAnchorPoint( AnchorPoint::CENTER );
131 button2.ClickedSignal().Connect( this, &ImageViewController::ChangeImageClicked );
132 button2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
133 buttonsTable.AddChild( button2, Toolkit::TableView::CellPosition( 1, 0 ) );
135 Toolkit::CheckBoxButton button3 = Toolkit::CheckBoxButton::New();
136 button3.SetLabelText( "Use Resource Images" );
137 button3.SetParentOrigin( ParentOrigin::CENTER );
138 button3.SetAnchorPoint( AnchorPoint::CENTER );
139 button3.ClickedSignal().Connect( this, &ImageViewController::UseResourceImagesClicked );
140 button3.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
141 buttonsTable.AddChild( button3, Toolkit::TableView::CellPosition( 2, 0 ) );
143 mContentLayer.Add(buttonsTable);
147 bool ToggleImageOnStage( Toolkit::Button button )
149 Toolkit::ImageView imageView = mImageViews[ mCurrentPositionToggle.columnIndex ][ mCurrentPositionToggle.rowIndex ];
153 imageView.Unparent();
157 mTable.AddChild( imageView, mCurrentPositionToggle );
160 ++mCurrentPositionToggle.columnIndex;
161 if( mCurrentPositionToggle.columnIndex == COLUMNS )
163 mCurrentPositionToggle.columnIndex = 0;
164 ++mCurrentPositionToggle.rowIndex;
166 if( mCurrentPositionToggle.rowIndex == ROWS )
168 mCurrentPositionToggle.rowIndex = 0;
169 mToggleOff = !mToggleOff;
175 bool ChangeImageClicked( Toolkit::Button button )
177 Toolkit::ImageView imageView = mImageViews[ mCurrentPositionImage.columnIndex ][ mCurrentPositionImage.rowIndex ];
181 ResourceImage image = ResourceImage::New( RESOURCE_IMAGE_PATH[ mImageIdx ] );
182 imageView.SetImage( image );
186 imageView.SetImage( IMAGE_PATH[ mImageIdx ] );
189 ++mCurrentPositionImage.columnIndex;
190 if( mCurrentPositionImage.columnIndex == COLUMNS )
192 mCurrentPositionImage.columnIndex = 0;
193 ++mCurrentPositionImage.rowIndex;
195 if( mCurrentPositionImage.rowIndex == ROWS )
197 mCurrentPositionImage.rowIndex = 0;
200 int numImages = mUseResource ? NUM_RESOURCE_IMAGES : NUM_IMAGES;
201 if( mImageIdx == numImages )
210 bool UseResourceImagesClicked( Toolkit::Button button )
212 mUseResource = !mUseResource;
214 int numImages = mUseResource ? NUM_RESOURCE_IMAGES : NUM_IMAGES;
215 if( mImageIdx >= numImages )
224 Application& mApplication;
226 Toolkit::Control mView; ///< The View instance.
227 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
228 Layer mContentLayer; ///< Content layer
229 Toolkit::TableView mTable;
230 Toolkit::ImageView mImageViews[ COLUMNS ][ ROWS ];
232 Toolkit::TableView::CellPosition mCurrentPositionToggle;
233 Toolkit::TableView::CellPosition mCurrentPositionImage;
241 void RunTest( Application& application )
243 ImageViewController test( application );
245 application.MainLoop();
248 // Entry point for Linux & Tizen applications
250 int main( int argc, char **argv )
252 Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH );
254 RunTest( application );