*/
Result spread(FillSpread s) noexcept;
+ /**
+ * @brief Sets the matrix of the affine transformation for the gradient fill.
+ *
+ * The augmented matrix of the transformation is expected to be given.
+ *
+ * @param[in] m The 3x3 augmented matrix.
+ *
+ * @return Result::Success when succeed, Result::FailedAllocation otherwise.
+ *
+ * @BETA_API
+ */
+ Result transform(const Matrix& m) noexcept;
+
/**
* @brief Gets the parameters of the colors of the gradient, their position and number.
*
- * @param[in] colorStops A pointer to the memory location, where the array of the gradient's ColorStop is stored.
+ * @param[out] colorStops A pointer to the memory location, where the array of the gradient's ColorStop is stored.
*
* @return The number of colors used in the gradient. This value corresponds to the length of the @p colorStops array.
*/
*/
FillSpread spread() const noexcept;
+ /**
+ * @brief Gets the matrix of the affine transformation of the gradient fill.
+ *
+ * In case no transformation was applied, the identity matrix is returned.
+ *
+ * @retval The augmented transformation matrix.
+ *
+ * @BETA_API
+ */
+ Matrix transform() const noexcept;
+
/**
* @brief Creates a copy of the Fill object.
*
* It's useful when you need to save the composed scene or image from a paint object and recreate it later.
*
* The file format is decided by the extension name(i.e. "*.tvg") while the supported formats depend on the TVG packaging environment.
- * If it doesn't support the file format, the save() method returns the @c NonSuppport result.
+ * If it doesn't support the file format, the save() method returns the @c Result::NonSuppport result.
*
* Once you export a paint to the file successfully, you can recreate it using the Picture class.
*
}
+Result Fill::transform(const Matrix& m) noexcept
+{
+ if (!pImpl->transform) pImpl->transform = new Matrix();
+ if (!pImpl->transform) return Result::FailedAllocation;
+ *pImpl->transform = m;
+ return Result::Success;
+}
+
+
+Matrix Fill::transform() const noexcept
+{
+ if (pImpl->transform) return *pImpl->transform;
+ return {1, 0, 0, 0, 1, 0, 0, 0, 1};
+}
+
+
Fill* Fill::duplicate() const noexcept
{
return pImpl->duplicate();
struct Fill::Impl
{
ColorStop* colorStops = nullptr;
+ Matrix* transform = nullptr;
uint32_t cnt = 0;
FillSpread spread;
DuplicateMethod<Fill>* dup = nullptr;
{
if (dup) delete(dup);
if (colorStops) free(colorStops);
+ if (transform) delete(transform);
}
void method(DuplicateMethod<Fill>* dup)
ret->pImpl->spread = spread;
ret->pImpl->colorStops = static_cast<ColorStop*>(malloc(sizeof(ColorStop) * cnt));
memcpy(ret->pImpl->colorStops, colorStops, sizeof(ColorStop) * cnt);
-
+ if (transform) {
+ ret->pImpl->transform = new Matrix;
+ if (ret->pImpl->transform) *ret->pImpl->transform = *transform;
+ }
return ret;
}
};