mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-07 07:42:11 +02:00
Cocoa: refactor in TCocoaContext.StretchDraw()
This commit is contained in:
parent
9376f57403
commit
8ecc0ea6cc
@ -2164,7 +2164,7 @@ function TCocoaContext.StretchDraw(X, Y, Width, Height: Integer;
|
|||||||
Msk: TCocoaBitmap; XMsk, YMsk: Integer; Rop: DWORD): Boolean;
|
Msk: TCocoaBitmap; XMsk, YMsk: Integer; Rop: DWORD): Boolean;
|
||||||
var
|
var
|
||||||
Bmp: TCocoaBitmap;
|
Bmp: TCocoaBitmap;
|
||||||
MskImage: CGImageRef;
|
MskImage: CGImageRef = nil;
|
||||||
ImgRect: CGRect;
|
ImgRect: CGRect;
|
||||||
|
|
||||||
dcWidth: Integer;
|
dcWidth: Integer;
|
||||||
@ -2185,31 +2185,31 @@ begin
|
|||||||
inc(XSrc, -SrcDC.WindowOfs.X);
|
inc(XSrc, -SrcDC.WindowOfs.X);
|
||||||
inc(YSrc, -SrcDC.WindowOfs.Y);
|
inc(YSrc, -SrcDC.WindowOfs.Y);
|
||||||
|
|
||||||
|
CGContextSaveGState(CGContext);
|
||||||
//apply window offset
|
//apply window offset
|
||||||
if (Msk <> nil) and (Msk.Image <> nil) then
|
if (Msk <> nil) and (Msk.Image <> nil) then begin
|
||||||
begin
|
|
||||||
MskImage := Msk.CreateMaskImage(Bounds(XMsk, YMsk, SrcWidth, SrcHeight));
|
MskImage := Msk.CreateMaskImage(Bounds(XMsk, YMsk, SrcWidth, SrcHeight));
|
||||||
ImgRect := CGRectMake(x, y, dcWidth, dcHeight);
|
ImgRect := CGRectMake(x, y, dcWidth, dcHeight);
|
||||||
CGContextSaveGState(CGContext);
|
CGContextClipToMask(CGContext, ImgRect, MskImage);
|
||||||
CGContextClipToMask(CGContext, ImgRect, MskImage );
|
|
||||||
|
|
||||||
if NOT ctx.isFlipped then begin
|
|
||||||
CGContextScaleCTM(CGContext, 1, -1);
|
|
||||||
CGContextTranslateCTM(CGContext, 0, -dcHeight);
|
|
||||||
Y:= dcHeight - (Height + Y);
|
|
||||||
end;
|
|
||||||
Result := bmp.ImageRep.drawInRect_fromRect_operation_fraction_respectFlipped_hints(
|
|
||||||
GetNSRect(X, Y, Width, Height), GetNSRect(XSrc, YSrc, SrcWidth, SrcHeight), NSCompositeSourceOver, 1.0, True, nil );
|
|
||||||
|
|
||||||
CGImageRelease(MskImage);
|
|
||||||
CGContextRestoreGState(CGContext);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
// convert Y coordinate of the source bitmap
|
|
||||||
YSrc := Bmp.Height - (SrcHeight + YSrc);
|
|
||||||
Result := DrawImageRep(GetNSRect(X, Y, Width, Height),GetNSRect(XSrc, YSrc, SrcWidth, SrcHeight), bmp.ImageRep);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if NOT ctx.isFlipped then begin
|
||||||
|
CGContextScaleCTM(CGContext, 1, -1);
|
||||||
|
CGContextTranslateCTM(CGContext, 0, -dcHeight);
|
||||||
|
Y:= dcHeight - (Height + Y);
|
||||||
|
end;
|
||||||
|
|
||||||
|
if NOT SrcDC.ctx.isFlipped then begin
|
||||||
|
YSrc := Bmp.Height - (SrcHeight + YSrc);
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result := bmp.ImageRep.drawInRect_fromRect_operation_fraction_respectFlipped_hints(
|
||||||
|
GetNSRect(X, Y, Width, Height), GetNSRect(XSrc, YSrc, SrcWidth, SrcHeight), NSCompositeSourceOver, 1.0, True, nil );
|
||||||
|
|
||||||
|
if Assigned(MskImage) then
|
||||||
|
CGImageRelease(MskImage);
|
||||||
|
CGContextRestoreGState(CGContext);
|
||||||
|
|
||||||
AttachedBitmap_SetModified();
|
AttachedBitmap_SetModified();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user