summaryrefslogtreecommitdiff
path: root/dggui
diff options
context:
space:
mode:
Diffstat (limited to 'dggui')
-rw-r--r--dggui/nativewindow.h5
-rw-r--r--dggui/nativewindow_cocoa.h31
-rw-r--r--dggui/nativewindow_cocoa.mm6
-rw-r--r--dggui/nativewindow_win32.cc9
-rw-r--r--dggui/nativewindow_win32.h1
-rw-r--r--dggui/nativewindow_x11.cc9
-rw-r--r--dggui/nativewindow_x11.h1
7 files changed, 47 insertions, 15 deletions
diff --git a/dggui/nativewindow.h b/dggui/nativewindow.h
index 07c3559..715d7ca 100644
--- a/dggui/nativewindow.h
+++ b/dggui/nativewindow.h
@@ -59,6 +59,11 @@ public:
//! Query size of the native window.
virtual std::pair<std::size_t, std::size_t> getSize() const = 0;
+ //! While there isn’t a universally agreed-upon meaning for what constitutes
+ //! HiDPI, a common benchmark is that displays with more than double the PPI
+ //! of the old standard (72-96) can arguably be classified as HiDPI.
+ virtual bool isHiDPI() = 0;
+
//! Move the window to a new position.
//! Note: negative value are allowed.
virtual void move(int x, int y) = 0;
diff --git a/dggui/nativewindow_cocoa.h b/dggui/nativewindow_cocoa.h
index e17d4af..0bfa73b 100644
--- a/dggui/nativewindow_cocoa.h
+++ b/dggui/nativewindow_cocoa.h
@@ -42,21 +42,22 @@ public:
~NativeWindowCocoa();
// From NativeWindow:
- virtual void setFixedSize(std::size_t width, std::size_t height) override;
- virtual void setAlwaysOnTop(bool always_on_top) override;
- virtual void resize(std::size_t width, std::size_t height) override;
- virtual std::pair<std::size_t, std::size_t> getSize() const override;
- virtual void move(int x, int y) override;
- virtual std::pair<int, int> getPosition() const override;
- virtual void show() override;
- virtual void hide() override;
- virtual bool visible() const override;
- virtual void setCaption(const std::string &caption) override;
- virtual void redraw(const Rect& dirty_rect) override;
- virtual void grabMouse(bool grab) override;
- virtual EventQueue getEvents() override;
- virtual void* getNativeWindowHandle() const override;
- virtual Point translateToScreen(const Point& point) override;
+ void setFixedSize(std::size_t width, std::size_t height) override;
+ void setAlwaysOnTop(bool always_on_top) override;
+ void resize(std::size_t width, std::size_t height) override;
+ std::pair<std::size_t, std::size_t> getSize() const override;
+ bool isHiDPI() override;
+ void move(int x, int y) override;
+ std::pair<int, int> getPosition() const override;
+ void show() override;
+ void hide() override;
+ bool visible() const override;
+ void setCaption(const std::string &caption) override;
+ void redraw(const Rect& dirty_rect) override;
+ void grabMouse(bool grab) override;
+ EventQueue getEvents() override;
+ void* getNativeWindowHandle() const override;
+ Point translateToScreen(const Point& point) override;
// Expose friend members of Window to ObjC++ implementation.
class Window& getWindow();
diff --git a/dggui/nativewindow_cocoa.mm b/dggui/nativewindow_cocoa.mm
index 3214f57..9484af7 100644
--- a/dggui/nativewindow_cocoa.mm
+++ b/dggui/nativewindow_cocoa.mm
@@ -609,6 +609,12 @@ std::pair<std::size_t, std::size_t> NativeWindowCocoa::getSize() const
}
}
+bool NativeWindowCocoa::isHiDPI()
+{
+ float dpi = [priv->window backingScaleFactor];
+ return dpi > 1.0f;
+}
+
void NativeWindowCocoa::move(int x, int y)
{
NSRect screen = [[NSScreen mainScreen] frame];
diff --git a/dggui/nativewindow_win32.cc b/dggui/nativewindow_win32.cc
index db785e9..45cbd30 100644
--- a/dggui/nativewindow_win32.cc
+++ b/dggui/nativewindow_win32.cc
@@ -489,6 +489,15 @@ std::pair<std::size_t, std::size_t> NativeWindowWin32::getSize() const
return std::make_pair(rect.right - rect.left, rect.bottom - rect.top);
}
+bool NativeWindowWin32::isHiDPI()
+{
+ HDC hDC = GetDC(m_hwnd);
+ INT xres = GetDeviceCaps(hDC, LOGPIXELSX);
+ INT yres = GetDeviceCaps(hDC, LOGPIXELSY);
+ ReleaseDC(m_hwnd, hDC);
+ return xres >= 2 * 96 || yres >= 2 * 96;
+}
+
void NativeWindowWin32::move(int x, int y)
{
SetWindowPos(m_hwnd, always_on_top ? HWND_TOPMOST : nullptr,
diff --git a/dggui/nativewindow_win32.h b/dggui/nativewindow_win32.h
index f4748fe..e8adbfd 100644
--- a/dggui/nativewindow_win32.h
+++ b/dggui/nativewindow_win32.h
@@ -49,6 +49,7 @@ public:
void setAlwaysOnTop(bool always_on_top) override;
void resize(std::size_t width, std::size_t height) override;
std::pair<std::size_t, std::size_t> getSize() const override;
+ bool isHiDPI() override;
void move(int x, int y) override;
std::pair<int, int> getPosition() const override;
void show() override;
diff --git a/dggui/nativewindow_x11.cc b/dggui/nativewindow_x11.cc
index 04f1b35..2f94935 100644
--- a/dggui/nativewindow_x11.cc
+++ b/dggui/nativewindow_x11.cc
@@ -240,6 +240,15 @@ std::pair<std::size_t, std::size_t> NativeWindowX11::getSize() const
return {width, height};
}
+bool NativeWindowX11::isHiDPI()
+{
+ auto xres = ((((double) DisplayWidth(display, screen)) * 25.4) /
+ ((double) DisplayWidthMM(display, screen))) + 0.5;
+ auto yres = ((((double) DisplayHeight(display, screen)) * 25.4) /
+ ((double) DisplayHeightMM(display, screen))) + 0.5;
+ return xres >= 2 * 96 || yres >= 2 * 96;
+}
+
void NativeWindowX11::move(int x, int y)
{
if(display == nullptr)
diff --git a/dggui/nativewindow_x11.h b/dggui/nativewindow_x11.h
index bed86bd..94ac6a7 100644
--- a/dggui/nativewindow_x11.h
+++ b/dggui/nativewindow_x11.h
@@ -50,6 +50,7 @@ public:
void setAlwaysOnTop(bool always_on_top) override;
void resize(std::size_t width, std::size_t height) override;
std::pair<std::size_t, std::size_t> getSize() const override;
+ bool isHiDPI() override;;
void move(int x, int y) override;
std::pair<int, int> getPosition() const override;
void show() override;