2019-09-04 18:26:26 +02:00
|
|
|
#include "pch.h"
|
|
|
|
|
|
2020-04-20 18:09:10 +02:00
|
|
|
|
|
|
|
|
#include <Shellscalingapi.h>
|
|
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
#include <common/display/dpi_aware.h>
|
|
|
|
|
#include <common/display/monitors.h>
|
2019-12-17 11:21:46 +03:00
|
|
|
#include "Zone.h"
|
|
|
|
|
#include "Settings.h"
|
2020-04-10 16:09:08 +02:00
|
|
|
#include "util.h"
|
2019-12-17 11:21:46 +03:00
|
|
|
|
2020-09-08 12:06:54 +02:00
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
bool ValidateZoneRect(const RECT& rect)
|
|
|
|
|
{
|
|
|
|
|
int width = rect.right - rect.left;
|
|
|
|
|
int height = rect.bottom - rect.top;
|
2020-10-14 17:42:47 +02:00
|
|
|
return rect.left >= ZoneConstants::MAX_NEGATIVE_SPACING &&
|
|
|
|
|
rect.right >= ZoneConstants::MAX_NEGATIVE_SPACING &&
|
|
|
|
|
rect.top >= ZoneConstants::MAX_NEGATIVE_SPACING &&
|
|
|
|
|
rect.bottom >= ZoneConstants::MAX_NEGATIVE_SPACING &&
|
|
|
|
|
width >= 0 && height >= 0;
|
2020-09-08 12:06:54 +02:00
|
|
|
}
|
2020-10-14 09:00:50 +02:00
|
|
|
}
|
2020-04-20 18:09:10 +02:00
|
|
|
|
2020-10-14 09:00:50 +02:00
|
|
|
struct Zone : winrt::implements<Zone, IZone>
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-08-11 17:05:03 +03:00
|
|
|
Zone(RECT zoneRect, const ZoneIndex zoneId) :
|
2020-10-14 09:00:50 +02:00
|
|
|
m_zoneRect(zoneRect),
|
|
|
|
|
m_id(zoneId)
|
2020-04-20 18:09:10 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 09:00:50 +02:00
|
|
|
IFACEMETHODIMP_(RECT) GetZoneRect() const noexcept { return m_zoneRect; }
|
2021-06-22 11:34:27 +03:00
|
|
|
IFACEMETHODIMP_(long) GetZoneArea() const noexcept { return max(m_zoneRect.bottom - m_zoneRect.top, 0) * max(m_zoneRect.right - m_zoneRect.left, 0); }
|
2021-08-11 17:05:03 +03:00
|
|
|
IFACEMETHODIMP_(ZoneIndex) Id() const noexcept { return m_id; }
|
2020-04-20 18:09:10 +02:00
|
|
|
|
2020-10-14 09:00:50 +02:00
|
|
|
private:
|
|
|
|
|
RECT m_zoneRect{};
|
2021-08-11 17:05:03 +03:00
|
|
|
const ZoneIndex m_id{};
|
2020-10-14 09:00:50 +02:00
|
|
|
};
|
2020-04-20 18:09:10 +02:00
|
|
|
|
2021-08-11 17:05:03 +03:00
|
|
|
winrt::com_ptr<IZone> MakeZone(const RECT& zoneRect, const ZoneIndex zoneId) noexcept
|
2019-09-04 18:26:26 +02:00
|
|
|
{
|
2020-10-26 09:07:11 +01:00
|
|
|
if (ValidateZoneRect(zoneRect) && zoneId >= 0)
|
2020-09-08 12:06:54 +02:00
|
|
|
{
|
2020-10-14 09:00:50 +02:00
|
|
|
return winrt::make_self<Zone>(zoneRect, zoneId);
|
2020-09-08 12:06:54 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2019-12-17 12:34:45 +03:00
|
|
|
}
|