Support Retina displays

This commit is contained in:
Roza 2021-05-21 16:28:51 -04:00
parent 4829f63e45
commit 1a304da43d
7 changed files with 28 additions and 6 deletions

View file

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

View file

@ -415,6 +415,10 @@ struct GraphicsPrivate {
* is blitted inside the game window */
Vec2i scOffset;
// Scaling factor, used to display the screen properly
// on Retina displays
int scalingFactor;
ScreenScene screen;
RGSSThreadData *threadData;
SDL_GLContext glCtx;
@ -450,7 +454,7 @@ struct GraphicsPrivate {
glCtx(SDL_GL_GetCurrentContext()), frameRate(DEF_FRAMERATE),
frameCount(0), brightness(255), fpsLimiter(frameRate),
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>();
avgFPSLock = SDL_CreateMutex();
@ -547,7 +551,10 @@ struct GraphicsPrivate {
void metaBlitBufferFlippedScaled() {
GLMeta::blitRectangle(
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);
}
@ -589,7 +596,7 @@ struct GraphicsPrivate {
}
double averageFPS() {
double ret;
double ret = 0;
SDL_LockMutex(avgFPSLock);
for (unsigned long long times : avgFPSData)
ret += times;

View file

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

View file

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

View file

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

View file

@ -54,3 +54,8 @@ std::string systemImpl::getUserName() {
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);
}
int systemImpl::getScalingFactor() {
return NSApplication.sharedApplication.mainWindow.backingScaleFactor;
}
// constant, if it's not nil then just raise the menu instead
SettingsMenu *smenu = nil;