소스 검색

retina scale volatile scrollbar

Johann ELSASS 4 년 전
부모
커밋
add8d84836
6개의 변경된 파일38개의 추가작업 그리고 22개의 파일을 삭제
  1. 1 0
      lazpaint/dialog/ulayerstackinterface.pas
  2. 0 2
      lazpaint/lazpaintinstance.pas
  3. 1 0
      lazpaint/uimagepreview.pas
  4. 8 8
      lazpaint/umyslv.pas
  5. 15 4
      lazpaint/upalettetoolbar.pas
  6. 13 8
      lazpaint/uvolatilescrollbar.pas

+ 1 - 0
lazpaint/dialog/ulayerstackinterface.pas

@@ -166,6 +166,7 @@ end;
 procedure TLayerStackInterface.BGRALayerStack_Redraw(Sender: TObject;
   Bitmap: TBGRABitmap);
 begin
+  TVolatileScrollBar.InitDPI((Sender as TControl).GetCanvasScaleFactor);
   DrawLayerStack(Bitmap, not FPartialRedraw, -1);
 end;
 

+ 0 - 2
lazpaint/lazpaintinstance.pas

@@ -430,8 +430,6 @@ end;
 
 procedure TLazPaintInstance.Init(AEmbedded: boolean);
 begin
-  TVolatileScrollBar.InitDPI;
-
   Title := 'LazPaint ' + LazPaintCurrentVersion;
   FCustomImageList := TImageListList.Create;
   FTopMostInfo.choosecolorHidden := 0;

+ 1 - 0
lazpaint/uimagepreview.pas

@@ -140,6 +140,7 @@ end;
 procedure TImagePreview.SurfaceRedraw(Sender: TObject; Bitmap: TBGRABitmap);
 begin
   FScaling := FSurface.GetCanvasScaleFactor;
+  TVolatileScrollBar.InitDPI(FScaling);
   FSurfaceScaledHeight := Bitmap.Height;
   if (Bitmap.Width = 0) or (Bitmap.Height = 0) then
   begin

+ 8 - 8
lazpaint/umyslv.pas

@@ -539,15 +539,9 @@ var
       FVScrollBar := TVolatileScrollBar.Create(w-VolatileScrollBarSize,textHeight,
          VolatileScrollBarSize,h-textHeight,sbVertical,FVerticalScrollPos,0,maxScroll);
     end;
-    if Assigned(FVScrollBar) then
-    begin
-      FVScrollBar.Draw(ABitmap);
-      clientArea := rect(0,textHeight,w-VolatileScrollBarSize,h);
-    end else
-    begin
-      clientArea := rect(0,textHeight,w,h);
+    if not Assigned(FVScrollBar) then
       FVerticalScrollPos:= 0;
-    end;
+    clientArea := rect(0,textHeight,w,h);
     FItemsPerPage:= Size(clientArea).cy div FActualRowHeight;
 
     setlength(colPos,ColumnCount+1);
@@ -603,6 +597,10 @@ var
       inc(curY, FActualRowHeight);
       inc(row);
     end;
+    ABitmap.NoClip;
+
+    if Assigned(FVScrollBar) then
+      FVScrollBar.Draw(ABitmap);
   end;
 
   procedure DrawIcons;
@@ -692,6 +690,8 @@ var
 var i: integer;
 
 begin
+  TVolatileScrollBar.InitDPI((Sender as TControl).GetCanvasScaleFactor);
+
   if SelectedIndex = -1 then FKeySelectionRangeStart := -1
   else if FKeySelectionRangeStart = -1 then FKeySelectionRangeStart:= SelectedIndex;
   for i := 0 to ColumnCount-1 do

+ 15 - 4
lazpaint/upalettetoolbar.pas

@@ -45,6 +45,7 @@ type
     FLazPaintInstance: TLazPaintCustomInstance;
     FOnVisibilityChangedByUser: TPaletteVisibilityChangedByUserHandler;
     FPanelPalette: TBGRAVirtualScreen;
+    FCanvasScale: single;
     FVisible: boolean;
     FScrollbar: TVolatileScrollBar;
     FScrollPos: integer;
@@ -132,6 +133,8 @@ end;
 procedure TPaletteToolbar.PanelMouseDown(Sender: TObject; Button: TMouseButton;
   Shift: TShiftState; X, Y: Integer);
 begin
+  X := round(X*FCanvasScale);
+  Y := round(Y*FCanvasScale);
   if (Button = mbLeft) and Assigned(FScrollbar) then
   begin
     if FScrollbar.MouseDown(X,Y) then
@@ -147,6 +150,8 @@ end;
 procedure TPaletteToolbar.PanelMouseMove(Sender: TObject; Shift: TShiftState;
   X, Y: Integer);
 begin
+  X := round(X*FCanvasScale);
+  Y := round(Y*FCanvasScale);
   if Assigned(FScrollbar) then
   begin
     if FScrollbar.MouseMove(X,Y) then
