Compare commits

...

1 Commits

Author SHA1 Message Date
Fabrice de Gans
3f77a55f7c [hidpi] Add High DPI support for all platforms
wxWidgets now supports High DPI natively.
2022-09-26 23:31:43 -07:00
3 changed files with 14 additions and 60 deletions

View File

@@ -7,22 +7,6 @@
#include "wxvbam.h"
#include "drawing.h"
double HiDPIAware::HiDPIScaleFactor()
{
if (hidpi_scale_factor == 0) {
NSWindow* window = [(NSView*)GetWindow()->GetHandle() window];
if ([window respondsToSelector:@selector(backingScaleFactor)]) {
hidpi_scale_factor = [window backingScaleFactor];
}
else {
hidpi_scale_factor = 1.0;
}
}
return hidpi_scale_factor;
}
void HiDPIAware::RequestHighResolutionOpenGLSurface()
{
NSView* view = (NSView*)(GetWindow()->GetHandle());
@@ -32,16 +16,6 @@ void HiDPIAware::RequestHighResolutionOpenGLSurface()
}
}
void HiDPIAware::GetRealPixelClientSize(int* x, int* y)
{
NSView* view = (NSView*)(GetWindow()->GetHandle());
NSSize backing_size = [view convertSizeToBacking:view.bounds.size];
*x = backing_size.width;
*y = backing_size.height;
}
Quartz2DDrawingPanel::Quartz2DDrawingPanel(wxWindow* parent, int _width, int _height)
: BasicDrawingPanel(parent, _width, _height)
{

View File

@@ -745,12 +745,12 @@ void GameArea::DelBorder()
void GameArea::AdjustMinSize()
{
wxWindow* frame = wxGetApp().frame;
double hidpi_scale_factor = HiDPIScaleFactor();
double hidpi_scale_factor = GetDPIScaleFactor();
// note: could safely set min size to 1x or less regardless of video_scale
// but setting it to scaled size makes resizing to default easier
wxSize sz((std::ceil(basic_width * gopts.video_scale) / hidpi_scale_factor),
(std::ceil(basic_height * gopts.video_scale) / hidpi_scale_factor));
wxSize sz((std::ceil(basic_width * gopts.video_scale) * hidpi_scale_factor),
(std::ceil(basic_height * gopts.video_scale) * hidpi_scale_factor));
SetMinSize(sz);
#if wxCHECK_VERSION(2, 8, 8)
sz = frame->ClientToWindowSize(sz);
@@ -763,10 +763,10 @@ void GameArea::AdjustMinSize()
void GameArea::LowerMinSize()
{
wxWindow* frame = wxGetApp().frame;
double hidpi_scale_factor = HiDPIScaleFactor();
double hidpi_scale_factor = GetDPIScaleFactor();
wxSize sz(std::ceil(basic_width / hidpi_scale_factor),
std::ceil(basic_height / hidpi_scale_factor));
wxSize sz(std::ceil(basic_width * hidpi_scale_factor),
std::ceil(basic_height * hidpi_scale_factor));
SetMinSize(sz);
// do not take decorations into account
@@ -780,9 +780,9 @@ void GameArea::AdjustSize(bool force)
if (fullscreen)
return;
double hidpi_scale_factor = HiDPIScaleFactor();
const wxSize newsz((std::ceil(basic_width * gopts.video_scale) / hidpi_scale_factor),
(std::ceil(basic_height * gopts.video_scale) / hidpi_scale_factor));
double hidpi_scale_factor = GetDPIScaleFactor();
const wxSize newsz((std::ceil(basic_width * gopts.video_scale) * hidpi_scale_factor),
(std::ceil(basic_height * gopts.video_scale) * hidpi_scale_factor));
if (!force) {
wxSize sz = GetClientSize();
@@ -2251,7 +2251,7 @@ void GLDrawingPanel::AdjustViewport()
#endif
int x, y;
GetRealPixelClientSize(&x, &y);
GetClientSize(&x, &y);
glViewport(0, 0, x, y);
#ifdef DEBUG
@@ -2515,23 +2515,7 @@ void GameArea::ShowMenuBar()
#endif
}
// stub HiDPI methods, see macsupport.mm for the Mac support
#ifndef __WXMAC__
double HiDPIAware::HiDPIScaleFactor()
{
if (hidpi_scale_factor == 0) {
hidpi_scale_factor = 1.0;
}
return hidpi_scale_factor;
}
void HiDPIAware::RequestHighResolutionOpenGLSurface()
{
}
void HiDPIAware::GetRealPixelClientSize(int* x, int* y)
{
GetWindow()->GetClientSize(x, y);
}
#endif // HiDPI stubs
// stub HiDPI method, see macsupport.mm for the Mac support
void HiDPIAware::RequestHighResolutionOpenGLSurface() {}
#endif // __WXMAC__ stub

View File

@@ -391,13 +391,9 @@ private:
// helper class to add HiDPI awareness (mostly for Mac OS X)
class HiDPIAware {
public:
HiDPIAware() { hidpi_scale_factor = 0; }
virtual double HiDPIScaleFactor();
HiDPIAware() = default;
virtual void RequestHighResolutionOpenGLSurface();
virtual void GetRealPixelClientSize(int* x, int* y);
virtual wxWindow* GetWindow() = 0;
private:
double hidpi_scale_factor;
};
// a class for polling joystick keys