CVideo: remove get_dpi and get_dpi_scale_factor.

screen_pitch_microns is deprecated, and has been removed from the
GUI_SCALE_RESOLUTION macro in WML. The macro itself has been left in
place for potential future use.

The screen_pitch_microns variable has been left in place, but is now
a constant and will only ever return the default value equivalent to
96 DPI.
This commit is contained in:
Tommy 2022-06-03 14:55:56 +12:00
parent c1fa2bed0b
commit 575286cb86
8 changed files with 14 additions and 76 deletions

View file

@ -4,7 +4,7 @@
{gui/macros}
#define FORMULA_GUI_SCALE_RESOLUTION SIZE
"(max({SIZE}, floor({SIZE} * 265 * 2 / (3 * screen_pitch_microns))))"
"({SIZE})"
#enddef
[resolution]

View file

@ -373,14 +373,11 @@
window_height = 900
#enddef
# The magic number 265 in the below formula is the pixel pitch in microns
# corresponding to 96 dpi, which the old layout seems to have been based on.
# The extra factor of 2/3 in the formula is a fudge factor based on the guess
# that the old fonts took up approximately 1.5 pixels per point size at 96
# dpi. It came out looking pretty decent on my 90-micron monitor.
# scaling based on physical DPI has been disabled. This macro remains,
# and may still be used in the future for adaptive or manual UI scaling.
#define GUI_SCALE_RESOLUTION SIZE
(max({SIZE}, floor({SIZE} * 265 * 2 / (3 * screen_pitch_microns))))
({SIZE})
#enddef
#define GUI_WINDOW_PERC_FIXED_SIZE_CENTERED PERC_W PERC_H WIDTH HEIGHT

View file

@ -568,17 +568,6 @@ list_formatter video_settings_report_internal(const std::string& heading = "")
const auto& current_driver = CVideo::current_driver();
auto drivers = CVideo::enumerate_drivers();
const auto& dpi = video.get_dpi();
const auto& scale = video.get_dpi_scale_factor();
std::string dpi_report, scale_report;
if(dpi.first == 0.0f || dpi.second == 0.0f) {
scale_report = dpi_report = "<unknown>";
} else {
dpi_report = geometry_to_string(dpi.first, dpi.second);
scale_report = geometry_to_string(scale.first, scale.second);
}
fmt.insert("SDL video drivers", format_sdl_driver_list(drivers, current_driver));
fmt.insert("Window size", geometry_to_string(
video.current_resolution().x, video.current_resolution().y));
@ -587,8 +576,6 @@ list_formatter video_settings_report_internal(const std::string& heading = "")
fmt.insert("Final render target size", geometry_to_string(
video.output_size().x, video.output_size().y));
fmt.insert("Screen refresh rate", std::to_string(video.current_refresh_rate()));
fmt.insert("Screen dots per inch", dpi_report);
fmt.insert("Screen dpi scale factor", scale_report);
return fmt;
}

View file

@ -302,6 +302,7 @@ void draw::tiled(const texture& tex, const SDL_Rect& dst, bool centered,
/* RAII state manipulation */
/***************************/
draw::clip_setter::clip_setter(const SDL_Rect& clip)
: c_()
{

View file

@ -17,9 +17,6 @@
#include "display.hpp"
#define MAGIC_DPI_MATCH_VIDEO 96
#define MICRONS_PER_INCH 25400
namespace gui2
{
bool new_widgets = false;
@ -28,7 +25,14 @@ namespace settings
{
unsigned screen_width = 0;
unsigned screen_height = 0;
unsigned screen_pitch_microns = MICRONS_PER_INCH / MAGIC_DPI_MATCH_VIDEO;
/** screen_pitch_microns is deprecated. Do not use it.
*
* This value corresponds to a physical DPI of 96. But physical DPI should
* not be used to make rendering decisions. With the ability to set pixel
* scale, it can be assumed that one pixel in draw-space is neither too
* small nor too large.
*/
const unsigned screen_pitch_microns = 265;
unsigned gamemap_x_offset = 0;
unsigned gamemap_width = 0;
@ -57,13 +61,6 @@ void update_screen_size_variables()
screen_width = rect.w;
screen_height = rect.h;
// TODO: highdpi - remove usage
// Use of screen_pitch_microns should probably be deprecated, as physical
// DPI is not an accurate method of determining perceptual pixel size.
//auto [scalew, scaleh] = video.get_dpi_scale_factor();
//float avgscale = (scalew + scaleh)/2;
//screen_pitch_microns = MICRONS_PER_INCH / (avgscale * MAGIC_DPI_MATCH_VIDEO);
gamemap_width = screen_width;
gamemap_height = screen_height;

View file

@ -44,7 +44,7 @@ namespace settings
*/
extern unsigned screen_width;
extern unsigned screen_height;
extern unsigned screen_pitch_microns; /* Pixel pitch in microns */
extern const unsigned screen_pitch_microns; /* Deprecated, do not use */
/**
* The offset between the left edge of the screen and the gamemap.

View file

@ -738,44 +738,6 @@ bool CVideo::window_has_flags(uint32_t flags) const
return (window->get_flags() & flags) != 0;
}
std::pair<float, float> CVideo::get_dpi() const
{
float hdpi, vdpi;
if(window && SDL_GetDisplayDPI(window->get_display_index(), nullptr, &hdpi, &vdpi) == 0) {
#ifdef TARGET_OS_OSX
// SDL 2.0.12 changes SDL_GetDisplayDPI. Function now returns DPI
// multiplied by screen's scale factor. This part of code reverts
// this multiplication.
//
// For more info see issue: https://github.com/wesnoth/wesnoth/issues/5019
if(sdl_get_version() >= version_info{2, 0, 12}) {
float scale_factor = desktop::apple::get_scale_factor(window->get_display_index());
hdpi /= scale_factor;
vdpi /= scale_factor;
}
#endif
return { hdpi, vdpi };
}
// SDL doesn't know the screen dpi, there's a configuration issue, or we
// don't have a window yet.
return { 0.0f, 0.0f };
}
std::pair<float, float> CVideo::get_dpi_scale_factor() const
{
auto dpi = get_dpi();
if(dpi.first != 0.0f && dpi.second != 0.0f) {
// adjust for pixel scale
SDL_Point wsize = window_size();
dpi.first *= float(get_width()) / wsize.x;
dpi.second *= float(get_height()) / wsize.y;
return { dpi.first / MAGIC_DPI_SCALE_NUMBER, dpi.second / MAGIC_DPI_SCALE_NUMBER };
}
// Assume a scale factor of 1.0 if the screen dpi is currently unknown.
return { 1.0f, 1.0f };
}
std::vector<point> CVideo::get_available_resolutions(const bool include_current)
{
std::vector<point> result;

View file

@ -196,12 +196,6 @@ public:
*/
int get_pixel_scale() const { return pixel_scale_; }
/** The current game screen dpi. */
std::pair<float, float> get_dpi() const;
/** The current scale factor on High-DPI screens. */
std::pair<float, float> get_dpi_scale_factor() const;
/**
* Clip a rectangle to the drawing area.
*