mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-29 12:10:31 +02:00
parent
e5ab08f99b
commit
fda9deecd3
@ -26,6 +26,14 @@ uses
|
||||
// Libs
|
||||
MacOSAll, CocoaAll;
|
||||
|
||||
type
|
||||
NSImageScaling = NSUInteger;
|
||||
const // NSImageScaling values
|
||||
NSImageScaleProportionallyDown = 0;
|
||||
NSImageScaleAxesIndependently = 1;
|
||||
NSImageScaleNone = 2;
|
||||
NSImageScaleProportionallyUpOrDown = 3;
|
||||
|
||||
type
|
||||
NSMenuFix = objccategory external (NSMenu)
|
||||
function itemAtIndex(index: NSInteger): NSMenuItem; message 'itemAtIndex:';
|
||||
@ -38,6 +46,7 @@ type
|
||||
|
||||
NSButtonSoundExtensionsCategory = objccategory external (NSButton)
|
||||
function intrinsicContentSize(): NSSize; message 'intrinsicContentSize';
|
||||
procedure setImageScaling(aScaling: NSImageScaling); message 'setImageScaling:';
|
||||
end;
|
||||
|
||||
// The following dummy categories fix bugs in the Cocoa bindings available in FPC
|
||||
|
@ -125,6 +125,7 @@ var
|
||||
AIndex: Integer;
|
||||
AEffect: TGraphicsDrawEffect;
|
||||
AImgRes: TScaledImageListResolution;
|
||||
ImgSize: NSSize;
|
||||
begin
|
||||
//WriteLn('[TCocoaWSBitBtn.SetGlyph]');
|
||||
Img := nil;
|
||||
@ -132,13 +133,20 @@ begin
|
||||
begin
|
||||
AGlyph := TBitmap.Create;
|
||||
AValue.GetImageIndexAndEffect(bsUp, ABitBtn.Font.PixelsPerInch,
|
||||
1{To-Do: ABitBtn.GetCanvasScaleFactor}, AImgRes, AIndex, AEffect);
|
||||
ABitBtn.GetCanvasScaleFactor, AImgRes, AIndex, AEffect);
|
||||
AImgRes.GetBitmap(AIndex, AGlyph, AEffect);
|
||||
Img := TCocoaBitmap(AGlyph.Handle).image;
|
||||
if AImgRes.Resolution.ImageList.Scaled then // resize only if the image list is scaled
|
||||
begin
|
||||
ImgSize := Img.size;
|
||||
ImgSize.height := ImgSize.height / ABitBtn.GetCanvasScaleFactor;
|
||||
ImgSize.width := ImgSize.width / ABitBtn.GetCanvasScaleFactor;
|
||||
Img.setSize(ImgSize);
|
||||
end;
|
||||
lButtonHandle := TCocoaButton(ABitBtn.Handle);
|
||||
lButtonHandle.setImage(Img);
|
||||
lButtonHandle.setImagePosition(LCLGlyphPosToCocoa(ABitBtn.Layout));
|
||||
//To-Do: tell Cocoa lButtonHandle should not scale the image (and enable ABitBtn.GetCanvasScaleFactor above)
|
||||
lButtonHandle.setImageScaling(NSImageScaleNone); // do not scale - retina scaling is done above with Img.setSize
|
||||
if Assigned(lButtonHandle.Glyph) then
|
||||
FreeAndNil(lButtonHandle.Glyph);
|
||||
lButtonHandle.Glyph := AGlyph;
|
||||
|
Loading…
Reference in New Issue
Block a user