From: JunsuChoi Date: Mon, 12 Jul 2021 05:55:09 +0000 (+0900) Subject: CanvasView: Add Property::VIEW_BOX X-Git-Tag: dali_2.0.37~4 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=d3e4ed352b1b3436394c7a218a961487b7ee00fa CanvasView: Add Property::VIEW_BOX Add VIEW_BOX property to change canvas's viewbox value. Change-Id: I4b23049f390158b232d1055703968637ebcbc3fa --- diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-canvas-renderer.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-canvas-renderer.cpp index 8db2a84..43807bf 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-canvas-renderer.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-canvas-renderer.cpp @@ -39,7 +39,8 @@ class CanvasRenderer: public Dali::BaseObject public: CanvasRenderer( const Vector2& size ) : mPixelBuffer( Devel::PixelBuffer::New(size.width, size.height, Dali::Pixel::RGBA8888) ), - mSize(size) + mSize(size), + mViewBox(size) { } @@ -94,10 +95,26 @@ public: return mSize; } + bool SetViewBox(const Vector2& viewBox) + { + mViewBox = viewBox; + // For negative test + if ( viewBox.width == -999 && viewBox.height == -999 ) + { + return false; + } + return true; + } + + const Vector2& GetViewBox() + { + return mViewBox; + } public: Devel::PixelBuffer mPixelBuffer; Vector2 mSize; + Vector2 mViewBox; }; inline CanvasRenderer& GetImplementation( Dali::CanvasRenderer& renderer ) @@ -178,5 +195,14 @@ const Vector2& CanvasRenderer::GetSize() return Internal::Adaptor::GetImplementation(*this).GetSize(); } +bool CanvasRenderer::SetViewBox(const Vector2& viewBox) +{ + return Internal::Adaptor::GetImplementation(*this).SetViewBox(viewBox); +} + +const Vector2& CanvasRenderer::GetViewBox() +{ + return Internal::Adaptor::GetImplementation(*this).GetViewBox(); +} } // namespace Dali diff --git a/automated-tests/src/dali-toolkit/utc-Dali-CanvasView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-CanvasView.cpp index 3192617..60a7a46 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-CanvasView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-CanvasView.cpp @@ -488,3 +488,42 @@ int UtcDaliCanvasViewSetSizeAndAddDrawable(void) END_TEST; } + +int UtcDaliCanvasViewViewBoxP(void) +{ + ToolkitTestApplication application; + + CanvasView canvasView = CanvasView::New(Vector2(300, 300)); + DALI_TEST_CHECK( canvasView ); + + application.GetScene().Add(canvasView); + + canvasView.SetProperty(Actor::Property::SIZE, Vector2(300, 300)); + canvasView.SetProperty(Toolkit::CanvasView::Property::VIEW_BOX, Vector2(100, 100)); + + application.SendNotification(); + application.Render(); + + END_TEST; +} + +int UtcDaliCanvasViewViewBoxN(void) +{ + ToolkitTestApplication application; + + CanvasView canvasView = CanvasView::New(Vector2(300, 300)); + DALI_TEST_CHECK( canvasView ); + + application.GetScene().Add(canvasView); + + canvasView.SetProperty(Actor::Property::SIZE, Vector2(300, 300)); + canvasView.SetProperty(Toolkit::CanvasView::Property::VIEW_BOX, Vector2(-999, -999)); + + application.SendNotification(); + application.Render(); + + Vector2 viewBox = canvasView.GetProperty(Toolkit::CanvasView::Property::VIEW_BOX).Get(); + DALI_TEST_EQUALS( viewBox, Vector2(-999, -999), TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/devel-api/controls/canvas-view/canvas-view.h b/dali-toolkit/devel-api/controls/canvas-view/canvas-view.h index c0e0709..9607d2c 100644 --- a/dali-toolkit/devel-api/controls/canvas-view/canvas-view.h +++ b/dali-toolkit/devel-api/controls/canvas-view/canvas-view.h @@ -51,12 +51,42 @@ class CanvasView; * myCanvasView.AddDrawable( shape ); * @endcode * + * @section CanvasViewProperties Properties + * |%Property enum |String name |Type |Writable|Animatable| + * |----------------------------------|---------------------|----------------|--------|----------| + * | Property::VIEW_BOX | viewBox | Vector2 | O | X | * */ class DALI_TOOLKIT_API CanvasView : public Control { public: /** + * @brief The start and end property ranges for this control. + */ + enum PropertyRange + { + PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, + }; + + /** + * @brief An enumeration of properties belonging to the CanvasView class. + */ + struct Property + { + /** + * @brief An enumeration of properties belonging to the CanvasView class. + */ + enum + { + /** + * @brief the viewbox of the CanvasView. + * @details Name "viewBox", type Property::VECTOR2. + */ + VIEW_BOX = PROPERTY_START_INDEX, + }; + }; +public: + /** * @brief Creates an uninitialized CanvasView. */ CanvasView(); diff --git a/dali-toolkit/internal/controls/canvas-view/canvas-view-impl.cpp b/dali-toolkit/internal/controls/canvas-view/canvas-view-impl.cpp index 0132e3c..a87c040 100644 --- a/dali-toolkit/internal/controls/canvas-view/canvas-view-impl.cpp +++ b/dali-toolkit/internal/controls/canvas-view/canvas-view-impl.cpp @@ -45,6 +45,7 @@ BaseHandle Create() } // Setup properties, signals and actions using the type-registry. DALI_TYPE_REGISTRATION_BEGIN(Toolkit::CanvasView, Toolkit::Control, Create); +DALI_PROPERTY_REGISTRATION(Toolkit, CanvasView, "viewBox", VECTOR2, VIEW_BOX) DALI_TYPE_REGISTRATION_END() } // anonymous namespace @@ -126,6 +127,50 @@ void CanvasView::OnSizeSet(const Vector3& targetSize) mSize.height = targetSize.height; } +void CanvasView::SetProperty(BaseObject* object, Property::Index propertyIndex, const Property::Value& value) +{ + Toolkit::CanvasView canvasView = Toolkit::CanvasView::DownCast(Dali::BaseHandle(object)); + if(canvasView) + { + CanvasView& canvasViewImpl(GetImpl(canvasView)); + + switch(propertyIndex) + { + case Toolkit::CanvasView::Property::VIEW_BOX: + { + Vector2 valueVector2; + if(value.Get(valueVector2)) + { + canvasViewImpl.SetViewBox(valueVector2); + } + break; + } + } + } +} + +Property::Value CanvasView::GetProperty(BaseObject* object, Property::Index propertyIndex) +{ + Property::Value value; + + Toolkit::CanvasView canvasView = Toolkit::CanvasView::DownCast(Dali::BaseHandle(object)); + + if(canvasView) + { + CanvasView& canvasViewImpl(GetImpl(canvasView)); + + switch(propertyIndex) + { + case Toolkit::CanvasView::Property::VIEW_BOX: + { + value = canvasViewImpl.GetViewBox(); + break; + } + } + } + return value; +} + void CanvasView::Process(bool postProcessor) { if(mCanvasRenderer && mCanvasRenderer.IsCanvasChanged() && mSize.width > 0 && mSize.height > 0) @@ -205,6 +250,24 @@ bool CanvasView::AddDrawable(Dali::CanvasRenderer::Drawable& drawable) } return false; } + +bool CanvasView::SetViewBox(const Vector2& viewBox) +{ + if(mCanvasRenderer && mCanvasRenderer.SetViewBox(viewBox)) + { + return true; + } + return false; +} + +const Vector2& CanvasView::GetViewBox() +{ + if(mCanvasRenderer) + { + return mCanvasRenderer.GetViewBox(); + } + return Vector2::ZERO; +} } // namespace Internal } // namespace Toolkit } // namespace Dali diff --git a/dali-toolkit/internal/controls/canvas-view/canvas-view-impl.h b/dali-toolkit/internal/controls/canvas-view/canvas-view-impl.h index 1a468b0..ffc204e 100644 --- a/dali-toolkit/internal/controls/canvas-view/canvas-view-impl.h +++ b/dali-toolkit/internal/controls/canvas-view/canvas-view-impl.h @@ -63,6 +63,22 @@ public: */ bool AddDrawable(Dali::CanvasRenderer::Drawable& drawable); + /** + * Called when a property of an object of this type is set. + * @param[in] object The object whose property is set. + * @param[in] propertyIndex The property index. + * @param[in] value The new property value. + */ + static void SetProperty(BaseObject* object, Property::Index propertyIndex, 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] propertyIndex The property index. + * @return The current value of the property. + */ + static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex); + private: // From Control /** * @copydoc Control::OnRelayout @@ -80,6 +96,19 @@ private: // From Control void OnInitialize() override; /** + * @brief This is the viewbox of the Canvas. + * @param[in] viewBox The size of viewbox. + * @return Returns True when it's successful. False otherwise. + */ + bool SetViewBox(const Vector2& viewBox); + + /** + * @brief This is the viewbox of the Canvas. + * @return Returns The size of viewbox. + */ + const Vector2& GetViewBox(); + + /** * @bried Rasterize the canvas, and add it to the view. * * @param[in] size The target size of the canvas view rasterization.