Commit fde46e3e0078d155bd9d9dc2e97b409b49453e59
Committed by
Gerrit Code Review
Merge "Example of animating around a pivot" into devel/master
Showing
6 changed files
with
171 additions
and
0 deletions
com.samsung.dali-demo.xml
| @@ -194,4 +194,7 @@ | @@ -194,4 +194,7 @@ | ||
| 194 | <ui-application appid="clipping.example" exec="/usr/apps/com.samsung.dali-demo/bin/clipping.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | 194 | <ui-application appid="clipping.example" exec="/usr/apps/com.samsung.dali-demo/bin/clipping.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 195 | <label>Clipping</label> | 195 | <label>Clipping</label> |
| 196 | </ui-application> | 196 | </ui-application> |
| 197 | + <ui-application appid="pivot.example" exec="/usr/apps/com.samsung.dali-demo/bin/pivot.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | ||
| 198 | + <label>Clipping</label> | ||
| 199 | + </ui-application> | ||
| 197 | </manifest> | 200 | </manifest> |
examples-reel/dali-examples-reel.cpp
| @@ -59,6 +59,7 @@ int DALI_EXPORT_API main(int argc, char **argv) | @@ -59,6 +59,7 @@ int DALI_EXPORT_API main(int argc, char **argv) | ||
| 59 | demo.AddExample(Example("motion-stretch.example", DALI_DEMO_STR_TITLE_MOTION_STRETCH)); | 59 | demo.AddExample(Example("motion-stretch.example", DALI_DEMO_STR_TITLE_MOTION_STRETCH)); |
| 60 | demo.AddExample(Example("native-image-source.example", DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE)); | 60 | demo.AddExample(Example("native-image-source.example", DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE)); |
| 61 | demo.AddExample(Example("popup.example", DALI_DEMO_STR_TITLE_POPUP)); | 61 | demo.AddExample(Example("popup.example", DALI_DEMO_STR_TITLE_POPUP)); |
| 62 | + demo.AddExample(Example("pivot.example", DALI_DEMO_STR_TITLE_PIVOT)); | ||
| 62 | demo.AddExample(Example("primitive-shapes.example", DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES)); | 63 | demo.AddExample(Example("primitive-shapes.example", DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES)); |
| 63 | demo.AddExample(Example("progress-bar.example", DALI_DEMO_STR_TITLE_PROGRESS_BAR)); | 64 | demo.AddExample(Example("progress-bar.example", DALI_DEMO_STR_TITLE_PROGRESS_BAR)); |
| 64 | demo.AddExample(Example("rendering-line.example", DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE)); | 65 | demo.AddExample(Example("rendering-line.example", DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE)); |
examples/pivot/pivot-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-toolkit/dali-toolkit.h> | ||
| 19 | +#include <dali/devel-api/actors/actor-devel.h> | ||
| 20 | + | ||
| 21 | +#include <iostream> | ||
| 22 | + | ||
| 23 | +using namespace Dali; | ||
| 24 | +using namespace Dali::Toolkit; | ||
| 25 | + | ||
| 26 | +namespace | ||
| 27 | +{ | ||
| 28 | +const int TABLE_VIEW_ROWS = 5; | ||
| 29 | +const int TABLE_VIEW_COLUMNS = 3; | ||
| 30 | +const Vector3 TABLE_VIEW_SIZE_MODE_FACTOR( 0.6f, 0.6f, 1.0f ); | ||
| 31 | + | ||
| 32 | +const Quaternion ANIMATION_ROTATION( Degree( 360.0f), Vector3::ZAXIS ); | ||
| 33 | +const AlphaFunction::BuiltinFunction ROTATION_ANIMATION_ALPHA_FUNCTION( AlphaFunction::EASE_IN_OUT ); | ||
| 34 | +const TimePeriod ROTATION_ANIMATION_TIME_PERIOD( 0.0f, 0.5f ); | ||
| 35 | + | ||
| 36 | +const Vector3 ANIMATION_SCALE( 2.0f, 2.0f, 1.0f ); | ||
| 37 | +const AlphaFunction::BuiltinFunction SCALE_ANIMATION_ALPHA_FUNCTION( AlphaFunction::SIN ); | ||
| 38 | +const TimePeriod SCALE_ANIMATION_TIME_PERIOD( 0.15f, 0.85f ); | ||
| 39 | +} // unnamed namespace | ||
| 40 | + | ||
| 41 | +/** | ||
| 42 | + * @brief Demonstrates how to animate a control in a layout-container using the anchor point as the pivot. | ||
| 43 | + * | ||
| 44 | + * Positions of the controls in the layout-container will be set using the top-left of the control. | ||
| 45 | + */ | ||
| 46 | +class PivotController : public ConnectionTracker | ||
| 47 | +{ | ||
| 48 | +public: | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * @brief Constructor. | ||
| 52 | + * @param[in] application Reference to the application instance. | ||
| 53 | + */ | ||
| 54 | + PivotController( Application& application ) | ||
| 55 | + : mApplication( application ) | ||
| 56 | + { | ||
| 57 | + mApplication.InitSignal().Connect( this, &PivotController::Create ); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | +private: | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * @brief The Init signal is received once (only) during the Application lifetime. | ||
| 64 | + */ | ||
| 65 | + void Create( Application& /* application */ ) | ||
| 66 | + { | ||
| 67 | + // Get a handle to the stage | ||
| 68 | + Stage stage = Stage::GetCurrent(); | ||
| 69 | + stage.SetBackgroundColor( Color::WHITE ); | ||
| 70 | + stage.KeyEventSignal().Connect( this, &PivotController::OnKeyEvent ); | ||
| 71 | + | ||
| 72 | + // Create a table view. | ||
| 73 | + TableView tableView = TableView::New( TABLE_VIEW_ROWS, TABLE_VIEW_COLUMNS ); | ||
| 74 | + tableView.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 75 | + tableView.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 76 | + tableView.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); | ||
| 77 | + tableView.SetSizeModeFactor( TABLE_VIEW_SIZE_MODE_FACTOR ); | ||
| 78 | + stage.Add( tableView ); | ||
| 79 | + | ||
| 80 | + // Create a tap detector - we are going to rotate an actor round our anchor-point (pivot) when one of our controls is tapped. | ||
| 81 | + mTapDetector = TapGestureDetector::New(); | ||
| 82 | + mTapDetector.DetectedSignal().Connect( this, &PivotController::OnTap ); | ||
| 83 | + | ||
| 84 | + Vector3 anchorPoint( AnchorPoint::CENTER ); // This will be changed depending on the row and column. | ||
| 85 | + | ||
| 86 | + // Add controls to the table-view - each control will have a random color. | ||
| 87 | + for( int row = 0; row < TABLE_VIEW_ROWS; ++row ) | ||
| 88 | + { | ||
| 89 | + anchorPoint.y = ( row % TABLE_VIEW_ROWS ) * ( 1.0f / ( TABLE_VIEW_ROWS - 1 ) ); // Calculate this row's y anchor-point. | ||
| 90 | + | ||
| 91 | + for( int column = 0; column < TABLE_VIEW_COLUMNS; ++column ) | ||
| 92 | + { | ||
| 93 | + anchorPoint.x = ( column % TABLE_VIEW_COLUMNS ) * ( 1.0f / ( TABLE_VIEW_COLUMNS - 1 ) ); // Calculate this column's x anchor-point. | ||
| 94 | + | ||
| 95 | + // Create a control with a randomly chosen background color. | ||
| 96 | + Control control = Control::New(); | ||
| 97 | + control.SetBackgroundColor( Vector4( Random::Range( 0.0f, 1.0f ), Random::Range( 0.0f, 1.0f ), Random::Range( 0.0f, 1.0f ), 1.0f ) ); | ||
| 98 | + control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); | ||
| 99 | + control.SetProperty( DevelActor::Property::POSITION_USES_ANCHOR_POINT, false ); // Ensures the position always uses top-left for its calculations. | ||
| 100 | + control.SetAnchorPoint( anchorPoint ); // This anchor-point is used for the rotation and the scale. | ||
| 101 | + | ||
| 102 | + // Add to the table-view | ||
| 103 | + tableView.AddChild( control, TableView::CellPosition( row, column ) ); | ||
| 104 | + | ||
| 105 | + // Attach each control to the tap-detector so we can start the animation around our anchor point. | ||
| 106 | + mTapDetector.Attach( control ); | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * @brief Called when a control is tapped. | ||
| 113 | + * | ||
| 114 | + * Here we will start an animation around our pivot. | ||
| 115 | + */ | ||
| 116 | + void OnTap( Actor actor, const TapGesture& /* tap */ ) | ||
| 117 | + { | ||
| 118 | + // Raise the actor to the top. | ||
| 119 | + DevelActor::RaiseToTop( actor ); | ||
| 120 | + | ||
| 121 | + // Create the animation to rotate and scale our actor. | ||
| 122 | + Animation animation = Animation::New( 1.0f ); | ||
| 123 | + animation.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), ANIMATION_ROTATION, ROTATION_ANIMATION_ALPHA_FUNCTION, ROTATION_ANIMATION_TIME_PERIOD ); | ||
| 124 | + animation.AnimateTo( Property( actor, Actor::Property::SCALE ), ANIMATION_SCALE, SCALE_ANIMATION_ALPHA_FUNCTION, SCALE_ANIMATION_TIME_PERIOD ); | ||
| 125 | + | ||
| 126 | + // Play the animation. | ||
| 127 | + animation.Play(); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * @brief Called when any key event is received | ||
| 132 | + * | ||
| 133 | + * Will use this to quit the application if Back or the Escape key is received | ||
| 134 | + * @param[in] event The key event information | ||
| 135 | + */ | ||
| 136 | + void OnKeyEvent( const KeyEvent& event ) | ||
| 137 | + { | ||
| 138 | + if( event.state == KeyEvent::Down ) | ||
| 139 | + { | ||
| 140 | + if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) | ||
| 141 | + { | ||
| 142 | + mApplication.Quit(); | ||
| 143 | + } | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | +private: | ||
| 148 | + | ||
| 149 | + Application& mApplication; ///< Reference to the Application instance. | ||
| 150 | + TapGestureDetector mTapDetector; ///< Used for animating the tapped control. | ||
| 151 | +}; | ||
| 152 | + | ||
| 153 | +int DALI_EXPORT_API main( int argc, char **argv ) | ||
| 154 | +{ | ||
| 155 | + Application application = Application::New( &argc, &argv ); | ||
| 156 | + PivotController test( application ); | ||
| 157 | + application.MainLoop(); | ||
| 158 | + return 0; | ||
| 159 | +} |
resources/po/en_GB.po
| @@ -94,6 +94,9 @@ msgstr "Negotiate Size" | @@ -94,6 +94,9 @@ msgstr "Negotiate Size" | ||
| 94 | msgid "DALI_DEMO_STR_TITLE_POPUP" | 94 | msgid "DALI_DEMO_STR_TITLE_POPUP" |
| 95 | msgstr "Popup" | 95 | msgstr "Popup" |
| 96 | 96 | ||
| 97 | +msgid "DALI_DEMO_STR_TITLE_PIVOT" | ||
| 98 | +msgstr "Pivot" | ||
| 99 | + | ||
| 97 | msgid "DALI_DEMO_STR_TITLE_PROGRESS_BAR" | 100 | msgid "DALI_DEMO_STR_TITLE_PROGRESS_BAR" |
| 98 | msgstr "Progress Bar" | 101 | msgstr "Progress Bar" |
| 99 | 102 |
resources/po/en_US.po
| @@ -94,6 +94,9 @@ msgstr "Negotiate Size" | @@ -94,6 +94,9 @@ msgstr "Negotiate Size" | ||
| 94 | msgid "DALI_DEMO_STR_TITLE_POPUP" | 94 | msgid "DALI_DEMO_STR_TITLE_POPUP" |
| 95 | msgstr "Popup" | 95 | msgstr "Popup" |
| 96 | 96 | ||
| 97 | +msgid "DALI_DEMO_STR_TITLE_PIVOT" | ||
| 98 | +msgstr "Pivot" | ||
| 99 | + | ||
| 97 | msgid "DALI_DEMO_STR_TITLE_PROGRESS_BAR" | 100 | msgid "DALI_DEMO_STR_TITLE_PROGRESS_BAR" |
| 98 | msgstr "Progress Bar" | 101 | msgstr "Progress Bar" |
| 99 | 102 |
shared/dali-demo-strings.h
| @@ -65,6 +65,7 @@ extern "C" | @@ -65,6 +65,7 @@ extern "C" | ||
| 65 | #define DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE") | 65 | #define DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE") |
| 66 | #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE") | 66 | #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE") |
| 67 | #define DALI_DEMO_STR_TITLE_POPUP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_POPUP") | 67 | #define DALI_DEMO_STR_TITLE_POPUP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_POPUP") |
| 68 | +#define DALI_DEMO_STR_TITLE_PIVOT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PIVOT") | ||
| 68 | #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES") | 69 | #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES") |
| 69 | #define DALI_DEMO_STR_TITLE_PROGRESS_BAR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROGRESS_BAR") | 70 | #define DALI_DEMO_STR_TITLE_PROGRESS_BAR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROGRESS_BAR") |
| 70 | #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE") | 71 | #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE") |
| @@ -123,6 +124,7 @@ extern "C" | @@ -123,6 +124,7 @@ extern "C" | ||
| 123 | #define DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE "Native Image Source" | 124 | #define DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE "Native Image Source" |
| 124 | #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE "Negotiate Size" | 125 | #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE "Negotiate Size" |
| 125 | #define DALI_DEMO_STR_TITLE_POPUP "Popup" | 126 | #define DALI_DEMO_STR_TITLE_POPUP "Popup" |
| 127 | +#define DALI_DEMO_STR_TITLE_PIVOT "Pivot" | ||
| 126 | #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES "Primitive Shapes" | 128 | #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES "Primitive Shapes" |
| 127 | #define DALI_DEMO_STR_TITLE_PROGRESS_BAR "Progress Bar" | 129 | #define DALI_DEMO_STR_TITLE_PROGRESS_BAR "Progress Bar" |
| 128 | #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE "Draw Line" | 130 | #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE "Draw Line" |