mirror of https://github.com/axmolengine/axmol.git
Refactor full screen support, fix different behavior when enter full screen between 1 and >=2 times
This commit is contained in:
parent
8cc189fb4d
commit
106d8e2ecf
|
@ -545,7 +545,7 @@ void GLViewImpl::pollEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLViewImpl::enableRetina(bool enabled)
|
void GLViewImpl::enableRetina(bool enabled)
|
||||||
{
|
{ // official v4 comment follow sources
|
||||||
// #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
// #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||||
// _isRetinaEnabled = enabled;
|
// _isRetinaEnabled = enabled;
|
||||||
// if (_isRetinaEnabled)
|
// if (_isRetinaEnabled)
|
||||||
|
@ -673,6 +673,8 @@ void GLViewImpl::setFullscreen(int monitorIndex) {
|
||||||
void GLViewImpl::setFullscreen(const GLFWvidmode &videoMode, GLFWmonitor *monitor) {
|
void GLViewImpl::setFullscreen(const GLFWvidmode &videoMode, GLFWmonitor *monitor) {
|
||||||
_monitor = monitor;
|
_monitor = monitor;
|
||||||
glfwSetWindowMonitor(_mainWindow, _monitor, 0, 0, videoMode.width, videoMode.height, videoMode.refreshRate);
|
glfwSetWindowMonitor(_mainWindow, _monitor, 0, 0, videoMode.width, videoMode.height, videoMode.refreshRate);
|
||||||
|
|
||||||
|
updateWindowSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLViewImpl::setWindowed(int width, int height) {
|
void GLViewImpl::setWindowed(int width, int height) {
|
||||||
|
@ -690,9 +692,22 @@ void GLViewImpl::setWindowed(int width, int height) {
|
||||||
// on mac window will sometimes lose title when windowed
|
// on mac window will sometimes lose title when windowed
|
||||||
glfwSetWindowTitle(_mainWindow, _viewName.c_str());
|
glfwSetWindowTitle(_mainWindow, _viewName.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
updateWindowSize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLViewImpl::updateWindowSize()
|
||||||
|
{
|
||||||
|
int w = 0, h = 0;
|
||||||
|
glfwGetFramebufferSize(_mainWindow, &w, &h);
|
||||||
|
int frameWidth = w / _frameZoomFactor;
|
||||||
|
int frameHeight = h / _frameZoomFactor;
|
||||||
|
setFrameSize(frameWidth, frameHeight);
|
||||||
|
updateDesignResolutionSize();
|
||||||
|
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GLViewImpl::EVENT_WINDOW_RESIZED, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
int GLViewImpl::getMonitorCount() const {
|
int GLViewImpl::getMonitorCount() const {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
glfwGetMonitors(&count);
|
glfwGetMonitors(&count);
|
||||||
|
@ -726,21 +741,21 @@ void GLViewImpl::updateFrameSize()
|
||||||
int frameBufferW = 0, frameBufferH = 0;
|
int frameBufferW = 0, frameBufferH = 0;
|
||||||
glfwGetFramebufferSize(_mainWindow, &frameBufferW, &frameBufferH);
|
glfwGetFramebufferSize(_mainWindow, &frameBufferW, &frameBufferH);
|
||||||
|
|
||||||
// if (frameBufferW == 2 * w && frameBufferH == 2 * h)
|
if (frameBufferW == 2 * w && frameBufferH == 2 * h)
|
||||||
// {
|
{
|
||||||
// if (_isRetinaEnabled)
|
if (_isRetinaEnabled)
|
||||||
// {
|
{
|
||||||
// _retinaFactor = 1;
|
_retinaFactor = 1;
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// _retinaFactor = 2;
|
_retinaFactor = 2;
|
||||||
// }
|
}
|
||||||
// glfwSetWindowSize(_mainWindow, _screenSize.width/2 * _retinaFactor * _frameZoomFactor, _screenSize.height/2 * _retinaFactor * _frameZoomFactor);
|
glfwSetWindowSize(_mainWindow, _screenSize.width/2 * _retinaFactor * _frameZoomFactor, _screenSize.height/2 * _retinaFactor * _frameZoomFactor);
|
||||||
|
|
||||||
// _isInRetinaMonitor = true;
|
_isInRetinaMonitor = true;
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
{
|
{
|
||||||
if (_isInRetinaMonitor)
|
if (_isInRetinaMonitor)
|
||||||
{
|
{
|
||||||
|
@ -966,7 +981,7 @@ void GLViewImpl::onGLFWWindowPosCallback(GLFWwindow* /*window*/, int /*x*/, int
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLViewImpl::onGLFWFramebufferSizeCallback(GLFWwindow* window, int w, int h)
|
void GLViewImpl::onGLFWFramebufferSizeCallback(GLFWwindow* window, int w, int h)
|
||||||
{ // win32 glfw never invoke this callback
|
{ // win32 glfw same with onGLFWWindowSizeCallback
|
||||||
#if CC_TARGET_PLATFORM != CC_PLATFORM_WIN32
|
#if CC_TARGET_PLATFORM != CC_PLATFORM_WIN32
|
||||||
float frameSizeW = _screenSize.width;
|
float frameSizeW = _screenSize.width;
|
||||||
float frameSizeH = _screenSize.height;
|
float frameSizeH = _screenSize.height;
|
||||||
|
@ -1000,13 +1015,18 @@ void GLViewImpl::onGLFWWindowSizeCallback(GLFWwindow* /*window*/, int w, int h)
|
||||||
{
|
{
|
||||||
if (w && h && _resolutionPolicy != ResolutionPolicy::UNKNOWN)
|
if (w && h && _resolutionPolicy != ResolutionPolicy::UNKNOWN)
|
||||||
{
|
{
|
||||||
Size baseDesignSize = _designResolutionSize;
|
/*
|
||||||
ResolutionPolicy baseResolutionPolicy = _resolutionPolicy;
|
x-studio spec, fix view size incorrect when window size changed.
|
||||||
|
The original code behavior:
|
||||||
|
1. first time enter full screen: w,h=1920,1080
|
||||||
|
2. second or later enter full screen: will trigger 2 times WindowSizeCallback
|
||||||
|
1). w,h=976,679
|
||||||
|
2). w,h=1024,768
|
||||||
|
|
||||||
int frameWidth = w / _frameZoomFactor;
|
@remark: we should use glfwSetWindowMonitor to control the window size in full screen mode
|
||||||
int frameHeight = h / _frameZoomFactor;
|
@see also: updateWindowSize (call after enter/exit full screen mode)
|
||||||
setFrameSize(frameWidth, frameHeight);
|
*/
|
||||||
setDesignResolutionSize(baseDesignSize.width, baseDesignSize.height, baseResolutionPolicy);
|
updateDesignResolutionSize();
|
||||||
|
|
||||||
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GLViewImpl::EVENT_WINDOW_RESIZED, nullptr);
|
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GLViewImpl::EVENT_WINDOW_RESIZED, nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@ public:
|
||||||
void setFullscreen(int monitorIndex);
|
void setFullscreen(int monitorIndex);
|
||||||
void setFullscreen(const GLFWvidmode &videoMode, GLFWmonitor *monitor);
|
void setFullscreen(const GLFWvidmode &videoMode, GLFWmonitor *monitor);
|
||||||
void setWindowed(int width, int height);
|
void setWindowed(int width, int height);
|
||||||
|
|
||||||
int getMonitorCount() const;
|
int getMonitorCount() const;
|
||||||
Size getMonitorSize() const;
|
Size getMonitorSize() const;
|
||||||
|
|
||||||
|
@ -139,6 +140,9 @@ protected:
|
||||||
|
|
||||||
bool loadGL();
|
bool loadGL();
|
||||||
|
|
||||||
|
/* update frame layout when enter/exit full screen mode */
|
||||||
|
void updateWindowSize();
|
||||||
|
|
||||||
void updateFrameSize();
|
void updateFrameSize();
|
||||||
|
|
||||||
// GLFW callbacks
|
// GLFW callbacks
|
||||||
|
|
Loading…
Reference in New Issue