Commit a42a6ed5b508de91d3bc6fbac1cbd2d0dc756f46
1 parent
752e2a16
Update AnimatedVectorImageVisual example
Change-Id: I97f0f8f0c543323bc65e64bb4c817158685492a8
Showing
1 changed file
with
45 additions
and
47 deletions
examples/animated-vector-images/animated-vector-images-example.cpp
| ... | ... | @@ -21,6 +21,8 @@ |
| 21 | 21 | #include <dali-toolkit/dali-toolkit.h> |
| 22 | 22 | #include <dali-toolkit/devel-api/controls/control-devel.h> |
| 23 | 23 | #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h> |
| 24 | +#include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h> | |
| 25 | +#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h> | |
| 24 | 26 | |
| 25 | 27 | using namespace Dali; |
| 26 | 28 | using namespace Dali::Toolkit; |
| ... | ... | @@ -48,14 +50,14 @@ enum CellPlacement |
| 48 | 50 | NUMBER_OF_ROWS |
| 49 | 51 | }; |
| 50 | 52 | |
| 51 | -unsigned int GetButtonIndex( Button button ) | |
| 53 | +unsigned int GetControlIndex( Control control ) | |
| 52 | 54 | { |
| 53 | - std::string buttonName = button.GetName(); | |
| 55 | + std::string controlName = control.GetName(); | |
| 54 | 56 | unsigned int index = 0; |
| 55 | 57 | |
| 56 | - if ( buttonName != "") | |
| 58 | + if ( controlName != "") | |
| 57 | 59 | { |
| 58 | - index = std::stoul( buttonName ); | |
| 60 | + index = std::stoul( controlName ); | |
| 59 | 61 | } |
| 60 | 62 | |
| 61 | 63 | return index; |
| ... | ... | @@ -114,31 +116,31 @@ class AnimatedVectorImageViewController: public ConnectionTracker |
| 114 | 116 | mPlayButtons[x].SetName( s ); |
| 115 | 117 | mTable.AddChild( mPlayButtons[x], TableView::CellPosition( CellPlacement::TOP_BUTTON, x ) ); |
| 116 | 118 | |
| 117 | - mPauseButtons[x] = PushButton::New(); | |
| 118 | - mPauseButtons[x].SetProperty( Button::Property::LABEL, "Pause" ); | |
| 119 | - mPauseButtons[x].SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); | |
| 120 | - mPauseButtons[x].SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); | |
| 121 | - mPauseButtons[x].ClickedSignal().Connect( this, &AnimatedVectorImageViewController::OnPauseButtonClicked ); | |
| 122 | - mPauseButtons[x].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); | |
| 123 | - mPauseButtons[x].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); | |
| 124 | - mPauseButtons[x].SetName( s ); | |
| 125 | - mTable.AddChild( mPauseButtons[x], TableView::CellPosition( CellPlacement::LOWER_BUTTON, x ) ); | |
| 119 | + mStopButtons[x] = PushButton::New(); | |
| 120 | + mStopButtons[x].SetProperty( Button::Property::LABEL, "Stop" ); | |
| 121 | + mStopButtons[x].SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); | |
| 122 | + mStopButtons[x].SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); | |
| 123 | + mStopButtons[x].ClickedSignal().Connect( this, &AnimatedVectorImageViewController::OnStopButtonClicked ); | |
| 124 | + mStopButtons[x].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); | |
| 125 | + mStopButtons[x].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); | |
| 126 | + mStopButtons[x].SetName( s ); | |
| 127 | + mTable.AddChild( mStopButtons[x], TableView::CellPosition( CellPlacement::LOWER_BUTTON, x ) ); | |
| 126 | 128 | |
| 127 | 129 | mImageViews[x] = ImageView::New( ); |
| 128 | 130 | Property::Map imagePropertyMap; |
| 129 | - imagePropertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); | |
| 130 | - imagePropertyMap.Insert( ImageVisual::Property::URL, IMAGE_PATH[ x ] ); | |
| 131 | - mImageViews[x].SetProperty( ImageView::Property::IMAGE , imagePropertyMap ); | |
| 131 | + imagePropertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); | |
| 132 | + imagePropertyMap.Insert( ImageVisual::Property::URL, IMAGE_PATH[ x ] ); | |
| 133 | + imagePropertyMap.Insert( DevelImageVisual::Property::LOOP_COUNT, 3 ); | |
| 134 | + mImageViews[x].SetProperty( ImageView::Property::IMAGE, imagePropertyMap ); | |
| 132 | 135 | |
| 133 | 136 | mImageViews[x].SetParentOrigin( ParentOrigin::CENTER ); |
| 134 | 137 | mImageViews[x].SetAnchorPoint( AnchorPoint::CENTER ); |
| 135 | 138 | mImageViews[x].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); |
| 139 | + mImageViews[x].SetName( s ); | |
| 136 | 140 | |
| 137 | - mTable.AddChild( mImageViews[x], TableView::CellPosition( CellPlacement::IMAGE, x ) ); | |
| 141 | + DevelControl::VisualEventSignal( mImageViews[x] ).Connect( this, &AnimatedVectorImageViewController::OnVisualEvent ); | |
| 138 | 142 | |
| 139 | - // Set changeable counter and toggle for each ImageView | |
| 140 | - mImageViewPlayStatus[x] = false; | |
| 141 | - mImageViewPauseStatus[x] = false; | |
| 143 | + mTable.AddChild( mImageViews[x], TableView::CellPosition( CellPlacement::IMAGE, x ) ); | |
| 142 | 144 | } |
| 143 | 145 | |
| 144 | 146 | Stage::GetCurrent().KeyEventSignal().Connect(this, &AnimatedVectorImageViewController::OnKeyEvent); |
| ... | ... | @@ -148,48 +150,46 @@ private: |
| 148 | 150 | |
| 149 | 151 | bool OnPlayButtonClicked( Button button ) |
| 150 | 152 | { |
| 151 | - unsigned int buttonIndex = GetButtonIndex( button ); | |
| 153 | + unsigned int controlIndex = GetControlIndex( button ); | |
| 154 | + | |
| 155 | + ImageView imageView = mImageViews[controlIndex]; | |
| 152 | 156 | |
| 153 | - ImageView imageView = mImageViews[buttonIndex]; | |
| 154 | - if( !mImageViewPlayStatus[buttonIndex] ) | |
| 157 | + Property::Map map = imageView.GetProperty< Property::Map >( ImageView::Property::IMAGE ); | |
| 158 | + Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE ); | |
| 159 | + | |
| 160 | + if( value->Get< int >() != static_cast< int >( DevelImageVisual::PlayState::PLAYING ) ) | |
| 155 | 161 | { |
| 156 | - mPlayButtons[buttonIndex].SetProperty( Button::Property::LABEL, "Stop" ); | |
| 162 | + mPlayButtons[controlIndex].SetProperty( Button::Property::LABEL, "Pause" ); | |
| 157 | 163 | |
| 158 | 164 | DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PLAY, Property::Value() ); |
| 159 | 165 | } |
| 160 | 166 | else |
| 161 | 167 | { |
| 162 | - mPlayButtons[buttonIndex].SetProperty( Button::Property::LABEL, "Play" ); | |
| 168 | + mPlayButtons[controlIndex].SetProperty( Button::Property::LABEL, "Play" ); | |
| 163 | 169 | |
| 164 | - DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::STOP, Property::Value() ); | |
| 170 | + DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PAUSE, Property::Value() ); | |
| 165 | 171 | } |
| 166 | 172 | |
| 167 | - mImageViewPlayStatus[buttonIndex] = !mImageViewPlayStatus[buttonIndex]; | |
| 168 | - | |
| 169 | 173 | return true; |
| 170 | 174 | } |
| 171 | 175 | |
| 172 | - bool OnPauseButtonClicked( Button button ) | |
| 176 | + bool OnStopButtonClicked( Button button ) | |
| 173 | 177 | { |
| 174 | - unsigned int buttonIndex = GetButtonIndex( button ); | |
| 178 | + unsigned int controlIndex = GetControlIndex( button ); | |
| 179 | + ImageView imageView = mImageViews[controlIndex]; | |
| 180 | + DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::STOP, Property::Value() ); | |
| 175 | 181 | |
| 176 | - ImageView imageView = mImageViews[buttonIndex]; | |
| 177 | - if( !mImageViewPauseStatus[buttonIndex] ) | |
| 178 | - { | |
| 179 | - mPauseButtons[buttonIndex].SetProperty( Button::Property::LABEL, "Resume" ); | |
| 182 | + return true; | |
| 183 | + } | |
| 180 | 184 | |
| 181 | - DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PAUSE, Property::Value() ); | |
| 182 | - } | |
| 183 | - else | |
| 184 | - { | |
| 185 | - mPauseButtons[buttonIndex].SetProperty( Button::Property::LABEL, "Pause" ); | |
| 185 | + void OnVisualEvent( Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId ) | |
| 186 | + { | |
| 187 | + unsigned int controlIndex = GetControlIndex( control ); | |
| 186 | 188 | |
| 187 | - DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::RESUME, Property::Value() ); | |
| 189 | + if( visualIndex == ImageView::Property::IMAGE && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED ) | |
| 190 | + { | |
| 191 | + mPlayButtons[controlIndex].SetProperty( Button::Property::LABEL, "Play" ); | |
| 188 | 192 | } |
| 189 | - | |
| 190 | - mImageViewPauseStatus[buttonIndex] = !mImageViewPauseStatus[buttonIndex]; | |
| 191 | - | |
| 192 | - return true; | |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| ... | ... | @@ -215,9 +215,7 @@ private: |
| 215 | 215 | TableView mTable; |
| 216 | 216 | ImageView mImageViews[ NUMBER_OF_IMAGES ]; |
| 217 | 217 | PushButton mPlayButtons[ NUMBER_OF_IMAGES ]; |
| 218 | - PushButton mPauseButtons[ NUMBER_OF_IMAGES ]; | |
| 219 | - bool mImageViewPlayStatus[ NUMBER_OF_IMAGES ]; | |
| 220 | - bool mImageViewPauseStatus[ NUMBER_OF_IMAGES ]; | |
| 218 | + PushButton mStopButtons[ NUMBER_OF_IMAGES ]; | |
| 221 | 219 | |
| 222 | 220 | }; |
| 223 | 221 | ... | ... |