Skip to content
Permalink
Browse files

Qt/macOS: enable HiDPI ( retina display ) support

  • Loading branch information
CarterLi committed Jan 5, 2020
1 parent 97de0ac commit 0a2aa2c3af0b8744af6d49437c1b258735028c8b
Showing with 42 additions and 21 deletions.
  1. +6 −1 Core/Core.cpp
  2. +19 −15 Qt/QtMain.cpp
  3. +15 −5 Qt/mainwindow.cpp
  4. +2 −0 ext/native/base/NativeApp.h
@@ -150,7 +150,12 @@ static bool IsWindowSmall(int pixelWidth, int pixelHeight) {
// TODO: Feels like this belongs elsewhere.
bool UpdateScreenScale(int width, int height) {
bool smallWindow;
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
#if defined(USING_QT_UI)
g_dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_DPI);
float g_logical_dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_LOGICAL_DPI);
g_dpi_scale_x = g_logical_dpi / g_dpi;
g_dpi_scale_y = g_logical_dpi / g_dpi;
#elif PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
g_dpi = (float)System_GetPropertyInt(SYSPROP_DISPLAY_DPI);
g_dpi_scale_x = 96.0f / g_dpi;
g_dpi_scale_y = 96.0f / g_dpi;
@@ -159,11 +159,24 @@ int System_GetPropertyInt(SystemProperty prop) {
#else
return DEVICE_TYPE_DESKTOP;
#endif
case SYSPROP_DISPLAY_COUNT:
return QApplication::screens().size();
default:
return -1;
}
}

int System_GetPropertyFloat(SystemProperty prop) {
switch (prop) {
case SYSPROP_DISPLAY_LOGICAL_DPI:
return QApplication::primaryScreen()->logicalDotsPerInch();
case SYSPROP_DISPLAY_DPI:
return QApplication::primaryScreen()->physicalDotsPerInch();
default:
return System_GetPropertyInt(prop);
}
}

bool System_GetPropertyBool(SystemProperty prop) {
switch (prop) {
case SYSPROP_HAS_BACK_BUTTON:
@@ -229,16 +242,6 @@ void LaunchBrowser(const char *url)
QDesktopServices::openUrl(QUrl(url));
}

float CalculateDPIScale()
{
// Sane default rather than check DPI
#if defined(USING_GLES2)
return 1.2f;
#else
return 1.0f;
#endif
}

static int mainInternal(QApplication &a) {
#ifdef MOBILE_DEVICE
emugl = new MainUI();
@@ -628,19 +631,21 @@ int main(int argc, char *argv[])
QGLFormat::setDefaultFormat(format);

QApplication a(argc, argv);
QSize res = QApplication::desktop()->screenGeometry().size();
QScreen* screen = a.primaryScreen();
QSizeF res = screen->physicalSize();
if (res.width() < res.height())
res.transpose();
pixel_xres = res.width();
pixel_yres = res.height();
g_dpi_scale_x = CalculateDPIScale();
g_dpi_scale_y = CalculateDPIScale();

g_dpi_scale_x = screen->logicalDotsPerInchX() / screen->physicalDotsPerInchX();
g_dpi_scale_y = screen->logicalDotsPerInchY() / screen->physicalDotsPerInchY();
g_dpi_scale_real_x = g_dpi_scale_x;
g_dpi_scale_real_y = g_dpi_scale_y;
dp_xres = (int)(pixel_xres * g_dpi_scale_x);
dp_yres = (int)(pixel_yres * g_dpi_scale_y);

refreshRate = (int)(a.primaryScreen()->refreshRate() * 1000);
refreshRate = (int)(screen->refreshRate() * 1000);

std::string savegame_dir = ".";
std::string external_dir = ".";
@@ -669,4 +674,3 @@ int main(int argc, char *argv[])
glslang::FinalizeProcess();
return ret;
}

@@ -24,7 +24,7 @@ MainWindow::MainWindow(QWidget *parent, bool fullscreen) :
{
QDesktopWidget *desktop = QApplication::desktop();
int screenNum = QProcessEnvironment::systemEnvironment().value("SDL_VIDEO_FULLSCREEN_HEAD", "0").toInt();

// Move window to the center of selected screen
QRect rect = desktop->screenGeometry(screenNum);
move((rect.width()-frameGeometry().width()) / 4, (rect.height()-frameGeometry().height()) / 4);
@@ -295,28 +295,33 @@ void MainWindow::consoleAct()
void MainWindow::raiseTopMost()
{
setWindowState( (windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
raise();
raise();
activateWindow();
}

void MainWindow::SetFullScreen(bool fullscreen) {
if (fullscreen) {
#if !PPSSPP_PLATFORM(MAC)
menuBar()->hide();

emugl->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
// TODO: Shouldn't this be physicalSize()?
emugl->resizeGL(emugl->size().width(), emugl->size().height());
// TODO: Won't showFullScreen do this for us?
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
#endif

showFullScreen();
InitPadLayout(dp_xres, dp_yres);

if (GetUIState() == UISTATE_INGAME && !g_Config.bShowTouchControls)
QApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
} else {
#if !PPSSPP_PLATFORM(MAC)
menuBar()->show();
updateMenus();
#endif

showNormal();
SetWindowScale(-1);
@@ -346,7 +351,7 @@ void MainWindow::forumAct()
QDesktopServices::openUrl(QUrl("https://forums.ppsspp.org/"));
}

void MainWindow::gitAct()
void MainWindow::gitAct()
{
QDesktopServices::openUrl(QUrl("https://github.com/hrydgard/ppsspp/"));
}
@@ -394,9 +399,14 @@ void MainWindow::SetWindowScale(int zoom) {
g_Config.iWindowWidth = width;
g_Config.iWindowHeight = height;

#if !PPSSPP_PLATFORM(MAC)
emugl->setFixedSize(g_Config.iWindowWidth, g_Config.iWindowHeight);
// TODO: Shouldn't this be scaled size?
emugl->resizeGL(g_Config.iWindowWidth, g_Config.iWindowHeight);
setFixedSize(sizeHint());
#else
resize(g_Config.iWindowWidth, g_Config.iWindowHeight);
#endif
}

void MainWindow::SetGameTitle(QString text)
@@ -585,7 +595,7 @@ void MainWindow::createMenus()
}
}
langMenu->addActions(langGroup->actions());

// Help
MenuTree* helpMenu = new MenuTree(this, menuBar(), QT_TR_NOOP("&Help"));
helpMenu->add(new MenuAction(this, SLOT(websiteAct()), QT_TR_NOOP("Official &website"), QKeySequence::HelpContents));
@@ -149,6 +149,7 @@ enum SystemProperty {
SYSPROP_DISPLAY_XRES,
SYSPROP_DISPLAY_YRES,
SYSPROP_DISPLAY_REFRESH_RATE, // returns 1000*the refresh rate in Hz as it can be non-integer
SYSPROP_DISPLAY_LOGICAL_DPI,
SYSPROP_DISPLAY_DPI,
SYSPROP_DISPLAY_COUNT,
SYSPROP_MOGA_VERSION,
@@ -173,6 +174,7 @@ enum SystemProperty {

std::string System_GetProperty(SystemProperty prop);
int System_GetPropertyInt(SystemProperty prop);
int System_GetPropertyFloat(SystemProperty prop);
bool System_GetPropertyBool(SystemProperty prop);

std::vector<std::string> __cameraGetDeviceList();

0 comments on commit 0a2aa2c

Please sign in to comment.
You can’t perform that action at this time.