| ThorVG v0.8

Public Member Functions | List of all members
Paint
ThorVG

An abstract class for managing graphical elements. More...

Inheritance diagram for Paint:
[legend]

## Public Member Functions
Result | rotate (float degree) noexcept
| Sets the angle by which the object is rotated. More...
Result | scale (float factor) noexcept
| Sets the scale value of the object. More...
Result | translate (float x, float y) noexcept
| Sets the values by which the object is moved in a two-dimensional space. More...
Result | transform (const Matrix &m) noexcept
| Sets the matrix of the affine transformation for the object. More...
Matrix | transform () noexcept
| Gets the matrix of the affine transformation of the object. More...
Result | opacity (uint8_t o) noexcept
| Sets the opacity of the object. More...
Result | composite (std::unique_ptr< Paint > target, CompositeMethod method) noexcept
| Sets the composition target object and the composition method. More...
TVG_DEPRECATED Result | bounds (float *x, float *y, float *w, float *h) const noexcept
| Gets the bounding box of the paint object before any transformation. More...
Result | bounds (float *x, float *y, float *w, float *h, bool transformed) const noexcept
| Gets the axis-aligned bounding box of the paint object. More...
Paint * | duplicate () const noexcept
| Duplicates the object. More...
uint8_t | opacity () const noexcept
| Gets the opacity value of the object. More...
CompositeMethod | composite (const Paint **target) const noexcept
| Gets the composition target object and the composition method. More...
uint32_t | identifier () const noexcept
| Return the unique id value of the paint instance. More...

## Detailed Description

An abstract class for managing graphical elements.

A graphical element in TVG is any object composed into a Canvas. Paint represents such a graphical object and its behaviors such as duplication, transformation and composition. TVG recommends the user to regard a paint as a set of volatile commands. They can prepare a Paint and then request a Canvas to run them.

## Member Function Documentation

## ◆ bounds() [1/2]

TVG_DEPRECATED Result bounds | ( | float * | x,
|  | float * | y,
|  | float * | w,
|  | float * | h
| ) |  | const
| noexcept

Gets the bounding box of the paint object before any transformation.

Parameters

  [out] | x | The x coordinate of the upper left corner of the object.
  [out] | y | The y coordinate of the upper left corner of the object.
  [out] | w | The width of the object.
  [out] | h | The height of the object.

Returns
  Result::Success when succeed, Result::InsufficientCondition otherwise.

Note
  The bounding box doesn't indicate the final rendered region. It's the smallest rectangle that encloses the object.

See also
  Paint::bounds(float* x, float* y, float* w, float* h, bool transformed);

## ◆ bounds() [2/2]

Result bounds | ( | float * | x,
|  | float * | y,
|  | float * | w,
|  | float * | h,
|  | bool | transformed
| ) |  | const
| noexcept

Gets the axis-aligned bounding box of the paint object.

In case `transform` is `true`, all object's transformations are applied first, and then the bounding box is established. Otherwise, the bounding box is determined before any transformations.

Parameters

  [out] | x | The x coordinate of the upper left corner of the object.
  [out] | y | The y coordinate of the upper left corner of the object.
  [out] | w | The width of the object.
  [out] | h | The height of the object.
  [in] | transformed | If `true`, the paint's transformations are taken into account, otherwise they aren't.

Returns
  Result::Success when succeed, Result::InsufficientCondition otherwise.

Note
  The bounding box doesn't indicate the actual drawing region. It's the smallest rectangle that encloses the object.

## ◆ composite() [1/2]

CompositeMethod composite | ( | const Paint ** | target | ) | const
| noexcept

Gets the composition target object and the composition method.

Parameters

  [out] | target | The paint of the target object.

Returns
  The method used to composite the source object with the target.

Since
  0.5

## ◆ composite() [2/2]

Result composite | ( | std::unique_ptr< Paint > | target,
|  | CompositeMethod | method
| ) |  |
| noexcept

Sets the composition target object and the composition method.

Parameters

  [in] | target | The paint of the target object.
  [in] | method | The method used to composite the source object with the target.

Returns
  Result::Success when succeed, Result::InvalidArguments otherwise.

## ◆ duplicate()

Paint* duplicate | ( |  | ) | const
| noexcept

Duplicates the object.

Creates a new object and sets its all properties as in the original object.

Returns
  The created object when succeed, `nullptr` otherwise.

## ◆ identifier()

uint32_t identifier | ( |  | ) | const
| noexcept

Return the unique id value of the paint instance.

This method can be called for checking the current concrete instance type.

Returns
  The type id of the Paint instance.

@BETA_API

## ◆ opacity() [1/2]

uint8_t opacity | ( |  | ) | const
| noexcept

Gets the opacity value of the object.

Returns
  The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.

## ◆ opacity() [2/2]

Result opacity | ( | uint8_t | o | ) |
| noexcept

Sets the opacity of the object.

Parameters

  [in] | o | The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.

Returns
  Result::Success when succeed.

Note
  Setting the opacity with this API may require multiple render pass for composition. It is recommended to avoid changing the opacity if possible.

## ◆ rotate()

Result rotate | ( | float | degree | ) |
| noexcept

Sets the angle by which the object is rotated.

The angle in measured clockwise from the horizontal axis. The rotational axis passes through the point on the object with zero coordinates.

Parameters

  [in] | degree | The value of the angle in degrees.

Returns
  Result::Success when succeed, Result::FailedAllocation otherwise.

## ◆ scale()

Result scale | ( | float | factor | ) |
| noexcept

Sets the scale value of the object.

Parameters

  [in] | factor | The value of the scaling factor. The default value is 1.

Returns
  Result::Success when succeed, Result::FailedAllocation otherwise.

## ◆ transform() [1/2]

Matrix transform | ( |  | ) |
| noexcept

Gets the matrix of the affine transformation of the object.

The values of the matrix can be set by the transform() API, as well by the translate(), scale() and rotate(). In case no transformation was applied, the identity matrix is returned.

Return values

  The | augmented transformation matrix.

Since
  0.4

## ◆ transform() [2/2]

Result transform | ( | const Matrix & | m | ) |
| noexcept

Sets the matrix of the affine transformation for the object.

The augmented matrix of the transformation is expected to be given.

Parameters

  [in] | m | The 3x3 augmented matrix.

Returns
  Result::Success when succeed, Result::FailedAllocation otherwise.

## ◆ translate()

Result translate | ( | float | x,
|  | float | y
| ) |  |
| noexcept

Sets the values by which the object is moved in a two-dimensional space.

The origin of the coordinate system is in the upper left corner of the canvas. The horizontal and vertical axes point to the right and down, respectively.

Parameters

  [in] | x | The value of the horizontal shift.
  [in] | y | The value of the vertical shift.

Returns
  Result::Success when succeed, Result::FailedAllocation otherwise.