Add VIEW_BOX property to change canvas's viewbox value.
Change-Id: I4b23049f390158b232d1055703968637ebcbc3fa
public:
CanvasRenderer( const Vector2& size )
: mPixelBuffer( Devel::PixelBuffer::New(size.width, size.height, Dali::Pixel::RGBA8888) ),
- mSize(size)
+ mSize(size),
+ mViewBox(size)
{
}
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 )
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 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;
+}
* 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();
}
// 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::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);
+
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.