From f3991535133e30659a361402f7a19c8a8eb2ffec Mon Sep 17 00:00:00 2001 From: u0u0 Date: Thu, 18 Mar 2021 12:02:19 +0800 Subject: [PATCH] center the window on desktop. --- cocos/platform/desktop/CCGLViewImpl-desktop.cpp | 10 ++++++---- cocos/platform/mac/CCGLViewImpl-mac.mm | 10 +++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cocos/platform/desktop/CCGLViewImpl-desktop.cpp b/cocos/platform/desktop/CCGLViewImpl-desktop.cpp index fd65a79..aac0265 100644 --- a/cocos/platform/desktop/CCGLViewImpl-desktop.cpp +++ b/cocos/platform/desktop/CCGLViewImpl-desktop.cpp @@ -306,10 +306,8 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram int neededWidth = (int)(rect.size.width * _frameZoomFactor); int neededHeight = (int)(rect.size.height * _frameZoomFactor); - _mainWindow = glfwCreateWindow(neededWidth, neededHeight, _viewName.c_str(), _monitor, nullptr); - - if (_mainWindow == nullptr) - { + _mainWindow = glfwCreateWindow(neededWidth, neededHeight, _viewName.c_str(), nullptr, nullptr); + if (!_mainWindow) { std::string message = "Can't create window"; if (!_glfwError.empty()) { @@ -384,6 +382,10 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram // setViewPortInPoints(0, 0, neededWidth, neededHeight); // #endif + + // center the window + const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + glfwSetWindowPos(_mainWindow, (mode->width - realW) / 2, (mode->height - realH) / 2); return true; } diff --git a/cocos/platform/mac/CCGLViewImpl-mac.mm b/cocos/platform/mac/CCGLViewImpl-mac.mm index d67a986..495e1d0 100644 --- a/cocos/platform/mac/CCGLViewImpl-mac.mm +++ b/cocos/platform/mac/CCGLViewImpl-mac.mm @@ -305,10 +305,8 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram int neededWidth = rect.size.width * _frameZoomFactor; int neededHeight = rect.size.height * _frameZoomFactor; - _mainWindow = glfwCreateWindow(neededWidth, neededHeight, _viewName.c_str(), _monitor, nullptr); - - if (_mainWindow == nullptr) - { + _mainWindow = glfwCreateWindow(neededWidth, neededHeight, _viewName.c_str(), nullptr, nullptr); + if (!_mainWindow) { std::string message = "Can't create window"; if (!_glfwError.empty()) { @@ -378,7 +376,9 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram glfwSetWindowFocusCallback(_mainWindow, GLFWEventHandler::onGLFWWindowFocusCallback); setFrameSize(rect.size.width, rect.size.height); - + // center the window + const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + glfwSetWindowPos(_mainWindow, (mode->width - realW) / 2, (mode->height - realH) / 2); return true; }