From: Adeel Kazmi Date: Fri, 19 Jun 2015 13:57:36 +0000 (+0100) Subject: (Magnifier) Properties added, APIs removed, Tests added X-Git-Tag: dali_1.0.46~13^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=85c8b711d555be339ec76c00e146a1d3051b5eb8 (Magnifier) Properties added, APIs removed, Tests added Change-Id: If66553b3abc998209ea0c10b7d9292bf9a2c32e9 --- diff --git a/automated-tests/src/dali-toolkit/CMakeLists.txt b/automated-tests/src/dali-toolkit/CMakeLists.txt index bc2bfb0..803d2ed 100644 --- a/automated-tests/src/dali-toolkit/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit/CMakeLists.txt @@ -49,6 +49,7 @@ SET(TC_SOURCES utc-Dali-ItemLayout.cpp utc-Dali-ItemView.cpp utc-Dali-KeyboardFocusManager.cpp + utc-Dali-Magnifier.cpp utc-Dali-MaskEffect.cpp utc-Dali-NinePatchMaskEffect.cpp utc-Dali-Popup.cpp diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Magnifier.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Magnifier.cpp new file mode 100644 index 0000000..1d6ba1b --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-Magnifier.cpp @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2014 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. + * + */ + +#include +#include +#include +#include +#include +#include + +using namespace Dali; +using namespace Toolkit; + +void dali_magnifier_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void dali_magnifier_cleanup(void) +{ + test_return_value = TET_PASS; +} + +int UtcDaliMagnifierNew(void) +{ + ToolkitTestApplication application; + + Magnifier magnifier; + DALI_TEST_CHECK( !magnifier ); + + magnifier = Magnifier::New(); + DALI_TEST_CHECK( magnifier ); + + Stage::GetCurrent().Add( magnifier ); + + application.SendNotification(); + application.Render(); + + END_TEST; +} + +int UtcDaliMagnifierCopyAndAssignment(void) +{ + ToolkitTestApplication application; + + Magnifier view = Magnifier::New(); + DALI_TEST_CHECK( view ); + + Magnifier copy( view ); + DALI_TEST_CHECK( copy == view ); + + Magnifier assign; + DALI_TEST_CHECK( !assign ); + assign = view; + DALI_TEST_CHECK( assign == view ); + + // Self assignment + assign = assign; + DALI_TEST_CHECK( assign ); + DALI_TEST_CHECK( assign == view ); + + END_TEST; +} + +int UtcDaliMagnifierDownCast(void) +{ + ToolkitTestApplication application; + + BaseHandle view = Magnifier::New(); + DALI_TEST_CHECK( Magnifier::DownCast( view ) ); + + BaseHandle empty; + DALI_TEST_CHECK( ! Magnifier::DownCast( empty ) ); + + BaseHandle another = Actor::New(); + DALI_TEST_CHECK( ! Magnifier::DownCast( another ) ); + + END_TEST; +} + +int UtcDaliMagnifierTypeRegistry(void) +{ + ToolkitTestApplication application; + + TypeRegistry typeRegistry = TypeRegistry::Get(); + DALI_TEST_CHECK( typeRegistry ); + + TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Magnifier" ); + DALI_TEST_CHECK( typeInfo ); + + BaseHandle handle = typeInfo.CreateInstance(); + DALI_TEST_CHECK( handle ); + + Magnifier view = Magnifier::DownCast( handle ); + DALI_TEST_CHECK( view ); + + END_TEST; +} + +int UtcDaliMagnifierSetSourceActorP(void) +{ + ToolkitTestApplication application; + + Stage stage = Stage::GetCurrent(); + + Magnifier view = Magnifier::New(); + stage.Add( view ); + + application.SendNotification(); + application.Render(); + + RenderTaskList renderTaskList = stage.GetRenderTaskList(); + DALI_TEST_CHECK( renderTaskList.GetTaskCount() > 1 ); + + Actor actor = Actor::New(); + stage.Add( actor ); + DALI_TEST_CHECK( stage.GetRenderTaskList().GetTask( 1 ).GetSourceActor() != actor ); + + view.SetSourceActor( actor ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( stage.GetRenderTaskList().GetTask( 1 ).GetSourceActor(), actor, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliMagnifierSetSourceActorN(void) +{ + ToolkitTestApplication application; + + Magnifier view; + + try + { + view.SetSourceActor( Actor::New() ); + DALI_TEST_CHECK( false ); // should not get here + } + catch( ... ) + { + DALI_TEST_CHECK( true ); + } + + END_TEST; +} + +int UtcDaliMagnifierFrameVisibility(void) +{ + ToolkitTestApplication application; + + Stage stage = Stage::GetCurrent(); + + Magnifier view = Magnifier::New(); + stage.Add( view ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( view.GetProperty( Magnifier::Property::FRAME_VISIBILITY ).Get< bool >(), true, TEST_LOCATION ); + + view.SetProperty( Magnifier::Property::FRAME_VISIBILITY, false ); + DALI_TEST_EQUALS( view.GetProperty( Magnifier::Property::FRAME_VISIBILITY ).Get< bool >(), false, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( view.GetProperty( Magnifier::Property::FRAME_VISIBILITY ).Get< bool >(), false, TEST_LOCATION ); + + view.SetProperty( Magnifier::Property::FRAME_VISIBILITY, true ); + DALI_TEST_EQUALS( view.GetProperty( Magnifier::Property::FRAME_VISIBILITY ).Get< bool >(), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( view.GetProperty( Magnifier::Property::FRAME_VISIBILITY ).Get< bool >(), true, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliMagnifierMagnificationFactor(void) +{ + ToolkitTestApplication application; + + Stage stage = Stage::GetCurrent(); + + Magnifier view = Magnifier::New(); + stage.Add( view ); + + application.SendNotification(); + application.Render(); + + float magnificationFactor( 200.0f ); + + DALI_TEST_CHECK( view.GetProperty( Magnifier::Property::MAGNIFICATION_FACTOR ).Get< float >() != magnificationFactor ); + + view.SetProperty( Magnifier::Property::MAGNIFICATION_FACTOR, magnificationFactor ); + DALI_TEST_EQUALS( view.GetProperty( Magnifier::Property::MAGNIFICATION_FACTOR ).Get< float >(), magnificationFactor, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( view.GetProperty( Magnifier::Property::MAGNIFICATION_FACTOR ).Get< float >(), magnificationFactor, TEST_LOCATION ); + + view.SetProperty( Magnifier::Property::MAGNIFICATION_FACTOR, 1.0f ); + DALI_TEST_EQUALS( view.GetProperty( Magnifier::Property::MAGNIFICATION_FACTOR ).Get< float >(), 1.0f, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( view.GetProperty( Magnifier::Property::MAGNIFICATION_FACTOR ).Get< float >(), 1.0f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliMagnifierSourcePosition(void) +{ + ToolkitTestApplication application; + + Stage stage = Stage::GetCurrent(); + + Magnifier view = Magnifier::New(); + stage.Add( view ); + + application.SendNotification(); + application.Render(); + + Vector3 position( 100.0f, 200.0f, 300.0f ); + + DALI_TEST_CHECK( view.GetProperty( Magnifier::Property::SOURCE_POSITION ).Get< Vector3 >() != position ); + + view.SetProperty( Magnifier::Property::SOURCE_POSITION, position ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( view.GetProperty( Magnifier::Property::SOURCE_POSITION ).Get< Vector3 >(), position, TEST_LOCATION ); + + view.SetProperty( Magnifier::Property::SOURCE_POSITION, Vector3::ONE ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( view.GetProperty( Magnifier::Property::SOURCE_POSITION ).Get< Vector3 >(), Vector3::ONE, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliMagnifierOnSizeSet(void) +{ + ToolkitTestApplication application; + + Magnifier view = Magnifier::New(); + + Stage::GetCurrent().Add( view ); + + application.SendNotification(); + application.Render(); + + Vector3 size( 200.0f, 300.0f, 200.0f ); + view.SetSize( size ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( view.GetCurrentSize(), size, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/devel-api/controls/magnifier/magnifier.cpp b/dali-toolkit/devel-api/controls/magnifier/magnifier.cpp index e51ee1e..40da8c8 100644 --- a/dali-toolkit/devel-api/controls/magnifier/magnifier.cpp +++ b/dali-toolkit/devel-api/controls/magnifier/magnifier.cpp @@ -36,8 +36,6 @@ namespace Toolkit // Magnifier /////////////////////////////////////////////////////////////////////////////////////////////////// -const std::string Magnifier::SOURCE_POSITION_PROPERTY_NAME( "source-position" ); - Magnifier::Magnifier() { } @@ -86,32 +84,6 @@ void Magnifier::SetSourceActor(Actor actor) GetImpl(*this).SetSourceActor( actor ); } -void Magnifier::SetSourcePosition(Vector3 position) -{ - GetImpl(*this).SetSourcePosition( position ); -} - -bool Magnifier::GetFrameVisibility() const -{ - return GetImpl(*this).GetFrameVisibility(); -} - -void Magnifier::SetFrameVisibility(bool visible) -{ - GetImpl(*this).SetFrameVisibility(visible); -} - -float Magnifier::GetMagnificationFactor() const -{ - return GetImpl(*this).GetMagnificationFactor(); -} - -void Magnifier::SetMagnificationFactor(float value) -{ - GetImpl(*this).SetMagnificationFactor( value ); -} - - } // namespace Toolkit } // namespace Dali diff --git a/dali-toolkit/devel-api/controls/magnifier/magnifier.h b/dali-toolkit/devel-api/controls/magnifier/magnifier.h index 95c5a2b..181320d 100644 --- a/dali-toolkit/devel-api/controls/magnifier/magnifier.h +++ b/dali-toolkit/devel-api/controls/magnifier/magnifier.h @@ -45,9 +45,33 @@ class DALI_IMPORT_API Magnifier : public Control { public: - // Custom properties + /** + * @brief The start and end property ranges for this control. + */ + enum PropertyRange + { + PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ///< Reserve property indices + + ANIMATABLE_PROPERTY_START_INDEX = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, + ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1000 ///< Reserve animatable property indices + }; - static const std::string SOURCE_POSITION_PROPERTY_NAME; ///< Property, name "source-position", type Vector3 + /** + * @brief An enumeration of properties belonging to the Magnifier class. + */ + struct Property + { + enum + { + // Event side properties + FRAME_VISIBILITY = PROPERTY_START_INDEX, ///< name "frame-visibility", Whether a frame is visible or not, type boolean + MAGNIFICATION_FACTOR, ///< name "magnification-factor", Larger value means greater magnification, type float + + // Animatable properties + SOURCE_POSITION = ANIMATABLE_PROPERTY_START_INDEX, ///< name "source-position", The position of the source, type Vector3 + }; + }; public: @@ -96,41 +120,6 @@ public: */ void SetSourceActor(Actor actor); - /** - * Set the source camera position to render in magnifier - * @param[in] position The target position from which to render source. - */ - void SetSourcePosition(Vector3 position); - - /** - * Returns whether the frame is visible or not. - * @return true if frame is visible, false if not. - */ - bool GetFrameVisibility() const; - - /** - * Sets whether the frame part of the magnifier should be visible - * or not. - * @param[in] visible true to display frame, false to hide frame. - */ - void SetFrameVisibility(bool visible); - - /** - * Get the magnification factor of the magnifier - * The larger the value the larger the contents magnified. - * A value of 1.0f indications 1x magnification. - * @return Magnification factor is returned - */ - float GetMagnificationFactor() const; - - /** - * Set the magnification factor of the magnifier - * The larger the value the larger the contents magnified. - * A value of 1.0f indications 1x magnification. - * @param[in] value Magnification factor. - */ - void SetMagnificationFactor(float value); - public: // Not intended for application developers /** diff --git a/dali-toolkit/internal/controls/magnifier/magnifier-impl.cpp b/dali-toolkit/internal/controls/magnifier/magnifier-impl.cpp index 15de6ea..bdc59ae 100644 --- a/dali-toolkit/internal/controls/magnifier/magnifier-impl.cpp +++ b/dali-toolkit/internal/controls/magnifier/magnifier-impl.cpp @@ -24,12 +24,36 @@ #include #include #include +#include +#include -using namespace Dali; +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ namespace // unnamed namespace { + +Dali::BaseHandle Create() +{ + return Toolkit::Magnifier::New(); +} + +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Magnifier, Toolkit::Control, Create ) + +DALI_PROPERTY_REGISTRATION( Toolkit, Magnifier, "frame-visibility", BOOLEAN, FRAME_VISIBILITY ) +DALI_PROPERTY_REGISTRATION( Toolkit, Magnifier, "magnification-factor", FLOAT, MAGNIFICATION_FACTOR ) + +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, Magnifier, "source-position", VECTOR3, SOURCE_POSITION ) + +DALI_TYPE_REGISTRATION_END() + const char* DEFAULT_FRAME_IMAGE_PATH = DALI_IMAGE_DIR "magnifier-image-frame.png"; const float IMAGE_BORDER_INDENT = 14.0f; ///< Indent of border in pixels. @@ -92,16 +116,7 @@ struct RenderTaskViewportSizeConstraint } }; -} - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Internal -{ +} // unnamed namespace /////////////////////////////////////////////////////////////////////////////////////////////////// // Magnifier @@ -124,7 +139,6 @@ Dali::Toolkit::Magnifier Magnifier::New() Magnifier::Magnifier() : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ), - mPropertySourcePosition(Property::INVALID_INDEX), mDefaultCameraDistance(1000.f), mActorSize(Vector3::ZERO), mMagnificationFactor(1.0f) @@ -136,15 +150,9 @@ void Magnifier::SetSourceActor(Actor actor) mTask.SetSourceActor( actor ); } -void Magnifier::SetSourcePosition(const Vector3& position) -{ - Self().SetProperty(mPropertySourcePosition, position); -} - void Magnifier::Initialize() { Actor self = Self(); - mPropertySourcePosition = self.RegisterProperty( Toolkit::Magnifier::SOURCE_POSITION_PROPERTY_NAME, Vector3::ZERO ); Vector2 stageSize(Stage::GetCurrent().GetSize()); // NOTE: @@ -161,7 +169,7 @@ void Magnifier::Initialize() Stage().GetCurrent().Add(mSourceActor); mSourceActor.SetParentOrigin(ParentOrigin::CENTER); Constraint constraint = Constraint::New( mSourceActor, Actor::Property::POSITION, EqualToConstraint() ); - constraint.AddSource( Source( self, mPropertySourcePosition ) ); + constraint.AddSource( Source( self, Toolkit::Magnifier::Property::SOURCE_POSITION ) ); constraint.Apply(); // create the render task this will render content on top of everything @@ -317,6 +325,56 @@ void Magnifier::Update() mCameraActor.SetAspectRatio( worldSize.width / worldSize.height ); } +void Magnifier::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +{ + Toolkit::Magnifier magnifier = Toolkit::Magnifier::DownCast( Dali::BaseHandle( object ) ); + + if( magnifier ) + { + Magnifier& magnifierImpl( GetImpl( magnifier ) ); + switch( index ) + { + case Toolkit::Magnifier::Property::FRAME_VISIBILITY: + { + magnifierImpl.SetFrameVisibility( value.Get< bool >() ); + break; + } + case Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR: + { + magnifierImpl.SetMagnificationFactor( value.Get< float >() ); + break; + } + } + } +} + +Property::Value Magnifier::GetProperty( BaseObject* object, Property::Index index ) +{ + Property::Value value; + + Toolkit::Magnifier magnifier = Toolkit::Magnifier::DownCast( Dali::BaseHandle( object ) ); + + if( magnifier ) + { + Magnifier& magnifierImpl( GetImpl( magnifier ) ); + switch( index ) + { + case Toolkit::Magnifier::Property::FRAME_VISIBILITY: + { + value = magnifierImpl.GetFrameVisibility(); + break; + } + case Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR: + { + value = magnifierImpl.GetMagnificationFactor(); + break; + } + } + } + + return value; +} + } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/magnifier/magnifier-impl.h b/dali-toolkit/internal/controls/magnifier/magnifier-impl.h index d4fea4e..d8b990f 100644 --- a/dali-toolkit/internal/controls/magnifier/magnifier-impl.h +++ b/dali-toolkit/internal/controls/magnifier/magnifier-impl.h @@ -62,27 +62,30 @@ public: void SetSourceActor(Actor actor); /** - * @copydoc Toolkit::ImageView::SetSourcePosition - */ - void SetSourcePosition(const Vector3& position); - - /** - * @copydoc Toolkit::ImageView::GetFrameVisibility + * Returns whether the frame is visible or not. + * @return true if frame is visible, false if not. */ bool GetFrameVisibility() const; /** - * @copydoc Toolkit::ImageView::SetFrameVisibility + * Sets whether the frame part of the magnifier should be visible or not. + * @param[in] visible true to display frame, false to hide frame. */ void SetFrameVisibility(bool visible); /** - * @copydoc Toolkit::ImageView::GetMagnificationFactor + * Get the magnification factor of the magnifier + * The larger the value the larger the contents magnified. + * A value of 1.0f indications 1x magnification. + * @return Magnification factor is returned */ float GetMagnificationFactor() const; /** - * @copydoc Toolkit::ImageView::SetMagnificationFactor + * Set the magnification factor of the magnifier + * The larger the value the larger the contents magnified. + * A value of 1.0f indications 1x magnification. + * @param[in] value Magnification factor. */ void SetMagnificationFactor(float value); @@ -91,6 +94,24 @@ public: */ void Update(); + // Properties + + /** + * Called when a property of an object of this type is set. + * @param[in] object The object whose property is set. + * @param[in] index The property index. + * @param[in] value The new property value. + */ + static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ); + + /** + * Called to retrieve a property of an object of this type. + * @param[in] object The object whose property is to be retrieved. + * @param[in] index The property index. + * @return The current value of the property. + */ + static Property::Value GetProperty( BaseObject* object, Property::Index index ); + protected: /** @@ -132,7 +153,6 @@ private: RenderTask mTask; ///< Render Task to render the source actor contents. CameraActor mCameraActor; ///< CameraActor attached to RenderTask ImageActor mFrame; ///< The Magnifier Frame - Property::Index mPropertySourcePosition; ///< Source Position ("source-position") Actor mSourceActor; ///< Source Delegate Actor represents the source position to read. float mDefaultCameraDistance; ///< Default RenderTask's camera distance from target. Vector3 mActorSize; ///< The Actor size