Skip to content

Commit b73c719

Browse files
authored
Chore: RadialBlurFilter deprecate non-options constructor (#432)
* Chore: Radial Blur Filter Deprecations * Cleanup --------- Co-authored-by: Baz Utsahajit <[email protected]>
1 parent 2216543 commit b73c719

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

src/radial-blur/RadialBlurFilter.ts

+43-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Filter, GlProgram, GpuProgram } from 'pixi.js';
1+
import { deprecation, Filter, GlProgram, GpuProgram } from 'pixi.js';
22
import { vertex, wgslVertex } from '../defaults';
33
import fragment from './radial-blur.frag';
44
import source from './radial-blur.wgsl';
@@ -18,7 +18,7 @@ export interface RadialBlurFilterOptions
1818
* once defined in the constructor
1919
* @default {x:0,y:0}
2020
*/
21-
center?: PointData;
21+
center?: PointData | number[];
2222
/**
2323
* The kernelSize of the blur filter. Must be odd number >= 3
2424
* @default 5
@@ -59,8 +59,38 @@ export class RadialBlurFilter extends Filter
5959
private _angle!: number;
6060
private _kernelSize!: number;
6161

62-
constructor(options?: RadialBlurFilterOptions)
62+
constructor(options?: RadialBlurFilterOptions);
63+
/**
64+
* @deprecated since 6.0.0
65+
*
66+
* @param {number} [angle=0] - Sets the angle of the motion for blur effect.
67+
* @param {PIXI.Point|number[]} [center=[0,0]] - The center of the radial.
68+
* @param {number} [kernelSize=5] - The kernelSize of the blur filter. Must be odd number >= 3
69+
* @param {number} [radius=-1] - The maximum size of the blur radius, `-1` is infinite
70+
*/
71+
constructor(angle?: number, center?: PointData | number[], kernelSize?: number, radius?: number);
72+
constructor(...args: [RadialBlurFilterOptions?] | [number?, (PointData | number[])?, number?, number?])
6373
{
74+
let options = args[0] ?? {};
75+
76+
if (typeof options === 'number')
77+
{
78+
// eslint-disable-next-line max-len
79+
deprecation('6.0.0', 'RadialBlurFilter constructor params are now options object. See params: { angle, center, kernelSize, radius }');
80+
81+
options = { angle: options };
82+
83+
if (args[1])
84+
{
85+
const x = 'x' in args[1] ? args[1].x : args[1][0];
86+
const y = 'y' in args[1] ? args[1].y : args[1][1];
87+
88+
options.center = { x, y };
89+
}
90+
if (args[2]) options.kernelSize = args[2];
91+
if (args[3]) options.radius = args[3];
92+
}
93+
6494
options = { ...RadialBlurFilter.DEFAULT_OPTIONS, ...options };
6595

6696
const gpuProgram = GpuProgram.from({
@@ -87,7 +117,7 @@ export class RadialBlurFilter extends Filter
87117
radialBlurUniforms: {
88118
uRadian: { value: 0, type: 'f32' },
89119
uCenter: { value: options.center, type: 'vec2<f32>' },
90-
uKernelSize: { value: options.kernelSize, type: 'f32' },
120+
uKernelSize: { value: options.kernelSize, type: 'i32' },
91121
uRadius: { value: options.radius, type: 'f32' },
92122
}
93123
},
@@ -122,7 +152,15 @@ export class RadialBlurFilter extends Filter
122152
* @default {x:0,y:0}
123153
*/
124154
get center(): PointData { return this.uniforms.uCenter; }
125-
set center(value: PointData) { this.uniforms.uCenter = value; }
155+
set center(value: PointData | number[])
156+
{
157+
if (Array.isArray(value))
158+
{
159+
value = { x: value[0], y: value[1] };
160+
}
161+
162+
this.uniforms.uCenter = value;
163+
}
126164

127165
/**
128166
* Sets the velocity of the motion for blur effect on the `x` axis

0 commit comments

Comments
 (0)