- Timestamp:
- Jun 9, 2020, 12:43:25 AM (5 years ago)
- Location:
- branches/highdpi
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/LocalPlayer/Help.pas
r252 r255 477 477 ((y + ScaleToNative(dy)) shr 1 < ScaleToNative(nHeaven)) and 478 478 (ImpPtr[dy].Pixel^.B shl 16 + ImpPtr[dy].Pixel^.G shl 8 + 479 ImpPtr[dy].Pixel^.R = Heaven[(ScaleFromNative(y ) + dy) shr 1]) then479 ImpPtr[dy].Pixel^.R = Heaven[(ScaleFromNative(y + ScaleToNative(dy))) shr 1]) then 480 480 Sum := Sum + 9 * 255 481 481 else -
branches/highdpi/Packages/DpiControls/UDpiControls.pas
r254 r255 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 ;10 Types, CustApp, LMessages, LCLIntf, Menus, Math; 11 11 12 12 type … … 63 63 TDpiFont = class(TPersistent) 64 64 private 65 FNativeFont: TFont; 66 FNativeFontFree: Boolean; 65 67 FOnChange: TNotifyEvent; 66 68 FSize: Integer; … … 80 82 procedure SetHeight(AValue: Integer); 81 83 procedure SetName(AValue: string); 84 procedure SetNativeFont(AValue: TFont); 82 85 procedure SetOnChange(AValue: TNotifyEvent); 83 86 procedure SetPixelsPerInch(AValue: Integer); … … 90 93 function GetNativeFont: TFont; virtual; 91 94 public 92 NativeFont: TFont;95 property NativeFont: TFont read FNativeFont write SetNativeFont; 93 96 constructor Create; 94 97 destructor Destroy; override; … … 299 302 private 300 303 FFont: TDpiFont; 304 FFontFree: Boolean; 301 305 FNativeCanvas: TCanvas; 306 FNativeCanvasFree: Boolean; 302 307 function GetBrush: TBrush; 303 308 function GetHandle: HDC; … … 418 423 function GetNativeCustomControl: TCustomControl; virtual; 419 424 public 425 constructor Create(TheOwner: TComponent); override; 426 destructor Destroy; override; 420 427 property Canvas: TDpiCanvas read GetCanvas; 421 428 published … … 784 791 NativeJpeg: TJPEGImage; 785 792 constructor Create; override; 793 destructor Destroy; override; 786 794 end; 787 795 … … 795 803 NativePng: TPortableNetworkGraphic; 796 804 constructor Create; override; 805 destructor Destroy; override; 797 806 end; 798 807 … … 953 962 function ScaleFloatToNative(Value: Double): Double; 954 963 function ScaleFloatFromNative(Value: Double): Double; 955 964 procedure WriteLog(Text: string); 956 965 957 966 implementation … … 1001 1010 end; 1002 1011 1012 function Ceil(const X: Single): Integer; 1013 begin 1014 if X > High(Integer) then 1015 Result := High(Integer) 1016 else if X < Low(Integer) then 1017 Result := Low(Integer) 1018 else begin 1019 Result := Trunc(X); 1020 if (Result <> X) then begin 1021 if (Result > 0) then Inc(Result) else Dec(Result); 1022 end; 1023 end; 1024 end; 1025 1003 1026 function ScaleToNative(Value: Integer): Integer; 1004 1027 begin … … 1059 1082 begin 1060 1083 Result := Value * 96 / DpiScreen.Dpi; 1084 end; 1085 1086 procedure WriteLog(Text: string); 1087 var 1088 F: Text; 1089 const 1090 FileName = 'Log.txt'; 1091 begin 1092 AssignFile(F, FileName); 1093 if FileExists(FileName) then Append(F) else Rewrite(F); 1094 WriteLn(F, Text); 1095 CloseFile(F); 1061 1096 end; 1062 1097 … … 1330 1365 destructor TDpiMenuItem.Destroy; 1331 1366 begin 1367 FreeAndNil(NativeMenuItem); 1332 1368 FreeAndNil(FItems); 1333 1369 inherited Destroy; … … 1630 1666 function TDpiJpegImage.GetNativeJpeg: TJPEGImage; 1631 1667 begin 1632 if not Assigned(NativeJpeg) then NativeJpeg := TJPEGImage.Create;1633 1668 Result := NativeJpeg; 1634 1669 end; … … 1636 1671 constructor TDpiJpegImage.Create; 1637 1672 begin 1673 NativeJpeg := TJPEGImage.Create; 1638 1674 inherited; 1639 1675 NativeGraphicClass := TJPEGImage; 1640 1676 end; 1641 1677 1678 destructor TDpiJpegImage.Destroy; 1679 begin 1680 FreeAndNil(NativeJpeg); 1681 inherited Destroy; 1682 end; 1683 1642 1684 { TDpiPortableNetworkGraphic } 1643 1685 … … 1649 1691 function TDpiPortableNetworkGraphic.GetNativePng: TPortableNetworkGraphic; 1650 1692 begin 1651 if not Assigned(NativePng) then NativePng := TPortableNetworkGraphic.Create;1652 1693 Result := NativePng; 1653 1694 end; … … 1655 1696 constructor TDpiPortableNetworkGraphic.Create; 1656 1697 begin 1698 NativePng := TPortableNetworkGraphic.Create; 1657 1699 inherited; 1658 1700 NativeGraphicClass := TPortableNetworkGraphic; 1659 1701 end; 1660 1702 1703 destructor TDpiPortableNetworkGraphic.Destroy; 1704 begin 1705 Canvas.NativeCanvas := nil; 1706 FreeAndNil(NativePng); 1707 inherited; 1708 end; 1709 1661 1710 { TDpiCustomControl } 1662 1711 … … 1668 1717 function TDpiCustomControl.GetPixelsPerInch: Integer; 1669 1718 begin 1670 // Result := GetNativeCustomControl.P;1719 //Result := GetNativeCustomControl.Pix; 1671 1720 end; 1672 1721 1673 1722 function TDpiCustomControl.GetCanvas: TDpiCanvas; 1674 1723 begin 1675 if not Assigned(FCanvas) then begin1676 FCanvas := TDpiCanvas.Create;1677 FCanvas.NativeCanvas := GetNativeCustomControl.Canvas;1678 end;1679 1724 Result := FCanvas; 1680 1725 end; … … 1698 1743 begin 1699 1744 Result := nil; 1745 end; 1746 1747 constructor TDpiCustomControl.Create(TheOwner: TComponent); 1748 begin 1749 inherited; 1750 FCanvas := TDpiCanvas.Create; 1751 FCanvas.NativeCanvas := GetNativeCustomControl.Canvas; 1752 end; 1753 1754 destructor TDpiCustomControl.Destroy; 1755 begin 1756 FreeAndNil(FCanvas); 1757 inherited; 1700 1758 end; 1701 1759 … … 1793 1851 function TDpiRasterImage.GetNativeRasterImage: TRasterImage; 1794 1852 begin 1795 Result := GetNativeRasterImage;1853 Result := nil; 1796 1854 end; 1797 1855 … … 1868 1926 function TDpiBitmap.GetCanvas: TDpiCanvas; 1869 1927 begin 1870 if not Assigned(FCanvas) then begin1871 FCanvas := TDpiCanvas.Create;1872 FCanvas.NativeCanvas := GetNativeBitmap.Canvas;1873 end;1874 1928 Result := FCanvas; 1875 1929 end; … … 1929 1983 function TDpiBitmap.GetNativeBitmap: TCustomBitmap; 1930 1984 begin 1931 if not Assigned(NativeBitmap) then begin1932 NativeBitmap := TBitmap.Create;1933 Canvas.NativeCanvas := NativeBitmap.Canvas;1934 end;1935 1985 Result := NativeBitmap; 1936 1986 end; … … 1957 2007 inherited; 1958 2008 NativeGraphicClass := TBitmap; 2009 NativeBitmap := TBitmap.Create; 2010 FCanvas := TDpiCanvas.Create; 2011 FCanvas.NativeCanvas := GetNativeBitmap.Canvas; 1959 2012 end; 1960 2013 … … 2168 2221 begin 2169 2222 if FFont = AValue then Exit; 2223 if FFontFree then FreeAndNil(FFont); 2224 FFontFree := False; 2170 2225 FFont := AValue; 2171 2226 end; … … 2200 2255 begin 2201 2256 if FNativeCanvas = AValue then Exit; 2257 if FNativeCanvasFree then FreeAndNil(FNativeCanvas); 2258 FNativeCanvasFree := False; 2202 2259 FNativeCanvas := AValue; 2203 FFont.NativeFont := FNativeCanvas.Font; 2260 if Assigned(FNativeCanvas) then begin 2261 FFont.NativeFont := FNativeCanvas.Font; 2262 end; 2204 2263 end; 2205 2264 2206 2265 function TDpiCanvas.GetNativeCanvas: TCanvas; 2207 2266 begin 2208 //if not Assigned(NativeCanvas) then NativeCanvas := TCanvas.Create;2209 2267 Result := NativeCanvas; 2210 2268 end; … … 2289 2347 constructor TDpiCanvas.Create; 2290 2348 begin 2349 FNativeCanvas := nil; 2291 2350 FFont := TDpiFont.Create; 2351 FFontFree := True; 2292 2352 end; 2293 2353 2294 2354 destructor TDpiCanvas.Destroy; 2295 2355 begin 2296 FreeAndNil(FFont); 2356 if FFontFree then FreeAndNil(FFont); 2357 if FNativeCanvasFree then FreeAndNil(FNativeCanvasFree); 2297 2358 inherited; 2298 2359 end; … … 2324 2385 function TDpiGraphicControl.GetNativeGraphicControl: TGraphicControl; 2325 2386 begin 2326 if not Assigned(NativeGraphicControl) then begin2327 NativeGraphicControl := TGraphicControl.Create(nil);2328 end;2329 2387 Result := NativeGraphicControl; 2330 2388 end; … … 2348 2406 constructor TDpiGraphicControl.Create(TheOwner: TComponent); 2349 2407 begin 2408 NativeGraphicControl := TGraphicControl.Create(nil); 2350 2409 inherited; 2351 2410 FCanvas := TDpiCanvas.Create; … … 2356 2415 begin 2357 2416 FreeAndNil(FCanvas); 2417 FreeAndNil(NativeGraphicControl); 2358 2418 inherited; 2359 2419 end; … … 2410 2470 procedure TDpiFont.UpdateFont; 2411 2471 begin 2412 GetNativeFont.PixelsPerInch := FPixelsPerInch; 2413 GetNativeFont.Size := FSize; 2472 if Assigned(GetNativeFont) then begin 2473 GetNativeFont.PixelsPerInch := FPixelsPerInch; 2474 GetNativeFont.Size := FSize; 2475 end; 2414 2476 end; 2415 2477 … … 2421 2483 function TDpiFont.GetNativeFont: TFont; 2422 2484 begin 2423 if not Assigned(NativeFont) then NativeFont := TFont.Create;2424 2485 Result := NativeFont; 2425 2486 end; … … 2502 2563 end; 2503 2564 2565 procedure TDpiFont.SetNativeFont(AValue: TFont); 2566 begin 2567 if FNativeFont = AValue then Exit; 2568 if FNativeFontFree then FNativeFont.Free; 2569 FNativeFontFree := False; 2570 FNativeFont := AValue; 2571 end; 2572 2504 2573 constructor TDpiFont.Create; 2505 2574 begin 2575 FNativeFont := TFont.Create; 2576 FNativeFontFree := True; 2506 2577 FPixelsPerInch := DpiScreen.PixelsPerInch; 2507 2578 Size := 8; … … 2510 2581 destructor TDpiFont.Destroy; 2511 2582 begin 2512 inherited Destroy; 2583 if FNativeFontFree then 2584 FreeAndNil(FNativeFont); 2585 inherited; 2513 2586 end; 2514 2587 … … 2733 2806 begin 2734 2807 //Dpi := 96 * 2; //Screen.PixelsPerInch; 2808 //Dpi := 144; //Round(96 * 1.25) 2809 //Dpi := Round(96 * 1.6); 2735 2810 Dpi := Screen.PixelsPerInch; 2736 2811 end; … … 3162 3237 NewBounds := ScaleRectFromNative(GetNativeControl.BoundsRect); 3163 3238 if NewBounds <> BoundsRect then begin 3164 BoundsRect := NewBounds; 3239 FLeft := NewBounds.Left; 3240 FTop := NewBounds.Top; 3241 FWidth := NewBounds.Width; 3242 FHeight := NewBounds.Height; 3165 3243 DoChangeBounds; 3166 3244 end; … … 3169 3247 procedure TDpiControl.DoFormResize; 3170 3248 begin 3171 if Assigned(FOnResize) then FOnResize(Self); 3249 if Assigned(FOnResize) then begin 3250 FOnResize(Self); 3251 end; 3172 3252 end; 3173 3253 … … 3188 3268 3189 3269 procedure TDpiControl.UpdateBounds; 3270 var 3271 R: TRect; 3190 3272 begin 3191 3273 GetNativeControl.BoundsRect := ScaleRectToNative(BoundsRect); 3274 R := ScaleRectToNative(BoundsRect); 3275 //WriteLog(Name + ' ' + IntToStr(R.Left) + ', ' + IntToStr(R.Top) + ', ' + IntToStr(R.Width) + ', ' + IntToStr(R.Height)) 3192 3276 end; 3193 3277
Note:
See TracChangeset
for help on using the changeset viewer.