mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 04:09:20 +02:00
customdrawnws: Merges cocoa context and bitmap improvements from lcl-cocoa and advances a little bit the rendering
git-svn-id: trunk@33686 -
This commit is contained in:
parent
6c62624064
commit
f23a1b62cc
@ -8,8 +8,8 @@ interface
|
||||
{$modeswitch objectivec1}
|
||||
|
||||
uses
|
||||
MacOSAll, // for CGContextRef
|
||||
LCLtype,
|
||||
SysUtils, MacOSAll, // for CGContextRef
|
||||
LCLtype, LCLProc,
|
||||
CocoaAll, CocoaUtils,
|
||||
Classes, Types;
|
||||
|
||||
@ -172,6 +172,7 @@ type
|
||||
procedure TextOut(X,Y: Integer; UTF8Chars: PChar; Count: Integer; CharsDelta: PInteger);
|
||||
function GetTextExtentPoint(AStr: PChar; ACount: Integer; var Size: TSize): Boolean;
|
||||
function GetTextMetrics(var TM: TTextMetric): Boolean;
|
||||
procedure DrawBitmap(X,Y: Integer; ABitmap: TCocoaBitmap);
|
||||
procedure SetOrigin(X,Y: Integer);
|
||||
procedure GetOrigin(var X,Y: Integer);
|
||||
function CGContext: CGContextRef; virtual;
|
||||
@ -239,7 +240,15 @@ type
|
||||
constructor TCocoaBitmap.Create(AWidth, AHeight, ADepth, ABitsPerPixel: Integer;
|
||||
AAlignment: TCocoaBitmapAlignment; AType: TCocoaBitmapType;
|
||||
AData: Pointer; ACopyData: Boolean);
|
||||
var
|
||||
HasAlpha: Boolean;
|
||||
BitmapFormat: NSBitmapFormat;
|
||||
begin
|
||||
{$ifdef VerboseBitmaps}
|
||||
DebugLn(Format('[TCocoaBitmap.Create] AWidth=%d AHeight=%d ADepth=%d ABitsPerPixel=%d'
|
||||
+ ' AAlignment=%d AType=%d AData=? ACopyData=%d',
|
||||
[AWidth, AHeight, ADepth, ABitsPerPixel, Integer(AAlignment), Integer(AType), Integer(ACopyData)]));
|
||||
{$endif}
|
||||
SetInfo(AWidth, AHeight, ADepth, ABitsPerPixel, AAlignment, AType);
|
||||
|
||||
// Copy the image data, if necessary
|
||||
@ -258,6 +267,15 @@ begin
|
||||
FFreeData := False;
|
||||
end;
|
||||
|
||||
HasAlpha := AType in [cbtARGB, cbtRGBA, cbtBGRA];
|
||||
BitmapFormat := NSAlphaNonpremultipliedBitmapFormat;
|
||||
if AType = cbtARGB then
|
||||
BitmapFormat := BitmapFormat or NSAlphaFirstBitmapFormat;
|
||||
|
||||
{$ifdef VerboseBitmaps}
|
||||
DebugLn(Format('[TCocoaBitmap.Create] NSBitmapImageRep.alloc HasAlpha=%d',
|
||||
[Integer(HasAlpha)]));
|
||||
{$endif}
|
||||
// Create the associated NSImageRep
|
||||
imagerep := NSBitmapImageRep(NSBitmapImageRep.alloc.initWithBitmapDataPlanes_pixelsWide_pixelsHigh__colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel(
|
||||
@FData, // planes, BitmapDataPlanes
|
||||
@ -265,10 +283,10 @@ begin
|
||||
FHeight,// height, PixelsHigh
|
||||
FbitsPerSample,// bitsPerSample, bps
|
||||
FsamplesPerPixel, // samplesPerPixel, sps
|
||||
False, // hasAlpha
|
||||
HasAlpha, // hasAlpha
|
||||
False, // isPlanar
|
||||
NSCalibratedRGBColorSpace, // colorSpaceName
|
||||
NSAlphaNonpremultipliedBitmapFormat, // bitmapFormat
|
||||
BitmapFormat, // bitmapFormat
|
||||
FBytesPerRow, // bytesPerRow
|
||||
FBitsPerPixel //bitsPerPixel
|
||||
));
|
||||
@ -683,6 +701,14 @@ begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TCocoaContext.DrawBitmap(X,Y:Integer; ABitmap: TCocoaBitmap);
|
||||
begin
|
||||
NSGraphicsContext.saveGraphicsState();
|
||||
NSGraphicsContext.setCurrentContext(ctx);
|
||||
ABitmap.imagerep.drawAtPoint(NSMakePoint(X, Y));
|
||||
NSGraphicsContext.restoreGraphicsState();
|
||||
end;
|
||||
|
||||
procedure TCocoaContext.SetOrigin(X,Y:Integer);
|
||||
var
|
||||
cg : CGContextRef;
|
||||
|
@ -701,7 +701,7 @@ begin
|
||||
// Now render it into the control
|
||||
TCocoaCustomControl(Owner).Image.GetRawImage(lRawImage);
|
||||
Cocoa_RawImage_CreateBitmaps(lRawImage, lBitmap, lMask, True);
|
||||
//Context. <- ToDo Render the HBITMAP
|
||||
Context.DrawBitmap(0, 0, TCocoaBitmap(lBitmap));
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user