Scale resolution to true values

This commit is contained in:
Anders Jenbo 2021-12-18 18:00:10 +01:00
commit 7d239d9f89
3 changed files with 34 additions and 2 deletions

View file

@ -39,6 +39,7 @@
#include "options.h"
#include "qol/monhealthbar.h"
#include "qol/xpbar.h"
#include "utils/display.h"
#include "utils/file_util.h"
#include "utils/language.h"
#include "utils/log.hpp"
@ -677,6 +678,7 @@ void OptionEntryResolution::CheckResolutionsAreInitialized() const
return;
std::vector<Size> sizes;
float scaleFactor = GetDpiScalingFactor();
// Add resolutions
#ifdef USE_SDL1
@ -687,7 +689,9 @@ void OptionEntryResolution::CheckResolutionsAreInitialized() const
if (modes[i]->w < modes[i]->h) {
std::swap(modes[i]->w, modes[i]->h);
}
sizes.emplace_back(Size { modes[i]->w, modes[i]->h * scaleFactor });
sizes.emplace_back(Size {
static_cast<int>(modes[i]->w * scaleFactor),
static_cast<int>(modes[i]->h * scaleFactor) });
}
}
#else
@ -700,7 +704,9 @@ void OptionEntryResolution::CheckResolutionsAreInitialized() const
if (mode.w < mode.h) {
std::swap(mode.w, mode.h);
}
sizes.emplace_back(Size { mode.w, mode.h * scaleFactor });
sizes.emplace_back(Size {
static_cast<int>(mode.w * scaleFactor),
static_cast<int>(mode.h * scaleFactor) });
}
#endif

View file

@ -110,8 +110,32 @@ Size GetPreferredWindowSize()
AdjustToScreenGeometry(windowSize);
return windowSize;
}
} // namespace
float GetDpiScalingFactor()
{
#ifdef USE_SDL1
return 1.0F;
#else
if (renderer == nullptr)
return 1.0F;
int renderWidth;
int renderHeight;
SDL_GetRendererOutputSize(renderer, &renderWidth, &renderHeight);
int windowWidth;
int windowHeight;
SDL_GetWindowSize(ghMainWnd, &windowWidth, &windowHeight);
float hfactor = static_cast<float>(renderWidth) / windowWidth;
float vhfactor = static_cast<float>(renderHeight) / windowHeight;
return std::min(hfactor, vhfactor);
#endif
}
#ifdef USE_SDL1
void SetVideoMode(int width, int height, int bpp, uint32_t flags)
{

View file

@ -26,6 +26,8 @@ extern SDLPaletteUniquePtr Palette;
extern SDL_Surface *PalSurface;
extern unsigned int pal_surface_palette_version;
float GetDpiScalingFactor();
#ifdef USE_SDL1
void SetVideoMode(int width, int height, int bpp, uint32_t flags);
void SetVideoModeToPrimary(bool fullscreen, int width, int height);