Commit 72ca10bf96862808b57568cf8a71d6a95a237d04
1 parent
87d45c11
Added a property notification example
Change-Id: I0971701ac37ccc5e86bf88976bec17d59919025b
Showing
6 changed files
with
137 additions
and
0 deletions
com.samsung.dali-demo.xml
| ... | ... | @@ -235,6 +235,9 @@ |
| 235 | 235 | <ui-application appid="text-overlap.example" exec="/usr/apps/com.samsung.dali-demo/bin/text-overlap.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 236 | 236 | <label>Text Overlap</label> |
| 237 | 237 | </ui-application> |
| 238 | + <ui-application appid="property-notification.example" exec="/usr/apps/com.samsung.dali-demo/bin/property-notification.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | |
| 239 | + <label>Property Notification</label> | |
| 240 | + </ui-application> | |
| 238 | 241 | <privileges> |
| 239 | 242 | <privilege>http://tizen.org/privilege/mediastorage</privilege> |
| 240 | 243 | <privilege>http://tizen.org/privilege/externalstorage</privilege> | ... | ... |
examples-reel/dali-examples-reel.cpp
| ... | ... | @@ -65,6 +65,7 @@ int DALI_EXPORT_API main(int argc, char **argv) |
| 65 | 65 | demo.AddExample(Example("pivot.example", DALI_DEMO_STR_TITLE_PIVOT)); |
| 66 | 66 | demo.AddExample(Example("primitive-shapes.example", DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES)); |
| 67 | 67 | demo.AddExample(Example("progress-bar.example", DALI_DEMO_STR_TITLE_PROGRESS_BAR)); |
| 68 | + demo.AddExample(Example("property-notification.example", DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION)); | |
| 68 | 69 | demo.AddExample(Example("rendering-basic-light.example", DALI_DEMO_STR_TITLE_BASIC_LIGHT)); |
| 69 | 70 | demo.AddExample(Example("rendering-line.example", DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE)); |
| 70 | 71 | demo.AddExample(Example("rendering-triangle.example", DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE)); | ... | ... |
examples/property-notification/property-notification-example.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2017 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 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 | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 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. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + | |
| 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> | |
| 21 | + | |
| 22 | +using namespace Dali; | |
| 23 | +using namespace Dali::Toolkit; | |
| 24 | + | |
| 25 | +namespace | |
| 26 | +{ | |
| 27 | +const float COLOR_ANIMATION_DURATION( 5.0f ); | |
| 28 | +const float OPACITY_ANIMATION_DURATION( 1.0f ); | |
| 29 | +} // unnamed namespace | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * @brief An example that shows how to use property notifications. | |
| 33 | + * | |
| 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. | |
| 38 | + */ | |
| 39 | +class PropertyNotificationController : public ConnectionTracker | |
| 40 | +{ | |
| 41 | +public: | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @brief Constructor. | |
| 45 | + * @param[in] application A reference to the Application class. | |
| 46 | + */ | |
| 47 | + PropertyNotificationController( Application& application ) | |
| 48 | + : mApplication( application ) | |
| 49 | + { | |
| 50 | + // Connect to the Application's Init signal | |
| 51 | + mApplication.InitSignal().Connect( this, &PropertyNotificationController::Create ); | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * @brief Called to initialise the application content | |
| 56 | + * @param[in] application A reference to the Application class. | |
| 57 | + */ | |
| 58 | + void Create( Application& application ) | |
| 59 | + { | |
| 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 ); | |
| 64 | + | |
| 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 ); | |
| 73 | + | |
| 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 ); | |
| 77 | + animation.Play(); | |
| 78 | + | |
| 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 ); | |
| 82 | + } | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * @brief Called when any key event is received | |
| 86 | + * | |
| 87 | + * Will use this to quit the application if Back or the Escape key is received | |
| 88 | + * @param[in] event The key event information | |
| 89 | + */ | |
| 90 | + void OnKeyEvent( const KeyEvent& event ) | |
| 91 | + { | |
| 92 | + if( event.state == KeyEvent::Down ) | |
| 93 | + { | |
| 94 | + if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) | |
| 95 | + { | |
| 96 | + mApplication.Quit(); | |
| 97 | + } | |
| 98 | + } | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * @brief Called when the property notification condition is met. | |
| 103 | + * | |
| 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. | |
| 106 | + */ | |
| 107 | + void RedComponentNotification( PropertyNotification& /* source */ ) | |
| 108 | + { | |
| 109 | + Animation animation = Animation::New( OPACITY_ANIMATION_DURATION ); | |
| 110 | + animation.AnimateTo( Property( mTextLabel, DevelActor::Property::OPACITY ), 0.0f ); | |
| 111 | + animation.Play(); | |
| 112 | + } | |
| 113 | + | |
| 114 | +private: | |
| 115 | + Application& mApplication; | |
| 116 | + TextLabel mTextLabel; | |
| 117 | +}; | |
| 118 | + | |
| 119 | +int DALI_EXPORT_API main( int argc, char **argv ) | |
| 120 | +{ | |
| 121 | + Application application = Application::New( &argc, &argv ); | |
| 122 | + PropertyNotificationController test( application ); | |
| 123 | + application.MainLoop(); | |
| 124 | + return 0; | |
| 125 | +} | ... | ... |
resources/po/en_GB.po
| ... | ... | @@ -109,6 +109,9 @@ msgstr "Pivot" |
| 109 | 109 | msgid "DALI_DEMO_STR_TITLE_PROGRESS_BAR" |
| 110 | 110 | msgstr "Progress Bar" |
| 111 | 111 | |
| 112 | +msgid "DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION" | |
| 113 | +msgstr "Property Notification" | |
| 114 | + | |
| 112 | 115 | msgid "DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES" |
| 113 | 116 | msgstr "Primitive Shapes" |
| 114 | 117 | ... | ... |
resources/po/en_US.po
| ... | ... | @@ -109,6 +109,9 @@ msgstr "Pivot" |
| 109 | 109 | msgid "DALI_DEMO_STR_TITLE_PROGRESS_BAR" |
| 110 | 110 | msgstr "Progress Bar" |
| 111 | 111 | |
| 112 | +msgid "DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION" | |
| 113 | +msgstr "Property Notification" | |
| 114 | + | |
| 112 | 115 | msgid "DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES" |
| 113 | 116 | msgstr "Primitive Shapes" |
| 114 | 117 | ... | ... |
shared/dali-demo-strings.h
| ... | ... | @@ -73,6 +73,7 @@ extern "C" |
| 73 | 73 | #define DALI_DEMO_STR_TITLE_PIVOT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PIVOT") |
| 74 | 74 | #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES") |
| 75 | 75 | #define DALI_DEMO_STR_TITLE_PROGRESS_BAR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROGRESS_BAR") |
| 76 | +#define DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION") | |
| 76 | 77 | #define DALI_DEMO_STR_TITLE_REFRACTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFRACTION") |
| 77 | 78 | #define DALI_DEMO_STR_TITLE_REMOTE_IMAGE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REMOTE_IMAGE") |
| 78 | 79 | #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE") |
| ... | ... | @@ -142,6 +143,7 @@ extern "C" |
| 142 | 143 | #define DALI_DEMO_STR_TITLE_PIVOT "Pivot" |
| 143 | 144 | #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES "Primitive Shapes" |
| 144 | 145 | #define DALI_DEMO_STR_TITLE_PROGRESS_BAR "Progress Bar" |
| 146 | +#define DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION "Property Notification" | |
| 145 | 147 | #define DALI_DEMO_STR_TITLE_REFRACTION "Refract Effect" |
| 146 | 148 | #define DALI_DEMO_STR_TITLE_REMOTE_IMAGE "Remote Image" |
| 147 | 149 | #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE "Draw Line" | ... | ... |