Files
ewsdr/DpiUtils.pas
T

57 lines
2.1 KiB
ObjectPascal

{
Copyright (C)
2026 - Uladzimir Karpenka, EW8BAK
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}
unit DpiUtils;
{
DpiUtils.pas — общий пересчёт «дизайн-пикселей» в реальные экранные.
Вся UI-раскладка приложения (кастомные Flat*-контролы и окна, построенные
кодом — SettingsForm, DeviceForm) написана литеральными пикселями под
неявные 96 DPI. DpiScale переводит такое значение в пиксели текущего
монитора: на 96 DPI (обычный десктоп, Windows 100%) возвращает V без
изменений; на более высоком DPI (Windows 125/150/200%, HiDPI-десктопы)
масштабирует пропорционально — тот же приём, что и для стандартных
Windows-контролов (MulDiv), но управляемый вручную, т.к. вся раскладка
строится кодом, а не читается из .lfm (там масштабирование сделал бы LCL
сам через DesignTimePPI).
}
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
uses
Forms, LCLType;
function DpiScale(V: Integer): Integer;
implementation
function DpiScale(V: Integer): Integer;
begin
Result := MulDiv(V, Screen.PixelsPerInch, 96);
if (V > 0) and (Result < 1) then
Result := 1;
end;
end.