@@ -166,6 +171,8 @@ end;
 procedure TPaletteToolbar.PanelMouseUp(Sender: TObject; Button: TMouseButton;
   Shift: TShiftState; X, Y: Integer);
 begin
+  X := round(X*FCanvasScale);
+  Y := round(Y*FCanvasScale);
   if (Button = mbLeft) and Assigned(FScrollbar) then
   begin
     if FScrollbar.MouseUp(X,Y) then
@@ -481,6 +488,7 @@ begin
     FPanelPalette.OnMouseDown:=@PanelMouseDown;
     FPanelPalette.OnMouseUp:=@PanelMouseUp;
     FPanelPalette.OnMouseMove:=@PanelMouseMove;
+    FPanelPalette.BitmapAutoScale:= false;
     ApplyTheme;
     FPanelPalette.Caption := '';
     FColors := TBGRAPalette.Create;
@@ -730,6 +738,9 @@ var i,x,y,w,aw,a,h: integer;
   nbVisible, maxScroll, availHeight: integer;
   clInterm, cSign: TBGRAPixel;
 begin
+  FCanvasScale := (Sender as TControl).GetCanvasScaleFactor;
+  TVolatileScrollBar.InitDPI(FCanvasScale);
+
   if DarkTheme then
   begin
     clInterm := MergeBGRA(ColorToBGRA(clDarkBtnFace),ColorToBGRA(clLightText));
@@ -739,11 +750,11 @@ begin
   else
     clInterm := MergeBGRA(ColorToBGRA(ColorToRGB(clBtnFace)),ColorToBGRA(ColorToRGB(clBtnText)));
 
-  x := 2;
-  y := FMenuButton.Top+FMenuButton.Height+1;
+  x := round(2*FCanvasScale);
+  y := round((FMenuButton.Top+FMenuButton.Height+1)*FCanvasScale);
   w := Bitmap.Width-(VolatileScrollBarSize+1)-x;
-  aw := DoScaleX(FPaletteAlphaWidth, OriginalDPI);
-  h := DoScaleY(FPaletteItemHeight, OriginalDPI);
+  aw := DoScaleX(round(FPaletteAlphaWidth*FCanvasScale), OriginalDPI);
+  h := DoScaleY(round(FPaletteItemHeight*FCanvasScale), OriginalDPI);
   if h < 3 then h := 3;
   availHeight := Bitmap.Height - 2 - y - 1;
   nbVisible := availHeight div (h-1);

+ 13 - 8
lazpaint/uvolatilescrollbar.pas

@@ -8,10 +8,15 @@ interface
 uses
   Classes, SysUtils, Forms, BGRABitmap, BGRAGradients;
 
+const
+  OrigVolatileScrollBarSize = 14;
+  OrigVolatileThumbSize = 24;
+  OrigVolatileBorderSize = 3;
+
 var
-  VolatileScrollBarSize : integer = 14;
-  VolatileThumbSize : integer = 24;
-  VolatileBorderSize : integer = 3;
+  VolatileScrollBarSize : integer = OrigVolatileScrollBarSize;
+  VolatileThumbSize : integer = OrigVolatileThumbSize;
+  VolatileBorderSize : integer = OrigVolatileBorderSize;
 
 type
   TScrollBarKind = Forms.TScrollBarKind;
@@ -42,7 +47,7 @@ type
   public
     constructor Create(X,Y,AWidth,AHeight: integer; ADirection: TScrollBarKind; APosition, AMinimum, AMaximum: integer);
     destructor Destroy; override;
-    class procedure InitDPI;
+    class procedure InitDPI(ACanvasScaleFactor: single);
     function MouseDown(X,Y: integer): boolean;
     function MouseMove(X,Y: integer): boolean;
     function MouseUp({%H-}X,{%H-}Y: integer): boolean;
@@ -208,13 +213,13 @@ begin
   FPhong.DrawRectangle(ADest,lThumb,VolatileBorderSize,h,ColorToBGRA(ColorToRGB(clBtnFace)),true,[]);
 end;
 
-class procedure TVolatileScrollBar.InitDPI;
+class procedure TVolatileScrollBar.InitDPI(ACanvasScaleFactor: single);
 begin
   if not FInitDPI then
   begin
-    VolatileScrollBarSize := ScaleX(VolatileScrollBarSize, OriginalDPI);
-    VolatileThumbSize := ScaleX(VolatileThumbSize, OriginalDPI);
-    VolatileBorderSize := ScaleX(VolatileBorderSize, OriginalDPI);
+    VolatileScrollBarSize := ScaleX(round(VolatileScrollBarSize * ACanvasScaleFactor), OriginalDPI);
+    VolatileThumbSize := ScaleX(round(VolatileThumbSize * ACanvasScaleFactor), OriginalDPI);
+    VolatileBorderSize := ScaleX(round(VolatileBorderSize * ACanvasScaleFactor), OriginalDPI);
     FInitDPI := true;
   end;
 end;