mirror of
https://github.com/u0u0/Cocos2d-Lua-Community.git
synced 2026-06-20 18:56:03 +08:00
center the window on desktop.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user