Prechádzať zdrojové kódy

Merge branch 'dev-lazpaint' of https://github.com/bgrabitmap/lazpaint into dev-lazpaint

lainz 4 rokov pred
rodič
commit
13db8c677a

+ 2 - 2
lazpaint/dialog/ubrowseimages.pas

@@ -271,8 +271,8 @@ begin
   ScaleImageList(ImageListToolbar, DoScaleX(32, OriginalDPI),
     DoScaleY(32, OriginalDPI), ImageListToolbar);
 
-  ScaleControl(Panel1, OriginalDPI);
-  ScaleControl(Panel2, OriginalDPI);
+  ScaleControl(Panel1, OriginalDPI, 0,0, true);
+  ScaleControl(Panel2, OriginalDPI, 0,0, true);
 
   DarkThemeInstance.Apply(ComboBox_FileExtension, False, 0.40);
   vsList.BitmapAutoScale:= false;

+ 63 - 13
lazpaint/lazpaintinstance.pas

@@ -277,7 +277,7 @@ uses LCLType, Types, Forms, Dialogs, FileUtil, StdCtrls, LCLIntf, BGRAUTF8, UTra
      USharpen, uposterize, UPhongFilter, UFilterFunction,
      uprint, USaveOption, UFormRain,
 
-     ugraph, LCScaleDPI, ucommandline, uabout, UPython;
+     ugraph, LCScaleDPI, ucommandline, uabout, UPython, BGRAGraphics;
 
 { TLazPaintInstance }
 
@@ -1250,37 +1250,87 @@ begin
 end;
 
 function TLazPaintInstance.GetIcons(ASize: integer): TImageList;
-var
-  i: Integer;
-begin
-  if Assigned(FMain) then
-  begin
-    for i := 0 to FCustomImageList.Count-1 do
-      if FCustomImageList[i].Height = ASize then
-        exit(FCustomImageList[i]);
 
+  function GetUnscaledIcons(ASize: integer): TImageList;
+  begin
     if ASize < 24 then
     begin;
       if ASize = 16 then
-        result := FMain.ImageList16
+      begin
+        result := TImageList.Create(nil);
+        result.Assign(FMain.ImageList16);
+      end
       else
       begin
         result := TImageList.Create(nil);
         ScaleImageList(FMain.ImageList16, ASize,ASize, result);
-        FCustomImageList.Add(result);
       end;
     end
     else
     begin
       if ASize = 48 then
-        result := FMain.ImageList48
+      begin
+        result := TImageList.Create(nil);
+        result.Assign(FMain.ImageList48);
+      end
       else
       begin
         result := TImageList.Create(nil);
         ScaleImageList(FMain.ImageList48, ASize,ASize, result);
-        FCustomImageList.Add(result);
       end;
     end;
+  end;
+
+var
+  i: Integer;
+  {$IFDEF DARWIN}
+  retina, unscaled: TImageList;
+  bmpUnscaled, bmpRetina: TBitmap;
+  {$ENDIF}
+
+begin
+  if Assigned(FMain) then
+  begin
+    for i := 0 to FCustomImageList.Count-1 do
+      if FCustomImageList[i].Height = ASize then
+        exit(FCustomImageList[i]);
+
+    {$IFDEF DARWIN}
+    unscaled := GetUnscaledIcons(ASize);
+    retina := GetUnscaledIcons(ASize*2);
+    bmpUnscaled := TBitmap.Create;
+    bmpRetina := TBitmap.Create;
+
+    result := TImageList.Create(nil);
+    result.Width := ASize;
+    result.Height := ASize;
+    result.Scaled := true;
+    result.RegisterResolutions([ASize, ASize*2]);
+    for i := 0 to unscaled.Count-1 do
+    begin
+      unscaled.GetBitmap(i, bmpUnscaled);
+      retina.GetBitmap(i, bmpRetina);
+      result.AddMultipleResolutions([bmpUnscaled, bmpRetina]);
+    end;
+
+    bmpUnscaled.Free;
+    bmpRetina.Free;
+    unscaled.Free;
+    retina.Free;
+    {$ELSE}
+    if ASize = 16 then
+    begin
+      result := FMain.ImageList16;
+      exit
+    end else
+    if ASize = 48 then
+    begin
+      result := FMain.ImageList48;
+      exit;
+    end else
+      result := GetUnscaledIcons(ASize);
+    {$ENDIF}
+    FCustomImageList.Add(result);
   end else
     result := nil;
 end;

