mirror of
https://github.com/glfw/glfw.git
synced 2026-01-11 15:23:17 +01:00
Add content scale queries
This adds glfwGetWindowContentScale and glfwGetMonitorContentScale for querying the recommended drawing scale factor for DPI-aware rendering. Parts of this patch are based on code by @ferreiradaselva. Fixes #235. Fixes #439. Fixes #677. Fixes #845. Fixes #898.
This commit is contained in:
@@ -131,17 +131,34 @@ current _resolution_, i.e. the width and height of its current
|
||||
[video mode](@ref monitor_modes).
|
||||
|
||||
@code
|
||||
int widthMM, heightMM;
|
||||
glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM);
|
||||
int width_mm, height_mm;
|
||||
glfwGetMonitorPhysicalSize(monitor, &width_mm, &height_mm);
|
||||
@endcode
|
||||
|
||||
This can, for example, be used together with the current video mode to calculate
|
||||
the DPI of a monitor.
|
||||
While this can be used to calculate the raw DPI of a monitor, this is often not
|
||||
useful. Instead use the [monitor content scale](@ref monitor_scale) and
|
||||
[window content scale](@ref window_scale) to scale your content.
|
||||
|
||||
|
||||
@subsection monitor_scale Content scale
|
||||
|
||||
The content scale for a monitor can be retrieved with @ref
|
||||
glfwGetMonitorContentScale.
|
||||
|
||||
@code
|
||||
const double dpi = mode->width / (widthMM / 25.4);
|
||||
float xscale, yscale;
|
||||
glfwGetMonitorContentScale(monitor, &xscale, &yscale);
|
||||
@endcode
|
||||
|
||||
The content scale is the ratio between the current DPI and the platform's
|
||||
default DPI. If you scale all pixel dimensions by this scale then your content
|
||||
should appear at an appropriate size. This is especially important for text and
|
||||
any UI elements.
|
||||
|
||||
The content scale may depend on both the monitor resolution and pixel density
|
||||
and on user settings. It may be very different from the raw DPI calculated from
|
||||
the physical size and current resolution.
|
||||
|
||||
|
||||
@subsection monitor_pos Virtual position
|
||||
|
||||
|
||||
@@ -58,6 +58,15 @@ windows with @ref glfwSetWindowAttrib.
|
||||
@see @ref window_attribs
|
||||
|
||||
|
||||
@subsection news_33_contentscale Content scale queries for DPI-aware rendering
|
||||
|
||||
GLFW now supports querying the window and monitor content scale, i.e. the ratio
|
||||
between the current DPI and the platform's default DPI, with @ref
|
||||
glfwGetWindowContentScale and @ref glfwGetMonitorContentScale.
|
||||
|
||||
@see @ref window_scale
|
||||
|
||||
|
||||
@subsection news_33_inithint Support for initialization hints
|
||||
|
||||
GLFW now supports setting library initialization hints with @ref glfwInitHint
|
||||
|
||||
@@ -663,6 +663,26 @@ The size of a framebuffer may change independently of the size of a window, for
|
||||
example if the window is dragged between a regular monitor and a high-DPI one.
|
||||
|
||||
|
||||
@subsection window_scale Window content scale
|
||||
|
||||
The content scale for a window can be retrieved with @ref
|
||||
glfwGetWindowContentScale.
|
||||
|
||||
@code
|
||||
float xscale, yscale;
|
||||
glfwGetWindowContentScale(window, &xscale, &yscale);
|
||||
@endcode
|
||||
|
||||
The content scale of a window is the ratio between the current DPI and the
|
||||
platform's default DPI. If you scale all pixel dimensions by this scale then
|
||||
your content should appear at an appropriate size. This is especially important
|
||||
for text and any UI elements.
|
||||
|
||||
On systems where each monitors can have its own content scale, the window
|
||||
content scale will depend on which monitor the system considers the window to be
|
||||
on.
|
||||
|
||||
|
||||
@subsection window_sizelimits Window size limits
|
||||
|
||||
The minimum and maximum size of the client area of a windowed mode window can be
|
||||
|
||||
Reference in New Issue
Block a user