{
public:
CanvasRenderer( const Vector2& size )
- : mPixelBuffer( Devel::PixelBuffer::New(size.width, size.height, Dali::Pixel::RGBA8888) ),
- mSize(size)
+ : mDrawable(nullptr),
+ mPixelBuffer( Devel::PixelBuffer::New(size.width, size.height, Dali::Pixel::RGBA8888) ),
+ mSize(size),
+ mViewBox(size)
{
}
{
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;
+ }
+
+ bool RemoveAllDrawables()
+ {
+ if (mDrawable)
+ {
+ return true;
+ }
+ return false;
+ }
+
Devel::PixelBuffer GetPixelBuffer()
{
return mPixelBuffer;
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:
+ Dali::CanvasRenderer::Drawable* mDrawable;
Devel::PixelBuffer mPixelBuffer;
Vector2 mSize;
+ Vector2 mViewBox;
};
inline CanvasRenderer& GetImplementation( Dali::CanvasRenderer& renderer )
return Internal::Adaptor::GetImplementation(*this).AddDrawable(drawable);
}
+bool CanvasRenderer::RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable)
+{
+ return Internal::Adaptor::GetImplementation(*this).RemoveDrawable(drawable);
+}
+
+bool CanvasRenderer::RemoveAllDrawables()
+{
+ return Internal::Adaptor::GetImplementation(*this).RemoveAllDrawables();
+}
+
bool CanvasRenderer::SetSize(const Vector2& size)
{
return Internal::Adaptor::GetImplementation(*this).SetSize(size);
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
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 UtcDaliCanvasViewRemoveAllP(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);
+
+ canvasView.RemoveAllDrawables();
+
+ END_TEST;
+}
+
+int UtcDaliCanvasViewRemoveAllN(void)
+{
+ ToolkitTestApplication application;
+
+ CanvasView canvasView = CanvasView::New(Vector2(100,100));
+ DALI_TEST_CHECK( canvasView );
+
+ canvasView.RemoveAllDrawables();
+
+ END_TEST;
+}
+
+
int UtcDaliCanvasViewChangeSizeP(void)
{
ToolkitTestApplication application;
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<Vector2>();
+ DALI_TEST_EQUALS( viewBox, Vector2(-999, -999), TEST_LOCATION );
+
+ END_TEST;
+}
Dali::Toolkit::GetImpl(*this).AddDrawable(drawable);
}
+bool CanvasView::RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable)
+{
+ return Dali::Toolkit::GetImpl(*this).RemoveDrawable(drawable);
+}
+
+void CanvasView::RemoveAllDrawables()
+{
+ Dali::Toolkit::GetImpl(*this).RemoveAllDrawables();
+}
+
CanvasView::CanvasView(Internal::CanvasView& implementation)
: Control(implementation)
{
* 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();
/**
* @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);
+
+ /**
+ * @brief Remove all drawable objects added to the CanvasView.
+ */
+ void RemoveAllDrawables();
+
public: // Not intended for application developers
/// @cond internal
/**
}
// 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
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)
}
return false;
}
+
+bool CanvasView::RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable)
+{
+ if(mCanvasRenderer && mCanvasRenderer.RemoveDrawable(drawable))
+ {
+ return true;
+ }
+ return false;
+}
+
+bool CanvasView::RemoveAllDrawables()
+{
+ if(mCanvasRenderer && mCanvasRenderer.RemoveAllDrawables())
+ {
+ return true;
+ }
+ 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
*/
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);
+
+ /**
+ * @copydoc Toolkit::Control::CanvasView::RemoveDrawable
+ */
+ bool RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable);
+
+ /**
+ * @copydoc Toolkit::Control::CanvasView::RemoveAllDrawables
+ */
+ bool RemoveAllDrawables();
+
private: // From Control
/**
* @copydoc Control::OnRelayout
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.