Changeset 552 for trunk/Packages
- Timestamp:
- Apr 24, 2024, 10:28:34 AM (7 months ago)
- Location:
- trunk/Packages/DpiControls
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/DpiControls/Dpi.Common.pas
r547 r552 15 15 XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean; 16 16 function BitBltBitmap(Dest: TBitmap; X, Y, Width, Height: Integer; Src: TBitmap; 17 XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY ): Boolean;17 XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY; Precise: Boolean = False): Boolean; 18 18 function CreateRectRgn(X1, Y1, X2, Y2: Integer): HRGN; 19 19 {$IFDEF WINDOWS} … … 56 56 57 57 function BitBltBitmap(Dest: TBitmap; X, Y, Width, Height: Integer; 58 Src: TBitmap; XSrc, YSrc: Integer; Rop: DWORD): Boolean; 58 Src: TBitmap; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY; 59 Precise: Boolean = False): Boolean; 59 60 var 60 61 SrcPixel: TPixelPointer; … … 65 66 NewX, NewY: Integer; 66 67 begin 67 if Frac(ScreenInfo.Dpi / 96) = 0 then 68 begin 68 if not Precise or (Frac(ScreenInfo.Dpi / 96) = 0) then begin 69 69 // Use faster non-fractional scaling 70 70 Result := BitBlt(Dest.Canvas.Handle, X, Y, Width, Height, Src.Canvas.Handle, … … 238 238 function ScaleToNative(Value: Integer): Integer; 239 239 begin 240 // Round function is faster than Ceil and Floor 241 Result := Round(Value * ScreenInfo.ToNative); 240 Result := ScreenInfo.Lookup[Value]; 241 // Round and Trunc are fast. Ceil and Floor slow. 242 // Without lookup table we would use: 243 // Result := Ceil(Value * ScreenInfo.ToNative); 242 244 end; 243 245 … … 249 251 function ScaleFromNative(Value: Integer): Integer; 250 252 begin 251 Result := Floor(Value * ScreenInfo.FromNative);253 Result := Trunc(Value * ScreenInfo.FromNative); 252 254 end; 253 255 -
trunk/Packages/DpiControls/Dpi.Graphics.pas
r548 r552 4 4 5 5 uses 6 Classes, SysUtils, Graphics, LCLType, GraphType, Types;6 Classes, SysUtils, Math, Graphics, LCLType, GraphType, Types; 7 7 8 8 const … … 347 347 ToNative: Double; 348 348 FromNative: Double; 349 Lookup: array[-10000..10000] of Integer; // Should be sufficient for 8K screens 349 350 property Dpi: Integer read FDpi write SetDpi; 350 351 end; … … 1322 1323 1323 1324 procedure TScreenInfo.SetDpi(AValue: Integer); 1325 var 1326 I: Integer; 1324 1327 begin 1325 1328 if FDpi = AValue then Exit; … … 1327 1330 ToNative := ScreenInfo.Dpi / 96; 1328 1331 FromNative := 96 / ScreenInfo.Dpi; 1332 for I := -10000 to 10000 do 1333 Lookup[I] := Ceil(I * ToNative); 1329 1334 end; 1330 1335
Note:
See TracChangeset
for help on using the changeset viewer.