From 1e66a938687816031d8d9edad61a9dad10b8d60c Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 11 Mar 2023 22:53:55 +0800 Subject: [PATCH] Improve API GLViewImpl::createWithRect --- .../platform/android/CCGLViewImpl-android.cpp | 4 +- core/platform/android/CCGLViewImpl-android.h | 4 +- .../platform/desktop/CCGLViewImpl-desktop.cpp | 4 +- core/platform/desktop/CCGLViewImpl-desktop.h | 4 +- core/platform/winrt/CCGLViewImpl-winrt.cpp | 58 ++----------------- core/platform/winrt/CCGLViewImpl-winrt.h | 14 +---- core/platform/winrt/xaml/AxmolRenderer.cpp | 6 +- 7 files changed, 19 insertions(+), 75 deletions(-) diff --git a/core/platform/android/CCGLViewImpl-android.cpp b/core/platform/android/CCGLViewImpl-android.cpp index cb9eb2e57c..979f4a99a4 100644 --- a/core/platform/android/CCGLViewImpl-android.cpp +++ b/core/platform/android/CCGLViewImpl-android.cpp @@ -50,7 +50,7 @@ void initExtensions() NS_AX_BEGIN -GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName, Rect rect, float frameZoomFactor) +GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor) { auto ret = new GLViewImpl; if (ret && ret->initWithRect(viewName, rect, frameZoomFactor)) @@ -93,7 +93,7 @@ GLViewImpl::GLViewImpl() GLViewImpl::~GLViewImpl() {} -bool GLViewImpl::initWithRect(std::string_view viewName, Rect rect, float frameZoomFactor) +bool GLViewImpl::initWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor) { return true; } diff --git a/core/platform/android/CCGLViewImpl-android.h b/core/platform/android/CCGLViewImpl-android.h index 9fc1eb3be5..2e43e80bad 100644 --- a/core/platform/android/CCGLViewImpl-android.h +++ b/core/platform/android/CCGLViewImpl-android.h @@ -36,7 +36,7 @@ class AX_DLL GLViewImpl : public GLView public: // static function static GLViewImpl* create(std::string_view viewname); - static GLViewImpl* createWithRect(std::string_view viewName, Rect rect, float frameZoomFactor = 1.0f); + static GLViewImpl* createWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor = 1.0f); static GLViewImpl* createWithFullScreen(std::string_view viewName); bool isOpenGLReady() override; @@ -49,7 +49,7 @@ protected: GLViewImpl(); virtual ~GLViewImpl(); - bool initWithRect(std::string_view viewName, Rect rect, float frameZoomFactor); + bool initWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor); bool initWithFullScreen(std::string_view viewName); }; diff --git a/core/platform/desktop/CCGLViewImpl-desktop.cpp b/core/platform/desktop/CCGLViewImpl-desktop.cpp index 2415a9feb1..f012daa97a 100644 --- a/core/platform/desktop/CCGLViewImpl-desktop.cpp +++ b/core/platform/desktop/CCGLViewImpl-desktop.cpp @@ -389,7 +389,7 @@ GLViewImpl* GLViewImpl::create(std::string_view viewName, bool resizable) return nullptr; } -GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName, ax::Rect rect, float frameZoomFactor, bool resizable) +GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName, const ax::Rect& rect, float frameZoomFactor, bool resizable) { auto ret = new GLViewImpl; if (ret->initWithRect(viewName, rect, frameZoomFactor, resizable)) @@ -427,7 +427,7 @@ GLViewImpl* GLViewImpl::createWithFullScreen(std::string_view viewName, return nullptr; } -bool GLViewImpl::initWithRect(std::string_view viewName, ax::Rect rect, float frameZoomFactor, bool resizable) +bool GLViewImpl::initWithRect(std::string_view viewName, const ax::Rect& rect, float frameZoomFactor, bool resizable) { setViewName(viewName); diff --git a/core/platform/desktop/CCGLViewImpl-desktop.h b/core/platform/desktop/CCGLViewImpl-desktop.h index f9c8526701..e9fbdf36a3 100644 --- a/core/platform/desktop/CCGLViewImpl-desktop.h +++ b/core/platform/desktop/CCGLViewImpl-desktop.h @@ -41,7 +41,7 @@ public: static GLViewImpl* create(std::string_view viewName); static GLViewImpl* create(std::string_view viewName, bool resizable); static GLViewImpl* createWithRect(std::string_view viewName, - Rect size, + const Rect& size, float frameZoomFactor = 1.0f, bool resizable = false); static GLViewImpl* createWithFullScreen(std::string_view viewName); @@ -135,7 +135,7 @@ protected: GLViewImpl(bool initglfw = true); virtual ~GLViewImpl(); - bool initWithRect(std::string_view viewName, Rect rect, float frameZoomFactor, bool resizable); + bool initWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor, bool resizable); bool initWithFullScreen(std::string_view viewName); bool initWithFullscreen(std::string_view viewname, const GLFWvidmode& videoMode, GLFWmonitor* monitor); #if (AX_TARGET_PLATFORM != AX_PLATFORM_MAC) // Windows, Linux: use glad to loadGL diff --git a/core/platform/winrt/CCGLViewImpl-winrt.cpp b/core/platform/winrt/CCGLViewImpl-winrt.cpp index 08b58ff392..c0e840445c 100644 --- a/core/platform/winrt/CCGLViewImpl-winrt.cpp +++ b/core/platform/winrt/CCGLViewImpl-winrt.cpp @@ -74,17 +74,12 @@ GLViewImpl* GLViewImpl::create(std::string_view viewName) return nullptr; } -GLViewImpl* GLViewImpl::create(std::string_view viewName, - const Vec2& viewSize, - Windows::Graphics::Display::DisplayOrientations orientation, - float dpi) +GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName, + const Rect& rect, float frameZoomFactor) { auto ret = new GLViewImpl; - if (ret && ret->initWithFullScreen(viewName)) + if (ret && ret->initWithRect(viewName, rect, frameZoomFactor)) { - ret->m_orientation = orientation; - ret->m_dpi = dpi; - ret->UpdateForWindowSizeChange(viewSize.x, viewSize.y); ret->autorelease(); return ret; } @@ -125,11 +120,12 @@ GLViewImpl::~GLViewImpl() // TODO: cleanup } -bool GLViewImpl::initWithRect(std::string_view viewName, Rect rect, float frameZoomFactor) +bool GLViewImpl::initWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor) { setViewName(viewName); setFrameSize(rect.size.width, rect.size.height); setFrameZoomFactor(frameZoomFactor); + UpdateForWindowSizeChange(rect.size.width, rect.size.height); return true; } @@ -138,14 +134,6 @@ bool GLViewImpl::initWithFullScreen(std::string_view viewName) return initWithRect(viewName, Rect(0, 0, m_width, m_height), 1.0f); } -bool GLViewImpl::Create(float width, float height, float dpi, DisplayOrientations orientation) -{ - m_orientation = orientation; - m_dpi = dpi; - UpdateForWindowSizeChange(width, height); - return true; -} - void ax::GLViewImpl::setCursorVisible(bool isVisible) { _isCursorVisible = isVisible; @@ -509,23 +497,6 @@ void GLViewImpl::UpdateForWindowSizeChange(float width, float height) } } -#if 0 -win32 version - -void GLViewEventHandler::OnGLFWWindowSizeFunCallback(GLFWwindow *windows, int width, int height) -{ - auto view = Director::getInstance()->getOpenGLView(); - if(view && view->getResolutionPolicy() != ResolutionPolicy::UNKNOWN) - { - Size resSize=view->getDesignResolutionSize(); - ResolutionPolicy resPolicy=view->getResolutionPolicy(); - view->setFrameSize(width, height); - view->setDesignResolutionSize(resSize.width, resSize.height, resPolicy); - Director::getInstance()->setViewport(); - } -} -#endif - void GLViewImpl::UpdateWindowSize() { float width, height; @@ -561,25 +532,6 @@ ax::Vec2 GLViewImpl::TransformToOrientation(Windows::Foundation::Point p) float y = p.Y; returnValue = Vec2(x, y); -#if 0 - switch (m_orientation) - { - case DisplayOrientations::Portrait: - default: - returnValue = Vec2(x, y); - break; - case DisplayOrientations::Landscape: - returnValue = Vec2(y, m_width - x); - break; - case DisplayOrientations::PortraitFlipped: - returnValue = Vec2(m_width - x, m_height - y); - break; - case DisplayOrientations::LandscapeFlipped: - returnValue = Vec2(m_height - y, x); - break; - } -#endif - float zoomFactor = GLViewImpl::sharedOpenGLView()->getFrameZoomFactor(); if (zoomFactor > 0.0f) { diff --git a/core/platform/winrt/CCGLViewImpl-winrt.h b/core/platform/winrt/CCGLViewImpl-winrt.h index 8245dbaeb0..385cb3d83e 100644 --- a/core/platform/winrt/CCGLViewImpl-winrt.h +++ b/core/platform/winrt/CCGLViewImpl-winrt.h @@ -48,10 +48,7 @@ class AX_DLL GLViewImpl : public GLView { public: static GLViewImpl* create(std::string_view viewName); - static GLViewImpl* create(std::string_view viewName, - const Vec2& viewSize, - Windows::Graphics::Display::DisplayOrientations orientation, - float dpi); + static GLViewImpl* createWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor = 1.0f); /* override functions */ virtual bool isOpenGLReady(); @@ -64,11 +61,6 @@ public: virtual void setIMEKeyboardState(bool bOpen) override; virtual void setIMEKeyboardState(bool bOpen, std::string_view str); - virtual bool Create(float width, - float height, - float dpi, - Windows::Graphics::Display::DisplayOrientations orientation); - /** * Hide or Show the mouse cursor if there is one. * @@ -128,7 +120,6 @@ public: void SetDPI(float dpi) { m_dpi = dpi; } float GetDPI() { return m_dpi; } - // static function /** @brief get the shared main open gl window @@ -141,7 +132,7 @@ protected: GLViewImpl(); virtual ~GLViewImpl(); - bool initWithRect(std::string_view viewName, Rect rect, float frameZoomFactor); + bool initWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor); bool initWithFullScreen(std::string_view viewName); /* @@ -173,7 +164,6 @@ private: float m_width; float m_height; float m_dpi; - Windows::Graphics::Display::DisplayOrientations m_orientation; Windows::Foundation::Rect m_keyboardRect; diff --git a/core/platform/winrt/xaml/AxmolRenderer.cpp b/core/platform/winrt/xaml/AxmolRenderer.cpp index 2acdc890e8..5bb63dafae 100644 --- a/core/platform/winrt/xaml/AxmolRenderer.cpp +++ b/core/platform/winrt/xaml/AxmolRenderer.cpp @@ -59,8 +59,10 @@ void AxmolRenderer::Resume() if (!glview) { - GLViewImpl* glview = GLViewImpl::create( - "axmol", Vec2{static_cast(m_width), static_cast(m_height)}, m_orientation, m_dpi); + GLViewImpl* glview = GLViewImpl::createWithRect( + "AXMOL10", ax::Rect{0, 0, static_cast(m_width), static_cast(m_height)}); + glview->UpdateOrientation(m_orientation); + glview->SetDPI(m_dpi); glview->setDispatcher(m_dispatcher.Get()); glview->setPanel(m_panel.Get()); director->setOpenGLView(glview);