Browse Source

retina scaling for TBGRAShape

Johann ELSASS 5 years ago
parent
commit
7ac17bf8cc
1 changed files with 13 additions and 21 deletions
  1. 13 21
      bgrashape.pas

+ 13 - 21
bgrashape.pas

@@ -69,7 +69,6 @@ type
   protected
   protected
     { Protected declarations }
     { Protected declarations }
     procedure Paint; override;
     procedure Paint; override;
-    procedure Resize; override;
   public
   public
     { Public declarations }
     { Public declarations }
     constructor Create(AOwner: TComponent); override;
     constructor Create(AOwner: TComponent); override;
@@ -278,11 +277,11 @@ var
   minCoord, maxCoord: TPointF;
   minCoord, maxCoord: TPointF;
   i: integer;
   i: integer;
   borderGrad, fillGrad: TBGRACustomScanner;
   borderGrad, fillGrad: TBGRACustomScanner;
+  scaling: Double;
 begin
 begin
-  {$IFNDEF FPC}//# //@
-  if FBGRA <> nil then
-    FBGRA.SetSize(Width, Height);
-  {$ENDIF}
+  if FBGRA = nil then FBGRA := TBGRABitmap.Create;
+  scaling := GetCanvasScaleFactor;
+  FBGRA.SetSize(round(Width*scaling), round(Height*scaling));
 
 
   FBGRA.FillTransparent;
   FBGRA.FillTransparent;
   FBGRA.PenStyle := FBorderStyle;
   FBGRA.PenStyle := FBorderStyle;
@@ -291,7 +290,7 @@ begin
     lineJoin := 'round';
     lineJoin := 'round';
     if FUseBorderGradient then
     if FUseBorderGradient then
     begin
     begin
-      borderGrad := CreateGradient(FBorderGradient, Classes.rect(0, 0, Width, Height));
+      borderGrad := CreateGradient(FBorderGradient, Classes.rect(0, 0, FBGRA.Width, FBGRA.Height));
       strokeStyle(borderGrad);
       strokeStyle(borderGrad);
     end
     end
     else
     else
@@ -300,10 +299,10 @@ begin
       strokeStyle(ColorToBGRA(ColorToRGB(FBorderColor), FBorderOpacity));
       strokeStyle(ColorToBGRA(ColorToRGB(FBorderColor), FBorderOpacity));
     end;
     end;
     lineStyle(FBGRA.CustomPenStyle);
     lineStyle(FBGRA.CustomPenStyle);
-    lineWidth := FBorderWidth;
+    lineWidth := FBorderWidth*scaling;
     if FUseFillGradient then
     if FUseFillGradient then
     begin
     begin
-      fillGrad := CreateGradient(FFillGradient, Classes.rect(0, 0, Width, Height));
+      fillGrad := CreateGradient(FFillGradient, Classes.rect(0, 0, FBGRA.Width, FBGRA.Height));
       fillStyle(fillGrad);
       fillStyle(fillGrad);
     end
     end
     else
     else
@@ -311,10 +310,10 @@ begin
       fillGrad := nil;
       fillGrad := nil;
       fillStyle(ColorToBGRA(ColorToRGB(FFillColor), FFillOpacity));
       fillStyle(ColorToBGRA(ColorToRGB(FFillColor), FFillOpacity));
     end;
     end;
-    cx := Width / 2;
-    cy := Height / 2;
-    rx := (Width - FBorderWidth) / 2;
-    ry := (Height - FBorderWidth) / 2;
+    cx := FBGRA.Width / 2;
+    cy := FBGRA.Height / 2;
+    rx := (FBGRA.Width - FBorderWidth*scaling) / 2;
+    ry := (FBGRA.Height - FBorderWidth*scaling) / 2;
     if FUseRatioXY and (ry <> 0) and (FRatioXY <> 0) then
     if FUseRatioXY and (ry <> 0) and (FRatioXY <> 0) then
     begin
     begin
       curRatio := rx / ry;
       curRatio := rx / ry;
@@ -379,14 +378,7 @@ begin
     fillGrad.Free;
     fillGrad.Free;
     borderGrad.Free;
     borderGrad.Free;
   end;
   end;
-  FBGRA.Draw(Self.Canvas, 0, 0, False);
-end;
-
-procedure TBGRAShape.Resize;
-begin
-  if FBGRA <> nil then
-    FBGRA.SetSize(Width, Height);
-  inherited Resize;
+  FBGRA.Draw(Self.Canvas, rect(0,0,Width,Height), False);
 end;
 end;
 
 
 constructor TBGRAShape.Create(AOwner: TComponent);
 constructor TBGRAShape.Create(AOwner: TComponent);
@@ -396,7 +388,7 @@ begin
   with GetControlClassDefaultSize do
   with GetControlClassDefaultSize do
     SetInitialBounds(0, 0, CX, CY);
     SetInitialBounds(0, 0, CX, CY);
 
 
-  FBGRA := TBGRABitmap.Create(Width, Height, BGRAPixelTransparent);
+  FBGRA := nil;
 
 
   FBorderColor := clWindowText;
   FBorderColor := clWindowText;
   FBorderOpacity := 255;
   FBorderOpacity := 255;