From: JunsuChoi Date: Tue, 13 Jul 2021 02:05:56 +0000 (+0900) Subject: CanvasView: Add RemoveDrawable() API X-Git-Tag: dali_2.0.37~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F77%2F261177%2F5;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git CanvasView: Add RemoveDrawable() API Add an API that removes the Drawable registered with AddDrawable(). Change-Id: Icf5796ca03093d20f13e5fe12db8c75aa5965a7e --- 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 43807bf..5849f99 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 @@ -38,7 +38,8 @@ class CanvasRenderer: public Dali::BaseObject { public: CanvasRenderer( const Vector2& size ) - : mPixelBuffer( Devel::PixelBuffer::New(size.width, size.height, Dali::Pixel::RGBA8888) ), + : mDrawable(nullptr), + mPixelBuffer( Devel::PixelBuffer::New(size.width, size.height, Dali::Pixel::RGBA8888) ), mSize(size), mViewBox(size) { @@ -69,9 +70,24 @@ public: { return false; } + mDrawable = &drawable; return true; } + bool RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable) + { + if (!drawable) + { + return false; + } + if (mDrawable == &drawable) + { + mDrawable = nullptr; + return true; + } + return false; + } + Devel::PixelBuffer GetPixelBuffer() { return mPixelBuffer; @@ -112,6 +128,7 @@ public: } public: + Dali::CanvasRenderer::Drawable* mDrawable; Devel::PixelBuffer mPixelBuffer; Vector2 mSize; Vector2 mViewBox; @@ -185,6 +202,11 @@ bool CanvasRenderer::AddDrawable(Dali::CanvasRenderer::Drawable& drawable) return Internal::Adaptor::GetImplementation(*this).AddDrawable(drawable); } +bool CanvasRenderer::RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable) +{ + return Internal::Adaptor::GetImplementation(*this).RemoveDrawable(drawable); +} + bool CanvasRenderer::SetSize(const Vector2& size) { return Internal::Adaptor::GetImplementation(*this).SetSize(size); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-CanvasView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-CanvasView.cpp index 60a7a46..f6b3d10 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-CanvasView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-CanvasView.cpp @@ -167,6 +167,35 @@ int UtcDaliCanvasViewAddN(void) END_TEST; } +int UtcDaliCanvasViewRemoveP(void) +{ + ToolkitTestApplication application; + CanvasView canvasView = CanvasView::New(Vector2(100,100)); + DALI_TEST_CHECK( canvasView ); + + Dali::CanvasRenderer::Shape shape = Dali::CanvasRenderer::Shape::New(); + + canvasView.AddDrawable(shape); + + DALI_TEST_CHECK( canvasView.RemoveDrawable(shape) ); + + END_TEST; +} + +int UtcDaliCanvasViewRemoveN(void) +{ + ToolkitTestApplication application; + + CanvasView canvasView = CanvasView::New(Vector2(100,100)); + DALI_TEST_CHECK( canvasView ); + + Dali::CanvasRenderer::Shape shape = Dali::CanvasRenderer::Shape::New(); + + DALI_TEST_CHECK( !canvasView.RemoveDrawable(shape) ); + + END_TEST; +} + int UtcDaliCanvasViewChangeSizeP(void) { ToolkitTestApplication application; diff --git a/dali-toolkit/devel-api/controls/canvas-view/canvas-view.cpp b/dali-toolkit/devel-api/controls/canvas-view/canvas-view.cpp index f2a4a2e..a0577d8 100644 --- a/dali-toolkit/devel-api/controls/canvas-view/canvas-view.cpp +++ b/dali-toolkit/devel-api/controls/canvas-view/canvas-view.cpp @@ -73,6 +73,11 @@ void CanvasView::AddDrawable(Dali::CanvasRenderer::Drawable& drawable) Dali::Toolkit::GetImpl(*this).AddDrawable(drawable); } +bool CanvasView::RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable) +{ + return Dali::Toolkit::GetImpl(*this).RemoveDrawable(drawable); +} + CanvasView::CanvasView(Internal::CanvasView& implementation) : Control(implementation) { 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 9607d2c..5860539 100644 --- a/dali-toolkit/devel-api/controls/canvas-view/canvas-view.h +++ b/dali-toolkit/devel-api/controls/canvas-view/canvas-view.h @@ -157,9 +157,18 @@ public: /** * @brief Add drawable object to the CanvasView. * This method is similar to registration. The added shape is drawn on the inner canvas. + * @param[in] drawable the drawable object. */ void AddDrawable(Dali::CanvasRenderer::Drawable& drawable); + /** + * @brief Remove drawable object to the CanvasView. + * This method is similar to deregistration. + * @param[in] drawable the drawable object. + * @return Returns True when it's successful. False otherwise. + */ + bool RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable); + public: // Not intended for application developers /// @cond internal /** 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 a87c040..1e93358 100644 --- a/dali-toolkit/internal/controls/canvas-view/canvas-view-impl.cpp +++ b/dali-toolkit/internal/controls/canvas-view/canvas-view-impl.cpp @@ -251,6 +251,15 @@ bool CanvasView::AddDrawable(Dali::CanvasRenderer::Drawable& drawable) return false; } +bool CanvasView::RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable) +{ + if(mCanvasRenderer && mCanvasRenderer.RemoveDrawable(drawable)) + { + return true; + } + return false; +} + bool CanvasView::SetViewBox(const Vector2& viewBox) { if(mCanvasRenderer && mCanvasRenderer.SetViewBox(viewBox)) 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 ffc204e..842877d 100644 --- a/dali-toolkit/internal/controls/canvas-view/canvas-view-impl.h +++ b/dali-toolkit/internal/controls/canvas-view/canvas-view-impl.h @@ -79,6 +79,11 @@ public: */ static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex); + /** + * @copydoc Toolkit::Control::CanvasView::RemoveDrawable + */ + bool RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable); + private: // From Control /** * @copydoc Control::OnRelayout