Fixed buggy window resize in fullscreen
This commit is contained in:
parent
2f53489f2a
commit
b457f5fa6c
@ -55,6 +55,7 @@ namespace sf {
|
|||||||
NSWindow* m_window; ///< Underlying Cocoa window to be controlled
|
NSWindow* m_window; ///< Underlying Cocoa window to be controlled
|
||||||
SFOpenGLView* m_oglView; ///< OpenGL view for rendering
|
SFOpenGLView* m_oglView; ///< OpenGL view for rendering
|
||||||
sf::priv::WindowImplCocoa* m_requester; ///< Requester
|
sf::priv::WindowImplCocoa* m_requester; ///< Requester
|
||||||
|
BOOL m_fullscreen; ///< Indicate whether the window is fullscreen or not
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <SFML/Window/OSX/WindowImplCocoa.hpp>
|
#include <SFML/Window/OSX/WindowImplCocoa.hpp>
|
||||||
#include <SFML/System/Err.hpp>
|
#include <SFML/System/Err.hpp>
|
||||||
#include <ApplicationServices/ApplicationServices.h>
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#import <SFML/Window/OSX/Scaling.h>
|
#import <SFML/Window/OSX/Scaling.h>
|
||||||
#import <SFML/Window/OSX/SFApplication.h>
|
#import <SFML/Window/OSX/SFApplication.h>
|
||||||
@ -145,8 +146,9 @@
|
|||||||
m_window = nil;
|
m_window = nil;
|
||||||
m_oglView = nil;
|
m_oglView = nil;
|
||||||
m_requester = 0;
|
m_requester = 0;
|
||||||
|
m_fullscreen = (style & sf::Style::Fullscreen);
|
||||||
|
|
||||||
if (style & sf::Style::Fullscreen)
|
if (m_fullscreen)
|
||||||
[self setupFullscreenViewWithMode:mode];
|
[self setupFullscreenViewWithMode:mode];
|
||||||
else
|
else
|
||||||
[self setupWindowWithMode:mode andStyle:style];
|
[self setupWindowWithMode:mode andStyle:style];
|
||||||
@ -203,9 +205,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create our OpenGL view size and the view
|
// Create our OpenGL view size and the view
|
||||||
CGFloat x = (desktop.width - mode.width) / 2.0;
|
CGFloat width = std::min(mode.width, desktop.width);
|
||||||
CGFloat y = (desktop.height - mode.height) / 2.0;
|
CGFloat height = std::min(mode.height, desktop.height);
|
||||||
NSRect oglRect = NSMakeRect(x, y, mode.width, mode.height);
|
CGFloat x = (desktop.width - width) / 2.0;
|
||||||
|
CGFloat y = (desktop.height - height) / 2.0;
|
||||||
|
NSRect oglRect = NSMakeRect(x, y, width, height);
|
||||||
|
|
||||||
m_oglView = [[SFOpenGLView alloc] initWithFrame:oglRect
|
m_oglView = [[SFOpenGLView alloc] initWithFrame:oglRect
|
||||||
fullscreen:YES];
|
fullscreen:YES];
|
||||||
@ -387,6 +391,25 @@
|
|||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)resizeTo:(unsigned int)width by:(unsigned int)height
|
-(void)resizeTo:(unsigned int)width by:(unsigned int)height
|
||||||
{
|
{
|
||||||
|
if (m_fullscreen)
|
||||||
|
{
|
||||||
|
// Special case when fullscreen: only resize the opengl view
|
||||||
|
// and make sure the requested size is not bigger than the window.
|
||||||
|
sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
|
||||||
|
sf::priv::scaleInWidthHeight(desktop, nil);
|
||||||
|
|
||||||
|
width = std::min(width, desktop.width);
|
||||||
|
height = std::min(height, desktop.height);
|
||||||
|
|
||||||
|
CGFloat x = (desktop.width - width) / 2.0;
|
||||||
|
CGFloat y = (desktop.height - height) / 2.0;
|
||||||
|
NSRect oglRect = NSMakeRect(x, y, width, height);
|
||||||
|
|
||||||
|
[m_oglView setFrame:oglRect];
|
||||||
|
[m_oglView setNeedsDisplay:YES];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Before resizing, remove resizable mask to be able to resize
|
// Before resizing, remove resizable mask to be able to resize
|
||||||
// beyond the desktop boundaries.
|
// beyond the desktop boundaries.
|
||||||
NSUInteger styleMask = [m_window styleMask];
|
NSUInteger styleMask = [m_window styleMask];
|
||||||
@ -418,6 +441,7 @@
|
|||||||
|
|
||||||
// And restore the mask
|
// And restore the mask
|
||||||
[m_window setStyleMask:styleMask];
|
[m_window setStyleMask:styleMask];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user