+ 1 - 1
lazpaint/lazpaintmainform.pas

@@ -862,7 +862,7 @@ uses LCLIntf, BGRAUTF8, ugraph, math, umac, uclipboard, ucursors,
    ufilters, ULoadImage, ULoading, UFileExtensions, UBrushType,
    ugeometricbrush, UPreviewDialog, UQuestion, BGRALayerOriginal,
    BGRATransform, LCVectorPolyShapes, URaw, UFileSystem,
-   UTranslation, UPython;
+   UTranslation, UPython, BCTypes;
 
 const PenWidthFactor = 10;
 

+ 4 - 0
lazpaint/maintoolbar.inc

@@ -65,15 +65,18 @@ begin
   ComboBox_ArrowStart.OnChange := @ComboBox_ArrowStartChange;
   ComboBox_ArrowStart.OnDrawItem := @ComboBox_ArrowStartDrawItem;
   ComboBox_ArrowStart.OnDrawSelectedItem := @ComboBox_ArrowStartDrawSelectedItem;
+  ComboBox_ArrowStart.CanvasScaleMode:= csmFullResolution;
   ComboBox_ArrowEnd.OnChange := @ComboBox_ArrowEndChange;
   ComboBox_ArrowEnd.OnDrawItem := @ComboBox_ArrowEndDrawItem;
   ComboBox_ArrowEnd.OnDrawSelectedItem := @ComboBox_ArrowEndDrawSelectedItem;
+  ComboBox_ArrowEnd.CanvasScaleMode:= csmFullResolution;
   Tool_JoinBevel.OnClick := @Tool_JoinBevelClick;
   Tool_JoinRound.OnClick := @Tool_JoinRoundClick;
   Tool_JoinMiter.OnClick := @Tool_JoinMiterClick;
   ComboBox_PenStyle.OnChange:=@ComboBox_PenStyleChange;
   ComboBox_PenStyle.OnDrawItem:=@ComboBox_PenStyleDrawItem;
   ComboBox_PenStyle.OnDrawSelectedItem:=@ComboBox_PenStyleDrawSelectedItem;
+  ComboBox_PenStyle.CanvasScaleMode:= csmFullResolution;
   for ps := psSolid to psDashDotDot do ComboBox_PenStyle.Items.Add(inttostr(ord(ps)));
   Tool_GridMoveWithoutDeformation.OnClick := @Tool_GridMoveWithoutDeformationClick;
   Combo_SplineStyle.Items.Add('Inside');
@@ -115,6 +118,7 @@ begin
   ComboBox_BrushSelect.OnChange := @ComboBox_BrushSelectChange;
   ComboBox_BrushSelect.OnDrawItem := @ComboBox_BrushSelectDrawItem;
   ComboBox_BrushSelect.OnDrawSelectedItem:= @ComboBox_BrushSelectDrawSelectedItem;
+  ComboBox_BrushSelect.CanvasScaleMode:= csmFullResolution;
   Combo_Ratio.OnChange := @Combo_RatioChange;
 
   Panel_LineCap_FullSize := Panel_LineCap.Width;

+ 9 - 5
lazpaint/ugraph.pas

@@ -792,6 +792,7 @@ procedure DrawPenStyle(AComboBox: TBCComboBox; ARect: TRect;
   APenStyle: TPenStyle; State: TOwnerDrawState);
 var bmp : TBGRABitmap;
   c,c2: TBGRAPixel;
+  scale: Double;
 begin
   if odSelected in State then
   begin
@@ -803,9 +804,10 @@ begin
     c := ColorToBGRA(AComboBox.DropDownFontColor);
     c2 := ColorToBGRA(AComboBox.DropDownColor);
   end;
