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>
19 #include <dali-toolkit/devel-api/controls/control-devel.h>
20 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
21 #include <dali-toolkit/devel-api/visuals/color-visual-properties-devel.h>
22 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
25 using namespace Dali::Toolkit;
30 const char* IMAGE_FILE( DEMO_IMAGE_DIR "gallery-medium-1.jpg" );
32 const float BLUR_RADIUS_VALUE( 10.0f );
33 const float NO_BLUR_VALUE( 0.0f );
34 const float ANIMATION_DURATION( 2.0f );
36 const Property::Value SHADOW
38 { Visual::Property::TYPE, Visual::COLOR },
39 { Visual::Property::MIX_COLOR, Vector4( 0.0f, 0.0f, 0.0f, 0.5f ) },
40 { Visual::Property::TRANSFORM, Property::Map{ { Visual::Transform::Property::OFFSET, Vector2( 0.05f, 0.05f ) },
41 { Visual::Transform::Property::SIZE, Vector2( 1.05f, 1.05f ) },
42 { Visual::Transform::Property::ORIGIN, Align::CENTER },
43 { Visual::Transform::Property::ANCHOR_POINT, Align::CENTER } } },
44 { DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_VALUE }
49 // This example shows the blur radius property of the color visual and animates it.
51 class ColorVisualExample : public ConnectionTracker
55 ColorVisualExample( Application& application )
56 : mApplication( application ),
57 mShadowVisible( true )
59 // Connect to the Application's Init signal
60 mApplication.InitSignal().Connect( this, &ColorVisualExample::Create );
65 // Nothing to do here;
68 // The Init signal is received once (only) during the Application lifetime
69 void Create( Application& application )
71 // Get a handle to the window
72 Window window = application.GetWindow();
73 window.SetBackgroundColor( Color::WHITE );
75 mImageView = ImageView::New( IMAGE_FILE );
76 mImageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
77 mImageView.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
78 mImageView.SetProperty( DevelControl::Property::SHADOW, SHADOW );
80 window.Add( mImageView );
82 // Respond to a click anywhere on the window
83 window.GetRootLayer().TouchSignal().Connect( this, &ColorVisualExample::OnTouch );
85 // Respond to key events
86 window.KeyEventSignal().Connect( this, &ColorVisualExample::OnKeyEvent );
89 bool OnTouch( Actor actor, const TouchEvent& touch )
91 if( touch.GetState( 0 ) == PointState::UP )
93 float initialValue, targetValue;
96 initialValue = NO_BLUR_VALUE;
97 targetValue = BLUR_RADIUS_VALUE;
101 initialValue = BLUR_RADIUS_VALUE;
102 targetValue = NO_BLUR_VALUE;
105 mShadowVisible = !mShadowVisible;
107 TransitionData transitionData = TransitionData::New( Property::Map().Add( "target", "shadow" )
108 .Add( "property", "blurRadius" )
109 .Add( "initialValue", initialValue )
110 .Add( "targetValue", targetValue )
111 .Add( "animator", Property::Map().Add( "duration", ANIMATION_DURATION ) ) );
112 Animation animation = DevelControl::CreateTransition( Toolkit::Internal::GetImplementation( mImageView ), transitionData );
118 void OnKeyEvent( const KeyEvent& event )
120 if( event.state == KeyEvent::Down )
122 if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
130 Application& mApplication;
131 ImageView mImageView;
135 int DALI_EXPORT_API main( int argc, char **argv )
137 Application application = Application::New( &argc, &argv );
138 ColorVisualExample test( application );
139 application.MainLoop();