Property::Value DummyControlImpl::GetProperty( BaseObject* object, Dali::Property::Index propertyIndex )
{
- Dali::Property::Value value;
+ Toolkit::DummyControl control = Toolkit::DummyControl::DownCast( Dali::BaseHandle( object ) );
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>( control.GetImplementation() );
+
+ Visual::Base visual = dummyImpl.GetVisual( propertyIndex );
+ Property::Map map;
+ if( visual )
+ {
+ visual.CreatePropertyMap( map );
+ }
+ Dali::Property::Value value = map;
+
return value;
}
#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
#include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
+#include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h>
#include "dummy-control.h"
using namespace Dali;
const char* TEST_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json";
+bool gAnimationFinishedSignalFired = false;
+
+void VisualEventSignal( Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId )
+{
+ if( visualIndex == DummyControl::Property::TEST_VISUAL && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED )
+ {
+ gAnimationFinishedSignalFired = true;
+ }
+}
+
}
int UtcDaliVisualFactoryGetAnimatedVectorImageVisual01(void)
DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
- // test
+ Property::Map map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE );
+ DALI_TEST_CHECK( value->Get< int >() == static_cast< int >( DevelImageVisual::PlayState::PLAYING ) );
tet_infoline( "Test Pause action" );
DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes );
application.SendNotification();
application.Render(16);
- // test
+ map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ value = map.Find( DevelImageVisual::Property::PLAY_STATE );
+ DALI_TEST_CHECK( value->Get< int >() == static_cast< int >( DevelImageVisual::PlayState::PAUSED ) );
- tet_infoline( "Test Resume action" );
- DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::RESUME, attributes );
+ tet_infoline( "Test Play action" );
+ DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
application.SendNotification();
application.Render(16);
- // test
+ map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ value = map.Find( DevelImageVisual::Property::PLAY_STATE );
+ DALI_TEST_CHECK( value->Get< int >() == static_cast< int >( DevelImageVisual::PlayState::PLAYING ) );
tet_infoline( "Test Stop action" );
DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes );
application.SendNotification();
application.Render(16);
- // test
+ map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ value = map.Find( DevelImageVisual::Property::PLAY_STATE );
+ DALI_TEST_CHECK( value->Get< int >() == static_cast< int >( DevelImageVisual::PlayState::STOPPED ) );
tet_infoline( "Test Stop action again" );
DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes );
application.SendNotification();
application.Render(16);
- // test
+ map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ value = map.Find( DevelImageVisual::Property::PLAY_STATE );
+ DALI_TEST_CHECK( value->Get< int >() == static_cast< int >( DevelImageVisual::PlayState::STOPPED ) );
tet_infoline( "Test Play action" );
DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
application.SendNotification();
application.Render(16);
- // test
+ map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ value = map.Find( DevelImageVisual::Property::PLAY_STATE );
+ DALI_TEST_CHECK( value->Get< int >() == static_cast< int >( DevelImageVisual::PlayState::PLAYING ) );
- dummyControl.SetSize( 100.0f, 100.0f );
+ // Change Size
+ Vector3 newSize( 100.0f, 100.0f, 0.0f );
+ dummyControl.SetSize( newSize );
application.SendNotification();
application.Render(16);
- // test
// Size should be changed
+ Vector3 naturalSize = dummyControl.GetNaturalSize();
+ DALI_TEST_CHECK( naturalSize == newSize );
dummyControl.Unparent();
}
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+ // Trigger count is 2 - resource ready and animation finished
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
// renderer is added to actor
DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
END_TEST;
}
+
+int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal" );
+
+ Property::Map propertyMap;
+ propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
+ .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME )
+ .Add( DevelImageVisual::Property::LOOP_COUNT, 3 );
+
+ Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
+ DALI_TEST_CHECK( visual );
+
+ DummyControl actor = DummyControl::New( true );
+ DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
+
+ DevelControl::VisualEventSignal( actor ).Connect( &VisualEventSignal );
+
+ Vector2 controlSize( 20.f, 30.f );
+ actor.SetSize( controlSize );
+
+ Stage::GetCurrent().Add( actor );
+
+ Property::Map attributes;
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
+
+ application.SendNotification();
+ application.Render();
+
+ // Wait for animation finish
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
+
+ Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE );
+ DALI_TEST_CHECK( value->Get< int >() == static_cast< int >( DevelImageVisual::PlayState::STOPPED ) );
+
+ DALI_TEST_EQUALS( gAnimationFinishedSignalFired, true, TEST_LOCATION );
+
+ END_TEST;
+}
DALI_TEST_CHECK( !value.Get( url ) );
Property::Map map;
- DALI_TEST_CHECK( !value.Get( map ) );
+ value.Get( map );
+ DALI_TEST_CHECK( map.Empty() );
END_TEST;
}
DALI_TEST_CHECK( !value.Get( url ) );
Property::Map map;
- DALI_TEST_CHECK( !value.Get( map ) );
+ value.Get( map );
+ DALI_TEST_CHECK( map.Empty() );
END_TEST;
}
DALI_TEST_CHECK( !value.Get( url ) );
Property::Map map;
- DALI_TEST_CHECK( !value.Get( map ) );
+ value.Get( map );
+ DALI_TEST_CHECK( map.Empty() );
std::string resource_url;
Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
application.Render( 16 );
DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
- DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
+ value.Get( map );
+ DALI_TEST_CHECK( map.Empty() ); // Value should be empty
DALI_TEST_CHECK( ! visual ); // Visual should be invalid
// Set a URL
visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
- DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
+ value.Get( map );
+ DALI_TEST_CHECK( map.Empty() ); // Value should be empty
DALI_TEST_CHECK( ! visual ); // Visual should be invalid
// Set an Image
visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
- DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
+ value.Get( map );
+ DALI_TEST_CHECK( map.Empty() ); // Value should be empty
DALI_TEST_CHECK( ! visual ); // Visual should be invalid
// Set a URL in property map
return controlDataImpl.IsLayoutingRequired();
}
+VisualEventSignalType& VisualEventSignal( Control control )
+{
+ Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control );
+ Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( internalControl );
+ return controlDataImpl.VisualEventSignal();
+}
+
} // namespace DevelControl
} // namespace Toolkit
*/
DALI_TOOLKIT_API void SetInputMethodContext( Internal::Control& control, InputMethodContext& inputMethodContext );
-/*
+/**
* @brief Get the layout associated with this control, if any.
*
* @return A handle to the layout, or empty.
*/
DALI_TOOLKIT_API Toolkit::LayoutItem GetLayout( Internal::Control& control );
-/*
+/**
* @brief Get the layout associated with a control, if any.
*
* @return A handle to the layout, or empty.
*/
DALI_TOOLKIT_API bool IsLayoutingRequired( Control control );
+/**
+ * @brief Visual Event signal type
+ */
+using VisualEventSignalType = Signal< void ( Control, Dali::Property::Index, Dali::Property::Index ) >;
+
+/**
+ * @brief This signal is emitted when a visual has an event to notify.
+ *
+ * A callback of the following type may be connected:
+ * @code
+ * void YourCallbackName( Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId );
+ * @endcode
+ * @return The signal to connect to
+ */
+DALI_TOOLKIT_API VisualEventSignalType& VisualEventSignal( Control control );
+
} // namespace DevelControl
} // namespace Toolkit
$(devel_api_src_dir)/visuals/animated-gradient-visual-properties-devel.h \
$(devel_api_src_dir)/visuals/animated-image-visual-actions-devel.h \
$(devel_api_src_dir)/visuals/animated-vector-image-visual-actions-devel.h \
+ $(devel_api_src_dir)/visuals/animated-vector-image-visual-signals-devel.h \
$(devel_api_src_dir)/visuals/color-visual-properties-devel.h \
$(devel_api_src_dir)/visuals/image-visual-properties-devel.h \
$(devel_api_src_dir)/visuals/image-visual-actions-devel.h \
{
PLAY, ///< Play the animated vector image.
PAUSE, ///< Pause the animated vector image.
- RESUME, ///< Resume the animated vector image.
STOP ///< Stop the animated vector image. This is also Default playback mode.
};
--- /dev/null
+#ifndef DALI_TOOLKIT_DEVEL_API_VISUALS_ANIMATED_VECTOR_IMAGE_VISUAL_SIGNALS_DEVEL_H
+#define DALI_TOOLKIT_DEVEL_API_VISUALS_ANIMATED_VECTOR_IMAGE_VISUAL_SIGNALS_DEVEL_H
+
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace DevelAnimatedVectorImageVisual
+{
+
+/**
+ * @brief Signal that the animated vector image visual can emit.
+ */
+namespace Signal
+{
+/**
+ * @brief The available signals for this visual
+ */
+enum Type
+{
+ ANIMATION_FINISHED ///< Animation has finished.
+};
+
+} // namespace Signal
+
+} // namespace DevelAnimatedVectorImageVisual
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_DEVEL_API_VISUALS_ANIMATED_VECTOR_IMAGE_VISUAL_SIGNALS_DEVEL_H
* @details Name "playRange", Type Property::VECTOR2, between 0 and 1
* @note Default 0 and 1
*/
- PLAY_RANGE = ORIENTATION_CORRECTION + 4
+ PLAY_RANGE = ORIENTATION_CORRECTION + 4,
+
+ /**
+ * @brief The playing state the AnimatedVectorImageVisual will use.
+ * @details Name "playState", type PlayState (Property::INTEGER)
+ * @note This property is read-only.
+ */
+ PLAY_STATE = ORIENTATION_CORRECTION + 5
};
} //namespace Property
+/**
+ * @brief Enumeration for what state the animation is in.
+ */
+enum class PlayState
+{
+ STOPPED, ///< Animation has stopped
+ PLAYING, ///< The animation is playing
+ PAUSED ///< The animation is paused
+};
+
} // namespace DevelImageVisual
} // namespace Toolkit
mKeyInputFocusGainedSignal(),
mKeyInputFocusLostSignal(),
mResourceReadySignal(),
+ mVisualEventSignal(),
mPinchGestureDetector(),
mPanGestureDetector(),
mTapGestureDetector(),
Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
// Stop observing the visual
- visualImpl.RemoveResourceObserver( *this );
+ visualImpl.RemoveEventObserver( *this );
}
void Control::Impl::StartObservingVisual( Toolkit::Visual::Base& visual)
{
Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
- // start observing the visual for resource ready
- visualImpl.AddResourceObserver( *this );
+ // start observing the visual for events
+ visualImpl.AddEventObserver( *this );
}
// Called by a Visual when it's resource is ready
}
}
+void Control::Impl::NotifyVisualEvent( Visual::Base& object, Property::Index signalId )
+{
+ for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
+ {
+ Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
+ if( &object == ®isteredVisualImpl )
+ {
+ Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
+ mVisualEventSignal.Emit( handle, (*registeredIter)->index, signalId );
+ break;
+ }
+ }
+}
+
bool Control::Impl::IsResourceReady() const
{
// Iterate through and check all the enabled visuals are ready
return mControlImpl.mImpl->mIsLayoutingRequired;
}
+DevelControl::VisualEventSignalType& Control::Impl::VisualEventSignal()
+{
+ return mVisualEventSignal;
+}
+
} // namespace Internal
} // namespace Toolkit
#include <string>
// INTERNAL INCLUDES
-#include <dali-toolkit/internal/visuals/visual-resource-observer.h>
+#include <dali-toolkit/internal/visuals/visual-event-observer.h>
#include <dali-toolkit/public-api/controls/control-impl.h>
#include <dali/devel-api/common/owner-container.h>
#include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
/**
* @brief Holds the Implementation for the internal control class
*/
-class Control::Impl : public ConnectionTracker, public Visual::ResourceObserver
+class Control::Impl : public ConnectionTracker, public Visual::EventObserver
{
public:
/**
* @brief Called when a resource is ready.
* @param[in] object The visual whose resources are ready
- * @note Overriding method in Visual::ResourceObserver.
+ * @note Overriding method in Visual::EventObserver.
*/
- virtual void ResourceReady( Visual::Base& object );
+ virtual void ResourceReady( Visual::Base& object ) override;
+
+ /**
+ * @brief Called when an event occurs.
+ * @param[in] object The visual whose events occur
+ * @param[in] signalId The signal to emit. See Visual to find supported signals
+ * @note Overriding method in Visual::EventObserver.
+ */
+ virtual void NotifyVisualEvent( Visual::Base& object, Property::Index signalId ) override;
/**
* @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
*/
bool IsLayoutingRequired();
+ /**
+ * @copydoc DevelControl::VisualEventSignal()
+ */
+ DevelControl::VisualEventSignalType& VisualEventSignal();
+
private:
/**
Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
+ DevelControl::VisualEventSignalType mVisualEventSignal;
// Gesture Detection
PinchGestureDetector mPinchGestureDetector;
Scripting::CreatePropertyMap( impl.mImage, map );
value = map;
}
- else if( !impl.mPropertyMap.Empty() )
+ else
{
- value = impl.mPropertyMap;
+ Property::Map map;
+ Toolkit::Visual::Base visual = DevelControl::GetVisual( impl, Toolkit::ImageView::Property::IMAGE );
+ if( visual )
+ {
+ visual.CreatePropertyMap( map );
+ }
+ value = map;
}
break;
}
#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
+#include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h>
#include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
}
map.Insert( Toolkit::DevelImageVisual::Property::LOOP_COUNT, static_cast< int >( mLoopCount ) );
map.Insert( Toolkit::DevelImageVisual::Property::PLAY_RANGE, static_cast< Vector2 >( mPlayRange ) );
+
+ if( mVectorRasterizeThread )
+ {
+ map.Insert( Toolkit::DevelImageVisual::Property::PLAY_STATE, static_cast< int >( mVectorRasterizeThread->GetPlayState() ) );
+ }
+ else
+ {
+ map.Insert( Toolkit::DevelImageVisual::Property::PLAY_STATE, static_cast< int >( DevelImageVisual::PlayState::STOPPED ) );
+ }
}
void AnimatedVectorImageVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
mVectorRasterizeThread = std::unique_ptr< VectorRasterizeThread >( new VectorRasterizeThread( mUrl.GetUrl(), mImpl->mRenderer, width, height ) );
mVectorRasterizeThread->SetResourceReadyCallback( new EventThreadCallback( MakeCallback( this, &AnimatedVectorImageVisual::OnResourceReady ) ) );
+ mVectorRasterizeThread->SetAnimationFinishedCallback( new EventThreadCallback( MakeCallback( this, &AnimatedVectorImageVisual::OnAnimationFinished ) ) );
mVectorRasterizeThread->SetLoopCount( mLoopCount );
mVectorRasterizeThread->SetPlayRange( mPlayRange );
void AnimatedVectorImageVisual::OnDoAction( const Property::Index actionId, const Property::Value& attributes )
{
- if( actionId == mActionStatus )
- {
- return;
- }
-
// Check if action is valid for this visual type and perform action if possible
switch( actionId )
{
mActionStatus = DevelAnimatedVectorImageVisual::Action::PAUSE;
break;
}
- case DevelAnimatedVectorImageVisual::Action::RESUME:
- {
- if( mVectorRasterizeThread )
- {
- mVectorRasterizeThread->ResumeAnimation();
- DevelStage::SetRenderingBehavior( Stage::GetCurrent(), DevelStage::Rendering::CONTINUOUSLY );
- }
- mActionStatus = DevelAnimatedVectorImageVisual::Action::RESUME;
- break;
- }
case DevelAnimatedVectorImageVisual::Action::STOP:
{
if( mVectorRasterizeThread )
{
+ bool emitSignal = false;
+ if( mVectorRasterizeThread->GetPlayState() != DevelImageVisual::PlayState::STOPPED )
+ {
+ emitSignal = true;
+ }
+
mVectorRasterizeThread->StopAnimation();
DevelStage::SetRenderingBehavior( Stage::GetCurrent(), DevelStage::Rendering::IF_REQUIRED );
+
+ if( emitSignal )
+ {
+ OnAnimationFinished();
+ }
}
mActionStatus = DevelAnimatedVectorImageVisual::Action::STOP;
break;
}
}
+void AnimatedVectorImageVisual::OnAnimationFinished()
+{
+ if( mImpl->mEventObserver )
+ {
+ mImpl->mEventObserver->NotifyVisualEvent( *this, DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED );
+ }
+}
+
} // namespace Internal
} // namespace Toolkit
*/
void OnResourceReady();
+ /**
+ * @brief Event callback from rasterize thread. This is called after the animation is finished.
+ */
+ void OnAnimationFinished();
+
// Undefined
AnimatedVectorImageVisual( const AnimatedVectorImageVisual& visual ) = delete;
mVectorRenderer(),
mConditionalWait(),
mMutex(),
- mResourceReadyTrigger( NULL ),
+ mResourceReadyTrigger(),
+ mAnimationFinishedTrigger(),
mPlayRange( 0.0f, 1.0f ),
+ mPlayState( DevelImageVisual::PlayState::STOPPED ),
mCurrentFrame( 0 ),
mTotalFrame( 0 ),
mStartFrame( 0 ),
mLoopCount( LOOP_FOREVER ),
mCurrentLoop( 0 ),
mNeedRender( false ),
- mPlaying( false ),
- mPaused( false ),
mDestroyThread( false ),
mResourceReady( false ),
mLogFactory( Dali::Adaptor::Get().GetLogFactory() )
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::~VectorRasterizeThread: Join\n" );
Join();
-
- delete mResourceReadyTrigger;
}
void VectorRasterizeThread::Run()
void VectorRasterizeThread::StartAnimation()
{
ConditionalWait::ScopedLock lock( mConditionalWait );
- if( !mPlaying )
+ if( mPlayState != DevelImageVisual::PlayState::PLAYING )
{
- mPlaying = true;
- mPaused = false;
+ if( mPlayState == DevelImageVisual::PlayState::STOPPED )
+ {
+ // Reset the current frame and the current loop
+ mCurrentFrame = mStartFrame;
+ mCurrentLoop = 0;
+ }
+
+ mPlayState = DevelImageVisual::PlayState::PLAYING;
mConditionalWait.Notify( lock );
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StartAnimation: Start\n" );
void VectorRasterizeThread::StopAnimation()
{
ConditionalWait::ScopedLock lock( mConditionalWait );
- if( mPlaying )
+ if( mPlayState != DevelImageVisual::PlayState::STOPPED )
{
- mPlaying = false;
- mPaused = false;
+ mPlayState = DevelImageVisual::PlayState::STOPPED;
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StopAnimation: Stop\n" );
}
void VectorRasterizeThread::PauseAnimation()
{
ConditionalWait::ScopedLock lock( mConditionalWait );
- if( mPlaying && !mPaused )
+ if( mPlayState == DevelImageVisual::PlayState::PLAYING )
{
- mPaused = true;
+ mPlayState = DevelImageVisual::PlayState::PAUSED;
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PauseAnimation: Pause\n" );
}
}
-void VectorRasterizeThread::ResumeAnimation()
-{
- ConditionalWait::ScopedLock lock( mConditionalWait );
- if( mPlaying && mPaused )
- {
- mPaused = false;
- mConditionalWait.Notify( lock );
-
- DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::ResumeAnimation: Resume\n" );
- }
-}
-
void VectorRasterizeThread::RenderFrame()
{
ConditionalWait::ScopedLock lock( mConditionalWait );
void VectorRasterizeThread::SetResourceReadyCallback( EventThreadCallback* callback )
{
ConditionalWait::ScopedLock lock( mConditionalWait );
- mResourceReadyTrigger = callback;
+ mResourceReadyTrigger = std::unique_ptr< EventThreadCallback >( callback );
+}
+
+void VectorRasterizeThread::SetAnimationFinishedCallback( EventThreadCallback* callback )
+{
+ ConditionalWait::ScopedLock lock( mConditionalWait );
+ mAnimationFinishedTrigger = std::unique_ptr< EventThreadCallback >( callback );
}
void VectorRasterizeThread::SetLoopCount( int16_t count )
}
}
+DevelImageVisual::PlayState VectorRasterizeThread::GetPlayState()
+{
+ return mPlayState;
+}
+
bool VectorRasterizeThread::IsThreadReady()
{
ConditionalWait::ScopedLock lock( mConditionalWait );
- if( ( !mPlaying || mPaused ) && !mNeedRender && !mDestroyThread )
+ if( mPlayState != DevelImageVisual::PlayState::PLAYING && !mNeedRender && !mDestroyThread )
{
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::IsThreadReady: Wait\n" );
- if( !mPlaying )
- {
- mCurrentFrame = mStartFrame;
- mCurrentLoop = 0;
- }
-
mConditionalWait.Wait( lock );
}
// Rasterize
mVectorRenderer.Render( mCurrentFrame );
- if( mPlaying && !mPaused )
+ if( mPlayState == DevelImageVisual::PlayState::PLAYING )
{
if( ++mCurrentFrame >= mEndFrame )
{
if( mCurrentLoop >= mLoopCount )
{
// Animation is finished
- mPlaying = false;
+ mPlayState = DevelImageVisual::PlayState::STOPPED;
+
+ mAnimationFinishedTrigger->Trigger();
+
+ DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Animation is finished\n" );
}
else
{
#include <dali/devel-api/threading/thread.h>
#include <dali/integration-api/adaptors/log-factory-interface.h>
#include <string>
+#include <memory>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
namespace Dali
{
*/
void PauseAnimation();
- /**
- * @brief Resume the vector animation.
- */
- void ResumeAnimation();
-
/**
* @brief Render one frame. The current frame number will be increased.
*/
*/
void SetResourceReadyCallback( EventThreadCallback* callback );
+ /**
+ * @brief This callback is called after the animation is finished.
+ * @param[in] callback The animation finished callback
+ */
+ void SetAnimationFinishedCallback( EventThreadCallback* callback );
+
/**
* @brief Enable looping for 'count' repeats. -1 means to repeat forever.
* @param[in] count The number of times to loop
*/
void SetPlayRange( Vector2 range );
+ /**
+ * @brief Get the play state
+ * @return The play state
+ */
+ DevelImageVisual::PlayState GetPlayState();
+
protected:
/**
private:
- std::string mUrl;
- VectorAnimationRenderer mVectorRenderer;
- ConditionalWait mConditionalWait;
- Dali::Mutex mMutex;
- EventThreadCallback* mResourceReadyTrigger;
- Vector2 mPlayRange;
- uint32_t mCurrentFrame;
- uint32_t mTotalFrame;
- uint32_t mStartFrame;
- uint32_t mEndFrame;
- uint32_t mWidth;
- uint32_t mHeight;
- int16_t mLoopCount;
- int16_t mCurrentLoop;
- bool mNeedRender;
- bool mPlaying;
- bool mPaused;
- bool mDestroyThread; ///< Whether the thread be destroyed
- bool mResourceReady;
+ std::string mUrl;
+ VectorAnimationRenderer mVectorRenderer;
+ ConditionalWait mConditionalWait;
+ Dali::Mutex mMutex;
+ std::unique_ptr< EventThreadCallback > mResourceReadyTrigger;
+ std::unique_ptr< EventThreadCallback > mAnimationFinishedTrigger;
+ Vector2 mPlayRange;
+ DevelImageVisual::PlayState mPlayState;
+ uint32_t mCurrentFrame;
+ uint32_t mTotalFrame;
+ uint32_t mStartFrame;
+ uint32_t mEndFrame;
+ uint32_t mWidth;
+ uint32_t mHeight;
+ int16_t mLoopCount;
+ int16_t mCurrentLoop;
+ bool mNeedRender;
+ bool mDestroyThread; ///< Whether the thread be destroyed
+ bool mResourceReady;
const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
};
Internal::Visual::Base::Impl::Impl(FittingMode fittingMode)
: mCustomShader( NULL ),
mBlendSlotDelegate( NULL ),
- mResourceObserver( NULL ),
+ mEventObserver( NULL ),
mTransform(),
mMixColor( Color::WHITE ),
mControlSize( Vector2::ZERO ),
// INTERNAL INCLUDES
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
-#include <dali-toolkit/internal/visuals/visual-resource-observer.h>
+#include <dali-toolkit/internal/visuals/visual-event-observer.h>
#include <dali-toolkit/public-api/align-enumerations.h>
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
Renderer mRenderer;
CustomShader* mCustomShader;
SlotDelegate<Visual::Base>* mBlendSlotDelegate; ///< Used to own mix color animation connection
- ResourceObserver* mResourceObserver; ///< Allows controls to observe when the visual resources are loaded and ready
+ EventObserver* mEventObserver; ///< Allows controls to observe when the visual has events to notify
std::string mName;
Transform mTransform;
Vector4 mMixColor;
return mImpl->mMixColor;
}
-void Visual::Base::AddResourceObserver( Visual::ResourceObserver& observer)
+void Visual::Base::AddEventObserver( Visual::EventObserver& observer)
{
- mImpl->mResourceObserver = &observer;
+ mImpl->mEventObserver = &observer;
}
-void Visual::Base::RemoveResourceObserver( Visual::ResourceObserver& observer )
+void Visual::Base::RemoveEventObserver( Visual::EventObserver& observer )
{
- mImpl->mResourceObserver = NULL;
+ mImpl->mEventObserver = NULL;
}
void Visual::Base::ResourceReady(Toolkit::Visual::ResourceStatus resourceStatus)
{
mImpl->mResourceStatus = resourceStatus;
- if( mImpl->mResourceObserver )
+ if( mImpl->mEventObserver )
{
// observer is currently a control impl
- mImpl->mResourceObserver->ResourceReady( *this );
+ mImpl->mEventObserver->ResourceReady( *this );
}
}
}
namespace Visual
{
-class ResourceObserver;
+class EventObserver;
using FittingMode = DevelVisual::FittingMode;
Internal::TransitionData::Animator& animator );
/**
- * @brief Add an observer to watch for when the Visuals resources are loaded.
+ * @brief Add an observer to watch for when the Visuals have events to notify
* Currently only supports a single observer
- *
*/
- void AddResourceObserver( Visual::ResourceObserver& observer );
+ void AddEventObserver( Visual::EventObserver& observer );
/**
* @brief Remove an observer
*/
- void RemoveResourceObserver( Visual::ResourceObserver& observer );
+ void RemoveEventObserver( Visual::EventObserver& observer );
/**
* @brief Called when the visuals resources are loaded / ready
--- /dev/null
+#ifndef DALI_INTERNAL_TOOLKIT_VISUAL_EVENT_OBSERVER_H
+#define DALI_INTERNAL_TOOLKIT_VISUAL_EVENT_OBSERVER_H
+
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/property-value.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Internal
+{
+namespace Visual
+{
+
+class Base;
+
+/**
+ * Observer to be informed when visuals have events.
+ */
+class EventObserver
+{
+public:
+
+ /**
+ * Inform the observer of the object when a resource is ready.
+ * @param[in] object The connection owner
+ */
+ virtual void ResourceReady( Visual::Base& object ) = 0;
+
+ /**
+ * Inform the observer of the object when an event occurs.
+ * @param[in] object The connection owner
+ * @param[in] signalId The signal to emit. See Visual to find supported signals
+ */
+ virtual void NotifyVisualEvent( Visual::Base& object, Property::Index signalId ) = 0;
+
+protected:
+
+ /**
+ * constructor
+ */
+ EventObserver()
+ {
+ }
+
+ /**
+ * virtual destructor
+ */
+ virtual ~EventObserver()
+ {
+ }
+
+ // Undefined copy constructor.
+ EventObserver( const EventObserver& ) = delete;
+
+ // Undefined assignment operator.
+ EventObserver& operator=( const EventObserver& ) = delete;
+};
+
+} // Visual
+} // Internal
+} // Toolkit
+} // Dali
+
+#endif // DALI_INTERNAL_TOOLKIT_VISUAL_EVENT_OBSERVER_H
+++ /dev/null
-#ifndef DALI_INTERNAL_TOOLKIT_VISUAL_RESOURCE_OBSERVER_H
-#define DALI_INTERNAL_TOOLKIT_VISUAL_RESOURCE_OBSERVER_H
-
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-
-namespace Dali
-{
-namespace Toolkit
-{
-namespace Internal
-{
-namespace Visual
-{
-
-class Base;
-
-
-/**
- * Observer to be informed when a visuals resources are ready.
- */
-class ResourceObserver
-{
- public:
-
- /**
- * Inform the observer of the object that it's connections have changed
- * @param[in] object The connection owner
- */
- virtual void ResourceReady( Visual::Base& object) = 0;
-
- protected:
-
- /**
- * constructor
- */
- ResourceObserver()
- {
- };
-
- /**
- * virtual destructor
- */
- virtual ~ResourceObserver()
- {
- };
-
- // Undefined copy constructor.
- ResourceObserver( const ResourceObserver& );
-
- // Undefined assignment operator.
- ResourceObserver& operator=( const ResourceObserver& );
-};
-} // Visual
-} // Internal
-} // Toolkit
-} // Dali
-
-#endif // DALI_INTERNAL_TOOLKIT_VISUAL_RESOURCE_OBSERVER_H