54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace swf2ass;
|
|
|
|
class FocalGradient implements Gradient {
|
|
/** @var GradientItem[] */
|
|
public array $colors;
|
|
|
|
public MatrixTransform $transform;
|
|
|
|
public array $attributes;
|
|
|
|
/**
|
|
* @param GradientItem[] $colors
|
|
* @param MatrixTransform $transform
|
|
* @param array $attributes
|
|
*/
|
|
public function __construct(array $colors, MatrixTransform $transform, array $attributes) {
|
|
$this->colors = $colors;
|
|
$this->transform = $transform;
|
|
$this->attributes = $attributes;
|
|
}
|
|
|
|
public function getItems(): array {
|
|
return $this->colors;
|
|
}
|
|
|
|
public function getMatrixTransform(): MatrixTransform {
|
|
return $this->transform;
|
|
}
|
|
|
|
public static function fromArray(array $element, MatrixTransform $transform): FocalGradient {
|
|
$colors = [];
|
|
foreach ($element["gradientRecords"] as $item) {
|
|
$colors[] = GradientItem::fromArray($item);
|
|
}
|
|
|
|
//TODO: interpolationMode, spreadMode
|
|
|
|
return new FocalGradient($colors, $transform, [
|
|
"interpolationMode" => $element["interpolationMode"],
|
|
"spreadMode" => $element["spreadMode"],
|
|
"focalPoint" => $element["focalPoint"],
|
|
]);
|
|
}
|
|
|
|
public function applyColorTransform(ColorTransform $transform): Gradient{
|
|
$new = clone $this;
|
|
foreach ($new->colors as $i => $gradientItem){
|
|
$new->colors[$i] = new GradientItem($gradientItem->ratio, $transform->applyToColor($gradientItem->color));
|
|
}
|
|
return $new;
|
|
}
|
|
} |