2 * Copyright (c) 2017 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>
19 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
21 #include "shared/view.h"
27 const char* BIG_TEST_IMAGE( DEMO_IMAGE_DIR "book-landscape-cover.jpg" );
28 const char* SMALL_TEST_IMAGE( DEMO_IMAGE_DIR "gallery-large-1.jpg" );
30 const char * const APPLICATION_TITLE( "Pixel Area & Wrap Mode" );
31 const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
32 const char * const BUTTON_ICON( DEMO_IMAGE_DIR "icon-change.png" );
33 const char * const BUTTON_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" );
35 const Vector4 ORIGINAL_PIXEL_AREA( -0.5f, -0.5f, 2.f, 2.f );
38 class ImageViewPixelAreaApp : public ConnectionTracker
41 ImageViewPixelAreaApp( Application& application )
42 : mApplication( application ),
45 // Connect to the Application's Init signal
46 mApplication.InitSignal().Connect( this, &ImageViewPixelAreaApp::Create );
49 ~ImageViewPixelAreaApp()
51 // Nothing to do here;
55 // The Init signal is received once (only) during the Application lifetime
56 void Create( Application& application )
58 // Get a handle to the stage
59 Stage stage = Stage::GetCurrent();
60 stage.KeyEventSignal().Connect(this, &ImageViewPixelAreaApp::OnKeyEvent);
62 Toolkit::ToolBar toolBar;
63 Toolkit::Control background;
64 // Creates a default view with a default tool bar.
65 mContent = DemoHelper::CreateView( application,
72 // Add a button to switch the scene. (right of toolbar)
73 Toolkit::PushButton switchButton = Toolkit::PushButton::New();
74 switchButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_ICON );
75 switchButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, BUTTON_ICON_SELECTED );
76 switchButton.ClickedSignal().Connect( this, &ImageViewPixelAreaApp::OnButtonClicked );
77 toolBar.AddControl( switchButton,
78 DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
79 Toolkit::Alignment::HorizontalRight,
80 DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
83 // for testing image WITH automatic atlasing
84 visualPropertyMap[0][ Toolkit::ImageVisual::Property::URL ] = SMALL_TEST_IMAGE;
85 visualPropertyMap[0][ Toolkit::ImageVisual::Property::DESIRED_WIDTH ] = 500;
86 visualPropertyMap[0][ Toolkit::ImageVisual::Property::DESIRED_HEIGHT ] = 500;
87 visualPropertyMap[0][ Toolkit::ImageVisual::Property::WRAP_MODE_U ] = WrapMode::CLAMP_TO_EDGE;
88 visualPropertyMap[0][ Toolkit::ImageVisual::Property::WRAP_MODE_V ] = WrapMode::MIRRORED_REPEAT;
89 visualPropertyMap[0][ Toolkit::ImageVisual::Property::PIXEL_AREA ] = ORIGINAL_PIXEL_AREA;
91 // for testing image WITHOUT automatic atlasing
92 visualPropertyMap[1][ Toolkit::ImageVisual::Property::URL ] = BIG_TEST_IMAGE;
93 visualPropertyMap[1][ Toolkit::ImageVisual::Property::DESIRED_WIDTH ] = 640;
94 visualPropertyMap[1][ Toolkit::ImageVisual::Property::DESIRED_HEIGHT ] = 720;
95 visualPropertyMap[1][ Toolkit::ImageVisual::Property::WRAP_MODE_U ] = WrapMode::MIRRORED_REPEAT;
96 visualPropertyMap[1][ Toolkit::ImageVisual::Property::WRAP_MODE_V ] = WrapMode::REPEAT;
97 visualPropertyMap[1][ Toolkit::ImageVisual::Property::PIXEL_AREA ] = ORIGINAL_PIXEL_AREA;
99 CreateScene( visualPropertyMap[0] );
101 mWrapLabel = Toolkit::TextLabel::New(" Automatic atlasing\n WrapMode: CLAMP_TO_EDGE, MIRRORED_REPEAT");
102 mWrapLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
103 mWrapLabel.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER );
104 mWrapLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
105 mWrapLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
106 mWrapLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
107 mContent.Add( mWrapLabel );
109 mPixelAreaLabel = Toolkit::TextLabel::New( " Use ImageVisual::Property::PIXEL_AREA\n " );
110 mPixelAreaLabel.SetParentOrigin( ParentOrigin::TOP_CENTER );
111 mPixelAreaLabel.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER );
112 mPixelAreaLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
113 mPixelAreaLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
114 mPixelAreaLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
115 mWrapLabel.Add( mPixelAreaLabel );
118 void CreateScene( const Property::Value& propertyMap )
120 for( int i=0; i<3;i++ )
121 for( int j=0; j<3; j++ )
123 mImageView[i][j] = Toolkit::ImageView::New();
124 mImageView[i][j].SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
125 mImageView[i][j].SetPosition( 50.f*(i-1), 50.f*(j-1) );
128 mImageView[1][1].SetParentOrigin( ParentOrigin::CENTER );
129 mImageView[1][1].SetAnchorPoint(AnchorPoint::CENTER );
130 mImageView[1][1].SetScale( 1.f/3.f );
131 mContent.Add( mImageView[1][1] );
133 mImageView[0][0].SetParentOrigin( ParentOrigin::TOP_LEFT );
134 mImageView[0][0].SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT );
135 mImageView[0][0].SetPosition( -50.f, -50.f );
136 mImageView[1][1].Add( mImageView[0][0] );
138 mImageView[1][0].SetParentOrigin( ParentOrigin::TOP_CENTER );
139 mImageView[1][0].SetAnchorPoint(AnchorPoint::BOTTOM_CENTER );
140 mImageView[1][1].Add( mImageView[1][0] );
142 mImageView[2][0].SetParentOrigin( ParentOrigin::TOP_RIGHT );
143 mImageView[2][0].SetAnchorPoint(AnchorPoint::BOTTOM_LEFT );
144 mImageView[1][1].Add( mImageView[2][0] );
146 mImageView[0][1].SetParentOrigin( ParentOrigin::CENTER_LEFT );
147 mImageView[0][1].SetAnchorPoint(AnchorPoint::CENTER_RIGHT );
148 mImageView[1][1].Add( mImageView[0][1] );
150 mImageView[2][1].SetParentOrigin( ParentOrigin::CENTER_RIGHT );
151 mImageView[2][1].SetAnchorPoint(AnchorPoint::CENTER_LEFT );
152 mImageView[1][1].Add( mImageView[2][1] );
154 mImageView[0][2].SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
155 mImageView[0][2].SetAnchorPoint(AnchorPoint::TOP_RIGHT );
156 mImageView[1][1].Add( mImageView[0][2] );
158 mImageView[1][2].SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
159 mImageView[1][2].SetAnchorPoint(AnchorPoint::TOP_CENTER );
160 mImageView[1][1].Add( mImageView[1][2] );
162 mImageView[2][2].SetParentOrigin( ParentOrigin::BOTTOM_RIGHT );
163 mImageView[2][2].SetAnchorPoint(AnchorPoint::TOP_LEFT );
164 mImageView[1][1].Add( mImageView[2][2] );
168 bool OnButtonClicked( Toolkit::Button button )
176 mIndex = ( mIndex+1 ) % 4;
179 // switch to the other image
180 // set the pixel area to image visual, the pixel area property is registered on the renderer
181 mContent.Remove( mImageView[1][1] );
182 CreateScene( visualPropertyMap[mIndex/2] );
185 mWrapLabel.SetProperty( Toolkit::TextLabel::Property::TEXT," Automatic atlasing\n WrapMode: CLAMP_TO_EDGE, MIRRORED_REPEAT");
189 mWrapLabel.SetProperty( Toolkit::TextLabel::Property::TEXT," No atlasing\n WrapMode: MIRRORED_REPEAT, REPEAT");
191 mPixelAreaLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, " Use ImageVisual::Property::PIXEL_AREA\n " );
195 // animate the pixel area property on image view,
196 // the animatable pixel area property is registered on the actor, which overwrites the property on the renderer
197 mAnimation = Animation::New( 10.f );
198 float relativeSubSize = 0.33;
199 for( int i=0; i<3;i++ )
200 for( int j=0; j<3; j++ )
202 mImageView[i][j].SetProperty( Toolkit::ImageView::Property::PIXEL_AREA, ORIGINAL_PIXEL_AREA );
203 mAnimation.AnimateTo( Property(mImageView[i][j], Toolkit::ImageView::Property::PIXEL_AREA),
204 Vector4( relativeSubSize*i, relativeSubSize*j, relativeSubSize, relativeSubSize ),
205 AlphaFunction::BOUNCE );
207 mAnimation.SetLooping( true );
210 mPixelAreaLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, " Animate ImageView::Property::PIXEL_AREA \n (Overwrite the ImageVisual property) " );
215 void OnKeyEvent(const KeyEvent& event)
217 if(event.state == KeyEvent::Down)
219 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
227 Application& mApplication;
229 Toolkit::ImageView mImageView[3][3];
230 Property::Map visualPropertyMap[2];
231 Toolkit::TextLabel mWrapLabel;
232 Toolkit::TextLabel mPixelAreaLabel;
233 Animation mAnimation;
237 void RunTest( Application& application )
239 ImageViewPixelAreaApp test( application );
241 application.MainLoop();
244 // Entry point for Linux & Tizen applications
246 int DALI_EXPORT_API main( int argc, char **argv )
248 Application application = Application::New( &argc, &argv );
250 RunTest( application );