-  with Size(ARect) do bmp := TBGRABitmap.Create(cx,cy,c2);
-  DrawPenStyle(bmp, rect(0,0,ARect.Width,ARect.Height),APenStyle, c);
-  bmp.Draw(ACombobox.Canvas,ARect.Left,ARect.Top,true);
+  scale := AComboBox.GetCanvasScaleFactor;
+  with Size(ARect) do bmp := TBGRABitmap.Create(round(cx*scale),round(cy*scale),c2);
+  DrawPenStyle(bmp, bmp.ClipRect,APenStyle, c);
+  bmp.Draw(ACombobox.Canvas,ARect,true);
   bmp.Free;
 end;
 
@@ -821,6 +823,7 @@ end;
 procedure DrawArrow(AComboBox: TBCComboBox; ARect: TRect; AStart: boolean; AKindStr: string; ALineCap: TPenEndCap; State: TOwnerDrawState);
 var mask, bmp : TBGRABitmap;
   c,c2: TBGRAPixel;
+  scale: Double;
 begin
   if odSelected in State then
   begin
@@ -831,11 +834,12 @@ begin
     c2 := ColorToBGRA(AComboBox.DropDownColor);
     c := ColorToBGRA(AComboBox.DropDownFontColor);
   end;
-  with Size(ARect) do mask:= TBGRABitmap.Create(cx,cy,BGRABlack);
+  scale := AComboBox.GetCanvasScaleFactor;
+  with Size(ARect) do mask:= TBGRABitmap.Create(round(cx*scale),round(cy*scale),BGRABlack);
   DrawArrowMask(mask, AStart, AKindStr, ALineCap);
   bmp := TBGRABitmap.Create(mask.Width,mask.Height,c2);
   bmp.FillMask(0,0,mask,c,dmDrawWithTransparency);
-  bmp.Draw(ACombobox.Canvas,ARect.Left,ARect.Top,true);
+  bmp.Draw(ACombobox.Canvas,ARect,true);
   bmp.Free;
   mask.Free;
 end;

+ 8 - 3
lazpaintcontrols/lcscaledpi.pas

@@ -9,7 +9,8 @@ uses
   Forms, Graphics, Controls, ComCtrls;
 
 procedure ScaleForms(FromDPI: Integer);
-procedure ScaleControl(Control: TControl; FromDPI: Integer; ToDPI_X: Integer = 0; ToDPI_Y: Integer = 0);
+procedure ScaleControl(Control: TControl; FromDPI: Integer;
+  ToDPI_X: Integer = 0; ToDPI_Y: Integer = 0; ScaleToolbar: boolean = false);
 procedure ScaleImageList(SourceList: TImageList; newWidth, newHeight: Integer; TargetList: TImageList);
 function DoScaleX(Size: Integer; FromDPI: Integer; ToDPI: Integer = 0): integer;
 function DoScaleY(Size: Integer; FromDPI: Integer; ToDPI: Integer = 0): integer;
@@ -104,7 +105,8 @@ begin
     Result := Size * ToDPI / FromDPI;
 end;
 
-procedure ScaleControl(Control: TControl; FromDPI: Integer; ToDPI_X: Integer; ToDPI_Y: integer);
+procedure ScaleControl(Control: TControl; FromDPI: Integer; ToDPI_X: Integer; ToDPI_Y: integer;
+  ScaleToolbar: boolean = false);
 var
   n: Integer;
   WinControl: TWinControl;
@@ -129,11 +131,13 @@ begin
   end;
 
   if Control is TToolBar then begin
+    if not ScaleToolbar then exit;
     ToolBarControl:=TToolBar(Control);
     with ToolBarControl do begin
       ButtonWidth:=DoScaleX(ButtonWidth,FromDPI,ToDPI_X);
       ButtonHeight:=DoScaleY(ButtonHeight,FromDPI,ToDPI_Y);
     end;
+    exit;
   end;
 
   if Control is TWinControl then begin
@@ -148,7 +152,8 @@ begin
     if WinControl.ControlCount > 0 then begin
       for n:=0 to WinControl.ControlCount-1 do begin
         if WinControl.Controls[n] is TControl then begin
-          ScaleControl(WinControl.Controls[n],FromDPI,ToDPI_X,ToDPI_Y);
+          ScaleControl(WinControl.Controls[n],FromDPI,ToDPI_X,ToDPI_Y,
+            ScaleToolbar);
         end;
       end;
     end;