mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Improve high DPI handling on macOS
This commit is contained in:
parent
600d0f3baf
commit
2888d9c56e
@ -78,6 +78,7 @@ namespace sf {
|
||||
BOOL m_cursorGrabbed; ///< Is the mouse cursor trapped?
|
||||
CGFloat m_deltaXBuffer; ///< See note about cursor grabbing above
|
||||
CGFloat m_deltaYBuffer; ///< See note about cursor grabbing above
|
||||
BOOL m_highDpi; ///< Is high-DPI enabled?
|
||||
|
||||
// Hidden text view used to convert key event to actual chars.
|
||||
// We use a silent responder to prevent sound alerts.
|
||||
@ -99,7 +100,7 @@ namespace sf {
|
||||
/// \return an initialized view
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(id)initWithFrame:(NSRect)frameRect fullscreen:(BOOL)isFullscreen;
|
||||
-(id)initWithFrame:(NSRect)frameRect fullscreen:(BOOL)isFullscreen highDpi:(BOOL)isHighDpi;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Finish the creation of the SFML OpenGL view
|
||||
|
@ -86,11 +86,17 @@
|
||||
////////////////////////////////////////////////////////
|
||||
-(id)initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
return [self initWithFrame:frameRect fullscreen:NO];
|
||||
return [self initWithFrame:frameRect fullscreen:NO highDpi:NO];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(id)initWithFrame:(NSRect)frameRect fullscreen:(BOOL)isFullscreen
|
||||
{
|
||||
return [self initWithFrame:frameRect fullscreen:isFullscreen highDpi:NO];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(id)initWithFrame:(NSRect)frameRect fullscreen:(BOOL)isFullscreen highDpi:(BOOL)isHighDpi
|
||||
{
|
||||
if ((self = [super initWithFrame:frameRect]))
|
||||
{
|
||||
@ -118,8 +124,12 @@
|
||||
m_hiddenTextView = [[NSTextView alloc] initWithFrame:NSZeroRect];
|
||||
[m_hiddenTextView setNextResponder:m_silentResponder];
|
||||
|
||||
// Request high resolution on high DPI displays
|
||||
[self setWantsBestResolutionOpenGLSurface:YES];
|
||||
// If high DPI is requested, then use high resolution for the OpenGL view.
|
||||
// Currently, isHighDpi is always expected to be NO, and so the OpenGL view will render scaled.
|
||||
// Note: setWantsBestResolutionOpenGLSurface requires YES to work properly, rather than simply non-zero value.
|
||||
// isHighDpi is an Objective-C BOOL, which can have non-zero values other than YES.
|
||||
m_highDpi = isHighDpi ? YES : NO;
|
||||
[self setWantsBestResolutionOpenGLSurface:m_highDpi];
|
||||
|
||||
// At that point, the view isn't attached to a window. We defer the rest of
|
||||
// the initialization process to later.
|
||||
@ -224,7 +234,7 @@
|
||||
NSWindow* window = [self window];
|
||||
NSScreen* screen = window ? [window screen] : [NSScreen mainScreen];
|
||||
CGFloat oldScaleFactor = m_scaleFactor;
|
||||
m_scaleFactor = [screen backingScaleFactor];
|
||||
m_scaleFactor = m_highDpi ? [screen backingScaleFactor] : 1.0;
|
||||
|
||||
// Send a resize event if the scaling factor changed
|
||||
if ((m_scaleFactor != oldScaleFactor) && (m_requester != 0)) {
|
||||
|
@ -62,6 +62,7 @@ namespace sf {
|
||||
sf::priv::WindowImplCocoa* m_requester; ///< Requester
|
||||
BOOL m_fullscreen; ///< Indicate whether the window is fullscreen or not
|
||||
BOOL m_restoreResize; ///< See note above
|
||||
BOOL m_highDpi; ///< Support high-DPI rendering or not
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -99,6 +99,7 @@
|
||||
m_requester = 0;
|
||||
m_fullscreen = NO; // assuming this is the case... too hard to handle anyway.
|
||||
m_restoreResize = NO;
|
||||
m_highDpi = NO;
|
||||
|
||||
// Retain the window for our own use.
|
||||
m_window = [window retain];
|
||||
@ -111,7 +112,8 @@
|
||||
|
||||
// Create the view.
|
||||
m_oglView = [[SFOpenGLView alloc] initWithFrame:[[m_window contentView] frame]
|
||||
fullscreen:NO];
|
||||
fullscreen:NO
|
||||
highDpi:NO];
|
||||
|
||||
if (m_oglView == nil)
|
||||
{
|
||||
@ -153,6 +155,7 @@
|
||||
m_requester = 0;
|
||||
m_fullscreen = (style & sf::Style::Fullscreen);
|
||||
m_restoreResize = NO;
|
||||
m_highDpi = NO;
|
||||
|
||||
if (m_fullscreen)
|
||||
[self setupFullscreenViewWithMode:mode];
|
||||
@ -218,7 +221,8 @@
|
||||
NSRect oglRect = NSMakeRect(x, y, width, height);
|
||||
|
||||
m_oglView = [[SFOpenGLView alloc] initWithFrame:oglRect
|
||||
fullscreen:YES];
|
||||
fullscreen:YES
|
||||
highDpi:m_highDpi];
|
||||
|
||||
if (m_oglView == nil)
|
||||
{
|
||||
@ -277,7 +281,8 @@
|
||||
|
||||
// Create the view.
|
||||
m_oglView = [[SFOpenGLView alloc] initWithFrame:[[m_window contentView] frame]
|
||||
fullscreen:NO];
|
||||
fullscreen:NO
|
||||
highDpi:m_highDpi];
|
||||
|
||||
if (m_oglView == nil)
|
||||
{
|
||||
|
@ -130,9 +130,6 @@ m_showCursor(true)
|
||||
// Transform the app process.
|
||||
setUpProcess();
|
||||
|
||||
// Use backing size
|
||||
scaleInWidthHeight(mode, nil);
|
||||
|
||||
m_delegate = [[SFWindowController alloc] initWithMode:mode andStyle:style];
|
||||
[m_delegate changeTitle:sfStringToNSString(title)];
|
||||
[m_delegate setRequesterTo:this];
|
||||
@ -544,4 +541,3 @@ bool WindowImplCocoa::hasFocus() const
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user