2 * Copyright (c) 2020 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>
20 #include "shared/view.h"
26 const char* BIG_TEST_IMAGE( DEMO_IMAGE_DIR "book-landscape-cover.jpg" );
27 const char* SMALL_TEST_IMAGE( DEMO_IMAGE_DIR "gallery-large-1.jpg" );
29 const char * const APPLICATION_TITLE( "Pixel Area & Wrap Mode" );
30 const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
31 const char * const BUTTON_ICON( DEMO_IMAGE_DIR "icon-change.png" );
32 const char * const BUTTON_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" );
34 const Vector4 ORIGINAL_PIXEL_AREA( -0.5f, -0.5f, 2.f, 2.f );
37 class ImageViewPixelAreaApp : public ConnectionTracker
40 ImageViewPixelAreaApp( Application& application )
41 : mApplication( application ),
44 // Connect to the Application's Init signal
45 mApplication.InitSignal().Connect( this, &ImageViewPixelAreaApp::Create );
48 ~ImageViewPixelAreaApp()
50 // Nothing to do here;
54 // The Init signal is received once (only) during the Application lifetime
55 void Create( Application& application )
57 // Get a handle to the window
58 Window window = application.GetWindow();
59 window.KeyEventSignal().Connect(this, &ImageViewPixelAreaApp::OnKeyEvent);
61 Toolkit::ToolBar toolBar;
62 Toolkit::Control background;
63 // Creates a default view with a default tool bar.
64 mContent = DemoHelper::CreateView( application,
71 // Add a button to switch the scene. (right of toolbar)
72 Toolkit::PushButton switchButton = Toolkit::PushButton::New();
73 switchButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_ICON );
74 switchButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, BUTTON_ICON_SELECTED );
75 switchButton.ClickedSignal().Connect( this, &ImageViewPixelAreaApp::OnButtonClicked );
76 toolBar.AddControl( switchButton,
77 DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
78 Toolkit::Alignment::HorizontalRight,
79 DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
82 // for testing image WITH automatic atlasing
83 visualPropertyMap[0][ Toolkit::ImageVisual::Property::URL ] = SMALL_TEST_IMAGE;
84 visualPropertyMap[0][ Toolkit::ImageVisual::Property::DESIRED_WIDTH ] = 500;
85 visualPropertyMap[0][ Toolkit::ImageVisual::Property::DESIRED_HEIGHT ] = 500;
86 visualPropertyMap[0][ Toolkit::ImageVisual::Property::WRAP_MODE_U ] = WrapMode::CLAMP_TO_EDGE;
87 visualPropertyMap[0][ Toolkit::ImageVisual::Property::WRAP_MODE_V ] = WrapMode::MIRRORED_REPEAT;
88 visualPropertyMap[0][ Toolkit::ImageVisual::Property::PIXEL_AREA ] = ORIGINAL_PIXEL_AREA;
90 // for testing image WITHOUT automatic atlasing
91 visualPropertyMap[1][ Toolkit::ImageVisual::Property::URL ] = BIG_TEST_IMAGE;
92 visualPropertyMap[1][ Toolkit::ImageVisual::Property::DESIRED_WIDTH ] = 640;
93 visualPropertyMap[1][ Toolkit::ImageVisual::Property::DESIRED_HEIGHT ] = 720;
94 visualPropertyMap[1][ Toolkit::ImageVisual::Property::WRAP_MODE_U ] = WrapMode::MIRRORED_REPEAT;
95 visualPropertyMap[1][ Toolkit::ImageVisual::Property::WRAP_MODE_V ] = WrapMode::REPEAT;
96 visualPropertyMap[1][ Toolkit::ImageVisual::Property::PIXEL_AREA ] = ORIGINAL_PIXEL_AREA;
98 CreateScene( visualPropertyMap[0] );
100 mWrapLabel = Toolkit::TextLabel::New(" Automatic atlasing\n WrapMode: CLAMP_TO_EDGE, MIRRORED_REPEAT");
101 mWrapLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
102 mWrapLabel.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_CENTER );
103 mWrapLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
104 mWrapLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
105 mWrapLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
106 mContent.Add( mWrapLabel );
108 mPixelAreaLabel = Toolkit::TextLabel::New( " Use ImageVisual::Property::PIXEL_AREA\n " );
109 mPixelAreaLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
110 mPixelAreaLabel.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_CENTER );
111 mPixelAreaLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
112 mPixelAreaLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
113 mPixelAreaLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
114 mWrapLabel.Add( mPixelAreaLabel );
117 void CreateScene( const Property::Value& propertyMap )
119 for( int i=0; i<3;i++ )
120 for( int j=0; j<3; j++ )
122 mImageView[i][j] = Toolkit::ImageView::New();
123 mImageView[i][j].SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
124 mImageView[i][j].SetProperty( Actor::Property::POSITION, Vector2( 50.f*(i-1), 50.f*(j-1) ));
127 mImageView[1][1].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
128 mImageView[1][1].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER );
129 mImageView[1][1].SetProperty( Actor::Property::SCALE, 1.f/3.f );
130 mContent.Add( mImageView[1][1] );
132 mImageView[0][0].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
133 mImageView[0][0].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT );
134 mImageView[0][0].SetProperty( Actor::Property::POSITION, Vector2( -50.f, -50.f ));
135 mImageView[1][1].Add( mImageView[0][0] );
137 mImageView[1][0].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
138 mImageView[1][0].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_CENTER );
139 mImageView[1][1].Add( mImageView[1][0] );
141 mImageView[2][0].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT );
142 mImageView[2][0].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_LEFT );
143 mImageView[1][1].Add( mImageView[2][0] );
145 mImageView[0][1].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT );
146 mImageView[0][1].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER_RIGHT );
147 mImageView[1][1].Add( mImageView[0][1] );
149 mImageView[2][1].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_RIGHT );
150 mImageView[2][1].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER_LEFT );
151 mImageView[1][1].Add( mImageView[2][1] );
153 mImageView[0][2].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT );
154 mImageView[0][2].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_RIGHT );
155 mImageView[1][1].Add( mImageView[0][2] );
157 mImageView[1][2].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
158 mImageView[1][2].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER );
159 mImageView[1][1].Add( mImageView[1][2] );
161 mImageView[2][2].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT );
162 mImageView[2][2].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT );
163 mImageView[1][1].Add( mImageView[2][2] );
167 bool OnButtonClicked( Toolkit::Button button )
175 mIndex = ( mIndex+1 ) % 4;
178 // switch to the other image
179 // set the pixel area to image visual, the pixel area property is registered on the renderer
180 mContent.Remove( mImageView[1][1] );
181 CreateScene( visualPropertyMap[mIndex/2] );
184 mWrapLabel.SetProperty( Toolkit::TextLabel::Property::TEXT," Automatic atlasing\n WrapMode: CLAMP_TO_EDGE, MIRRORED_REPEAT");
188 mWrapLabel.SetProperty( Toolkit::TextLabel::Property::TEXT," No atlasing\n WrapMode: MIRRORED_REPEAT, REPEAT");
190 mPixelAreaLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, " Use ImageVisual::Property::PIXEL_AREA\n " );
194 // animate the pixel area property on image view,
195 // the animatable pixel area property is registered on the actor, which overwrites the property on the renderer
196 mAnimation = Animation::New( 10.f );
197 float relativeSubSize = 0.33;
198 for( int i=0; i<3;i++ )
199 for( int j=0; j<3; j++ )
201 mImageView[i][j].SetProperty( Toolkit::ImageView::Property::PIXEL_AREA, ORIGINAL_PIXEL_AREA );
202 mAnimation.AnimateTo( Property(mImageView[i][j], Toolkit::ImageView::Property::PIXEL_AREA),
203 Vector4( relativeSubSize*i, relativeSubSize*j, relativeSubSize, relativeSubSize ),
204 AlphaFunction::BOUNCE );
206 mAnimation.SetLooping( true );
209 mPixelAreaLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, " Animate ImageView::Property::PIXEL_AREA \n (Overwrite the ImageVisual property) " );
214 void OnKeyEvent(const KeyEvent& event)
216 if(event.GetState() == KeyEvent::DOWN)
218 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
226 Application& mApplication;
228 Toolkit::ImageView mImageView[3][3];
229 Property::Map visualPropertyMap[2];
230 Toolkit::TextLabel mWrapLabel;
231 Toolkit::TextLabel mPixelAreaLabel;
232 Animation mAnimation;
236 int DALI_EXPORT_API main( int argc, char **argv )
238 Application application = Application::New( &argc, &argv );
239 ImageViewPixelAreaApp test( application );
240 application.MainLoop();