Support Retina displays

This commit is contained in:
Struma 2021-05-21 16:28:51 -04:00 committed by Roza
parent 78e823a040
commit 699ffc0245
7 changed files with 28 additions and 6 deletions

View file

@ -25,7 +25,7 @@
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.role-playing-games</string> <string>public.app-category.role-playing-games</string>
<key>NSHighResolutionCapable</key> <key>NSHighResolutionCapable</key>
<false/> <true/>
<key>NSRequiresAquaSystemAppearance</key> <key>NSRequiresAquaSystemAppearance</key>
<string>False</string> <string>False</string>
</dict> </dict>

View file

@ -415,6 +415,10 @@ struct GraphicsPrivate {
* is blitted inside the game window */ * is blitted inside the game window */
Vec2i scOffset; Vec2i scOffset;
// Scaling factor, used to display the screen properly
// on Retina displays
int scalingFactor;
ScreenScene screen; ScreenScene screen;
RGSSThreadData *threadData; RGSSThreadData *threadData;
SDL_GLContext glCtx; SDL_GLContext glCtx;
@ -450,7 +454,7 @@ struct GraphicsPrivate {
glCtx(SDL_GL_GetCurrentContext()), frameRate(DEF_FRAMERATE), glCtx(SDL_GL_GetCurrentContext()), frameRate(DEF_FRAMERATE),
frameCount(0), brightness(255), fpsLimiter(frameRate), frameCount(0), brightness(255), fpsLimiter(frameRate),
useFrameSkip(rtData->config.frameSkip), frozen(false), useFrameSkip(rtData->config.frameSkip), frozen(false),
last_update(0), last_avg_update(0) { last_update(0), last_avg_update(0), scalingFactor(rtData->scale){
avgFPSData = std::vector<unsigned long long>(); avgFPSData = std::vector<unsigned long long>();
avgFPSLock = SDL_CreateMutex(); avgFPSLock = SDL_CreateMutex();
@ -547,7 +551,10 @@ struct GraphicsPrivate {
void metaBlitBufferFlippedScaled() { void metaBlitBufferFlippedScaled() {
GLMeta::blitRectangle( GLMeta::blitRectangle(
IntRect(0, 0, scRes.x, scRes.y), IntRect(0, 0, scRes.x, scRes.y),
IntRect(scOffset.x, scSize.y + scOffset.y, scSize.x, -scSize.y), IntRect(scOffset.x * scalingFactor,
(scSize.y + scOffset.y) * scalingFactor,
scSize.x * scalingFactor,
-scSize.y * scalingFactor),
threadData->config.smoothScaling); threadData->config.smoothScaling);
} }
@ -589,7 +596,7 @@ struct GraphicsPrivate {
} }
double averageFPS() { double averageFPS() {
double ret; double ret = 0;
SDL_LockMutex(avgFPSLock); SDL_LockMutex(avgFPSLock);
for (unsigned long long times : avgFPSData) for (unsigned long long times : avgFPSData)
ret += times; ret += times;

View file

@ -257,6 +257,7 @@ struct RGSSThreadData
Vec2 sizeResoRatio; Vec2 sizeResoRatio;
Vec2i screenOffset; Vec2i screenOffset;
int scale;
const int refreshRate; const int refreshRate;
Config config; Config config;
@ -268,6 +269,7 @@ struct RGSSThreadData
SDL_Window *window, SDL_Window *window,
ALCdevice *alcDev, ALCdevice *alcDev,
int refreshRate, int refreshRate,
int scalingFactor,
const Config& newconf, const Config& newconf,
SDL_GLContext ctx) SDL_GLContext ctx)
: ethread(ethread), : ethread(ethread),
@ -276,6 +278,7 @@ struct RGSSThreadData
alcDev(alcDev), alcDev(alcDev),
sizeResoRatio(1, 1), sizeResoRatio(1, 1),
refreshRate(refreshRate), refreshRate(refreshRate),
scale(scalingFactor),
config(newconf), config(newconf),
glContext(ctx) glContext(ctx)
{} {}

View file

@ -45,6 +45,8 @@
#include "filesystem/filesystem.h" #include "filesystem/filesystem.h"
#include "system/system.h"
#if defined(__WINDOWS__) #if defined(__WINDOWS__)
#include "resource.h" #include "resource.h"
#include <Winsock2.h> #include <Winsock2.h>
@ -191,8 +193,8 @@ int main(int argc, char *argv[]) {
#ifndef WORKDIR_CURRENT #ifndef WORKDIR_CURRENT
char dataDir[512]{}; char dataDir[512]{};
char *tmp{};
#if defined(__linux__) #if defined(__linux__)
char *tmp{};
tmp = getenv("SRCDIR"); tmp = getenv("SRCDIR");
if (tmp) { if (tmp) {
strncpy(dataDir, tmp, sizeof(dataDir)); strncpy(dataDir, tmp, sizeof(dataDir));
@ -384,7 +386,7 @@ int main(int argc, char *argv[]) {
#endif #endif
RGSSThreadData rtData(&eventThread, argv[0], win, alcDev, mode.refresh_rate, RGSSThreadData rtData(&eventThread, argv[0], win, alcDev, mode.refresh_rate,
conf, glCtx); mkxp_sys::getScalingFactor(), conf, glCtx);
int winW, winH; int winW, winH;
SDL_GetWindowSize(win, &winW, &winH); SDL_GetWindowSize(win, &winW, &winH);

View file

@ -13,6 +13,7 @@
namespace systemImpl { namespace systemImpl {
std::string getSystemLanguage(); std::string getSystemLanguage();
std::string getUserName(); std::string getUserName();
int getScalingFactor();
} }
#ifdef MKXPZ_BUILD_XCODE #ifdef MKXPZ_BUILD_XCODE

View file

@ -54,3 +54,8 @@ std::string systemImpl::getUserName() {
return std::string(ret); return std::string(ret);
} }
// HiDPI scaling not supported outside of macOS for now
int systemImpl::getScalingFactor() {
return 1;
}

View file

@ -19,6 +19,10 @@ std::string systemImpl::getUserName() {
return std::string(NSUserName().UTF8String); return std::string(NSUserName().UTF8String);
} }
int systemImpl::getScalingFactor() {
return NSApplication.sharedApplication.mainWindow.backingScaleFactor;
}
// constant, if it's not nil then just raise the menu instead // constant, if it's not nil then just raise the menu instead
SettingsMenu *smenu = nil; SettingsMenu *smenu = nil;