Changeset 265 for branches/highdpi/Packages/DpiControls/UDpiControls.pas
- Timestamp:
- Jun 25, 2020, 10:24:44 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/DpiControls/UDpiControls.pas
r255 r265 8 8 {$IFDEF WINDOWS}Windows, {$ENDIF}Classes, SysUtils, LCLProc, LResources, Forms, FormEditingIntf, ProjectIntf, 9 9 Controls, StdCtrls, fgl, Graphics, ComCtrls, ExtCtrls, LCLType, GraphType, 10 Types, CustApp, LMessages, LCLIntf, Menus, Math ;10 Types, CustApp, LMessages, LCLIntf, Menus, Math, UPixelPointer2; 11 11 12 12 type … … 953 953 const lprcClip:TRect; hrgnUpdate: Handle; lprcUpdate: PRect): Boolean; 954 954 function ScaleToNative(Value: Integer): Integer; 955 function ScaleToNativeDist(Base, Value: Integer): Integer; 955 956 function ScaleFromNative(Value: Integer): Integer; 956 957 function ScalePointToNative(Value: TPoint): TPoint; … … 963 964 function ScaleFloatFromNative(Value: Double): Double; 964 965 procedure WriteLog(Text: string); 966 function DpiGetSystemMetrics(nIndex: Integer): Integer; 965 967 966 968 implementation … … 1029 1031 end; 1030 1032 1033 function ScaleToNativeDist(Base, Value: Integer): Integer; 1034 begin 1035 Result := ScaleToNative(Base + Value) - ScaleToNative(Base); 1036 end; 1037 1031 1038 function ScaleFromNative(Value: Integer): Integer; 1032 1039 begin … … 1096 1103 end; 1097 1104 1105 function DpiGetSystemMetrics(nIndex: Integer): Integer; 1106 begin 1107 Result := ScaleFromNative(GetSystemMetrics(nIndex)); 1108 end; 1109 1098 1110 function DpiBitBlt(DestDC: HDC; X, Y, Width, Height: Integer; SrcDC: HDC; XSrc, 1099 1111 YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean; 1112 var 1113 DstWidth, DstHeight: Integer; 1114 SrcWidth, SrcHeight: Integer; 1100 1115 begin 1101 1116 {$IFDEF WINDOWS} … … 1105 1120 ScaleToNative(XSrc), ScaleToNative(YSrc), Rop); 1106 1121 {$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), 1108 1140 ScaleToNative(Width), ScaleToNative(Height), SrcDC, 1109 1141 ScaleToNative(XSrc), ScaleToNative(YSrc), Rop); 1142 } 1110 1143 {$ENDIF} 1111 1144 end; … … 1886 1919 end; 1887 1920 1921 procedure StretchDrawBitmap(Src: TRasterImage; Dst: TBitmap); 1922 var 1923 SrcPtr: TPixelPointer; 1924 DstPtr: TPixelPointer; 1925 xx, yy: Integer; 1926 SrcX, SrcY: Integer; 1927 DstX, DstY: Integer; 1928 DstWidth, DstHeight: Integer; 1929 begin 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; 1964 end; 1965 1888 1966 procedure TDpiGraphic.LoadFromFile(const Filename: string); 1889 1967 var … … 1894 1972 Width := Bitmap.Width; 1895 1973 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); 1900 1979 Bitmap.Free; 1901 1980 end; … … 2806 2885 begin 2807 2886 //Dpi := 96 * 2; //Screen.PixelsPerInch; 2808 //Dpi := 144; //Round(96 * 1.25) 2887 //Dpi := Round(96 * 1.35); 2888 //Dpi := 144; //Round(96 * 2); 2809 2889 //Dpi := Round(96 * 1.6); 2810 2890 Dpi := Screen.PixelsPerInch;
Note:
See TracChangeset
for help on using the changeset viewer.