PlatformMacOS: Update layer scale on screen change

Qt seems to do this, and if you don't, MVK doesn't realize it needs to resize things
This commit is contained in:
TellowKrinkle 2023-06-25 20:08:43 -05:00 committed by BeezBumba
parent 7c685a863a
commit f545b49d12

View File

@ -21,6 +21,39 @@
#include <cstring>
#include <thread>
@class AppDelegate;
class PlatformMacOS : public Platform
{
public:
~PlatformMacOS() override;
bool Init() override;
void SetTitle(const std::string& title) override;
void MainLoop() override;
WindowSystemInfo GetWindowSystemInfo() const override;
NSWindow* Window() const { return m_window; }
private:
void ProcessEvents();
void UpdateWindowPosition();
void HandleSaveStates(NSUInteger key, NSUInteger flags);
void SetupMenu();
NSRect m_window_rect;
NSWindow* m_window;
NSMenu* menuBar;
AppDelegate* m_app_delegate;
int m_window_x = Config::Get(Config::MAIN_RENDER_WINDOW_XPOS);
int m_window_y = Config::Get(Config::MAIN_RENDER_WINDOW_YPOS);
unsigned int m_window_width = Config::Get(Config::MAIN_RENDER_WINDOW_WIDTH);
unsigned int m_window_height = Config::Get(Config::MAIN_RENDER_WINDOW_HEIGHT);
bool m_window_fullscreen = Config::Get(Config::MAIN_FULLSCREEN);
};
@interface Application : NSApplication
@property Platform* platform;
- (void)shutdown;
@ -82,7 +115,7 @@
@interface AppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate>
@property(readonly) Platform* platform;
@property(readonly) PlatformMacOS* platform;
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender;
- (id)initWithPlatform:(Platform*)platform;
@ -95,7 +128,7 @@
return YES;
}
- (id)initWithPlatform:(Platform*)platform
- (id)initWithPlatform:(PlatformMacOS*)platform
{
self = [super init];
if (self)
@ -115,42 +148,14 @@
- (void)windowDidChangeScreen:(NSNotification *)notification
{
if (NSWindow* window = _platform->Window())
if (CALayer* layer = [[window contentView] layer])
[layer setContentsScale:[window backingScaleFactor]];
[self windowDidResize:notification];
}
@end
namespace
{
class PlatformMacOS : public Platform
{
public:
~PlatformMacOS() override;
bool Init() override;
void SetTitle(const std::string& title) override;
void MainLoop() override;
WindowSystemInfo GetWindowSystemInfo() const override;
private:
void ProcessEvents();
void UpdateWindowPosition();
void HandleSaveStates(NSUInteger key, NSUInteger flags);
void SetupMenu();
NSRect m_window_rect;
NSWindow* m_window;
NSMenu* menuBar;
AppDelegate* m_app_delegate;
int m_window_x = Config::Get(Config::MAIN_RENDER_WINDOW_XPOS);
int m_window_y = Config::Get(Config::MAIN_RENDER_WINDOW_YPOS);
unsigned int m_window_width = Config::Get(Config::MAIN_RENDER_WINDOW_WIDTH);
unsigned int m_window_height = Config::Get(Config::MAIN_RENDER_WINDOW_HEIGHT);
bool m_window_fullscreen = Config::Get(Config::MAIN_FULLSCREEN);
};
PlatformMacOS::~PlatformMacOS()
{
[m_window close];
@ -425,8 +430,6 @@ void PlatformMacOS::SetupMenu()
}
}
} // namespace
std::unique_ptr<Platform> Platform::CreateMacOSPlatform()
{
return std::make_unique<PlatformMacOS>();