mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
[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:
@@ -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{};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#pragma comment(lib, "Gdi32.lib")
|
||||
#include <Windows.h>
|
||||
|
||||
#include <compare>
|
||||
@@ -42,6 +43,15 @@ struct Box
|
||||
|
||||
class MonitorInfo
|
||||
{
|
||||
public:
|
||||
typedef struct Size
|
||||
{
|
||||
uint32_t width_logical, height_logical;
|
||||
uint32_t width_physical, height_physical;
|
||||
float width_mm, height_mm;
|
||||
} Size;
|
||||
|
||||
private:
|
||||
HMONITOR handle;
|
||||
MONITORINFOEX info = {};
|
||||
|
||||
@@ -53,8 +63,14 @@ public:
|
||||
}
|
||||
Box GetScreenSize(const bool includeNonWorkingArea) const;
|
||||
bool IsPrimary() const;
|
||||
Size GetSize() const;
|
||||
|
||||
// Returns monitor rects ordered from left to right
|
||||
static std::vector<MonitorInfo> GetMonitors(bool includeNonWorkingArea);
|
||||
static MonitorInfo GetPrimaryMonitor();
|
||||
static MonitorInfo GetFromWindow(HWND);
|
||||
static MonitorInfo GetFromPoint(int32_t, int32_t);
|
||||
|
||||
private:
|
||||
static Size GetSize(const MONITORINFOEX&);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user