2
0
Эх сурвалжийг харах

retina scaling for resample form

Johann ELSASS 5 жил өмнө
parent
commit
eb6cf44234

+ 20 - 12
lazpaint/dialog/uresample.pas

@@ -54,7 +54,7 @@ function ShowResampleDialog(Instance: TLazPaintCustomInstance; AParameters: TVar
 
 
 implementation
 implementation
 
 
-uses BGRABitmapTypes, umac, uimage;
+uses ugraph, BGRABitmapTypes, umac, uimage;
 
 
 { TFResample }
 { TFResample }
 
 
@@ -83,6 +83,7 @@ procedure TFResample.FormCreate(Sender: TObject);
 begin
 begin
   FIgnoreInput := true;
   FIgnoreInput := true;
   ScaleControl(Self,OriginalDPI);
   ScaleControl(Self,OriginalDPI);
+  vsPreview.BitmapAutoScale:= false;
 
 
   SpinEdit_Width.MaxValue := MaxImageWidth;
   SpinEdit_Width.MaxValue := MaxImageWidth;
   SpinEdit_Height.MaxValue := MaxImageHeight;
   SpinEdit_Height.MaxValue := MaxImageHeight;
@@ -200,10 +201,12 @@ end;
 procedure TFResample.vsPreviewRedraw(Sender: TObject; Bitmap: TBGRABitmap);
 procedure TFResample.vsPreviewRedraw(Sender: TObject; Bitmap: TBGRABitmap);
 var
 var
   tx,ty,px,py,x,y,px2,py2,x2,y2: NativeInt;
   tx,ty,px,py,x,y,px2,py2,x2,y2: NativeInt;
-  ratio,zoom: double;
+  ratio,zoom,scaling: double;
   deltaX: NativeInt;
   deltaX: NativeInt;
 begin
 begin
-  deltaX := vsPreview.Width-vsPreview.Height;
+  scaling := DoScaleX(60, OriginalDPI)/60 * GetCanvasScaleFactor;
+
+  deltaX := Bitmap.Width-Bitmap.Height;
   if deltaX < 0 then deltaX := 0;
   if deltaX < 0 then deltaX := 0;
   tx := NewWidth;
   tx := NewWidth;
   ty := NewHeight;
   ty := NewHeight;
@@ -212,31 +215,36 @@ begin
   if (tx > 0) and (ty > 0) then
   if (tx > 0) and (ty > 0) then
   begin
   begin
     ratio := tx/ty;
     ratio := tx/ty;
-    if (vsPreview.Width-deltaX)/ratio < vsPreview.Height then
-      zoom := (vsPreview.Width-deltaX)/tx
+    if (Bitmap.Width-deltaX)/ratio < Bitmap.Height then
+      zoom := (Bitmap.Width-deltaX)/tx
     else
     else
-      zoom := vsPreview.height/ty;
+      zoom := Bitmap.height/ty;
 
 
     px := round(NewWidth*zoom);
     px := round(NewWidth*zoom);
     py := round(NewHeight*zoom);
     py := round(NewHeight*zoom);
-    x := vsPreview.Width-px;
-    y := (vsPreview.height-py) div 2;
+    if px < 1 then px := 1;
+    if py < 1 then py := 1;
+    x := Bitmap.Width-px;
+    y := (Bitmap.height-py) div 2;
 
 
     px2 := round(LazPaintInstance.Image.Width*zoom);
     px2 := round(LazPaintInstance.Image.Width*zoom);
     py2 := round(LazPaintInstance.Image.Height*zoom);
     py2 := round(LazPaintInstance.Image.Height*zoom);
     x2 := 0;
     x2 := 0;
-    y2 := (vsPreview.height-py2) div 2;
+    y2 := (Bitmap.height-py2) div 2;
 
 
     if (px = 1) or (py = 1) then
     if (px = 1) or (py = 1) then
       Bitmap.FillRect(x,y,x+px,y+py,BGRA(0,0,0,192),dmDrawWithTransparency)
       Bitmap.FillRect(x,y,x+px,y+py,BGRA(0,0,0,192),dmDrawWithTransparency)
     else
     else
-      Bitmap.Rectangle(x,y,x+px,y+py,BGRA(0,0,0,192),BGRA(255,255,255,192),dmDrawWithTransparency);
+    begin
+      Bitmap.Rectangle(x,y,x+px,y+py,BGRA(0,0,0,192),dmDrawWithTransparency);
+      DrawCheckers(Bitmap, rect(x+1,y+1,x+px-1,y+py-1), scaling);
+    end;
     Bitmap.StretchPutImage(rect(x,y,x+px,y+py),LazPaintInstance.Image.RenderedImage,dmDrawWithTransparency);
     Bitmap.StretchPutImage(rect(x,y,x+px,y+py),LazPaintInstance.Image.RenderedImage,dmDrawWithTransparency);
 
 
     if (px2 = 1) or (py2 = 1) then
     if (px2 = 1) or (py2 = 1) then
-      Bitmap.DrawLineAntialias(x2,y2,x2+px2-1,y2+py2-1,BGRA(0,0,0,160),BGRA(255,255,255,160),1,True)
+      Bitmap.DrawLineAntialias(x2,y2,x2+px2-1,y2+py2-1,BGRA(0,0,0,160),BGRA(255,255,255,160),round(scaling),True)
     else
     else
-      Bitmap.DrawPolyLineAntialias([Point(x2,y2),Point(x2+px2-1,y2),Point(x2+px2-1,y2+py2-1),Point(x2,y2+py2-1),Point(x2,y2)],BGRA(0,0,0,160),BGRA(255,255,255,160),1,False);
+      Bitmap.DrawPolyLineAntialias([Point(x2,y2),Point(x2+px2-1,y2),Point(x2+px2-1,y2+py2-1),Point(x2,y2+py2-1),Point(x2,y2)],BGRA(0,0,0,160),BGRA(255,255,255,160),round(scaling),False);
     Bitmap.StretchPutImage(rect(x2,y2,x2+px2,y2+py2),LazPaintInstance.Image.RenderedImage,dmDrawWithTransparency,48);
     Bitmap.StretchPutImage(rect(x2,y2,x2+px2,y2+py2),LazPaintInstance.Image.RenderedImage,dmDrawWithTransparency,48);
   end;
   end;
 end;
 end;