get dpi of monitor and calculate actual size of it.

This commit is contained in:
hecomi
2016-11-06 12:17:29 +09:00
parent 15a98cd774
commit 6ac1a5ee60
7 changed files with 70 additions and 9 deletions
@@ -1,4 +1,5 @@
#include <d3d11.h>
#include <ShellScalingAPI.h>
#include "Common.h"
#include "Cursor.h"
#include "MonitorManager.h"
@@ -18,6 +19,8 @@ HRESULT Monitor::Initialize(IDXGIOutput* output)
monitorInfo_.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(outputDesc_.Monitor, &monitorInfo_);
GetDpiForMonitor(outputDesc_.Monitor, MDT_RAW_DPI, &dpiX_, &dpiY_);
auto output1 = reinterpret_cast<IDXGIOutput1*>(output);
const auto hr = output1->DuplicateOutput(GetDevice(), &deskDupl_);
@@ -196,6 +199,18 @@ int Monitor::GetRotation() const
}
int Monitor::GetDpiX() const
{
return static_cast<int>(dpiX_);
}
int Monitor::GetDpiY() const
{
return static_cast<int>(dpiY_);
}
int Monitor::GetWidth() const
{
const auto rect = monitorInfo_.rcMonitor;
@@ -41,11 +41,14 @@ public:
int GetWidth() const;
int GetHeight() const;
int GetRotation() const;
int GetDpiX() const;
int GetDpiY() const;
IDXGIOutputDuplication* GetDeskDupl();
const std::unique_ptr<Cursor>& GetCursor();
private:
int id_ = -1;
UINT dpiX_ = -1, dpiY_ = -1;
State state_ = State::NotSet;
std::unique_ptr<Cursor> cursor_;
IDXGIOutputDuplication* deskDupl_ = nullptr;
@@ -15,6 +15,7 @@
#include "MonitorManager.h"
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "Shcore.lib")
namespace
@@ -234,6 +235,26 @@ extern "C"
return DXGI_MODE_ROTATION_UNSPECIFIED;
}
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetDpiX(int id)
{
if (!g_manager) return -1;
if (auto monitor = g_manager->GetMonitor(id))
{
return monitor->GetDpiX();
}
return -1;
}
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetDpiY(int id)
{
if (!g_manager) return -1;
if (auto monitor = g_manager->GetMonitor(id))
{
return monitor->GetDpiY();
}
return -1;
}
UNITY_INTERFACE_EXPORT bool UNITY_INTERFACE_API IsCursorVisible(int id)
{
if (!g_manager) return false;