{ 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 MacScale; { MacScale.pas — единственное место, где проекту нужен Objective-C. Вынесен из PlatformUtils, потому что {$MODESWITCH OBJECTIVEC1} несовместим с {$MODE Delphi} (компилятор падает с internal error 200609171). Здесь свой режим ObjFPC; наружу торчит одна обычная функция. Модуль имеет смысл только на macOS с GUI: под HEADLESS и на других платформах он не компилируется и не подключается. } {$MODE ObjFPC}{$H+} {$MODESWITCH OBJECTIVEC1} // FPC 3.2.4 падает с internal error 200609171, когда генерирует DWARF-3 // (-gw3, режим Debug у lazbuild) для Objective-C типов. Отладочная информация // для этих сорока строк не нужна. {$DEBUGINFO OFF} interface // Целочисленный масштаб основного экрана: 2 на Retina, 1 иначе. function MacBackingScale: Integer; // Масштаб окна, которому принадлежит NSView (Handle контрола LCL). Именно в // этом масштабе Cocoa рисует канву контрола, и он меняется сам, когда окно // перетаскивают между мониторами. Возвращает 0, если окна ещё нет. function MacBackingScaleForView(AView: Pointer): Integer; implementation uses CocoaAll; function MacBackingScale: Integer; var Sc: NSScreen; begin Result := 1; Sc := NSScreen.mainScreen; if Sc = nil then Exit; Result := Round(Sc.backingScaleFactor); if Result < 1 then Result := 1; end; function MacBackingScaleForView(AView: Pointer): Integer; var Wnd: NSWindow; begin Result := 0; if AView = nil then Exit; Wnd := NSView(AView).window; if Wnd = nil then Exit; // контрол ещё не показан — масштаб неизвестен Result := Round(Wnd.backingScaleFactor); if Result < 1 then Result := 1; end; end.