Ignore:
Timestamp:
Jun 25, 2020, 10:24:44 PM (4 years ago)
Author:
chronos
Message:
  • Fixed: Scaling IsoEngine ForgOfWar sprites.
  • Fixed: PopupMenu position calculated using not scaled GetSystemMetrics.
  • Fixed: Scale TDpiBitmaps using normal scaling functions to get pixels on valid expected possition.
  • Fixed: DpiBitBlt needs to be executed as StretchDraw for non-integer pixel scaling. This leads to slower drawing.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/Packages/DpiControls/UDpiControls.pas

    r255 r265  
    88  {$IFDEF WINDOWS}Windows, {$ENDIF}Classes, SysUtils, LCLProc, LResources, Forms, FormEditingIntf, ProjectIntf,
    99  Controls, StdCtrls, fgl, Graphics, ComCtrls, ExtCtrls, LCLType, GraphType,
    10   Types, CustApp, LMessages, LCLIntf, Menus, Math;
     10  Types, CustApp, LMessages, LCLIntf, Menus, Math, UPixelPointer2;
    1111
    1212type
     
    953953  const lprcClip:TRect; hrgnUpdate: Handle; lprcUpdate: PRect): Boolean;
    954954function ScaleToNative(Value: Integer): Integer;
     955function ScaleToNativeDist(Base, Value: Integer): Integer;
    955956function ScaleFromNative(Value: Integer): Integer;
    956957function ScalePointToNative(Value: TPoint): TPoint;
     
    963964function ScaleFloatFromNative(Value: Double): Double;
    964965procedure WriteLog(Text: string);
     966function DpiGetSystemMetrics(nIndex: Integer): Integer;
    965967
    966968implementation
     
    10291031end;
    10301032
     1033function ScaleToNativeDist(Base, Value: Integer): Integer;
     1034begin
     1035  Result := ScaleToNative(Base + Value) - ScaleToNative(Base);
     1036end;
     1037
    10311038function ScaleFromNative(Value: Integer): Integer;
    10321039begin
     
    10961103end;
    10971104
     1105function DpiGetSystemMetrics(nIndex: Integer): Integer;
     1106begin
     1107  Result := ScaleFromNative(GetSystemMetrics(nIndex));
     1108end;
     1109
    10981110function DpiBitBlt(DestDC: HDC; X, Y, Width, Height: Integer; SrcDC: HDC; XSrc,
    10991111  YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean;
     1112var
     1113  DstWidth, DstHeight: Integer;
     1114  SrcWidth, SrcHeight: Integer;
    11001115begin
    11011116  {$IFDEF WINDOWS}
     
    11051120    ScaleToNative(XSrc), ScaleToNative(YSrc), Rop);
    11061121  {$ELSE}
    1107   Result := BitBlt(DestDC, ScaleToNative(X), ScaleToNative(Y),
     1122
     1123
     1124  DstWidth := ScaleToNativeDist(X, Width);
     1125  DstHeight := ScaleToNativeDist(Y, Height);
     1126  SrcWidth := ScaleToNativeDist(XSrc, Width);
     1127  SrcHeight := ScaleToNativeDist(YSrc, Height);
     1128  if (DstWidth = SrcWidth) and (DstHeight = SrcHeight) then begin
     1129    Result := BitBlt(DestDC, ScaleToNative(X), ScaleToNative(Y),
     1130      DstWidth, DstHeight, SrcDC,
     1131      ScaleToNative(XSrc), ScaleToNative(YSrc), Rop);
     1132  end else begin
     1133    Result := StretchBlt(DestDC, ScaleToNative(X), ScaleToNative(Y),
     1134      DstWidth, DstHeight, SrcDC,
     1135      ScaleToNative(XSrc), ScaleToNative(YSrc),
     1136      SrcWidth, SrcHeight, Rop);
     1137  end;
     1138
     1139{  Result := BitBlt(DestDC, ScaleToNative(X), ScaleToNative(Y),
    11081140    ScaleToNative(Width), ScaleToNative(Height), SrcDC,
    11091141    ScaleToNative(XSrc), ScaleToNative(YSrc), Rop);
     1142 }
    11101143  {$ENDIF}
    11111144end;
     
    18861919end;
    18871920
     1921procedure StretchDrawBitmap(Src: TRasterImage; Dst: TBitmap);
     1922var
     1923  SrcPtr: TPixelPointer;
     1924  DstPtr: TPixelPointer;
     1925  xx, yy: Integer;
     1926  SrcX, SrcY: Integer;
     1927  DstX, DstY: Integer;
     1928  DstWidth, DstHeight: Integer;
     1929begin
     1930  Dst.BeginUpdate;
     1931  SrcPtr := PixelPointer(Src, 0, 0);
     1932  DstPtr := PixelPointer(Dst, 0, 0);
     1933  {for yy := 0 to Dst.Height - 1 do begin
     1934    for xx := 0 to Dst.Width - 1 do begin
     1935      SrcPtr.SetXY(Min(ScaleFromNative(xx), Src.Width - 1),
     1936        Min(ScaleFromNative(yy), Src.Height - 1));
     1937      DstPtr.Pixel^.B := SrcPtr.Pixel^.B;
     1938      DstPtr.Pixel^.G := SrcPtr.Pixel^.G;
     1939      DstPtr.Pixel^.R := SrcPtr.Pixel^.R;
     1940      DstPtr.NextPixel;
     1941    end;
     1942    DstPtr.NextLine;
     1943  end;
     1944  }
     1945  for SrcY := 0 to Src.Height - 1 do begin
     1946    DstHeight := ScaleToNative(SrcY + 1) - ScaleToNative(SrcY);
     1947    for DstY := 0 to DstHeight - 1 do begin
     1948      for SrcX := 0 to Src.Width - 1 do begin
     1949        DstWidth := ScaleToNative(SrcX + 1) - ScaleToNative(SrcX);
     1950        for DstX := 0 to DstWidth - 1 do begin
     1951          DstPtr.Pixel^.B := SrcPtr.Pixel^.B;
     1952          DstPtr.Pixel^.G := SrcPtr.Pixel^.G;
     1953          DstPtr.Pixel^.R := SrcPtr.Pixel^.R;
     1954          DstPtr.NextPixel;
     1955        end;
     1956        SrcPtr.NextPixel;
     1957      end;
     1958      DstPtr.NextLine;
     1959      SrcPtr.SetX(0);
     1960    end;
     1961    SrcPtr.NextLine;
     1962  end;
     1963  Dst.EndUpdate;
     1964end;
     1965
    18881966procedure TDpiGraphic.LoadFromFile(const Filename: string);
    18891967var
     
    18941972  Width := Bitmap.Width;
    18951973  Height := Bitmap.Height;
    1896   if Self is TDpiBitmap then
    1897     TBitmap(GetNativeGraphic).Canvas.StretchDraw(Bounds(0, 0,
    1898     TBitmap(GetNativeGraphic).Width, TBitmap(GetNativeGraphic).Height), Bitmap)
    1899     else raise Exception.Create('Unsupported class ' + Self.ClassName);
     1974  if Self is TDpiBitmap then begin
     1975    StretchDrawBitmap(TRasterImage(Bitmap), TBitmap(GetNativeGraphic));
     1976    //TBitmap(GetNativeGraphic).Canvas.StretchDraw(Bounds(0, 0,
     1977    //TBitmap(GetNativeGraphic).Width, TBitmap(GetNativeGraphic).Height), Bitmap);
     1978  end else raise Exception.Create('Unsupported class ' + Self.ClassName);
    19001979  Bitmap.Free;
    19011980end;
     
    28062885begin
    28072886  //Dpi := 96 * 2; //Screen.PixelsPerInch;
    2808   //Dpi := 144; //Round(96 * 1.25)
     2887  //Dpi := Round(96 * 1.35);
     2888  //Dpi := 144; //Round(96 * 2);
    28092889  //Dpi := Round(96 * 1.6);
    28102890  Dpi := Screen.PixelsPerInch;
Note: See TracChangeset for help on using the changeset viewer.