[ScreenRuler]Add setting to show the measurement in an extra unit (#35887)

* display ruler: supporting millimeter and other units

* Measurement Tool: UI Setting for an extra unit

* Update images

* spelling

* spelling

* suit code style

* Fix for code review

* remove weird file

* rename field
This commit is contained in:
Wenjian Chern
2024-12-06 06:02:17 +08:00
committed by GitHub
parent 076461e460
commit 09ce610dbb
26 changed files with 333 additions and 101 deletions

View File

@@ -52,3 +52,55 @@ MonitorInfo MonitorInfo::GetPrimaryMonitor()
}
return monitors[0];
}
MonitorInfo MonitorInfo::GetFromWindow(const HWND window)
{
auto monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONULL);
return MonitorInfo::MonitorInfo(monitor);
}
MonitorInfo MonitorInfo::GetFromPoint(int32_t x, int32_t y)
{
auto monitor = MonitorFromPoint(POINT{ x, y }, MONITOR_DEFAULTTONULL);
return MonitorInfo::MonitorInfo(monitor);
}
MonitorInfo::Size MonitorInfo::GetSize(const MONITORINFOEX& monitorInfoEx)
{
Size size = {};
auto device_name = PCTSTR(monitorInfoEx.szDevice);
auto hdc = CreateDC(device_name, nullptr, nullptr, nullptr);
size.width_mm = static_cast<float>(GetDeviceCaps(hdc, HORZSIZE));
size.height_mm = static_cast<float>(GetDeviceCaps(hdc, VERTSIZE));
if (hdc != nullptr)
{
ReleaseDC(nullptr, hdc);
}
auto monitor = &monitorInfoEx.rcMonitor;
size.width_logical = static_cast<uint32_t>(monitor->right - monitor->left);
size.height_logical = static_cast<uint32_t>(monitor->bottom - monitor->top);
DEVMODE dev_mode = { .dmSize = sizeof DEVMODE };
if (EnumDisplaySettingsEx(device_name, ENUM_CURRENT_SETTINGS, &dev_mode, EDS_RAWMODE))
{
size.width_physical = dev_mode.dmPelsWidth;
size.height_physical = dev_mode.dmPelsHeight;
}
return size;
}
MonitorInfo::Size MonitorInfo::GetSize() const
{
if (this->handle)
{
return MonitorInfo::GetSize(this->info);
}
else
{
return MonitorInfo::Size{};
}
}