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/devel-api/actors/actor-devel.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
23 using namespace Dali::Toolkit;
27 const float COLOR_ANIMATION_DURATION( 5.0f );
28 const float OPACITY_ANIMATION_DURATION( 1.0f );
29 } // unnamed namespace
32 * @brief An example that shows how to use property notifications.
34 * - Creates a text label and sets its text color to black.
35 * - Animates the text color of a text label to red.
36 * - Sets up a property notification so that we are informed when the color is 50% red.
37 * - When we are notified, we start a new animation which animates the text label to transparent.
39 class PropertyNotificationController : public ConnectionTracker
45 * @param[in] application A reference to the Application class.
47 PropertyNotificationController( Application& application )
48 : mApplication( application )
50 // Connect to the Application's Init signal
51 mApplication.InitSignal().Connect( this, &PropertyNotificationController::Create );
55 * @brief Called to initialise the application content
56 * @param[in] application A reference to the Application class.
58 void Create( Application& application )
60 // Set the stage background color and connect to the stage's key signal to allow Back and Escape to exit.
61 Stage stage = Stage::GetCurrent();
62 stage.SetBackgroundColor( Color::WHITE );
63 stage.KeyEventSignal().Connect( this, &PropertyNotificationController::OnKeyEvent );
65 // Create a text label and set the text color to black
66 mTextLabel = TextLabel::New( "Black to Red Animation\nNew opacity animation at 50% Red" );
67 mTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
68 mTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
69 mTextLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
70 mTextLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
71 mTextLabel.SetProperty( DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE, Color::BLACK );
72 stage.Add( mTextLabel );
74 // Create an animation and animate the text color to red
75 Animation animation = Animation::New( COLOR_ANIMATION_DURATION );
76 animation.AnimateTo( Property( mTextLabel, DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE ), Color::RED );
79 // Set up a property notification so we are notified when the red component of the text-color reaches 50%
80 PropertyNotification notification = mTextLabel.AddPropertyNotification( DevelTextLabel::Property::TEXT_COLOR_RED, GreaterThanCondition( 0.5f ) );
81 notification.NotifySignal().Connect( this, &PropertyNotificationController::RedComponentNotification );
85 * @brief Called when any key event is received
87 * Will use this to quit the application if Back or the Escape key is received
88 * @param[in] event The key event information
90 void OnKeyEvent( const KeyEvent& event )
92 if( event.state == KeyEvent::Down )
94 if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
102 * @brief Called when the property notification condition is met.
104 * In our case, it's when the red component is greater than 50%.
105 * Will use this notification to animate the opacity of the text-label to transparent.
107 void RedComponentNotification( PropertyNotification& /* source */ )
109 Animation animation = Animation::New( OPACITY_ANIMATION_DURATION );
110 animation.AnimateTo( Property( mTextLabel, DevelActor::Property::OPACITY ), 0.0f );
115 Application& mApplication;
116 TextLabel mTextLabel;
119 int DALI_EXPORT_API main( int argc, char **argv )
121 Application application = Application::New( &argc, &argv );
122 PropertyNotificationController test( application );
123 application.MainLoop();