Skip to content

Commit 1394fc3

Browse files
committed
feat(ios): localMatrix support for shaders
1 parent 130ef9e commit 1394fc3

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

src/ui-canvas/index.ios.ts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,14 +1233,20 @@ export class Paint implements IPaint {
12331233

12341234
const w = source.size.width;
12351235
const h = source.size.height;
1236-
const rect = CGRectMake(0, 0, w, h);
1236+
const rect = new Rect(CGRectMake(0, 0, w, h));
1237+
1238+
let transform = CGAffineTransformMakeTranslation(0, rect.cgRect.size.height);
1239+
transform = CGAffineTransformScale(transform, 1.0, -1.0);
1240+
if (this.shader.localMatrix) {
1241+
this.shader.localMatrix.mapRect(rect);
1242+
}
1243+
rect.cgRect = CGRectApplyAffineTransform(rect.cgRect, transform);
12371244

12381245
// draw original image
12391246
CGContextSaveGState(ctx);
12401247
CGContextClip(ctx);
1241-
CGContextTranslateCTM(ctx, 0, source.size.height);
1242-
CGContextScaleCTM(ctx, 1.0, -1.0);
1243-
CGContextDrawImage(ctx, rect, source.CGImage);
1248+
CGContextConcatCTM(ctx, transform);
1249+
CGContextDrawImage(ctx, rect.cgRect, source.CGImage);
12441250
CGContextRestoreGState(ctx);
12451251
// CGContextAddPath(ctx, path);
12461252
}
@@ -2206,9 +2212,33 @@ export class ColorMatrixColorFilter {
22062212
}
22072213
}
22082214
}
2209-
export class RadialGradient {
2215+
2216+
class Shader {
2217+
localMatrix: Matrix;
2218+
2219+
getLocalMatrix(localM: Matrix): boolean {
2220+
if (this.localMatrix && !this.localMatrix.isIdentity()) {
2221+
localM.set(this.localMatrix);
2222+
return true;
2223+
}
2224+
return false;
2225+
}
2226+
setLocalMatrix(localM: Matrix) {
2227+
if (localM) {
2228+
if (!this.localMatrix) {
2229+
this.localMatrix = new Matrix();
2230+
}
2231+
this.localMatrix.set(localM);
2232+
} else {
2233+
this.localMatrix = null;
2234+
}
2235+
}
2236+
}
2237+
export class RadialGradient extends Shader {
22102238
mGradient;
2211-
constructor(public centerX: number, public centerY: number, public radius: number, public colors: any, public stops: any, public tileMode: TileMode) {}
2239+
constructor(public centerX: number, public centerY: number, public radius: number, public colors: any, public stops: any, public tileMode: TileMode) {
2240+
super();
2241+
}
22122242
get gradient() {
22132243
if (!this.mGradient) {
22142244
if (Array.isArray(this.colors)) {
@@ -2230,8 +2260,10 @@ export class RadialGradient {
22302260
}
22312261
}
22322262
}
2233-
export class BitmapShader {
2234-
constructor(public bitmap: any, public tileX: any, public tileY: any) {}
2263+
export class BitmapShader extends Shader {
2264+
constructor(public bitmap: any, public tileX: any, public tileY: any) {
2265+
super();
2266+
}
22352267
get image() {
22362268
if (this.bitmap instanceof ImageSource) {
22372269
return this.bitmap.ios;

0 commit comments

Comments
 (0)