center the window on desktop.

This commit is contained in:
u0u0
2021-03-18 12:02:19 +08:00
parent 26cfe3eadb
commit f399153513
2 changed files with 11 additions and 9 deletions

View File

@@ -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;
}

View File

@@ -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;
}