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>
19 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
20 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
27 const char* const IMAGE_PATH_1 ( DEMO_IMAGE_DIR "people-small-7b.jpg" ); // 100x100
28 const char* const IMAGE_PATH_2 ( DEMO_IMAGE_DIR "people-medium-7.jpg" );
29 const char* const IMAGE_PATH_3 ( DEMO_IMAGE_DIR "people-medium-7-rgb565.png" ); // is compressed
30 const char* const IMAGE_PATH_4 ( DEMO_IMAGE_DIR "people-medium-7-masked.png" ); // has alpha channel
31 const char* const MASK_IMAGE_PATH_1 ( DEMO_IMAGE_DIR "store_mask_profile_f.png" );
32 const char* const MASK_IMAGE_PATH_2 ( DEMO_IMAGE_DIR "store_mask_profile_n.png" ); // 300x300
35 class ImageViewAlphaBlendApp : public ConnectionTracker
38 ImageViewAlphaBlendApp( Application& application )
39 : mApplication( application ),
40 mImageCombinationIndex( 0 )
42 // Connect to the Application's Init signal
43 mApplication.InitSignal().Connect( this, &ImageViewAlphaBlendApp::Create );
46 ~ImageViewAlphaBlendApp()
48 // Nothing to do here;
52 // The Init signal is received once (only) during the Application lifetime
53 void Create( Application& application )
55 // This creates an image view with one of 3 images, and one of 2 masks.
56 // Clicking the screen will cycle through each combination of mask and image.
58 // Get a handle to the stage
59 Stage stage = Stage::GetCurrent();
60 stage.KeyEventSignal().Connect(this, &ImageViewAlphaBlendApp::OnKeyEvent);
61 stage.SetBackgroundColor( Color::WHITE );
63 mImageView = Toolkit::ImageView::New();
65 mImageView.SetSize(200, 200);
66 mImageView.SetParentOrigin( ParentOrigin::CENTER );
67 stage.Add(mImageView);
69 mImageLabel = Toolkit::TextLabel::New();
70 mImageLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
71 mImageLabel.SetAnchorPoint( ParentOrigin::BOTTOM_CENTER );
72 mImageLabel.SetPosition( Vector3( 0.0f, -50.0f, 0.0f ) );
73 mImageLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::BLACK );
74 stage.Add(mImageLabel);
76 mMaskLabel = Toolkit::TextLabel::New();
77 mMaskLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
78 mMaskLabel.SetAnchorPoint( ParentOrigin::BOTTOM_CENTER );
79 mMaskLabel.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) );
80 mMaskLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::BLACK );
81 stage.Add(mMaskLabel);
85 stage.TouchSignal().Connect( this, &ImageViewAlphaBlendApp::OnTouched );
88 void OnTouched( const TouchData& touchData )
90 static bool touched = false;
91 if( touchData.GetState( 0 ) == PointState::DOWN )
96 if( touchData.GetState( 0 ) == PointState::UP && touched)
98 mImageCombinationIndex++;
106 const char* images[4] = { IMAGE_PATH_1, IMAGE_PATH_2, IMAGE_PATH_3, IMAGE_PATH_4 };
107 const char* masks[2] = { MASK_IMAGE_PATH_1, MASK_IMAGE_PATH_2 };
109 const char* mask = masks[mImageCombinationIndex%2 ]; // Cycle through masks
110 const char* image = images[(mImageCombinationIndex/2)%4]; // then images
112 map.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::Type::IMAGE );
113 map.Add( Toolkit::ImageVisual::Property::URL, image );
114 map.Add( Toolkit::DevelImageVisual::Property::ALPHA_MASK_URL, mask );
115 mImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
117 mImageLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, strrchr(image, '/') );
118 mMaskLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, strrchr(mask, '/') );
121 void OnKeyEvent(const KeyEvent& event)
123 if(event.state == KeyEvent::Down)
125 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
134 Application& mApplication;
135 Toolkit::ImageView mImageView;
136 Toolkit::TextLabel mImageLabel;
137 Toolkit::TextLabel mMaskLabel;
139 int mImageCombinationIndex;
142 void RunTest( Application& application )
144 ImageViewAlphaBlendApp test( application );
146 application.MainLoop();
149 // Entry point for Linux & Tizen applications
151 int DALI_EXPORT_API main( int argc, char **argv )
153 Application application = Application::New( &argc, &argv );
155 RunTest( application );