This commit is contained in:
halx99 2023-03-11 23:14:04 +08:00
parent 2a86953e67
commit 418bef4bae
1 changed files with 9 additions and 6 deletions

View File

@ -433,6 +433,8 @@ bool GLViewImpl::initWithRect(std::string_view viewName, const ax::Rect& rect, f
_frameZoomFactor = frameZoomFactor; _frameZoomFactor = frameZoomFactor;
Vec2 frameSize = rect.size;
#if defined(AX_USE_GLES) #if defined(AX_USE_GLES)
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
@ -458,14 +460,15 @@ bool GLViewImpl::initWithRect(std::string_view viewName, const ax::Rect& rect, f
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
#endif #endif
int neededWidth = (int)(rect.size.width * _frameZoomFactor); int neededWidth = static_cast<int>(frameSize.width * _frameZoomFactor);
int neededHeight = (int)(rect.size.height * _frameZoomFactor); int neededHeight = static_cast<int>(frameSize.height * _frameZoomFactor);
#if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32) #if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32)
glfwxSetParent((HWND)_glContextAttrs.viewParent); glfwxSetParent((HWND)_glContextAttrs.viewParent);
#endif #endif
_mainWindow = glfwCreateWindow(neededWidth, neededHeight, _viewName.c_str(), _monitor, nullptr); _mainWindow = glfwCreateWindow(neededWidth, neededHeight, _viewName.c_str(),
_monitor, nullptr);
if (_mainWindow == nullptr) if (_mainWindow == nullptr)
{ {
@ -526,11 +529,11 @@ bool GLViewImpl::initWithRect(std::string_view viewName, const ax::Rect& rect, f
glfwGetWindowSize(_mainWindow, &realW, &realH); glfwGetWindowSize(_mainWindow, &realW, &realH);
if (realW != neededWidth) if (realW != neededWidth)
{ {
rect.size.width = realW / _frameZoomFactor; frameSize.width = realW / _frameZoomFactor;
} }
if (realH != neededHeight) if (realH != neededHeight)
{ {
rect.size.height = realH / _frameZoomFactor; frameSize.height = realH / _frameZoomFactor;
} }
glfwSetMouseButtonCallback(_mainWindow, GLFWEventHandler::onGLFWMouseCallBack); glfwSetMouseButtonCallback(_mainWindow, GLFWEventHandler::onGLFWMouseCallBack);
@ -543,7 +546,7 @@ bool GLViewImpl::initWithRect(std::string_view viewName, const ax::Rect& rect, f
glfwSetWindowIconifyCallback(_mainWindow, GLFWEventHandler::onGLFWWindowIconifyCallback); glfwSetWindowIconifyCallback(_mainWindow, GLFWEventHandler::onGLFWWindowIconifyCallback);
glfwSetWindowFocusCallback(_mainWindow, GLFWEventHandler::onGLFWWindowFocusCallback); glfwSetWindowFocusCallback(_mainWindow, GLFWEventHandler::onGLFWWindowFocusCallback);
setFrameSize(rect.size.width, rect.size.height); setFrameSize(frameSize.width, frameSize.height);
#if (AX_TARGET_PLATFORM != AX_PLATFORM_MAC) #if (AX_TARGET_PLATFORM != AX_PLATFORM_MAC)
loadGL(); loadGL();