mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
* [Screen Ruler] simplify lines calculation * [Screen Ruler] Add inches and centimeters support * [Chore] prefer x64 toolset to avoid hitting C1076 * [Screen Ruler] Allow making screenshots in non-continuous mode * [Screen Ruler] Use single d3d device for all ops * [Screen Ruler] remove gpu mutex and clean up screen capturing * [Screen Ruler] handle and log DXGI initialization failure * [Screen Ruler] Add unhandled exception handler * [Screen Ruler] comment out Units of Measure setting * [Screen Ruler] introduce a separate device dedicated for capturing
92 lines
2.5 KiB
C++
92 lines
2.5 KiB
C++
#include "pch.h"
|
|
|
|
#include "Measurement.h"
|
|
|
|
Measurement::Measurement(RECT winRect)
|
|
{
|
|
rect.left = static_cast<float>(winRect.left);
|
|
rect.right = static_cast<float>(winRect.right);
|
|
rect.top = static_cast<float>(winRect.top);
|
|
rect.bottom = static_cast<float>(winRect.bottom);
|
|
}
|
|
|
|
Measurement::Measurement(D2D1_RECT_F d2dRect) :
|
|
rect{ d2dRect }
|
|
{
|
|
}
|
|
|
|
namespace
|
|
{
|
|
inline float Convert(const float pixels, const Measurement::Unit units)
|
|
{
|
|
switch (units)
|
|
{
|
|
case Measurement::Unit::Pixel:
|
|
return pixels;
|
|
case Measurement::Unit::Inch:
|
|
return pixels / 96.f;
|
|
case Measurement::Unit::Centimetre:
|
|
return pixels / 96.f * 2.54f;
|
|
default:
|
|
return pixels;
|
|
}
|
|
}
|
|
}
|
|
|
|
inline float Measurement::Width(const Unit units) const
|
|
{
|
|
return Convert(rect.right - rect.left + 1.f, units);
|
|
}
|
|
|
|
inline float Measurement::Height(const Unit units) const
|
|
{
|
|
return Convert(rect.bottom - rect.top + 1.f, units);
|
|
}
|
|
|
|
Measurement::PrintResult Measurement::Print(wchar_t* buf,
|
|
const size_t bufSize,
|
|
const bool printWidth,
|
|
const bool printHeight,
|
|
const Unit units) const
|
|
{
|
|
PrintResult result;
|
|
if (printWidth)
|
|
{
|
|
result.strLen += swprintf_s(buf,
|
|
bufSize,
|
|
L"%g",
|
|
Width(units));
|
|
if (printHeight)
|
|
{
|
|
result.crossSymbolPos = result.strLen + 1;
|
|
result.strLen += swprintf_s(buf + result.strLen,
|
|
bufSize - result.strLen,
|
|
L" \x00D7 ");
|
|
}
|
|
}
|
|
|
|
if (printHeight)
|
|
{
|
|
result.strLen += swprintf_s(buf + result.strLen,
|
|
bufSize - result.strLen,
|
|
L"%g",
|
|
Height(units));
|
|
}
|
|
|
|
switch (units)
|
|
{
|
|
case Measurement::Unit::Inch:
|
|
result.strLen += swprintf_s(buf + result.strLen,
|
|
bufSize - result.strLen,
|
|
L" in");
|
|
break;
|
|
case Measurement::Unit::Centimetre:
|
|
result.strLen += swprintf_s(buf + result.strLen,
|
|
bufSize - result.strLen,
|
|
L" cm");
|
|
break;
|
|
}
|
|
|
|
return result;
|
|
}
|