X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fmagnifier%2Fmagnifier-example.cpp;h=0f0f08fa8bef46d315ba04fa356d5b609acceadd;hb=2e182925204bf3ef9f2a36cbfbf998e79fbafaf5;hp=cb38a8715856a717c25606260cb8f32c1963ed9f;hpb=6a3b548331ddab7938735468fae9bb2ac6c3712d;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/magnifier/magnifier-example.cpp b/examples/magnifier/magnifier-example.cpp index cb38a87..0f0f08f 100644 --- a/examples/magnifier/magnifier-example.cpp +++ b/examples/magnifier/magnifier-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. @@ -21,13 +21,13 @@ #include "shared/view.h" #include - +#include using namespace Dali; namespace { -const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-magnifier.jpg" ); -const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); +const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-magnifier.jpg" ); +const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); const char* APPLICATION_TITLE( "Magnifier Example" ); const Vector3 MAGNIFIER_SIZE(0.25f, 0.25f, 0.0f); ///< Magnifier sides should be 25% of the width of the stage const float ANIMATION_DURATION(60.0f); ///< Run animation for a minute before repeating. @@ -57,20 +57,16 @@ struct MagnifierPathConstraint { } - Vector3 operator()(const Vector3& current, - const PropertyInput& sizeProperty, - const PropertyInput& animationTimeProperty) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - float time = animationTimeProperty.GetFloat(); - const Vector3& size = sizeProperty.GetVector3(); - - Vector3 range(mStageSize - size - Vector3::ONE * MAGNIFIER_INDENT * 2.0f); - Vector3 position(mOffset); + float time = inputs[1]->GetFloat(); + const Vector3& size = inputs[0]->GetVector3(); - position.x += 0.5f * sinf(time * 0.471f) * range.width; - position.y += 0.5f * sinf(time * 0.8739f) * range.height; + current = mOffset; - return position; + Vector3 range( mStageSize - size - Vector3::ONE * MAGNIFIER_INDENT * 2.0f ); + current.x += 0.5f * sinf(time * 0.471f) * range.width; + current.y += 0.5f * sinf(time * 0.8739f) * range.height; } Vector3 mStageSize; ///< Keep track of the stage size for determining path within stage bounds @@ -103,23 +99,19 @@ struct ConfinementConstraint { } - Vector3 operator()(const Vector3& constPosition, - const PropertyInput& sizeProperty, - const PropertyInput& parentOriginProperty, - const PropertyInput& anchorPointProperty, - const PropertyInput& referenceSizeProperty) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - const Vector3& size = sizeProperty.GetVector3(); - const Vector3 origin = parentOriginProperty.GetVector3(); - const Vector3& anchor = anchorPointProperty.GetVector3(); - const Vector3& referenceSize = referenceSizeProperty.GetVector3(); + const Vector3& size = inputs[0]->GetVector3(); + const Vector3 origin = inputs[1]->GetVector3(); + const Vector3& anchor = inputs[2]->GetVector3(); + const Vector3& referenceSize = inputs[3]->GetVector3(); Vector3 offset(mOffsetOrigin * referenceSize); - Vector3 newPosition( constPosition + offset ); - // Get actual position of Actor relative to parent's Top-Left. - Vector3 position(constPosition + offset + origin * referenceSize); + Vector3 position(current + offset + origin * referenceSize); + + current += offset; // if top-left corner is outside of Top-Left bounds, then push back in screen. Vector3 corner(position - size * anchor - mMinIndent); @@ -127,17 +119,17 @@ struct ConfinementConstraint if(mFlipHorizontal && corner.x < 0.0f) { corner.x = 0.0f; - newPosition.x += size.width; + current.x += size.width; } if(mFlipVertical && corner.y < 0.0f) { corner.y = 0.0f; - newPosition.y += size.height; + current.y += size.height; } - newPosition.x -= std::min(corner.x, 0.0f); - newPosition.y -= std::min(corner.y, 0.0f); + current.x -= std::min(corner.x, 0.0f); + current.y -= std::min(corner.y, 0.0f); // if bottom-right corner is outside of Bottom-Right bounds, then push back in screen. corner += size - referenceSize + mMinIndent + mMaxIndent; @@ -145,19 +137,17 @@ struct ConfinementConstraint if(mFlipHorizontal && corner.x > 0.0f) { corner.x = 0.0f; - newPosition.x -= size.width; + current.x -= size.width; } if(mFlipVertical && corner.y > 0.0f) { corner.y = 0.0f; - newPosition.y -= size.height; + current.y -= size.height; } - newPosition.x -= std::max(corner.x, 0.0f); - newPosition.y -= std::max(corner.y, 0.0f); - - return newPosition; + current.x -= std::max(corner.x, 0.0f); + current.y -= std::max(corner.y, 0.0f); } Vector3 mOffsetOrigin; ///< Manual Parent Offset Origin. @@ -183,6 +173,7 @@ public: : mApplication( application ), mView(), mAnimationTime(0.0f), + mAnimationTimeProperty( Property::INVALID_INDEX ), mMagnifierShown(false) { // Connect to the Application's Init signal @@ -222,56 +213,53 @@ public: TOOLBAR_IMAGE, APPLICATION_TITLE ); - mContent.SetLeaveRequired(true); - mContent.TouchedSignal().Connect( this, &ExampleController::OnTouched ); + mContent.SetProperty( Actor::Property::LEAVE_REQUIRED,true); + mContent.TouchSignal().Connect( this, &ExampleController::OnTouched ); // Create magnifier (controlled by human touch) Layer overlay = Layer::New(); - overlay.SetSensitive(false); - overlay.SetParentOrigin( ParentOrigin::CENTER ); - overlay.SetSize(mStageSize); + overlay.SetProperty( Actor::Property::SENSITIVE,false); + overlay.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + overlay.SetProperty( Actor::Property::SIZE, mStageSize); Stage::GetCurrent().Add(overlay); mMagnifier = Toolkit::Magnifier::New(); - mMagnifier.SetSourceActor( mView.GetBackgroundLayer() ); - mMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width - mMagnifier.SetMagnificationFactor( MAGNIFICATION_FACTOR ); - mMagnifier.SetScale(Vector3::ZERO); + mMagnifier.SetSourceActor( mView ); + mMagnifier.SetProperty( Actor::Property::SIZE, MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width + mMagnifier.SetProperty( Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR, MAGNIFICATION_FACTOR ); + mMagnifier.SetProperty( Actor::Property::SCALE,Vector3::ZERO); overlay.Add( mMagnifier ); // Apply constraint to animate the position of the magnifier. - Constraint constraint = Constraint::New(Actor::Property::POSITION, - LocalSource(Actor::Property::SIZE), - LocalSource(Actor::Property::PARENT_ORIGIN), - LocalSource(Actor::Property::ANCHOR_POINT), - ParentSource(Actor::Property::SIZE), - ConfinementConstraint(ParentOrigin::CENTER, Vector2::ONE * MAGNIFIER_INDENT, Vector2::ONE * MAGNIFIER_INDENT)); + Constraint constraint = Constraint::New( mMagnifier, Actor::Property::POSITION, ConfinementConstraint(Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ONE * MAGNIFIER_INDENT, Vector2::ONE * MAGNIFIER_INDENT) ); + constraint.AddSource( LocalSource(Actor::Property::SIZE) ); + constraint.AddSource( LocalSource(Actor::Property::PARENT_ORIGIN) ); + constraint.AddSource( LocalSource(Actor::Property::ANCHOR_POINT) ); + constraint.AddSource( ParentSource(Actor::Property::SIZE) ); constraint.SetRemoveAction(Constraint::Discard); - mMagnifier.ApplyConstraint( constraint ); + constraint.Apply(); // Create bouncing magnifier automatically bounces around screen. mBouncingMagnifier = Toolkit::Magnifier::New(); - mBouncingMagnifier.SetSourceActor( mView.GetBackgroundLayer() ); - mBouncingMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width - mBouncingMagnifier.SetMagnificationFactor( MAGNIFICATION_FACTOR ); + mBouncingMagnifier.SetSourceActor( mView ); + mBouncingMagnifier.SetProperty( Actor::Property::SIZE, MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width + mBouncingMagnifier.SetProperty( Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR, MAGNIFICATION_FACTOR ); overlay.Add( mBouncingMagnifier ); - mAnimationTimeProperty = mBouncingMagnifier.RegisterProperty("animation-time", 0.0f); + mAnimationTimeProperty = mBouncingMagnifier.RegisterProperty("animationTime", 0.0f); ContinueAnimation(); // Apply constraint to animate the position of the magnifier. - constraint = Constraint::New(Actor::Property::POSITION, - LocalSource(Actor::Property::SIZE), - LocalSource(mAnimationTimeProperty), - MagnifierPathConstraint(mStageSize, mStageSize * 0.5f)); - mBouncingMagnifier.ApplyConstraint( constraint ); + constraint = Constraint::New( mBouncingMagnifier, Actor::Property::POSITION, MagnifierPathConstraint(mStageSize, mStageSize * 0.5f) ); + constraint.AddSource( LocalSource(Actor::Property::SIZE) ); + constraint.AddSource( LocalSource(mAnimationTimeProperty) ); + constraint.Apply(); // Apply constraint to animate the source of the magnifier. - constraint = Constraint::New(mBouncingMagnifier.GetPropertyIndex( Toolkit::Magnifier::SOURCE_POSITION_PROPERTY_NAME ), - LocalSource(Actor::Property::SIZE), - LocalSource(mAnimationTimeProperty), - MagnifierPathConstraint(mStageSize)); - mBouncingMagnifier.ApplyConstraint( constraint ); + constraint = Constraint::New( mBouncingMagnifier, Toolkit::Magnifier::Property::SOURCE_POSITION, MagnifierPathConstraint(mStageSize) ); + constraint.AddSource( LocalSource(Actor::Property::SIZE) ); + constraint.AddSource( LocalSource(mAnimationTimeProperty) ); + constraint.Apply(); } /** @@ -313,33 +301,32 @@ public: * @param[in] actor The actor that received the touch * @param[in] event The touch-event information */ - bool OnTouched( Actor actor, const TouchEvent& event ) + bool OnTouched( Actor actor, const TouchData& event ) { if(event.GetPointCount() > 0) { - const TouchPoint& point = event.GetPoint(0); - switch(point.state) + switch( event.GetState( 0 ) ) { - case TouchPoint::Down: - case TouchPoint::Motion: + case PointState::DOWN: + case PointState::MOTION: { ShowMagnifier(); break; } - case TouchPoint::Up: - case TouchPoint::Leave: - case TouchPoint::Interrupted: + case PointState::UP: + case PointState::LEAVE: + case PointState::INTERRUPTED: { HideMagnifier(); break; } - default: + case PointState::STATIONARY: { break; } } // end switch - Vector3 touchPoint(point.screen); + Vector3 touchPoint( event.GetScreenPosition( 0 ) ); SetMagnifierPosition(touchPoint - mStageSize * 0.5f); } @@ -355,7 +342,7 @@ public: if(!mMagnifierShown) { Animation animation = Animation::New(MAGNIFIER_DISPLAY_DURATION); - animation.AnimateTo(Property(mMagnifier, Actor::Property::SCALE), Vector3::ONE, AlphaFunctions::EaseIn); + animation.AnimateTo(Property(mMagnifier, Actor::Property::SCALE), Vector3::ONE, AlphaFunction::EASE_IN); animation.Play(); mMagnifierShown = true; } @@ -369,7 +356,7 @@ public: if(mMagnifierShown) { Animation animation = Animation::New(MAGNIFIER_DISPLAY_DURATION); - animation.AnimateTo(Property(mMagnifier, Actor::Property::SCALE), Vector3::ZERO, AlphaFunctions::EaseOut); + animation.AnimateTo(Property(mMagnifier, Actor::Property::SCALE), Vector3::ZERO, AlphaFunction::EASE_OUT); animation.Play(); mMagnifierShown = false; } @@ -381,13 +368,13 @@ public: */ void SetMagnifierPosition(const Vector3 position) { - mMagnifier.SetSourcePosition( position ); + mMagnifier.SetProperty( Toolkit::Magnifier::Property::SOURCE_POSITION, position ); // position magnifier glass such that bottom edge is touching/near top of finger. Vector3 glassPosition(position); glassPosition.y -= mStageSize.width * MAGNIFIER_SIZE.height * 0.5f + Stage::GetCurrent().GetDpi().height * FINGER_RADIUS_INCHES; - mMagnifier.SetPosition( glassPosition ); + mMagnifier.SetProperty( Actor::Property::POSITION, glassPosition ); } void OnKeyEvent(const KeyEvent& event) @@ -404,7 +391,7 @@ public: private: Application& mApplication; ///< Application instance - Toolkit::View mView; ///< The view + Toolkit::Control mView; ///< The view Layer mContent; ///< The content layer Toolkit::Magnifier mMagnifier; ///< The manually controlled magnifier Toolkit::Magnifier mBouncingMagnifier; ///< The animating magnifier (swirly animation) @@ -415,20 +402,10 @@ private: }; -void RunTest( Application& application ) +int DALI_EXPORT_API main( int argc, char **argv ) { + Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); ExampleController test( application ); - application.MainLoop(); -} - -// Entry point for Linux & SLP applications -// -int main( int argc, char **argv ) -{ - Application application = Application::New( &argc, &argv ); - - RunTest( application ); - return 0; }