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>
25 const char* const IMAGE_PATH_1 ( DEMO_IMAGE_DIR "people-small-7b.jpg" ); // 100x100
26 const char* const IMAGE_PATH_2 ( DEMO_IMAGE_DIR "people-medium-7.jpg" );
27 const char* const IMAGE_PATH_3 ( DEMO_IMAGE_DIR "people-medium-7-rgb565.png" ); // is compressed
28 const char* const IMAGE_PATH_4 ( DEMO_IMAGE_DIR "people-medium-7-masked.png" ); // has alpha channel
29 const char* const MASK_IMAGE_PATH_1 ( DEMO_IMAGE_DIR "store_mask_profile_n.png" ); // 300x300
30 const char* const MASK_IMAGE_PATH_2 ( DEMO_IMAGE_DIR "store_mask_profile_f.png" );
33 class ImageViewAlphaBlendApp : public ConnectionTracker
36 ImageViewAlphaBlendApp( Application& application )
37 : mApplication( application ),
38 mImageCombinationIndex( 0 )
40 // Connect to the Application's Init signal
41 mApplication.InitSignal().Connect( this, &ImageViewAlphaBlendApp::Create );
44 ~ImageViewAlphaBlendApp()
46 // Nothing to do here;
50 // The Init signal is received once (only) during the Application lifetime
51 void Create( Application& application )
53 // This creates an image view with one of 3 images, and one of 2 masks.
54 // Clicking the screen will cycle through each combination of mask and image.
56 // Get a handle to the stage
57 Stage stage = Stage::GetCurrent();
58 stage.KeyEventSignal().Connect(this, &ImageViewAlphaBlendApp::OnKeyEvent);
59 stage.SetBackgroundColor( Color::WHITE );
61 mImageView = Toolkit::ImageView::New();
63 mImageView.SetSize(200, 200);
64 mImageView.SetParentOrigin( ParentOrigin::CENTER );
65 stage.Add(mImageView);
67 mImageLabel = Toolkit::TextLabel::New();
68 mImageLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
69 mImageLabel.SetAnchorPoint( ParentOrigin::BOTTOM_CENTER );
70 mImageLabel.SetPosition( Vector3( 0.0f, -50.0f, 0.0f ) );
71 mImageLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::BLACK );
72 stage.Add(mImageLabel);
74 mMaskLabel = Toolkit::TextLabel::New();
75 mMaskLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
76 mMaskLabel.SetAnchorPoint( ParentOrigin::BOTTOM_CENTER );
77 mMaskLabel.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) );
78 mMaskLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::BLACK );
79 stage.Add(mMaskLabel);
83 stage.TouchSignal().Connect( this, &ImageViewAlphaBlendApp::OnTouched );
86 void OnTouched( const TouchData& touchData )
88 static bool touched = false;
89 if( touchData.GetState( 0 ) == PointState::DOWN )
94 if( touchData.GetState( 0 ) == PointState::UP && touched)
96 mImageCombinationIndex++;
104 const char* images[4] = { IMAGE_PATH_1, IMAGE_PATH_2, IMAGE_PATH_3, IMAGE_PATH_4 };
105 const char* masks[2] = { MASK_IMAGE_PATH_1, MASK_IMAGE_PATH_2 };
107 const char* mask = masks[mImageCombinationIndex%2 ]; // Cycle through masks
108 const char* image = images[(mImageCombinationIndex/2)%4]; // then images
111 map.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::Type::IMAGE );
112 map.Add( Toolkit::ImageVisual::Property::URL, image );
113 map.Add( Toolkit::ImageVisual::Property::ALPHA_MASK_URL, mask );
115 if( mImageCombinationIndex%2 == 0 )
117 map.Add( Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE, 1.f );
118 map.Add( Toolkit::ImageVisual::Property::CROP_TO_MASK, false );
122 map.Add( Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
123 map.Add( Toolkit::ImageVisual::Property::CROP_TO_MASK, true );
126 mImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
128 mImageLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, strrchr(image, '/') );
129 mMaskLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, strrchr(mask, '/') );
132 void OnKeyEvent(const KeyEvent& event)
134 if(event.state == KeyEvent::Down)
136 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
145 Application& mApplication;
146 Toolkit::ImageView mImageView;
147 Toolkit::TextLabel mImageLabel;
148 Toolkit::TextLabel mMaskLabel;
150 int mImageCombinationIndex;
153 void RunTest( Application& application )
155 ImageViewAlphaBlendApp test( application );
157 application.MainLoop();
160 // Entry point for Linux & Tizen applications
162 int DALI_EXPORT_API main( int argc, char **argv )
164 Application application = Application::New( &argc, &argv );
166 RunTest( application );