X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-demo.git;a=blobdiff_plain;f=examples%2Feffects-view%2Feffects-view-example.cpp;h=b041a26f9ea0f3cb59237f3141f8e25cec9a57f7;hp=c446cfb5ad848eef4289f8fdc46385204cee75e8;hb=1b19fd140ff139b5854a1a62447faf31b175d8f6;hpb=b26d446b0cb6a316abc3a79d4fc70d0ae1b7994c diff --git a/examples/effects-view/effects-view-example.cpp b/examples/effects-view/effects-view-example.cpp index c446cfb..b041a26 100644 --- a/examples/effects-view/effects-view-example.cpp +++ b/examples/effects-view/effects-view-example.cpp @@ -20,9 +20,9 @@ // INTERNAL INCLUDES #include "shared/view.h" -#include #include #include +#include #include using namespace Dali; @@ -30,11 +30,11 @@ using namespace Dali::Toolkit; namespace { -const char* const TITLE( "EffectsView: effect size = " ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* VIEW_SWAP_IMAGE( DEMO_IMAGE_DIR "icon-change.png" ); -const char* VIEW_SWAP_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-change-selected.png" ); -const char* TEST_IMAGE( DEMO_IMAGE_DIR "Kid1.svg" ); +const char* const TITLE("EffectsView: effect size = "); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* VIEW_SWAP_IMAGE(DEMO_IMAGE_DIR "icon-change.png"); +const char* VIEW_SWAP_SELECTED_IMAGE(DEMO_IMAGE_DIR "icon-change-selected.png"); +const char* TEST_IMAGE(DEMO_IMAGE_DIR "Kid1.svg"); } // namespace // This example illustrates the capabilities of the EffectsView container @@ -42,22 +42,20 @@ const char* TEST_IMAGE( DEMO_IMAGE_DIR "Kid1.svg" ); class EffectsViewApp : public ConnectionTracker { public: - /** * Constructor */ - EffectsViewApp( Application& application ); + EffectsViewApp(Application& application); /** * Destructor */ ~EffectsViewApp(); private: - /** * Initialisation. This method gets called once the main loop of application is up and running */ - void OnAppInitialize( Application& application ); + void OnAppInitialize(Application& application); /** * Create a effect view of drop shadow @@ -66,13 +64,13 @@ private: * @param[in] viewSize Size of the effect view * @param[in] effectSize The effect size used in image filters. */ - EffectsView CreateEffectsView( EffectsView::EffectType type, const Vector2& viewSize, int effectSize ); + EffectsView CreateEffectsView(EffectsView::EffectType type, const Vector2& viewSize, int effectSize); /** * Animate the effect offset and color properties. * @param[in] effectsView The view whose properties to be animated. */ - void AnimateEffectProperties( EffectsView& effectsView ); + void AnimateEffectProperties(EffectsView& effectsView); /** * Set title onto the toolbar @@ -84,7 +82,7 @@ private: * Callback function to change the effect size. * @param[in] button The button which triggered the callback. */ - bool ChangeEffectSize( Button button ); + bool ChangeEffectSize(Button button); /** * Main key event handler @@ -92,23 +90,23 @@ private: void OnKeyEvent(const KeyEvent& event); private: - Application& mApplication; - Layer mContents; - Toolkit::Control mView; - Toolkit::ToolBar mToolBar; - EffectsView mDropShadowView; - EffectsView mEmbossView; - Toolkit::TextLabel mTitleActor; ///< The title on the toolbar - Vector2 mWindowSize; - int mEffectSize; + Application& mApplication; + Layer mContents; + Toolkit::Control mView; + Toolkit::ToolBar mToolBar; + EffectsView mDropShadowView; + EffectsView mEmbossView; + Toolkit::TextLabel mTitleActor; ///< The title on the toolbar + Vector2 mWindowSize; + int mEffectSize; }; -EffectsViewApp::EffectsViewApp( Application& application ) -: mApplication( application ), - mEffectSize( 2 ) +EffectsViewApp::EffectsViewApp(Application& application) +: mApplication(application), + mEffectSize(2) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &EffectsViewApp::OnAppInitialize ); + mApplication.InitSignal().Connect(this, &EffectsViewApp::OnAppInitialize); } EffectsViewApp::~EffectsViewApp() @@ -116,127 +114,125 @@ EffectsViewApp::~EffectsViewApp() // Nothing to do here; } -void EffectsViewApp::OnAppInitialize( Application& application ) +void EffectsViewApp::OnAppInitialize(Application& application) { // The Init signal is received once (only) during the Application lifetime auto window = application.GetWindow(); window.KeyEventSignal().Connect(this, &EffectsViewApp::OnKeyEvent); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); mWindowSize = window.GetSize(); // Creates a default view with a default tool bar. // The view is added to the window. - mContents = DemoHelper::CreateView( application, mView, mToolBar, "", TOOLBAR_IMAGE, "" ); + mContents = DemoHelper::CreateView(application, mView, mToolBar, "", TOOLBAR_IMAGE, ""); // Creates view change button. Toolkit::PushButton viewButton = Toolkit::PushButton::New(); - viewButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, VIEW_SWAP_IMAGE ); - viewButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, VIEW_SWAP_SELECTED_IMAGE ); + viewButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, VIEW_SWAP_IMAGE); + viewButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, VIEW_SWAP_SELECTED_IMAGE); // Connects the view change button clicked signal to the OnView method. - viewButton.ClickedSignal().Connect( this, &EffectsViewApp::ChangeEffectSize ); - mToolBar.AddControl( viewButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); - - Vector2 effectsViewSize( mWindowSize.width, mWindowSize.height * 0.25f ); - mDropShadowView = CreateEffectsView( EffectsView::DROP_SHADOW, effectsViewSize, mEffectSize ); - mDropShadowView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mDropShadowView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - mDropShadowView.SetProperty( Actor::Property::POSITION_Z, -mWindowSize.height * 0.1f ); - mContents.Add( mDropShadowView ); - - mEmbossView = CreateEffectsView( EffectsView::EMBOSS, effectsViewSize, mEffectSize ); - mEmbossView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mEmbossView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mEmbossView.SetProperty( Actor::Property::POSITION_Z, mWindowSize.height * 0.1f ); - mContents.Add( mEmbossView ); - - SetTitle( mEffectSize ); + viewButton.ClickedSignal().Connect(this, &EffectsViewApp::ChangeEffectSize); + mToolBar.AddControl(viewButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); + + Vector2 effectsViewSize(mWindowSize.width, mWindowSize.height * 0.25f); + mDropShadowView = CreateEffectsView(EffectsView::DROP_SHADOW, effectsViewSize, mEffectSize); + mDropShadowView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mDropShadowView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mDropShadowView.SetProperty(Actor::Property::POSITION_Z, -mWindowSize.height * 0.1f); + mContents.Add(mDropShadowView); + + mEmbossView = CreateEffectsView(EffectsView::EMBOSS, effectsViewSize, mEffectSize); + mEmbossView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mEmbossView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mEmbossView.SetProperty(Actor::Property::POSITION_Z, mWindowSize.height * 0.1f); + mContents.Add(mEmbossView); + + SetTitle(mEffectSize); } - -EffectsView EffectsViewApp::CreateEffectsView( EffectsView::EffectType type, const Vector2& viewSize, int effectSize ) +EffectsView EffectsViewApp::CreateEffectsView(EffectsView::EffectType type, const Vector2& viewSize, int effectSize) { Toolkit::EffectsView effectsView = Toolkit::EffectsView::New(type); // set control size - effectsView.SetProperty( Actor::Property::SIZE, Vector2( viewSize.width, viewSize.height ) ); + effectsView.SetProperty(Actor::Property::SIZE, Vector2(viewSize.width, viewSize.height)); // set effect size property - effectsView.SetProperty( EffectsView::Property::EFFECT_SIZE, effectSize ); + effectsView.SetProperty(EffectsView::Property::EFFECT_SIZE, effectSize); // Create some content // text - std::string text = ( type == EffectsView::DROP_SHADOW) ? "Drop Shadow" : "Emboss"; - TextLabel textActor( TextLabel::New( text ) ); - textActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT ); - textActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT ); - textActor.SetProperty( Actor::Property::SIZE, viewSize ); - textActor.SetProperty( Actor::Property::POSITION, Vector2( viewSize.width*0.4f, viewSize.height*0.3f )); - textActor.SetProperty( TextLabel::Property::POINT_SIZE, 14.f ); - effectsView.Add( textActor ); + std::string text = (type == EffectsView::DROP_SHADOW) ? "Drop Shadow" : "Emboss"; + TextLabel textActor(TextLabel::New(text)); + textActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT); + textActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT); + textActor.SetProperty(Actor::Property::SIZE, viewSize); + textActor.SetProperty(Actor::Property::POSITION, Vector2(viewSize.width * 0.4f, viewSize.height * 0.3f)); + textActor.SetProperty(TextLabel::Property::POINT_SIZE, 14.f); + effectsView.Add(textActor); // image - ImageView icon = ImageView::New( TEST_IMAGE ); - icon.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT ); - icon.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT ); - icon.SetProperty( Actor::Property::POSITION_X, viewSize.width*0.1f ); - icon.SetProperty( Actor::Property::SIZE, Vector2( viewSize.height*0.8f, viewSize.height*0.8f ) ); - effectsView.Add( icon ); + ImageView icon = ImageView::New(TEST_IMAGE); + icon.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT); + icon.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT); + icon.SetProperty(Actor::Property::POSITION_X, viewSize.width * 0.1f); + icon.SetProperty(Actor::Property::SIZE, Vector2(viewSize.height * 0.8f, viewSize.height * 0.8f)); + effectsView.Add(icon); - AnimateEffectProperties( effectsView ); + AnimateEffectProperties(effectsView); return effectsView; } -void EffectsViewApp::AnimateEffectProperties( EffectsView& effectsView ) +void EffectsViewApp::AnimateEffectProperties(EffectsView& effectsView) { - const float animationTime( 5.0f ); - Animation animation( Animation::New(animationTime) ); + const float animationTime(5.0f); + Animation animation(Animation::New(animationTime)); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_OFFSET ), Vector3( 2.f,-2.f, 0.0f), TimePeriod(animationTime * 0.0f, animationTime * 0.2f) ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_OFFSET ), Vector3(-2.f,-2.f, 0.0f), TimePeriod(animationTime * 0.2f, animationTime * 0.2f) ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_OFFSET ), Vector3(-2.f, 2.f, 0.0f), TimePeriod(animationTime * 0.4f, animationTime * 0.2f) ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_OFFSET ), Vector3( 4.f, 4.f, 0.0f), TimePeriod(animationTime * 0.6f, animationTime * 0.2f) ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_OFFSET ), Vector3::ZERO, TimePeriod(animationTime * 0.8f, animationTime * 0.2f) ); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_OFFSET), Vector3(2.f, -2.f, 0.0f), TimePeriod(animationTime * 0.0f, animationTime * 0.2f)); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_OFFSET), Vector3(-2.f, -2.f, 0.0f), TimePeriod(animationTime * 0.2f, animationTime * 0.2f)); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_OFFSET), Vector3(-2.f, 2.f, 0.0f), TimePeriod(animationTime * 0.4f, animationTime * 0.2f)); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_OFFSET), Vector3(4.f, 4.f, 0.0f), TimePeriod(animationTime * 0.6f, animationTime * 0.2f)); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_OFFSET), Vector3::ZERO, TimePeriod(animationTime * 0.8f, animationTime * 0.2f)); - effectsView.SetProperty( EffectsView::Property::EFFECT_COLOR, Color::BLACK ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_COLOR ), Color::BLUE, TimePeriod(animationTime * 0.0f, animationTime * 0.33f) ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_COLOR ), Color::RED, TimePeriod(animationTime * 0.33f, animationTime * 0.33f) ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_COLOR ), Color::BLACK, TimePeriod(animationTime * 0.66f, animationTime * 0.34f)); + effectsView.SetProperty(EffectsView::Property::EFFECT_COLOR, Color::BLACK); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_COLOR), Color::BLUE, TimePeriod(animationTime * 0.0f, animationTime * 0.33f)); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_COLOR), Color::RED, TimePeriod(animationTime * 0.33f, animationTime * 0.33f)); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_COLOR), Color::BLACK, TimePeriod(animationTime * 0.66f, animationTime * 0.34f)); - animation.SetLooping( true ); + animation.SetLooping(true); animation.Play(); } void EffectsViewApp::SetTitle(int effectSize) { std::ostringstream title; - title<